Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.84.6.2
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.84.6. (raeburn 4:): # $Id: domainprefs.pm,v 1.160.6.84.6.1 2020/04/06 21:56:01 raeburn Exp $
1.160.6.40 raeburn 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.160.6.78 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
30: ##############################################################
31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.160.6.13 raeburn 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.160.6.27 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20 raeburn 98: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 99: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 100:
1.101 raeburn 101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.160.6.30 raeburn 107: (official, unofficial, community, and textbook). In each case the radio buttons
108: allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.160.6.37 raeburn 168: use Apache::lonuserutils();
1.160.6.39 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.9 raeburn 173: use File::Copy;
1.43 raeburn 174: use Locale::Language;
1.62 raeburn 175: use DateTime::TimeZone;
1.68 raeburn 176: use DateTime::Locale;
1.1 raeburn 177:
1.155 raeburn 178: my $registered_cleanup;
179: my $modified_urls;
180:
1.1 raeburn 181: sub handler {
182: my $r=shift;
183: if ($r->header_only) {
184: &Apache::loncommon::content_type($r,'text/html');
185: $r->send_http_header;
186: return OK;
187: }
188:
1.91 raeburn 189: my $context = 'domain';
1.1 raeburn 190: my $dom = $env{'request.role.domain'};
1.5 albertel 191: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 192: if (&Apache::lonnet::allowed('mau',$dom)) {
193: &Apache::loncommon::content_type($r,'text/html');
194: $r->send_http_header;
195: } else {
196: $env{'user.error.msg'}=
197: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
198: return HTTP_NOT_ACCEPTABLE;
199: }
1.155 raeburn 200:
201: $registered_cleanup=0;
202: @{$modified_urls}=();
203:
1.1 raeburn 204: &Apache::lonhtmlcommon::clear_breadcrumbs();
205: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 206: ['phase','actions']);
1.30 raeburn 207: my $phase = 'pickactions';
1.3 raeburn 208: if ( exists($env{'form.phase'}) ) {
209: $phase = $env{'form.phase'};
210: }
1.150 raeburn 211: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 212: my %domconfig =
1.6 raeburn 213: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 214: 'quotas','autoenroll','autoupdate','autocreate',
215: 'directorysrch','usercreation','usermodification',
216: 'contacts','defaults','scantron','coursecategories',
1.160.6.73 raeburn 217: 'serverstatuses','requestcourses','helpsettings',
218: 'coursedefaults','usersessions','loadbalancing',
1.160.6.84.6. (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.6. (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.6. (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.6. (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.160.6.84.6. (raeburn 706:): } elsif ($action eq 'ltitools') {
707:): $output .= <itools_javascript($settings);
1.91 raeburn 708: }
1.160.6.40 raeburn 709: $output .=
1.30 raeburn 710: '<table class="LC_nested_outer">
1.3 raeburn 711: <tr>
1.66 raeburn 712: <th align="left" valign="middle"><span class="LC_nobreak">'.
713: &mt($item->{text}).' '.
714: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
715: '</tr>';
1.30 raeburn 716: $rowtotal ++;
1.110 raeburn 717: my $numheaders = 1;
718: if (ref($item->{'header'}) eq 'ARRAY') {
719: $numheaders = scalar(@{$item->{'header'}});
720: }
721: if ($numheaders > 1) {
1.64 raeburn 722: my $colspan = '';
1.145 raeburn 723: my $rightcolspan = '';
1.160.6.42 raeburn 724: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 725: ($action eq 'directorysrch') ||
1.160.6.56 raeburn 726: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 727: $colspan = ' colspan="2"';
728: }
1.145 raeburn 729: if ($action eq 'usersessions') {
730: $rightcolspan = ' colspan="3"';
731: }
1.30 raeburn 732: $output .= '
1.3 raeburn 733: <tr>
734: <td>
735: <table class="LC_nested">
736: <tr class="LC_info_row">
1.59 bisitz 737: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 738: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 739: </tr>';
1.69 raeburn 740: $rowtotal ++;
1.160.6.37 raeburn 741: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 742: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 743: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.78 raeburn 744: ($action eq 'helpsettings') || ($action eq 'contacts')) {
1.160.6.37 raeburn 745: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 746: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 747: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 748: } elsif ($action eq 'login') {
1.160.6.56 raeburn 749: if ($numheaders == 4) {
1.160.6.5 raeburn 750: $colspan = ' colspan="2"';
751: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
752: } else {
753: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
754: }
1.160.6.37 raeburn 755: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 756: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 757: } elsif ($action eq 'rolecolors') {
1.30 raeburn 758: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 759: }
1.30 raeburn 760: $output .= '
1.6 raeburn 761: </table>
762: </td>
763: </tr>
764: <tr>
765: <td>
766: <table class="LC_nested">
767: <tr class="LC_info_row">
1.160.6.37 raeburn 768: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 769: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 770: </tr>';
771: $rowtotal ++;
1.160.6.37 raeburn 772: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
773: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 774: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.80 raeburn 775: ($action eq 'contacts') || ($action eq 'defaults')) {
1.160.6.42 raeburn 776: if ($action eq 'coursecategories') {
777: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
778: $colspan = ' colspan="2"';
779: } else {
780: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
781: }
782: $output .= '
1.63 raeburn 783: </table>
784: </td>
785: </tr>
786: <tr>
787: <td>
788: <table class="LC_nested">
789: <tr class="LC_info_row">
790: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 791: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 792: </tr>'."\n";
793: if ($action eq 'coursecategories') {
794: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
795: } else {
796: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
797: }
1.63 raeburn 798: $rowtotal ++;
1.160.6.57 raeburn 799: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 800: ($action eq 'defaults') || ($action eq 'directorysrch') ||
801: ($action eq 'helpsettings')) {
1.160.6.37 raeburn 802: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 803: } elsif ($action eq 'login') {
1.160.6.56 raeburn 804: if ($numheaders == 4) {
1.160.6.5 raeburn 805: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
806: </table>
807: </td>
808: </tr>
809: <tr>
810: <td>
811: <table class="LC_nested">
812: <tr class="LC_info_row">
813: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 814: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 815: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
816: $rowtotal ++;
817: } else {
818: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
819: }
1.160.6.56 raeburn 820: $output .= '
821: </table>
822: </td>
823: </tr>
824: <tr>
825: <td>
826: <table class="LC_nested">
827: <tr class="LC_info_row">';
828: if ($numheaders == 4) {
829: $output .= '
830: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
831: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
832: </tr>';
833: } else {
834: $output .= '
835: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
836: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
837: </tr>';
838: }
839: $rowtotal ++;
840: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 841: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 842: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
843: $rowtotal ++;
844: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 845: </table>
846: </td>
847: </tr>
848: <tr>
849: <td>
850: <table class="LC_nested">
851: <tr class="LC_info_row">
852: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
853: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 854: &textbookcourses_javascript($settings).
855: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
856: </table>
857: </td>
858: </tr>
859: <tr>
860: <td>
861: <table class="LC_nested">
862: <tr class="LC_info_row">
863: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
864: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
865: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 866: </table>
867: </td>
868: </tr>
869: <tr>
870: <td>
871: <table class="LC_nested">
872: <tr class="LC_info_row">
1.160.6.46 raeburn 873: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
874: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 875: </tr>'.
876: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 877: } elsif ($action eq 'requestauthor') {
878: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 879: $rowtotal ++;
1.122 jms 880: } elsif ($action eq 'rolecolors') {
1.30 raeburn 881: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 882: </table>
883: </td>
884: </tr>
885: <tr>
886: <td>
887: <table class="LC_nested">
888: <tr class="LC_info_row">
1.69 raeburn 889: <td class="LC_left_item"'.$colspan.' valign="top">'.
890: &mt($item->{'header'}->[2]->{'col1'}).'</td>
891: <td class="LC_right_item" valign="top">'.
892: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 893: </tr>'.
1.30 raeburn 894: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 895: </table>
896: </td>
897: </tr>
898: <tr>
899: <td>
900: <table class="LC_nested">
901: <tr class="LC_info_row">
1.59 bisitz 902: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
903: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 904: </tr>'.
1.30 raeburn 905: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
906: $rowtotal += 2;
1.6 raeburn 907: }
1.3 raeburn 908: } else {
1.30 raeburn 909: $output .= '
1.3 raeburn 910: <tr>
911: <td>
912: <table class="LC_nested">
1.30 raeburn 913: <tr class="LC_info_row">';
1.160.6.72 raeburn 914: if ($action eq 'login') {
1.30 raeburn 915: $output .= '
1.59 bisitz 916: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 917: } elsif ($action eq 'serverstatuses') {
918: $output .= '
919: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
920: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
921:
1.6 raeburn 922: } else {
1.30 raeburn 923: $output .= '
1.69 raeburn 924: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
925: }
1.72 raeburn 926: if (defined($item->{'header'}->[0]->{'col3'})) {
927: $output .= '<td class="LC_left_item" valign="top">'.
928: &mt($item->{'header'}->[0]->{'col2'});
929: if ($action eq 'serverstatuses') {
930: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
931: }
1.69 raeburn 932: } else {
933: $output .= '<td class="LC_right_item" valign="top">'.
934: &mt($item->{'header'}->[0]->{'col2'});
935: }
936: $output .= '</td>';
937: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 938: if (defined($item->{'header'}->[0]->{'col4'})) {
939: $output .= '<td class="LC_left_item" valign="top">'.
940: &mt($item->{'header'}->[0]->{'col3'});
941: } else {
942: $output .= '<td class="LC_right_item" valign="top">'.
943: &mt($item->{'header'}->[0]->{'col3'});
944: }
1.69 raeburn 945: if ($action eq 'serverstatuses') {
946: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
947: }
948: $output .= '</td>';
1.6 raeburn 949: }
1.150 raeburn 950: if ($item->{'header'}->[0]->{'col4'}) {
951: $output .= '<td class="LC_right_item" valign="top">'.
952: &mt($item->{'header'}->[0]->{'col4'});
953: }
1.69 raeburn 954: $output .= '</tr>';
1.48 raeburn 955: $rowtotal ++;
1.160.6.5 raeburn 956: if ($action eq 'quotas') {
1.86 raeburn 957: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 958: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.84.6. (raeburn 959:): ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
960:): ($action eq 'ltitools')) {
1.160.6.37 raeburn 961: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 962: } elsif ($action eq 'scantron') {
963: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 964: }
1.3 raeburn 965: }
1.30 raeburn 966: $output .= '
1.3 raeburn 967: </table>
968: </td>
969: </tr>
1.30 raeburn 970: </table><br />';
971: return ($output,$rowtotal);
1.1 raeburn 972: }
973:
1.3 raeburn 974: sub print_login {
1.160.6.5 raeburn 975: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 976: my ($css_class,$datatable);
1.6 raeburn 977: my %choices = &login_choices();
1.110 raeburn 978:
1.160.6.5 raeburn 979: if ($caller eq 'service') {
1.149 raeburn 980: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 981: my $choice = $choices{'disallowlogin'};
982: $css_class = ' class="LC_odd_row"';
1.128 raeburn 983: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 984: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 985: '<th>'.$choices{'server'}.'</th>'.
986: '<th>'.$choices{'serverpath'}.'</th>'.
987: '<th>'.$choices{'custompath'}.'</th>'.
988: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 989: my %disallowed;
990: if (ref($settings) eq 'HASH') {
991: if (ref($settings->{'loginvia'}) eq 'HASH') {
992: %disallowed = %{$settings->{'loginvia'}};
993: }
994: }
995: foreach my $lonhost (sort(keys(%servers))) {
996: my $direct = 'selected="selected"';
1.128 raeburn 997: if (ref($disallowed{$lonhost}) eq 'HASH') {
998: if ($disallowed{$lonhost}{'server'} ne '') {
999: $direct = '';
1000: }
1.110 raeburn 1001: }
1.115 raeburn 1002: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1003: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1004: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1005: '</option>';
1.160.6.13 raeburn 1006: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1007: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1008: my $selected = '';
1.128 raeburn 1009: if (ref($disallowed{$lonhost}) eq 'HASH') {
1010: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1011: $selected = 'selected="selected"';
1012: }
1.110 raeburn 1013: }
1014: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1015: $servers{$hostid}.'</option>';
1016: }
1.128 raeburn 1017: $datatable .= '</select></td>'.
1018: '<td><select name="'.$lonhost.'_serverpath">';
1019: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1020: my $pathname = $path;
1021: if ($path eq 'custom') {
1022: $pathname = &mt('Custom Path').' ->';
1023: }
1024: my $selected = '';
1025: if (ref($disallowed{$lonhost}) eq 'HASH') {
1026: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1027: $selected = 'selected="selected"';
1028: }
1029: } elsif ($path eq '') {
1030: $selected = 'selected="selected"';
1031: }
1032: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1033: }
1034: $datatable .= '</select></td>';
1035: my ($custom,$exempt);
1036: if (ref($disallowed{$lonhost}) eq 'HASH') {
1037: $custom = $disallowed{$lonhost}{'custompath'};
1038: $exempt = $disallowed{$lonhost}{'exempt'};
1039: }
1040: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1041: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1042: '</tr>';
1.110 raeburn 1043: }
1044: $datatable .= '</table></td></tr>';
1045: return $datatable;
1.160.6.5 raeburn 1046: } elsif ($caller eq 'page') {
1047: my %defaultchecked = (
1048: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1049: 'helpdesk' => 'on',
1.160.6.5 raeburn 1050: 'adminmail' => 'off',
1051: 'newuser' => 'off',
1052: );
1.160.6.14 raeburn 1053: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1054: my (%checkedon,%checkedoff);
1.42 raeburn 1055: foreach my $item (@toggles) {
1.160.6.5 raeburn 1056: if ($defaultchecked{$item} eq 'on') {
1057: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1058: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1059: } elsif ($defaultchecked{$item} eq 'off') {
1060: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1061: $checkedon{$item} = ' ';
1062: }
1.1 raeburn 1063: }
1.160.6.5 raeburn 1064: my @images = ('img','logo','domlogo','login');
1065: my @logintext = ('textcol','bgcol');
1066: my @bgs = ('pgbg','mainbg','sidebg');
1067: my @links = ('link','alink','vlink');
1068: my %designhash = &Apache::loncommon::get_domainconf($dom);
1069: my %defaultdesign = %Apache::loncommon::defaultdesign;
1070: my (%is_custom,%designs);
1071: my %defaults = (
1072: font => $defaultdesign{'login.font'},
1073: );
1.6 raeburn 1074: foreach my $item (@images) {
1.160.6.5 raeburn 1075: $defaults{$item} = $defaultdesign{'login.'.$item};
1076: $defaults{'showlogo'}{$item} = 1;
1077: }
1078: foreach my $item (@bgs) {
1079: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1080: }
1.41 raeburn 1081: foreach my $item (@logintext) {
1.160.6.5 raeburn 1082: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1083: }
1.160.6.5 raeburn 1084: foreach my $item (@links) {
1085: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1086: }
1.160.6.5 raeburn 1087: if (ref($settings) eq 'HASH') {
1088: foreach my $item (@toggles) {
1089: if ($settings->{$item} eq '1') {
1090: $checkedon{$item} = ' checked="checked" ';
1091: $checkedoff{$item} = ' ';
1092: } elsif ($settings->{$item} eq '0') {
1093: $checkedoff{$item} = ' checked="checked" ';
1094: $checkedon{$item} = ' ';
1095: }
1.6 raeburn 1096: }
1.160.6.5 raeburn 1097: foreach my $item (@images) {
1098: if (defined($settings->{$item})) {
1099: $designs{$item} = $settings->{$item};
1100: $is_custom{$item} = 1;
1101: }
1102: if (defined($settings->{'showlogo'}{$item})) {
1103: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1104: }
1105: }
1106: foreach my $item (@logintext) {
1107: if ($settings->{$item} ne '') {
1108: $designs{'logintext'}{$item} = $settings->{$item};
1109: $is_custom{$item} = 1;
1110: }
1111: }
1112: if ($settings->{'font'} ne '') {
1113: $designs{'font'} = $settings->{'font'};
1114: $is_custom{'font'} = 1;
1115: }
1116: foreach my $item (@bgs) {
1117: if ($settings->{$item} ne '') {
1118: $designs{'bgs'}{$item} = $settings->{$item};
1119: $is_custom{$item} = 1;
1120: }
1121: }
1122: foreach my $item (@links) {
1123: if ($settings->{$item} ne '') {
1124: $designs{'links'}{$item} = $settings->{$item};
1125: $is_custom{$item} = 1;
1126: }
1127: }
1128: } else {
1129: if ($designhash{$dom.'.login.font'} ne '') {
1130: $designs{'font'} = $designhash{$dom.'.login.font'};
1131: $is_custom{'font'} = 1;
1132: }
1133: foreach my $item (@images) {
1134: if ($designhash{$dom.'.login.'.$item} ne '') {
1135: $designs{$item} = $designhash{$dom.'.login.'.$item};
1136: $is_custom{$item} = 1;
1137: }
1138: }
1139: foreach my $item (@bgs) {
1140: if ($designhash{$dom.'.login.'.$item} ne '') {
1141: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1142: $is_custom{$item} = 1;
1143: }
1144: }
1145: foreach my $item (@links) {
1146: if ($designhash{$dom.'.login.'.$item} ne '') {
1147: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1148: $is_custom{$item} = 1;
1149: }
1.6 raeburn 1150: }
1151: }
1.160.6.5 raeburn 1152: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1153: logo => 'Institution Logo',
1154: domlogo => 'Domain Logo',
1155: login => 'Login box');
1156: my $itemcount = 1;
1157: foreach my $item (@toggles) {
1158: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1159: $datatable .=
1160: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1161: '</td><td>'.
1162: '<span class="LC_nobreak"><label><input type="radio" name="'.
1163: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1164: '</label> <label><input type="radio" name="'.$item.'"'.
1165: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1166: '</tr>';
1167: $itemcount ++;
1.6 raeburn 1168: }
1.160.6.5 raeburn 1169: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1170: $datatable .= '</tr></table></td></tr>';
1171: } elsif ($caller eq 'help') {
1172: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1173: my $switchserver = &check_switchserver($dom,$confname);
1174: my $itemcount = 1;
1175: $defaulturl = '/adm/loginproblems.html';
1176: $defaulttype = 'default';
1177: %lt = &Apache::lonlocal::texthash (
1178: del => 'Delete?',
1179: rep => 'Replace:',
1180: upl => 'Upload:',
1181: default => 'Default',
1182: custom => 'Custom',
1183: );
1184: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1185: my @currlangs;
1186: if (ref($settings) eq 'HASH') {
1187: if (ref($settings->{'helpurl'}) eq 'HASH') {
1188: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1189: next if ($settings->{'helpurl'}{$key} eq '');
1190: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1191: $type{$key} = 'custom';
1192: unless ($key eq 'nolang') {
1193: push(@currlangs,$key);
1194: }
1195: }
1196: } elsif ($settings->{'helpurl'} ne '') {
1197: $type{'nolang'} = 'custom';
1198: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1199: }
1200: }
1.160.6.5 raeburn 1201: foreach my $lang ('nolang',sort(@currlangs)) {
1202: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1203: $datatable .= '<tr'.$css_class.'>';
1204: if ($url{$lang} eq '') {
1205: $url{$lang} = $defaulturl;
1206: }
1207: if ($type{$lang} eq '') {
1208: $type{$lang} = $defaulttype;
1209: }
1210: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1211: if ($lang eq 'nolang') {
1212: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1213: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1214: } else {
1215: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1216: $langchoices{$lang},
1217: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1218: }
1219: $datatable .= '</span></td>'."\n".
1220: '<td class="LC_left_item">';
1221: if ($type{$lang} eq 'custom') {
1222: $datatable .= '<span class="LC_nobreak"><label>'.
1223: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1224: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1225: } else {
1226: $datatable .= $lt{'upl'};
1227: }
1228: $datatable .='<br />';
1229: if ($switchserver) {
1230: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1231: } else {
1232: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1233: }
1.160.6.5 raeburn 1234: $datatable .= '</td></tr>';
1235: $itemcount ++;
1.6 raeburn 1236: }
1.160.6.5 raeburn 1237: my @addlangs;
1238: foreach my $lang (sort(keys(%langchoices))) {
1239: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1240: push(@addlangs,$lang);
1241: }
1242: if (@addlangs > 0) {
1243: my %toadd;
1244: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1245: $toadd{''} = &mt('Select');
1246: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1247: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1248: &mt('Add log-in help page for a specific language:').' '.
1249: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1250: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1251: if ($switchserver) {
1252: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1253: } else {
1254: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1255: }
1.160.6.5 raeburn 1256: $datatable .= '</td></tr>';
1257: $itemcount ++;
1.6 raeburn 1258: }
1.160.6.5 raeburn 1259: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1260: } elsif ($caller eq 'headtag') {
1261: my %domservers = &Apache::lonnet::get_servers($dom);
1262: my $choice = $choices{'headtag'};
1263: $css_class = ' class="LC_odd_row"';
1264: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1265: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1266: '<th>'.$choices{'current'}.'</th>'.
1267: '<th>'.$choices{'action'}.'</th>'.
1268: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1269: my (%currurls,%currexempt);
1270: if (ref($settings) eq 'HASH') {
1271: if (ref($settings->{'headtag'}) eq 'HASH') {
1272: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1273: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1274: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1275: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1276: }
1277: }
1278: }
1279: }
1280: my %lt = &Apache::lonlocal::texthash(
1281: del => 'Delete?',
1282: rep => 'Replace:',
1283: upl => 'Upload:',
1284: curr => 'View contents',
1285: none => 'None',
1286: );
1287: my $switchserver = &check_switchserver($dom,$confname);
1288: foreach my $lonhost (sort(keys(%domservers))) {
1289: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1290: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1291: if ($currurls{$lonhost}) {
1292: $datatable .= '<td class="LC_right_item"><a href="'.
1293: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1294: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1295: '">'.$lt{'curr'}.'</a></td>'.
1296: '<td><span class="LC_nobreak"><label>'.
1297: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1298: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1299: } else {
1300: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1301: }
1302: $datatable .='<br />';
1303: if ($switchserver) {
1304: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1305: } else {
1306: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1307: }
1308: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1309: }
1310: $datatable .= '</table></td></tr>';
1.1 raeburn 1311: }
1.6 raeburn 1312: return $datatable;
1313: }
1314:
1315: sub login_choices {
1316: my %choices =
1317: &Apache::lonlocal::texthash (
1.116 bisitz 1318: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1319: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1320: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1321: disallowlogin => "Login page requests redirected",
1322: hostid => "Server",
1.128 raeburn 1323: server => "Redirect to:",
1324: serverpath => "Path",
1325: custompath => "Custom",
1326: exempt => "Exempt IP(s)",
1.110 raeburn 1327: directlogin => "No redirect",
1328: newuser => "Link to create a user account",
1329: img => "Header",
1330: logo => "Main Logo",
1331: domlogo => "Domain Logo",
1332: login => "Log-in Header",
1333: textcol => "Text color",
1334: bgcol => "Box color",
1335: bgs => "Background colors",
1336: links => "Link colors",
1337: font => "Font color",
1338: pgbg => "Header",
1339: mainbg => "Page",
1340: sidebg => "Login box",
1341: link => "Link",
1342: alink => "Active link",
1343: vlink => "Visited link",
1.160.6.56 raeburn 1344: headtag => "Custom markup",
1345: action => "Action",
1346: current => "Current",
1.6 raeburn 1347: );
1348: return %choices;
1349: }
1350:
1351: sub print_rolecolors {
1.30 raeburn 1352: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1353: my %choices = &color_font_choices();
1354: my @bgs = ('pgbg','tabbg','sidebg');
1355: my @links = ('link','alink','vlink');
1356: my @images = ('img');
1357: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1358: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1359: my %defaultdesign = %Apache::loncommon::defaultdesign;
1360: my (%is_custom,%designs);
1.160.6.22 raeburn 1361: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1362: if (ref($settings) eq 'HASH') {
1363: if (ref($settings->{$role}) eq 'HASH') {
1364: if ($settings->{$role}->{'img'} ne '') {
1365: $designs{'img'} = $settings->{$role}->{'img'};
1366: $is_custom{'img'} = 1;
1367: }
1368: if ($settings->{$role}->{'font'} ne '') {
1369: $designs{'font'} = $settings->{$role}->{'font'};
1370: $is_custom{'font'} = 1;
1371: }
1.97 tempelho 1372: if ($settings->{$role}->{'fontmenu'} ne '') {
1373: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1374: $is_custom{'fontmenu'} = 1;
1375: }
1.6 raeburn 1376: foreach my $item (@bgs) {
1377: if ($settings->{$role}->{$item} ne '') {
1378: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1379: $is_custom{$item} = 1;
1380: }
1381: }
1382: foreach my $item (@links) {
1383: if ($settings->{$role}->{$item} ne '') {
1384: $designs{'links'}{$item} = $settings->{$role}->{$item};
1385: $is_custom{$item} = 1;
1386: }
1387: }
1388: }
1389: } else {
1390: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1391: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1392: $is_custom{'img'} = 1;
1393: }
1.97 tempelho 1394: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1395: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1396: $is_custom{'fontmenu'} = 1;
1397: }
1.6 raeburn 1398: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1399: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1400: $is_custom{'font'} = 1;
1401: }
1402: foreach my $item (@bgs) {
1403: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1404: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1405: $is_custom{$item} = 1;
1406:
1407: }
1408: }
1409: foreach my $item (@links) {
1410: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1411: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1412: $is_custom{$item} = 1;
1413: }
1414: }
1415: }
1416: my $itemcount = 1;
1.30 raeburn 1417: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1418: $datatable .= '</tr></table></td></tr>';
1419: return $datatable;
1420: }
1421:
1.160.6.22 raeburn 1422: sub role_defaults {
1423: my ($role,$bgs,$links,$images,$logintext) = @_;
1424: my %defaults;
1425: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1426: return %defaults;
1427: }
1428: my %defaultdesign = %Apache::loncommon::defaultdesign;
1429: if ($role eq 'login') {
1430: %defaults = (
1431: font => $defaultdesign{$role.'.font'},
1432: );
1433: if (ref($logintext) eq 'ARRAY') {
1434: foreach my $item (@{$logintext}) {
1435: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1436: }
1437: }
1438: foreach my $item (@{$images}) {
1439: $defaults{'showlogo'}{$item} = 1;
1440: }
1441: } else {
1442: %defaults = (
1443: img => $defaultdesign{$role.'.img'},
1444: font => $defaultdesign{$role.'.font'},
1445: fontmenu => $defaultdesign{$role.'.fontmenu'},
1446: );
1447: }
1448: foreach my $item (@{$bgs}) {
1449: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1450: }
1451: foreach my $item (@{$links}) {
1452: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1453: }
1454: foreach my $item (@{$images}) {
1455: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1456: }
1457: return %defaults;
1458: }
1459:
1.6 raeburn 1460: sub display_color_options {
1.9 raeburn 1461: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1462: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1463: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1464: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1465: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1466: '<td>'.$choices->{'font'}.'</td>';
1467: if (!$is_custom->{'font'}) {
1.30 raeburn 1468: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1469: } else {
1470: $datatable .= '<td> </td>';
1471: }
1.160.6.9 raeburn 1472: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1473:
1.8 raeburn 1474: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1475: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1476: ' value="'.$current_color.'" /> '.
1477: ' </td></tr>';
1.107 raeburn 1478: unless ($role eq 'login') {
1479: $datatable .= '<tr'.$css_class.'>'.
1480: '<td>'.$choices->{'fontmenu'}.'</td>';
1481: if (!$is_custom->{'fontmenu'}) {
1482: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1483: } else {
1484: $datatable .= '<td> </td>';
1485: }
1.160.6.22 raeburn 1486: $current_color = $designs->{'fontmenu'} ?
1487: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1488: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1489: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1490: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1491: ' value="'.$current_color.'" /> '.
1492: ' </td></tr>';
1.97 tempelho 1493: }
1.9 raeburn 1494: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1495: foreach my $img (@{$images}) {
1.18 albertel 1496: $itemcount ++;
1.6 raeburn 1497: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1498: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1499: '<td>'.$choices->{$img};
1.41 raeburn 1500: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1501: if ($role eq 'login') {
1502: if ($img eq 'login') {
1503: $login_hdr_pick =
1.135 bisitz 1504: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1505: $logincolors =
1506: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1507: $designs,$defaults);
1.70 raeburn 1508: } elsif ($img ne 'domlogo') {
1509: $datatable.= &logo_display_options($img,$defaults,$designs);
1510: }
1511: }
1512: $datatable .= '</td>';
1.6 raeburn 1513: if ($designs->{$img} ne '') {
1514: $imgfile = $designs->{$img};
1.18 albertel 1515: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1516: } else {
1517: $imgfile = $defaults->{$img};
1518: }
1519: if ($imgfile) {
1.9 raeburn 1520: my ($showfile,$fullsize);
1521: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1522: my $urldir = $1;
1523: my $filename = $2;
1524: my @info = &Apache::lonnet::stat_file($designs->{$img});
1525: if (@info) {
1526: my $thumbfile = 'tn-'.$filename;
1527: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1528: if (@thumb) {
1529: $showfile = $urldir.'/'.$thumbfile;
1530: } else {
1531: $showfile = $imgfile;
1532: }
1533: } else {
1534: $showfile = '';
1535: }
1536: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1537: $showfile = $imgfile;
1.6 raeburn 1538: my $imgdir = $1;
1539: my $filename = $2;
1.159 raeburn 1540: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1541: $showfile = "/$imgdir/tn-".$filename;
1542: } else {
1.159 raeburn 1543: my $input = $londocroot.$imgfile;
1544: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1545: if (!-e $output) {
1.9 raeburn 1546: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1547: my ($fullwidth,$fullheight) = &check_dimensions($input);
1548: if ($fullwidth ne '' && $fullheight ne '') {
1549: if ($fullwidth > $width && $fullheight > $height) {
1550: my $size = $width.'x'.$height;
1551: system("convert -sample $size $input $output");
1.159 raeburn 1552: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1553: }
1554: }
1.6 raeburn 1555: }
1556: }
1.16 raeburn 1557: }
1.6 raeburn 1558: if ($showfile) {
1.40 raeburn 1559: if ($showfile =~ m{^/(adm|res)/}) {
1560: if ($showfile =~ m{^/res/}) {
1561: my $local_showfile =
1562: &Apache::lonnet::filelocation('',$showfile);
1563: &Apache::lonnet::repcopy($local_showfile);
1564: }
1565: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1566: }
1567: if ($imgfile) {
1568: if ($imgfile =~ m{^/(adm|res)/}) {
1569: if ($imgfile =~ m{^/res/}) {
1570: my $local_imgfile =
1571: &Apache::lonnet::filelocation('',$imgfile);
1572: &Apache::lonnet::repcopy($local_imgfile);
1573: }
1574: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1575: } else {
1576: $fullsize = $imgfile;
1577: }
1578: }
1.41 raeburn 1579: $datatable .= '<td>';
1580: if ($img eq 'login') {
1.135 bisitz 1581: $datatable .= $login_hdr_pick;
1582: }
1.41 raeburn 1583: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1584: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1585: } else {
1.160.6.22 raeburn 1586: $datatable .= '<td> </td><td class="LC_left_item">'.
1587: &mt('Upload:').'<br />';
1.6 raeburn 1588: }
1589: } else {
1.160.6.22 raeburn 1590: $datatable .= '<td> </td><td class="LC_left_item">'.
1591: &mt('Upload:').'<br />';
1.6 raeburn 1592: }
1.9 raeburn 1593: if ($switchserver) {
1594: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1595: } else {
1.135 bisitz 1596: if ($img ne 'login') { # suppress file selection for Log-in header
1597: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1598: }
1.9 raeburn 1599: }
1600: $datatable .= '</td></tr>';
1.6 raeburn 1601: }
1602: $itemcount ++;
1603: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1604: $datatable .= '<tr'.$css_class.'>'.
1605: '<td>'.$choices->{'bgs'}.'</td>';
1606: my $bgs_def;
1607: foreach my $item (@{$bgs}) {
1608: if (!$is_custom->{$item}) {
1.70 raeburn 1609: $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 1610: }
1611: }
1612: if ($bgs_def) {
1.8 raeburn 1613: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1614: } else {
1615: $datatable .= '<td> </td>';
1616: }
1617: $datatable .= '<td class="LC_right_item">'.
1618: '<table border="0"><tr>';
1.160.6.13 raeburn 1619:
1.6 raeburn 1620: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1621: $datatable .= '<td align="center">'.$choices->{$item};
1622: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1623: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1624: $datatable .= ' ';
1.6 raeburn 1625: }
1.160.6.9 raeburn 1626: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1627: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1628: }
1629: $datatable .= '</tr></table></td></tr>';
1630: $itemcount ++;
1631: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1632: $datatable .= '<tr'.$css_class.'>'.
1633: '<td>'.$choices->{'links'}.'</td>';
1634: my $links_def;
1635: foreach my $item (@{$links}) {
1636: if (!$is_custom->{$item}) {
1.30 raeburn 1637: $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 1638: }
1639: }
1640: if ($links_def) {
1.8 raeburn 1641: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1642: } else {
1643: $datatable .= '<td> </td>';
1644: }
1645: $datatable .= '<td class="LC_right_item">'.
1646: '<table border="0"><tr>';
1647: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1648: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1649: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1650: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1651: $datatable.=' ';
1.6 raeburn 1652: }
1.160.6.9 raeburn 1653: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1654: '" /></td>';
1655: }
1.30 raeburn 1656: $$rowtotal += $itemcount;
1.3 raeburn 1657: return $datatable;
1658: }
1659:
1.70 raeburn 1660: sub logo_display_options {
1661: my ($img,$defaults,$designs) = @_;
1662: my $checkedon;
1663: if (ref($defaults) eq 'HASH') {
1664: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1665: if ($defaults->{'showlogo'}{$img}) {
1666: $checkedon = 'checked="checked" ';
1667: }
1668: }
1669: }
1670: if (ref($designs) eq 'HASH') {
1671: if (ref($designs->{'showlogo'}) eq 'HASH') {
1672: if (defined($designs->{'showlogo'}{$img})) {
1673: if ($designs->{'showlogo'}{$img} == 0) {
1674: $checkedon = '';
1675: } elsif ($designs->{'showlogo'}{$img} == 1) {
1676: $checkedon = 'checked="checked" ';
1677: }
1678: }
1679: }
1680: }
1681: return '<br /><label> <input type="checkbox" name="'.
1682: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1683: &mt('show').'</label>'."\n";
1684: }
1685:
1.41 raeburn 1686: sub login_header_options {
1.135 bisitz 1687: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1688: my $output = '';
1.41 raeburn 1689: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1690: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1691: if (!$is_custom->{'textcol'}) {
1692: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1693: ' ';
1694: }
1695: if (!$is_custom->{'bgcol'}) {
1696: $output .= $choices->{'bgcol'}.': '.
1697: '<span id="css_'.$role.'_font" style="background-color: '.
1698: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1699: }
1700: $output .= '<br />';
1701: }
1702: $output .='<br />';
1703: return $output;
1704: }
1705:
1706: sub login_text_colors {
1.160.6.22 raeburn 1707: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1708: my $color_menu = '<table border="0"><tr>';
1709: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1710: $color_menu .= '<td align="center">'.$choices->{$item};
1711: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1712: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1713: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1714: }
1715: $color_menu .= '</tr></table><br />';
1716: return $color_menu;
1717: }
1718:
1719: sub image_changes {
1720: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1721: my $output;
1.135 bisitz 1722: if ($img eq 'login') {
1723: # suppress image for Log-in header
1724: } elsif (!$is_custom) {
1.70 raeburn 1725: if ($img ne 'domlogo') {
1.41 raeburn 1726: $output .= &mt('Default image:').'<br />';
1727: } else {
1728: $output .= &mt('Default in use:').'<br />';
1729: }
1730: }
1.135 bisitz 1731: if ($img eq 'login') { # suppress image for Log-in header
1732: $output .= '<td>'.$logincolors;
1.41 raeburn 1733: } else {
1.135 bisitz 1734: if ($img_import) {
1735: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1736: }
1737: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1738: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1739: if ($is_custom) {
1740: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1741: '<input type="checkbox" name="'.
1742: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1743: '</label> '.&mt('Replace:').'</span><br />';
1744: } else {
1.160.6.22 raeburn 1745: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1746: }
1.41 raeburn 1747: }
1748: return $output;
1749: }
1750:
1.3 raeburn 1751: sub print_quotas {
1.86 raeburn 1752: my ($dom,$settings,$rowtotal,$action) = @_;
1753: my $context;
1754: if ($action eq 'quotas') {
1755: $context = 'tools';
1756: } else {
1757: $context = $action;
1758: }
1.160.6.20 raeburn 1759: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1760: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1761: my $typecount = 0;
1.101 raeburn 1762: my ($css_class,%titles);
1.86 raeburn 1763: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1764: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1765: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1766: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1767: %titles = &courserequest_titles();
1.160.6.5 raeburn 1768: } elsif ($context eq 'requestauthor') {
1769: @usertools = ('author');
1770: @options = ('norequest','approval','automatic');
1771: %titles = &authorrequest_titles();
1.86 raeburn 1772: } else {
1.160.6.4 raeburn 1773: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1774: %titles = &tool_titles();
1.86 raeburn 1775: }
1.26 raeburn 1776: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1777: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1778: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1779: unless (($context eq 'requestcourses') ||
1780: ($context eq 'requestauthor')) {
1.86 raeburn 1781: if (ref($settings) eq 'HASH') {
1782: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1783: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1784: } else {
1785: $currdefquota = $settings->{$type};
1786: }
1.160.6.20 raeburn 1787: if (ref($settings->{authorquota}) eq 'HASH') {
1788: $currauthorquota = $settings->{authorquota}->{$type};
1789: }
1.78 raeburn 1790: }
1.72 raeburn 1791: }
1.3 raeburn 1792: if (defined($usertypes->{$type})) {
1793: $typecount ++;
1794: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1795: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1796: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1797: '<td class="LC_left_item">';
1.101 raeburn 1798: if ($context eq 'requestcourses') {
1799: $datatable .= '<table><tr>';
1800: }
1801: my %cell;
1.72 raeburn 1802: foreach my $item (@usertools) {
1.101 raeburn 1803: if ($context eq 'requestcourses') {
1804: my ($curroption,$currlimit);
1805: if (ref($settings) eq 'HASH') {
1806: if (ref($settings->{$item}) eq 'HASH') {
1807: $curroption = $settings->{$item}->{$type};
1808: if ($curroption =~ /^autolimit=(\d*)$/) {
1809: $currlimit = $1;
1810: }
1811: }
1812: }
1813: if (!$curroption) {
1814: $curroption = 'norequest';
1815: }
1816: $datatable .= '<th>'.$titles{$item}.'</th>';
1817: foreach my $option (@options) {
1818: my $val = $option;
1819: if ($option eq 'norequest') {
1820: $val = 0;
1821: }
1822: if ($option eq 'validate') {
1823: my $canvalidate = 0;
1824: if (ref($validations{$item}) eq 'HASH') {
1825: if ($validations{$item}{$type}) {
1826: $canvalidate = 1;
1827: }
1828: }
1829: next if (!$canvalidate);
1830: }
1831: my $checked = '';
1832: if ($option eq $curroption) {
1833: $checked = ' checked="checked"';
1834: } elsif ($option eq 'autolimit') {
1835: if ($curroption =~ /^autolimit/) {
1836: $checked = ' checked="checked"';
1837: }
1838: }
1839: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1840: '<input type="radio" name="crsreq_'.$item.
1841: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1842: $titles{$option}.'</label>';
1.101 raeburn 1843: if ($option eq 'autolimit') {
1.127 raeburn 1844: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1845: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1846: 'value="'.$currlimit.'" />';
1.101 raeburn 1847: }
1.127 raeburn 1848: $cell{$item} .= '</span> ';
1.103 raeburn 1849: if ($option eq 'autolimit') {
1.127 raeburn 1850: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1851: }
1.101 raeburn 1852: }
1.160.6.5 raeburn 1853: } elsif ($context eq 'requestauthor') {
1854: my $curroption;
1855: if (ref($settings) eq 'HASH') {
1856: $curroption = $settings->{$type};
1857: }
1858: if (!$curroption) {
1859: $curroption = 'norequest';
1860: }
1861: foreach my $option (@options) {
1862: my $val = $option;
1863: if ($option eq 'norequest') {
1864: $val = 0;
1865: }
1866: my $checked = '';
1867: if ($option eq $curroption) {
1868: $checked = ' checked="checked"';
1869: }
1870: $datatable .= '<span class="LC_nobreak"><label>'.
1871: '<input type="radio" name="authorreq_'.$type.
1872: '" value="'.$val.'"'.$checked.' />'.
1873: $titles{$option}.'</label></span> ';
1874: }
1.101 raeburn 1875: } else {
1876: my $checked = 'checked="checked" ';
1877: if (ref($settings) eq 'HASH') {
1878: if (ref($settings->{$item}) eq 'HASH') {
1879: if ($settings->{$item}->{$type} == 0) {
1880: $checked = '';
1881: } elsif ($settings->{$item}->{$type} == 1) {
1882: $checked = 'checked="checked" ';
1883: }
1.78 raeburn 1884: }
1.72 raeburn 1885: }
1.101 raeburn 1886: $datatable .= '<span class="LC_nobreak"><label>'.
1887: '<input type="checkbox" name="'.$context.'_'.$item.
1888: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1889: '</label></span> ';
1.72 raeburn 1890: }
1.101 raeburn 1891: }
1892: if ($context eq 'requestcourses') {
1893: $datatable .= '</tr><tr>';
1894: foreach my $item (@usertools) {
1.106 raeburn 1895: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1896: }
1897: $datatable .= '</tr></table>';
1.72 raeburn 1898: }
1.86 raeburn 1899: $datatable .= '</td>';
1.160.6.5 raeburn 1900: unless (($context eq 'requestcourses') ||
1901: ($context eq 'requestauthor')) {
1.86 raeburn 1902: $datatable .=
1.160.6.20 raeburn 1903: '<td class="LC_right_item">'.
1904: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1905: '<input type="text" name="quota_'.$type.
1.72 raeburn 1906: '" value="'.$currdefquota.
1.160.6.20 raeburn 1907: '" size="5" /></span>'.(' ' x 2).
1908: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1909: '<input type="text" name="authorquota_'.$type.
1910: '" value="'.$currauthorquota.
1911: '" size="5" /></span></td>';
1.86 raeburn 1912: }
1913: $datatable .= '</tr>';
1.3 raeburn 1914: }
1915: }
1916: }
1.160.6.5 raeburn 1917: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1918: $defaultquota = '20';
1.160.6.20 raeburn 1919: $authorquota = '500';
1.86 raeburn 1920: if (ref($settings) eq 'HASH') {
1921: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1922: $defaultquota = $settings->{'defaultquota'}->{'default'};
1923: } elsif (defined($settings->{'default'})) {
1924: $defaultquota = $settings->{'default'};
1925: }
1.160.6.20 raeburn 1926: if (ref($settings->{'authorquota'}) eq 'HASH') {
1927: $authorquota = $settings->{'authorquota'}->{'default'};
1928: }
1.3 raeburn 1929: }
1930: }
1931: $typecount ++;
1932: $css_class = $typecount%2?' class="LC_odd_row"':'';
1933: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1934: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1935: '<td class="LC_left_item">';
1.101 raeburn 1936: if ($context eq 'requestcourses') {
1937: $datatable .= '<table><tr>';
1938: }
1939: my %defcell;
1.72 raeburn 1940: foreach my $item (@usertools) {
1.101 raeburn 1941: if ($context eq 'requestcourses') {
1942: my ($curroption,$currlimit);
1943: if (ref($settings) eq 'HASH') {
1944: if (ref($settings->{$item}) eq 'HASH') {
1945: $curroption = $settings->{$item}->{'default'};
1946: if ($curroption =~ /^autolimit=(\d*)$/) {
1947: $currlimit = $1;
1948: }
1949: }
1950: }
1951: if (!$curroption) {
1952: $curroption = 'norequest';
1953: }
1954: $datatable .= '<th>'.$titles{$item}.'</th>';
1955: foreach my $option (@options) {
1956: my $val = $option;
1957: if ($option eq 'norequest') {
1958: $val = 0;
1959: }
1960: if ($option eq 'validate') {
1961: my $canvalidate = 0;
1962: if (ref($validations{$item}) eq 'HASH') {
1963: if ($validations{$item}{'default'}) {
1964: $canvalidate = 1;
1965: }
1966: }
1967: next if (!$canvalidate);
1968: }
1969: my $checked = '';
1970: if ($option eq $curroption) {
1971: $checked = ' checked="checked"';
1972: } elsif ($option eq 'autolimit') {
1973: if ($curroption =~ /^autolimit/) {
1974: $checked = ' checked="checked"';
1975: }
1976: }
1977: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1978: '<input type="radio" name="crsreq_'.$item.
1979: '_default" value="'.$val.'"'.$checked.' />'.
1980: $titles{$option}.'</label>';
1981: if ($option eq 'autolimit') {
1.127 raeburn 1982: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1983: $item.'_limit_default" size="1" '.
1984: 'value="'.$currlimit.'" />';
1985: }
1.127 raeburn 1986: $defcell{$item} .= '</span> ';
1.104 raeburn 1987: if ($option eq 'autolimit') {
1.127 raeburn 1988: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1989: }
1.101 raeburn 1990: }
1.160.6.5 raeburn 1991: } elsif ($context eq 'requestauthor') {
1992: my $curroption;
1993: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1994: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1995: }
1996: if (!$curroption) {
1997: $curroption = 'norequest';
1998: }
1999: foreach my $option (@options) {
2000: my $val = $option;
2001: if ($option eq 'norequest') {
2002: $val = 0;
2003: }
2004: my $checked = '';
2005: if ($option eq $curroption) {
2006: $checked = ' checked="checked"';
2007: }
2008: $datatable .= '<span class="LC_nobreak"><label>'.
2009: '<input type="radio" name="authorreq_default"'.
2010: ' value="'.$val.'"'.$checked.' />'.
2011: $titles{$option}.'</label></span> ';
2012: }
1.101 raeburn 2013: } else {
2014: my $checked = 'checked="checked" ';
2015: if (ref($settings) eq 'HASH') {
2016: if (ref($settings->{$item}) eq 'HASH') {
2017: if ($settings->{$item}->{'default'} == 0) {
2018: $checked = '';
2019: } elsif ($settings->{$item}->{'default'} == 1) {
2020: $checked = 'checked="checked" ';
2021: }
1.78 raeburn 2022: }
1.72 raeburn 2023: }
1.101 raeburn 2024: $datatable .= '<span class="LC_nobreak"><label>'.
2025: '<input type="checkbox" name="'.$context.'_'.$item.
2026: '" value="default" '.$checked.'/>'.$titles{$item}.
2027: '</label></span> ';
2028: }
2029: }
2030: if ($context eq 'requestcourses') {
2031: $datatable .= '</tr><tr>';
2032: foreach my $item (@usertools) {
1.106 raeburn 2033: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2034: }
1.101 raeburn 2035: $datatable .= '</tr></table>';
1.72 raeburn 2036: }
1.86 raeburn 2037: $datatable .= '</td>';
1.160.6.5 raeburn 2038: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2039: $datatable .= '<td class="LC_right_item">'.
2040: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2041: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2042: $defaultquota.'" size="5" /></span>'.(' ' x2).
2043: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2044: '<input type="text" name="authorquota" value="'.
2045: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2046: }
2047: $datatable .= '</tr>';
1.72 raeburn 2048: $typecount ++;
2049: $css_class = $typecount%2?' class="LC_odd_row"':'';
2050: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2051: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2052: if ($context eq 'requestcourses') {
1.109 raeburn 2053: $datatable .= &mt('(overrides affiliation, if set)').
2054: '</td>'.
2055: '<td class="LC_left_item">'.
2056: '<table><tr>';
1.101 raeburn 2057: } else {
1.109 raeburn 2058: $datatable .= &mt('(overrides affiliation, if checked)').
2059: '</td>'.
2060: '<td class="LC_left_item" colspan="2">'.
2061: '<br />';
1.101 raeburn 2062: }
2063: my %advcell;
1.72 raeburn 2064: foreach my $item (@usertools) {
1.101 raeburn 2065: if ($context eq 'requestcourses') {
2066: my ($curroption,$currlimit);
2067: if (ref($settings) eq 'HASH') {
2068: if (ref($settings->{$item}) eq 'HASH') {
2069: $curroption = $settings->{$item}->{'_LC_adv'};
2070: if ($curroption =~ /^autolimit=(\d*)$/) {
2071: $currlimit = $1;
2072: }
2073: }
2074: }
2075: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2076: my $checked = '';
2077: if ($curroption eq '') {
2078: $checked = ' checked="checked"';
2079: }
2080: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2081: '<input type="radio" name="crsreq_'.$item.
2082: '__LC_adv" value=""'.$checked.' />'.
2083: &mt('No override set').'</label></span> ';
1.101 raeburn 2084: foreach my $option (@options) {
2085: my $val = $option;
2086: if ($option eq 'norequest') {
2087: $val = 0;
2088: }
2089: if ($option eq 'validate') {
2090: my $canvalidate = 0;
2091: if (ref($validations{$item}) eq 'HASH') {
2092: if ($validations{$item}{'_LC_adv'}) {
2093: $canvalidate = 1;
2094: }
2095: }
2096: next if (!$canvalidate);
2097: }
2098: my $checked = '';
1.104 raeburn 2099: if ($val eq $curroption) {
1.101 raeburn 2100: $checked = ' checked="checked"';
2101: } elsif ($option eq 'autolimit') {
2102: if ($curroption =~ /^autolimit/) {
2103: $checked = ' checked="checked"';
2104: }
2105: }
2106: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2107: '<input type="radio" name="crsreq_'.$item.
2108: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2109: $titles{$option}.'</label>';
2110: if ($option eq 'autolimit') {
1.127 raeburn 2111: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2112: $item.'_limit__LC_adv" size="1" '.
2113: 'value="'.$currlimit.'" />';
2114: }
1.127 raeburn 2115: $advcell{$item} .= '</span> ';
1.104 raeburn 2116: if ($option eq 'autolimit') {
1.127 raeburn 2117: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2118: }
1.101 raeburn 2119: }
1.160.6.5 raeburn 2120: } elsif ($context eq 'requestauthor') {
2121: my $curroption;
2122: if (ref($settings) eq 'HASH') {
2123: $curroption = $settings->{'_LC_adv'};
2124: }
2125: my $checked = '';
2126: if ($curroption eq '') {
2127: $checked = ' checked="checked"';
2128: }
2129: $datatable .= '<span class="LC_nobreak"><label>'.
2130: '<input type="radio" name="authorreq__LC_adv"'.
2131: ' value=""'.$checked.' />'.
2132: &mt('No override set').'</label></span> ';
2133: foreach my $option (@options) {
2134: my $val = $option;
2135: if ($option eq 'norequest') {
2136: $val = 0;
2137: }
2138: my $checked = '';
2139: if ($val eq $curroption) {
2140: $checked = ' checked="checked"';
2141: }
2142: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2143: '<input type="radio" name="authorreq__LC_adv"'.
2144: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2145: $titles{$option}.'</label></span> ';
2146: }
1.101 raeburn 2147: } else {
2148: my $checked = 'checked="checked" ';
2149: if (ref($settings) eq 'HASH') {
2150: if (ref($settings->{$item}) eq 'HASH') {
2151: if ($settings->{$item}->{'_LC_adv'} == 0) {
2152: $checked = '';
2153: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2154: $checked = 'checked="checked" ';
2155: }
1.79 raeburn 2156: }
1.72 raeburn 2157: }
1.101 raeburn 2158: $datatable .= '<span class="LC_nobreak"><label>'.
2159: '<input type="checkbox" name="'.$context.'_'.$item.
2160: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2161: '</label></span> ';
2162: }
2163: }
2164: if ($context eq 'requestcourses') {
2165: $datatable .= '</tr><tr>';
2166: foreach my $item (@usertools) {
1.106 raeburn 2167: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2168: }
1.101 raeburn 2169: $datatable .= '</tr></table>';
1.72 raeburn 2170: }
1.98 raeburn 2171: $datatable .= '</td></tr>';
1.30 raeburn 2172: $$rowtotal += $typecount;
1.3 raeburn 2173: return $datatable;
2174: }
2175:
1.160.6.5 raeburn 2176: sub print_requestmail {
2177: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2178: my ($now,$datatable,%currapp);
1.102 raeburn 2179: $now = time;
2180: if (ref($settings) eq 'HASH') {
2181: if (ref($settings->{'notify'}) eq 'HASH') {
2182: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2183: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2184: }
2185: }
2186: }
1.160.6.16 raeburn 2187: my $numinrow = 2;
1.160.6.34 raeburn 2188: my $css_class;
2189: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2190: my $text;
2191: if ($action eq 'requestcourses') {
2192: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2193: } elsif ($action eq 'requestauthor') {
2194: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2195: } else {
1.160.6.34 raeburn 2196: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2197: }
1.160.6.34 raeburn 2198: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2199: ' <td>'.$text.'</td>'.
1.102 raeburn 2200: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2201: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2202: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2203: if ($numdc > 0) {
2204: $datatable .= $table;
1.102 raeburn 2205: } else {
2206: $datatable .= &mt('There are no active Domain Coordinators');
2207: }
2208: $datatable .='</td></tr>';
2209: return $datatable;
2210: }
2211:
1.160.6.30 raeburn 2212: sub print_studentcode {
2213: my ($settings,$rowtotal) = @_;
2214: my $rownum = 0;
2215: my ($output,%current);
2216: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2217: if (ref($settings) eq 'HASH') {
2218: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2219: foreach my $type (@crstypes) {
2220: $current{$type} = $settings->{'uniquecode'}{$type};
2221: }
1.160.6.30 raeburn 2222: }
2223: }
2224: $output .= '<tr>'.
2225: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2226: '<td class="LC_left_item">';
2227: foreach my $type (@crstypes) {
2228: my $check = ' ';
2229: if ($current{$type}) {
2230: $check = ' checked="checked" ';
2231: }
2232: $output .= '<span class="LC_nobreak"><label>'.
2233: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2234: &mt($type).'</label></span>'.(' 'x2).' ';
2235: }
2236: $output .= '</td></tr>';
2237: $$rowtotal ++;
2238: return $output;
2239: }
2240:
2241: sub print_textbookcourses {
1.160.6.46 raeburn 2242: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2243: my $rownum = 0;
2244: my $css_class;
2245: my $itemcount = 1;
2246: my $maxnum = 0;
2247: my $bookshash;
2248: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2249: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2250: }
2251: my %ordered;
2252: if (ref($bookshash) eq 'HASH') {
2253: foreach my $item (keys(%{$bookshash})) {
2254: if (ref($bookshash->{$item}) eq 'HASH') {
2255: my $num = $bookshash->{$item}{'order'};
2256: $ordered{$num} = $item;
2257: }
2258: }
2259: }
2260: my $confname = $dom.'-domainconfig';
2261: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2262: my $maxnum = scalar(keys(%ordered));
2263: my $datatable;
1.160.6.30 raeburn 2264: if (keys(%ordered)) {
2265: my @items = sort { $a <=> $b } keys(%ordered);
2266: for (my $i=0; $i<@items; $i++) {
2267: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2268: my $key = $ordered{$items[$i]};
2269: my %coursehash=&Apache::lonnet::coursedescription($key);
2270: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2271: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2272: if (ref($bookshash->{$key}) eq 'HASH') {
2273: $subject = $bookshash->{$key}->{'subject'};
2274: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2275: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2276: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2277: $author = $bookshash->{$key}->{'author'};
2278: $image = $bookshash->{$key}->{'image'};
2279: if ($image ne '') {
2280: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2281: my $imagethumb = "$path/tn-".$imagefile;
2282: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2283: }
1.160.6.30 raeburn 2284: }
2285: }
1.160.6.46 raeburn 2286: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2287: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2288: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2289: for (my $k=0; $k<=$maxnum; $k++) {
2290: my $vpos = $k+1;
2291: my $selstr;
2292: if ($k == $i) {
2293: $selstr = ' selected="selected" ';
2294: }
2295: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2296: }
2297: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2298: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2299: &mt('Delete?').'</label></span></td>'.
2300: '<td colspan="2">'.
1.160.6.46 raeburn 2301: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2302: (' 'x2).
1.160.6.46 raeburn 2303: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2304: if ($type eq 'textbooks') {
2305: $datatable .= (' 'x2).
1.160.6.47 raeburn 2306: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2307: (' 'x2).
1.160.6.46 raeburn 2308: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2309: (' 'x2).
2310: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2311: if ($image) {
2312: $datatable .= '<span class="LC_nobreak">'.
2313: $imgsrc.
2314: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2315: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2316: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2317: }
2318: if ($switchserver) {
2319: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2320: } else {
2321: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2322: }
1.160.6.30 raeburn 2323: }
1.160.6.46 raeburn 2324: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2325: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2326: $coursetitle.'</span></td></tr>'."\n";
2327: $itemcount ++;
2328: }
2329: }
2330: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2331: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2332: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2333: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2334: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2335: for (my $k=0; $k<$maxnum+1; $k++) {
2336: my $vpos = $k+1;
2337: my $selstr;
2338: if ($k == $maxnum) {
2339: $selstr = ' selected="selected" ';
2340: }
2341: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2342: }
2343: $datatable .= '</select> '."\n".
1.160.6.46 raeburn 2344: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.160.6.30 raeburn 2345: '<td colspan="2">'.
1.160.6.46 raeburn 2346: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2347: (' 'x2).
1.160.6.46 raeburn 2348: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2349: (' 'x2);
2350: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2351: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2352: (' 'x2).
2353: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2354: (' 'x2).
2355: '<span class="LC_nobreak">'.&mt('Image:').' ';
2356: if ($switchserver) {
2357: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2358: } else {
2359: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2360: }
1.160.6.30 raeburn 2361: }
2362: $datatable .= '</span>'."\n".
2363: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2364: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2365: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2366: &Apache::loncommon::selectcourse_link
1.160.6.46 raeburn 2367: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.160.6.30 raeburn 2368: '</span></td>'."\n".
2369: '</tr>'."\n";
2370: $itemcount ++;
2371: return $datatable;
2372: }
2373:
2374: sub textbookcourses_javascript {
1.160.6.46 raeburn 2375: my ($settings) = @_;
2376: return unless(ref($settings) eq 'HASH');
2377: my (%ordered,%total,%jstext);
2378: foreach my $type ('textbooks','templates') {
2379: $total{$type} = 0;
2380: if (ref($settings->{$type}) eq 'HASH') {
2381: foreach my $item (keys(%{$settings->{$type}})) {
2382: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2383: my $num = $settings->{$type}->{$item}{'order'};
2384: $ordered{$type}{$num} = $item;
2385: }
2386: }
2387: $total{$type} = scalar(keys(%{$settings->{$type}}));
2388: }
2389: my @jsarray = ();
2390: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2391: push(@jsarray,$ordered{$type}{$item});
2392: }
2393: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2394: }
2395: return <<"ENDSCRIPT";
2396: <script type="text/javascript">
2397: // <![CDATA[
1.160.6.46 raeburn 2398: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2399: var changedVal;
1.160.6.46 raeburn 2400: $jstext{'textbooks'};
2401: $jstext{'templates'};
2402: var newpos;
2403: var maxh;
2404: if (caller == 'textbooks') {
2405: newpos = 'textbooks_addbook_pos';
2406: maxh = 1 + $total{'textbooks'};
2407: } else {
2408: newpos = 'templates_addbook_pos';
2409: maxh = 1 + $total{'templates'};
2410: }
1.160.6.30 raeburn 2411: var current = new Array;
2412: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2413: if (item == newpos) {
2414: changedVal = newitemVal;
2415: } else {
2416: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2417: current[newitemVal] = newpos;
2418: }
1.160.6.46 raeburn 2419: if (caller == 'textbooks') {
2420: for (var i=0; i<textbooks.length; i++) {
2421: var elementName = 'textbooks_'+textbooks[i];
2422: if (elementName != item) {
2423: if (form.elements[elementName]) {
2424: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2425: current[currVal] = elementName;
2426: }
2427: }
2428: }
2429: }
2430: if (caller == 'templates') {
2431: for (var i=0; i<templates.length; i++) {
2432: var elementName = 'templates_'+templates[i];
2433: if (elementName != item) {
2434: if (form.elements[elementName]) {
2435: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2436: current[currVal] = elementName;
2437: }
1.160.6.30 raeburn 2438: }
2439: }
2440: }
2441: var oldVal;
2442: for (var j=0; j<maxh; j++) {
2443: if (current[j] == undefined) {
2444: oldVal = j;
2445: }
2446: }
2447: if (oldVal < changedVal) {
2448: for (var k=oldVal+1; k<=changedVal ; k++) {
2449: var elementName = current[k];
2450: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2451: }
2452: } else {
2453: for (var k=changedVal; k<oldVal; k++) {
2454: var elementName = current[k];
2455: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2456: }
2457: }
2458: return;
2459: }
2460:
2461: // ]]>
2462: </script>
2463:
2464: ENDSCRIPT
2465: }
2466:
1.160.6.84.6. (raeburn 2467:): sub ltitools_javascript {
2468:): my ($settings) = @_;
2469:): my $togglejs = <itools_toggle_js();
2470:): unless (ref($settings) eq 'HASH') {
2471:): return $togglejs;
2472:): }
2473:): my (%ordered,$total,%jstext);
2474:): $total = 0;
2475:): foreach my $item (keys(%{$settings})) {
2476:): if (ref($settings->{$item}) eq 'HASH') {
2477:): my $num = $settings->{$item}{'order'};
2478:): $ordered{$num} = $item;
2479:): }
2480:): }
2481:): $total = scalar(keys(%{$settings}));
2482:): my @jsarray = ();
2483:): foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2484:): push(@jsarray,$ordered{$item});
2485:): }
2486:): my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2487:): return <<"ENDSCRIPT";
2488:): <script type="text/javascript">
2489:): // <![CDATA[
2490:): function reorderLTITools(form,item) {
2491:): var changedVal;
2492:): $jstext
2493:): var newpos = 'ltitools_add_pos';
2494:): var maxh = 1 + $total;
2495:): var current = new Array;
2496:): var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2497:): if (item == newpos) {
2498:): changedVal = newitemVal;
2499:): } else {
2500:): changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2501:): current[newitemVal] = newpos;
2502:): }
2503:): for (var i=0; i<ltitools.length; i++) {
2504:): var elementName = 'ltitools_'+ltitools[i];
2505:): if (elementName != item) {
2506:): if (form.elements[elementName]) {
2507:): var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2508:): current[currVal] = elementName;
2509:): }
2510:): }
2511:): }
2512:): var oldVal;
2513:): for (var j=0; j<maxh; j++) {
2514:): if (current[j] == undefined) {
2515:): oldVal = j;
2516:): }
2517:): }
2518:): if (oldVal < changedVal) {
2519:): for (var k=oldVal+1; k<=changedVal ; k++) {
2520:): var elementName = current[k];
2521:): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2522:): }
2523:): } else {
2524:): for (var k=changedVal; k<oldVal; k++) {
2525:): var elementName = current[k];
2526:): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2527:): }
2528:): }
2529:): return;
2530:): }
2531:):
2532:): // ]]>
2533:): </script>
2534:):
2535:): $togglejs
2536:):
2537:): ENDSCRIPT
2538:): }
2539:):
2540:): sub ltitools_toggle_js {
2541:): return <<"ENDSCRIPT";
2542:): <script type="text/javascript">
2543:): // <![CDATA[
2544:):
2545:): function toggleLTITools(form,setting,item) {
2546:): var radioname = '';
2547:): var divid = '';
2548:): if (setting == 'user') {
2549:): divid = 'ltitools_'+setting+'_div_'+item;
2550:): var checkid = 'ltitools_'+setting+'_field_'+item;
2551:): if (document.getElementById(divid)) {
2552:): if (document.getElementById(checkid)) {
2553:): if (document.getElementById(checkid).checked) {
2554:): document.getElementById(divid).style.display = 'inline-block';
2555:): } else {
2556:): document.getElementById(divid).style.display = 'none';
2557:): }
2558:): }
2559:): }
2560:): }
2561:): return;
2562:): }
2563:): // ]]>
2564:): </script>
2565:):
2566:): ENDSCRIPT
2567:): }
2568:):
1.3 raeburn 2569: sub print_autoenroll {
1.30 raeburn 2570: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2571: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 2572: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2573: if (ref($settings) eq 'HASH') {
2574: if (exists($settings->{'run'})) {
2575: if ($settings->{'run'} eq '0') {
2576: $runoff = ' checked="checked" ';
2577: $runon = ' ';
2578: } else {
2579: $runon = ' checked="checked" ';
2580: $runoff = ' ';
2581: }
2582: } else {
2583: if ($autorun) {
2584: $runon = ' checked="checked" ';
2585: $runoff = ' ';
2586: } else {
2587: $runoff = ' checked="checked" ';
2588: $runon = ' ';
2589: }
2590: }
1.129 raeburn 2591: if (exists($settings->{'co-owners'})) {
2592: if ($settings->{'co-owners'} eq '0') {
2593: $coownersoff = ' checked="checked" ';
2594: $coownerson = ' ';
2595: } else {
2596: $coownerson = ' checked="checked" ';
2597: $coownersoff = ' ';
2598: }
2599: } else {
2600: $coownersoff = ' checked="checked" ';
2601: $coownerson = ' ';
2602: }
1.3 raeburn 2603: if (exists($settings->{'sender_domain'})) {
2604: $defdom = $settings->{'sender_domain'};
2605: }
1.160.6.68 raeburn 2606: if (exists($settings->{'autofailsafe'})) {
2607: $failsafe = $settings->{'autofailsafe'};
2608: }
1.14 raeburn 2609: } else {
2610: if ($autorun) {
2611: $runon = ' checked="checked" ';
2612: $runoff = ' ';
2613: } else {
2614: $runoff = ' checked="checked" ';
2615: $runon = ' ';
2616: }
1.3 raeburn 2617: }
2618: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2619: my $notif_sender;
2620: if (ref($settings) eq 'HASH') {
2621: $notif_sender = $settings->{'sender_uname'};
2622: }
1.3 raeburn 2623: my $datatable='<tr class="LC_odd_row">'.
2624: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2625: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2626: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2627: $runon.' value="1" />'.&mt('Yes').'</label> '.
2628: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2629: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2630: '</tr><tr>'.
2631: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2632: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2633: &mt('username').': '.
2634: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2635: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2636: ': '.$domform.'</span></td></tr>'.
2637: '<tr class="LC_odd_row">'.
2638: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2639: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2640: '<input type="radio" name="autoassign_coowners"'.
2641: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2642: '<label><input type="radio" name="autoassign_coowners"'.
2643: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 2644: '</tr><tr>'.
2645: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2646: '<td class="LC_right_item"><span class="LC_nobreak">'.
2647: '<input type="text" name="autoenroll_failsafe"'.
2648: ' value="'.$failsafe.'" size="4" /></td></tr>';
2649: $$rowtotal += 4;
1.3 raeburn 2650: return $datatable;
2651: }
2652:
2653: sub print_autoupdate {
1.30 raeburn 2654: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2655: my $datatable;
2656: if ($position eq 'top') {
2657: my $updateon = ' ';
2658: my $updateoff = ' checked="checked" ';
2659: my $classlistson = ' ';
2660: my $classlistsoff = ' checked="checked" ';
2661: if (ref($settings) eq 'HASH') {
2662: if ($settings->{'run'} eq '1') {
2663: $updateon = $updateoff;
2664: $updateoff = ' ';
2665: }
2666: if ($settings->{'classlists'} eq '1') {
2667: $classlistson = $classlistsoff;
2668: $classlistsoff = ' ';
2669: }
2670: }
2671: my %title = (
2672: run => 'Auto-update active?',
2673: classlists => 'Update information in classlists?',
2674: );
2675: $datatable = '<tr class="LC_odd_row">'.
2676: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2677: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2678: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2679: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2680: '<label><input type="radio" name="autoupdate_run"'.
2681: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2682: '</tr><tr>'.
2683: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2684: '<td class="LC_right_item"><span class="LC_nobreak">'.
2685: '<label><input type="radio" name="classlists"'.
2686: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2687: '<label><input type="radio" name="classlists"'.
2688: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2689: '</tr>';
1.30 raeburn 2690: $$rowtotal += 2;
1.131 raeburn 2691: } elsif ($position eq 'middle') {
2692: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2693: my $numinrow = 3;
2694: my $locknamesettings;
2695: $datatable .= &insttypes_row($settings,$types,$usertypes,
2696: $dom,$numinrow,$othertitle,
2697: 'lockablenames');
2698: $$rowtotal ++;
1.3 raeburn 2699: } else {
1.44 raeburn 2700: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2701: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2702: 'permanentemail','id');
1.33 raeburn 2703: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2704: my $numrows = 0;
1.26 raeburn 2705: if (ref($types) eq 'ARRAY') {
2706: if (@{$types} > 0) {
2707: $datatable =
2708: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2709: \@fields,$types,\$numrows);
1.30 raeburn 2710: $$rowtotal += @{$types};
1.26 raeburn 2711: }
1.3 raeburn 2712: }
2713: $datatable .=
2714: &usertype_update_row($settings,{'default' => $othertitle},
2715: \%fieldtitles,\@fields,['default'],
2716: \$numrows);
1.30 raeburn 2717: $$rowtotal ++;
1.3 raeburn 2718: }
2719: return $datatable;
2720: }
2721:
1.125 raeburn 2722: sub print_autocreate {
2723: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2724: my (%createon,%createoff,%currhash);
1.125 raeburn 2725: my @types = ('xml','req');
2726: if (ref($settings) eq 'HASH') {
2727: foreach my $item (@types) {
2728: $createoff{$item} = ' checked="checked" ';
2729: $createon{$item} = ' ';
2730: if (exists($settings->{$item})) {
2731: if ($settings->{$item}) {
2732: $createon{$item} = ' checked="checked" ';
2733: $createoff{$item} = ' ';
2734: }
2735: }
2736: }
1.160.6.16 raeburn 2737: if ($settings->{'xmldc'} ne '') {
2738: $currhash{$settings->{'xmldc'}} = 1;
2739: }
1.125 raeburn 2740: } else {
2741: foreach my $item (@types) {
2742: $createoff{$item} = ' checked="checked" ';
2743: $createon{$item} = ' ';
2744: }
2745: }
2746: $$rowtotal += 2;
1.160.6.16 raeburn 2747: my $numinrow = 2;
1.125 raeburn 2748: my $datatable='<tr class="LC_odd_row">'.
2749: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2750: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2751: '<input type="radio" name="autocreate_xml"'.
2752: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2753: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2754: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2755: '</td></tr><tr>'.
2756: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2757: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2758: '<input type="radio" name="autocreate_req"'.
2759: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2760: '<label><input type="radio" name="autocreate_req"'.
2761: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2762: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2763: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2764: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2765: if ($numdc > 1) {
1.160.6.50 raeburn 2766: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2767: '</td><td class="LC_left_item">';
1.125 raeburn 2768: } else {
1.160.6.50 raeburn 2769: $datatable .= &mt('Course creation processed as:').
2770: '</td><td class="LC_right_item">';
1.125 raeburn 2771: }
1.160.6.50 raeburn 2772: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2773: $$rowtotal += $rows;
1.125 raeburn 2774: return $datatable;
2775: }
2776:
1.23 raeburn 2777: sub print_directorysrch {
1.160.6.72 raeburn 2778: my ($position,$dom,$settings,$rowtotal) = @_;
2779: my $datatable;
2780: if ($position eq 'top') {
2781: my $instsrchon = ' ';
2782: my $instsrchoff = ' checked="checked" ';
2783: my ($exacton,$containson,$beginson);
2784: my $instlocalon = ' ';
2785: my $instlocaloff = ' checked="checked" ';
2786: if (ref($settings) eq 'HASH') {
2787: if ($settings->{'available'} eq '1') {
2788: $instsrchon = $instsrchoff;
2789: $instsrchoff = ' ';
2790: }
2791: if ($settings->{'localonly'} eq '1') {
2792: $instlocalon = $instlocaloff;
2793: $instlocaloff = ' ';
2794: }
2795: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2796: foreach my $type (@{$settings->{'searchtypes'}}) {
2797: if ($type eq 'exact') {
2798: $exacton = ' checked="checked" ';
2799: } elsif ($type eq 'contains') {
2800: $containson = ' checked="checked" ';
2801: } elsif ($type eq 'begins') {
2802: $beginson = ' checked="checked" ';
2803: }
2804: }
2805: } else {
2806: if ($settings->{'searchtypes'} eq 'exact') {
2807: $exacton = ' checked="checked" ';
2808: } elsif ($settings->{'searchtypes'} eq 'contains') {
2809: $containson = ' checked="checked" ';
2810: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2811: $exacton = ' checked="checked" ';
2812: $containson = ' checked="checked" ';
2813: }
2814: }
1.23 raeburn 2815: }
1.160.6.72 raeburn 2816: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2817: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2818:
1.160.6.72 raeburn 2819: my $numinrow = 4;
2820: my $cansrchrow = 0;
2821: $datatable='<tr class="LC_odd_row">'.
2822: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2823: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2824: '<input type="radio" name="dirsrch_available"'.
2825: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2826: '<label><input type="radio" name="dirsrch_available"'.
2827: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2828: '</tr><tr>'.
2829: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2830: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2831: '<input type="radio" name="dirsrch_instlocalonly"'.
2832: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2833: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2834: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2835: '</tr>';
2836: $$rowtotal += 2;
2837: if (ref($usertypes) eq 'HASH') {
2838: if (keys(%{$usertypes}) > 0) {
2839: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2840: $numinrow,$othertitle,'cansearch');
2841: $cansrchrow = 1;
2842: }
1.26 raeburn 2843: }
1.160.6.72 raeburn 2844: if ($cansrchrow) {
2845: $$rowtotal ++;
2846: $datatable .= '<tr>';
2847: } else {
2848: $datatable .= '<tr class="LC_odd_row">';
2849: }
2850: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2851: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2852: foreach my $title (@{$titleorder}) {
2853: if (defined($searchtitles->{$title})) {
2854: my $check = ' ';
2855: if (ref($settings) eq 'HASH') {
2856: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2857: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2858: $check = ' checked="checked" ';
2859: }
1.39 raeburn 2860: }
1.25 raeburn 2861: }
1.160.6.72 raeburn 2862: $datatable .= '<td class="LC_left_item">'.
2863: '<span class="LC_nobreak"><label>'.
2864: '<input type="checkbox" name="searchby" '.
2865: 'value="'.$title.'"'.$check.'/>'.
2866: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2867: }
2868: }
1.160.6.72 raeburn 2869: $datatable .= '</tr></table></td></tr>';
2870: $$rowtotal ++;
2871: if ($cansrchrow) {
2872: $datatable .= '<tr class="LC_odd_row">';
2873: } else {
2874: $datatable .= '<tr>';
2875: }
2876: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2877: '<td class="LC_left_item" colspan="2">'.
2878: '<span class="LC_nobreak"><label>'.
2879: '<input type="checkbox" name="searchtypes" '.
2880: $exacton.' value="exact" />'.&mt('Exact match').
2881: '</label> '.
2882: '<label><input type="checkbox" name="searchtypes" '.
2883: $beginson.' value="begins" />'.&mt('Begins with').
2884: '</label> '.
2885: '<label><input type="checkbox" name="searchtypes" '.
2886: $containson.' value="contains" />'.&mt('Contains').
2887: '</label></span></td></tr>';
2888: $$rowtotal ++;
1.26 raeburn 2889: } else {
1.160.6.72 raeburn 2890: my $domsrchon = ' checked="checked" ';
2891: my $domsrchoff = ' ';
2892: my $domlocalon = ' ';
2893: my $domlocaloff = ' checked="checked" ';
2894: if (ref($settings) eq 'HASH') {
2895: if ($settings->{'lclocalonly'} eq '1') {
2896: $domlocalon = $domlocaloff;
2897: $domlocaloff = ' ';
2898: }
2899: if ($settings->{'lcavailable'} eq '0') {
2900: $domsrchoff = $domsrchon;
2901: $domsrchon = ' ';
2902: }
2903: }
2904: $datatable='<tr class="LC_odd_row">'.
2905: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2906: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2907: '<input type="radio" name="dirsrch_domavailable"'.
2908: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2909: '<label><input type="radio" name="dirsrch_domavailable"'.
2910: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2911: '</tr><tr>'.
2912: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2913: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2914: '<input type="radio" name="dirsrch_domlocalonly"'.
2915: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2916: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2917: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2918: '</tr>';
2919: $$rowtotal += 2;
1.26 raeburn 2920: }
1.25 raeburn 2921: return $datatable;
2922: }
2923:
1.28 raeburn 2924: sub print_contacts {
1.160.6.78 raeburn 2925: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 2926: my $datatable;
2927: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 2928: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
2929: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
2930: if ($position eq 'top') {
2931: if (ref($settings) eq 'HASH') {
2932: foreach my $item (@contacts) {
2933: if (exists($settings->{$item})) {
2934: $to{$item} = $settings->{$item};
2935: }
1.28 raeburn 2936: }
2937: }
1.160.6.78 raeburn 2938: } elsif ($position eq 'middle') {
2939: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
2940: 'updatesmail','idconflictsmail');
1.28 raeburn 2941: foreach my $type (@mailings) {
1.160.6.78 raeburn 2942: $otheremails{$type} = '';
2943: }
2944: } else {
2945: @mailings = ('helpdeskmail','otherdomsmail');
2946: foreach my $type (@mailings) {
2947: $otheremails{$type} = '';
2948: }
2949: $bccemails{'helpdeskmail'} = '';
2950: $bccemails{'otherdomsmail'} = '';
2951: $includestr{'helpdeskmail'} = '';
2952: $includestr{'otherdomsmail'} = '';
2953: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
2954: }
2955: if (ref($settings) eq 'HASH') {
2956: unless ($position eq 'top') {
2957: foreach my $type (@mailings) {
2958: if (exists($settings->{$type})) {
2959: if (ref($settings->{$type}) eq 'HASH') {
2960: foreach my $item (@contacts) {
2961: if ($settings->{$type}{$item}) {
2962: $checked{$type}{$item} = ' checked="checked" ';
2963: }
1.28 raeburn 2964: }
1.160.6.78 raeburn 2965: $otheremails{$type} = $settings->{$type}{'others'};
2966: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2967: $bccemails{$type} = $settings->{$type}{'bcc'};
2968: if ($settings->{$type}{'include'} ne '') {
2969: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2970: $includestr{$type} = &unescape($includestr{$type});
2971: }
2972: }
2973: }
2974: } elsif ($type eq 'lonstatusmail') {
2975: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2976: }
2977: }
2978: }
2979: if ($position eq 'bottom') {
2980: foreach my $type (@mailings) {
2981: $bccemails{$type} = $settings->{$type}{'bcc'};
2982: if ($settings->{$type}{'include'} ne '') {
2983: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2984: $includestr{$type} = &unescape($includestr{$type});
2985: }
2986: }
2987: if (ref($settings->{'helpform'}) eq 'HASH') {
2988: if (ref($fields) eq 'ARRAY') {
2989: foreach my $field (@{$fields}) {
2990: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 2991: }
1.160.6.78 raeburn 2992: }
2993: if (exists($settings->{'helpform'}{'maxsize'})) {
2994: $maxsize = $settings->{'helpform'}{'maxsize'};
2995: } else {
2996: $maxsize = '1.0';
2997: }
2998: } else {
2999: if (ref($fields) eq 'ARRAY') {
3000: foreach my $field (@{$fields}) {
3001: $currfield{$field} = 'yes';
1.134 raeburn 3002: }
1.28 raeburn 3003: }
1.160.6.78 raeburn 3004: $maxsize = '1.0';
1.28 raeburn 3005: }
3006: }
3007: } else {
1.160.6.78 raeburn 3008: if ($position eq 'top') {
3009: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3010: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3011: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3012: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
3013: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3014: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3015: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3016: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3017: } elsif ($position eq 'bottom') {
3018: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3019: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3020: if (ref($fields) eq 'ARRAY') {
3021: foreach my $field (@{$fields}) {
3022: $currfield{$field} = 'yes';
3023: }
3024: }
3025: $maxsize = '1.0';
3026: }
1.28 raeburn 3027: }
3028: my ($titles,$short_titles) = &contact_titles();
3029: my $rownum = 0;
3030: my $css_class;
1.160.6.78 raeburn 3031: if ($position eq 'top') {
3032: foreach my $item (@contacts) {
3033: $css_class = $rownum%2?' class="LC_odd_row"':'';
3034: $datatable .= '<tr'.$css_class.'>'.
3035: '<td><span class="LC_nobreak">'.$titles->{$item}.
3036: '</span></td><td class="LC_right_item">'.
3037: '<input type="text" name="'.$item.'" value="'.
3038: $to{$item}.'" /></td></tr>';
3039: $rownum ++;
3040: }
3041: } else {
3042: foreach my $type (@mailings) {
3043: $css_class = $rownum%2?' class="LC_odd_row"':'';
3044: $datatable .= '<tr'.$css_class.'>'.
3045: '<td><span class="LC_nobreak">'.
3046: $titles->{$type}.': </span></td>'.
3047: '<td class="LC_left_item">';
3048: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3049: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3050: }
3051: $datatable .= '<span class="LC_nobreak">';
3052: foreach my $item (@contacts) {
3053: $datatable .= '<label>'.
3054: '<input type="checkbox" name="'.$type.'"'.
3055: $checked{$type}{$item}.
3056: ' value="'.$item.'" />'.$short_titles->{$item}.
3057: '</label> ';
3058: }
3059: $datatable .= '</span><br />'.&mt('Others').': '.
3060: '<input type="text" name="'.$type.'_others" '.
3061: 'value="'.$otheremails{$type}.'" />';
3062: my %locchecked;
3063: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3064: foreach my $loc ('s','b') {
3065: if ($includeloc{$type} eq $loc) {
3066: $locchecked{$loc} = ' checked="checked"';
3067: last;
3068: }
3069: }
3070: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3071: '<input type="text" name="'.$type.'_bcc" '.
3072: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3073: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3074: &mt('Text automatically added to e-mail:').' '.
3075: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
3076: '<span class="LC_nobreak">'.&mt('Location:').' '.
3077: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3078: (' 'x2).
3079: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3080: '</span></fieldset>';
3081: }
3082: $datatable .= '</td></tr>'."\n";
3083: $rownum ++;
3084: }
1.28 raeburn 3085: }
1.160.6.78 raeburn 3086: if ($position eq 'middle') {
3087: my %choices;
3088: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
3089: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3090: &mt('LON-CAPA core group - MSU'),600,500));
3091: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3092: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3093: &mt('LON-CAPA core group - MSU'),600,500));
3094: my @toggles = ('reporterrors','reportupdates');
3095: my %defaultchecked = ('reporterrors' => 'on',
3096: 'reportupdates' => 'on');
3097: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3098: \%choices,$rownum);
3099: $datatable .= $reports;
3100: } elsif ($position eq 'bottom') {
1.69 raeburn 3101: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 3102: $datatable .= '<tr'.$css_class.'>'.
1.160.6.78 raeburn 3103: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3104: &mt('(e-mail, subject, and description always shown)').
3105: '</td><td class="LC_left_item">';
3106: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3107: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3108: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3109: foreach my $field (@{$fields}) {
3110: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3111: if (($field eq 'screenshot') || ($field eq 'cc')) {
3112: $datatable .= ' '.&mt('(logged-in users)');
3113: }
3114: $datatable .='</td><td>';
3115: my $clickaction;
3116: if ($field eq 'screenshot') {
3117: $clickaction = ' onclick="screenshotSize(this);"';
3118: }
3119: if (ref($possoptions->{$field}) eq 'ARRAY') {
3120: foreach my $option (@{$possoptions->{$field}}) {
3121: my $checked;
3122: if ($currfield{$field} eq $option) {
3123: $checked = ' checked="checked"';
3124: }
3125: $datatable .= '<span class="LC_nobreak"><label>'.
3126: '<input type="radio" name="helpform_'.$field.'" '.
3127: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3128: '</label></span>'.(' 'x2);
3129: }
3130: }
3131: if ($field eq 'screenshot') {
3132: my $display;
3133: if ($currfield{$field} eq 'no') {
3134: $display = ' style="display:none"';
3135: }
3136: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
3137: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3138: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3139: }
3140: $datatable .= '</td></tr>';
3141: }
3142: $datatable .= '</table>';
1.134 raeburn 3143: }
3144: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 3145: $rownum ++;
1.28 raeburn 3146: }
1.30 raeburn 3147: $$rowtotal += $rownum;
1.28 raeburn 3148: return $datatable;
3149: }
3150:
1.160.6.78 raeburn 3151: sub contacts_javascript {
3152: return <<"ENDSCRIPT";
3153:
3154: <script type="text/javascript">
3155: // <![CDATA[
3156:
3157: function screenshotSize(field) {
3158: if (document.getElementById('help_screenshotsize')) {
3159: if (field.value == 'no') {
3160: document.getElementById('help_screenshotsize').style.display="none";
3161: } else {
3162: document.getElementById('help_screenshotsize').style.display="";
3163: }
3164: }
3165: return;
3166: }
3167:
3168: // ]]>
3169: </script>
3170:
3171: ENDSCRIPT
3172: }
3173:
1.118 jms 3174: sub print_helpsettings {
1.160.6.73 raeburn 3175: my ($position,$dom,$settings,$rowtotal) = @_;
3176: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 3177: my $formname = 'display';
1.160.6.5 raeburn 3178: my ($datatable,$itemcount);
1.160.6.73 raeburn 3179: if ($position eq 'top') {
3180: $itemcount = 1;
3181: my (%choices,%defaultchecked,@toggles);
3182: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3183: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3184: &mt('LON-CAPA bug tracker'),600,500));
3185: %defaultchecked = ('submitbugs' => 'on');
3186: @toggles = ('submitbugs');
3187: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3188: \%choices,$itemcount);
3189: $$rowtotal ++;
3190: } else {
3191: my $css_class;
3192: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 3193: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 3194: if (ref($settings) eq 'HASH') {
3195: if (ref($settings->{'adhoc'}) eq 'HASH') {
3196: %current = %{$settings->{'adhoc'}};
3197: }
1.160.6.77 raeburn 3198: }
3199: my $count = 0;
3200: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 3201: if ($key=~/^rolesdef\_(\w+)$/) {
3202: my $rolename = $1;
1.160.6.77 raeburn 3203: my (%privs,$order);
1.160.6.73 raeburn 3204: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3205: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 3206: if (ref($current{$rolename}) eq 'HASH') {
3207: $order = $current{$rolename}{'order'};
3208: }
3209: if ($order eq '') {
3210: $order = $count;
3211: }
3212: $ordered{$order} = $rolename;
3213: $count++;
1.160.6.73 raeburn 3214: }
3215: }
1.160.6.77 raeburn 3216: my $maxnum = scalar(keys(%ordered));
3217: my @roles_by_num = ();
3218: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3219: push(@roles_by_num,$item);
3220: }
3221: my $context = 'domprefs';
3222: my $crstype = 'Course';
3223: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 3224: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 3225: my ($numstatustypes,@jsarray);
3226: if (ref($types) eq 'ARRAY') {
3227: if (@{$types} > 0) {
3228: $numstatustypes = scalar(@{$types});
3229: push(@accesstypes,'status');
3230: @jsarray = ('bystatus');
3231: }
3232: }
1.160.6.84.6. (raeburn 3233:): my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 3234: if (keys(%domhelpdesk)) {
3235: push(@accesstypes,('inc','exc'));
3236: push(@jsarray,('notinc','notexc'));
3237: }
3238: my $hiddenstr = join("','",@jsarray);
3239: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 3240: my $context = 'domprefs';
3241: my $crstype = 'Course';
1.160.6.77 raeburn 3242: my $prefix = 'helproles_';
3243: my $add_class = 'LC_hidden';
3244: foreach my $num (@roles_by_num) {
3245: my $role = $ordered{$num};
3246: my ($desc,$access,@statuses);
3247: if (ref($current{$role}) eq 'HASH') {
3248: $desc = $current{$role}{'desc'};
3249: $access = $current{$role}{'access'};
3250: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3251: @statuses = @{$current{$role}{'insttypes'}};
3252: }
3253: }
3254: if ($desc eq '') {
3255: $desc = $role;
3256: }
3257: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 3258: my %full=();
3259: my %levels= (
3260: course => {},
3261: domain => {},
3262: system => {},
3263: );
3264: my %levelscurrent=(
3265: course => {},
3266: domain => {},
3267: system => {},
3268: );
3269: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3270: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3271: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 3272: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3273: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3274: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3275: for (my $k=0; $k<=$maxnum; $k++) {
3276: my $vpos = $k+1;
3277: my $selstr;
3278: if ($k == $num) {
3279: $selstr = ' selected="selected" ';
3280: }
3281: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3282: }
3283: $datatable .= '</select>'.(' 'x2).
3284: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3285: '</td>'.
3286: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3287: &mt('Name shown to users:').
3288: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3289: '</fieldset>'.
3290: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3291: $othertitle,$usertypes,$types,\%domhelpdesk).
3292: '<fieldset>'.
3293: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 3294: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 3295: \%levelscurrent,$identifier,
3296: 'LC_hidden',$prefix.$num.'_privs').
3297: '</fieldset></td>';
1.160.6.73 raeburn 3298: $itemcount ++;
3299: }
3300: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3301: my $newcust = 'custhelp'.$count;
3302: my (%privs,%levelscurrent);
3303: my %full=();
3304: my %levels= (
3305: course => {},
3306: domain => {},
3307: system => {},
3308: );
3309: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3310: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 3311: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3312: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3313: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3314: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3315: for (my $k=0; $k<$maxnum+1; $k++) {
3316: my $vpos = $k+1;
3317: my $selstr;
3318: if ($k == $maxnum) {
3319: $selstr = ' selected="selected" ';
3320: }
3321: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3322: }
3323: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 3324: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3325: '</label></span></td>'.
1.160.6.77 raeburn 3326: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3327: '<span class="LC_nobreak">'.
3328: &mt('Internal name:').
3329: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3330: '</span>'.(' 'x4).
3331: '<span class="LC_nobreak">'.
3332: &mt('Name shown to users:').
3333: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3334: '</span></fieldset>'.
3335: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3336: $usertypes,$types,\%domhelpdesk).
3337: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 3338: &Apache::lonuserutils::custom_role_header($context,$crstype,
3339: \@templateroles,$newcust).
3340: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3341: \%levelscurrent,$newcust).
1.160.6.77 raeburn 3342: '</fieldset></td></tr>';
1.160.6.73 raeburn 3343: $count ++;
3344: $$rowtotal += $count;
3345: }
1.160.6.5 raeburn 3346: return $datatable;
1.121 raeburn 3347: }
3348:
1.160.6.77 raeburn 3349: sub adhocbutton {
3350: my ($prefix,$num,$field,$visibility) = @_;
3351: my %lt = &Apache::lonlocal::texthash(
3352: show => 'Show details',
3353: hide => 'Hide details',
3354: );
3355: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3356: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3357: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3358: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3359: }
3360:
3361: sub helpsettings_javascript {
3362: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3363: return unless(ref($roles_by_num) eq 'ARRAY');
3364: my %html_js_lt = &Apache::lonlocal::texthash(
3365: show => 'Show details',
3366: hide => 'Hide details',
3367: );
3368: &html_escape(\%html_js_lt);
3369: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3370: return <<"ENDSCRIPT";
3371: <script type="text/javascript">
3372: // <![CDATA[
3373:
3374: function reorderHelpRoles(form,item) {
3375: var changedVal;
3376: $jstext
3377: var newpos = 'helproles_${total}_pos';
3378: var maxh = 1 + $total;
3379: var current = new Array();
3380: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3381: if (item == newpos) {
3382: changedVal = newitemVal;
3383: } else {
3384: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3385: current[newitemVal] = newpos;
3386: }
3387: for (var i=0; i<helproles.length; i++) {
3388: var elementName = 'helproles_'+helproles[i]+'_pos';
3389: if (elementName != item) {
3390: if (form.elements[elementName]) {
3391: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3392: current[currVal] = elementName;
3393: }
3394: }
3395: }
3396: var oldVal;
3397: for (var j=0; j<maxh; j++) {
3398: if (current[j] == undefined) {
3399: oldVal = j;
3400: }
3401: }
3402: if (oldVal < changedVal) {
3403: for (var k=oldVal+1; k<=changedVal ; k++) {
3404: var elementName = current[k];
3405: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3406: }
3407: } else {
3408: for (var k=changedVal; k<oldVal; k++) {
3409: var elementName = current[k];
3410: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3411: }
3412: }
3413: return;
3414: }
3415:
3416: function helpdeskAccess(num) {
3417: var curraccess = null;
3418: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3419: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3420: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3421: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3422: }
3423: }
3424: }
3425: var shown = Array();
3426: var hidden = Array();
3427: if (curraccess == 'none') {
3428: hidden = Array('$hiddenstr');
3429: } else {
3430: if (curraccess == 'status') {
3431: shown = Array('bystatus');
3432: hidden = Array('notinc','notexc');
3433: } else {
3434: if (curraccess == 'exc') {
3435: shown = Array('notexc');
3436: hidden = Array('notinc','bystatus');
3437: }
3438: if (curraccess == 'inc') {
3439: shown = Array('notinc');
3440: hidden = Array('notexc','bystatus');
3441: }
1.160.6.79 raeburn 3442: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 3443: hidden = Array('notinc','notexc','bystatus');
3444: }
3445: }
3446: }
3447: if (hidden.length > 0) {
3448: for (var i=0; i<hidden.length; i++) {
3449: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3450: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3451: }
3452: }
3453: }
3454: if (shown.length > 0) {
3455: for (var i=0; i<shown.length; i++) {
3456: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3457: if (shown[i] == 'privs') {
3458: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3459: } else {
3460: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3461: }
3462: }
3463: }
3464: }
3465: return;
3466: }
3467:
3468: function toggleHelpdeskItem(num,field) {
3469: if (document.getElementById('helproles_'+num+'_'+field)) {
3470: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3471: document.getElementById('helproles_'+num+'_'+field).className =
3472: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3473: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3474: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3475: }
3476: } else {
3477: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3478: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3479: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3480: }
3481: }
3482: }
3483: return;
3484: }
3485:
3486: // ]]>
3487: </script>
3488:
3489: ENDSCRIPT
3490: }
3491:
3492: sub helpdeskroles_access {
3493: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3494: $usertypes,$types,$domhelpdesk) = @_;
3495: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3496: my %lt = &Apache::lonlocal::texthash(
3497: 'rou' => 'Role usage',
3498: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 3499: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3500: 'dh' => 'All with domain helpdesk role',
3501: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 3502: 'none' => 'None',
3503: 'status' => 'Determined based on institutional status',
3504: 'inc' => 'Include all, but exclude specific personnel',
3505: 'exc' => 'Exclude all, but include specific personnel',
3506: );
3507: my %usecheck = (
3508: all => ' checked="checked"',
3509: );
3510: my %displaydiv = (
3511: status => 'none',
3512: inc => 'none',
3513: exc => 'none',
3514: priv => 'block',
3515: );
3516: my $output;
3517: if (ref($current) eq 'HASH') {
3518: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3519: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3520: $usecheck{$current->{access}} = $usecheck{'all'};
3521: delete($usecheck{'all'});
3522: if ($current->{access} =~ /^(status|inc|exc)$/) {
3523: my $access = $1;
3524: $displaydiv{$access} = 'inline';
3525: } elsif ($current->{access} eq 'none') {
3526: $displaydiv{'priv'} = 'none';
3527: }
3528: }
3529: }
3530: }
3531: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3532: '<p>'.$lt{'whi'}.'</p>';
3533: foreach my $access (@{$accesstypes}) {
3534: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3535: ' onclick="helpdeskAccess('."'$num'".');" />'.
3536: $lt{$access}.'</label>';
3537: if ($access eq 'status') {
3538: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3539: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3540: $othertitle,$usertypes,$types).
3541: '</div>';
3542: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3543: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3544: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3545: '</div>';
3546: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3547: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3548: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3549: '</div>';
3550: }
3551: $output .= '</p>';
3552: }
3553: $output .= '</fieldset>';
3554: return $output;
3555: }
3556:
1.121 raeburn 3557: sub radiobutton_prefs {
1.160.6.16 raeburn 3558: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 3559: $additional,$align) = @_;
1.121 raeburn 3560: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3561: (ref($choices) eq 'HASH'));
3562:
3563: my (%checkedon,%checkedoff,$datatable,$css_class);
3564:
3565: foreach my $item (@{$toggles}) {
3566: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3567: $checkedon{$item} = ' checked="checked" ';
3568: $checkedoff{$item} = ' ';
1.121 raeburn 3569: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3570: $checkedoff{$item} = ' checked="checked" ';
3571: $checkedon{$item} = ' ';
3572: }
3573: }
3574: if (ref($settings) eq 'HASH') {
1.121 raeburn 3575: foreach my $item (@{$toggles}) {
1.118 jms 3576: if ($settings->{$item} eq '1') {
3577: $checkedon{$item} = ' checked="checked" ';
3578: $checkedoff{$item} = ' ';
3579: } elsif ($settings->{$item} eq '0') {
3580: $checkedoff{$item} = ' checked="checked" ';
3581: $checkedon{$item} = ' ';
3582: }
3583: }
1.121 raeburn 3584: }
1.160.6.16 raeburn 3585: if ($onclick) {
3586: $onclick = ' onclick="'.$onclick.'"';
3587: }
1.121 raeburn 3588: foreach my $item (@{$toggles}) {
1.118 jms 3589: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3590: $datatable .=
1.160.6.16 raeburn 3591: '<tr'.$css_class.'><td valign="top">'.
3592: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3593: '</span></td>';
3594: if ($align eq 'left') {
3595: $datatable .= '<td class="LC_left_item">';
3596: } else {
3597: $datatable .= '<td class="LC_right_item">';
3598: }
3599: $datatable .=
3600: '<span class="LC_nobreak">'.
1.118 jms 3601: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3602: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3603: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3604: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3605: '</span>'.$additional.
3606: '</td>'.
1.118 jms 3607: '</tr>';
3608: $itemcount ++;
1.121 raeburn 3609: }
3610: return ($datatable,$itemcount);
3611: }
3612:
1.160.6.84.6. (raeburn 3613:): sub print_ltitools {
3614:): my ($dom,$settings,$rowtotal) = @_;
3615:): my $rownum = 0;
3616:): my $css_class;
3617:): my $itemcount = 1;
3618:): my $maxnum = 0;
3619:): my %ordered;
3620:): if (ref($settings) eq 'HASH') {
3621:): foreach my $item (keys(%{$settings})) {
3622:): if (ref($settings->{$item}) eq 'HASH') {
3623:): my $num = $settings->{$item}{'order'};
3624:): $ordered{$num} = $item;
3625:): }
3626:): }
3627:): }
3628:): my $confname = $dom.'-domainconfig';
3629:): my $switchserver = &check_switchserver($dom,$confname);
3630:): my $maxnum = scalar(keys(%ordered));
3631:): my $datatable;
3632:): my %lt = <itools_names();
3633:): my @courseroles = ('cc','in','ta','ep','st');
3634:): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3635:): my @fields = ('fullname','firstname','lastname','email','roles','user');
3636:): if (keys(%ordered)) {
3637:): my @items = sort { $a <=> $b } keys(%ordered);
3638:): for (my $i=0; $i<@items; $i++) {
3639:): $css_class = $itemcount%2?' class="LC_odd_row"':'';
3640:): my $item = $ordered{$items[$i]};
3641:): my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
3642:): if (ref($settings->{$item}) eq 'HASH') {
3643:): $title = $settings->{$item}->{'title'};
3644:): $url = $settings->{$item}->{'url'};
3645:): $key = $settings->{$item}->{'key'};
3646:): $secret = $settings->{$item}->{'secret'};
3647:): $lifetime = $settings->{$item}->{'lifetime'};
3648:): my $image = $settings->{$item}->{'image'};
3649:): if ($image ne '') {
3650:): $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3651:): }
3652:): if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
3653:): $sigsel{'HMAC-256'} = ' selected="selected"';
3654:): } else {
3655:): $sigsel{'HMAC-SHA1'} = ' selected="selected"';
3656:): }
3657:): }
3658:): my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
3659:): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3660:): .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3661:): for (my $k=0; $k<=$maxnum; $k++) {
3662:): my $vpos = $k+1;
3663:): my $selstr;
3664:): if ($k == $i) {
3665:): $selstr = ' selected="selected" ';
3666:): }
3667:): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3668:): }
3669:): $datatable .= '</select>'.(' 'x2).
3670:): '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3671:): &mt('Delete?').'</label></span></td>'.
3672:): '<td colspan="2">'.
3673:): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3674:): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3675:): (' 'x2).
3676:): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3677:): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3678:): (' 'x2).
3679:): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3680:): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3681:): (' 'x2).
3682:): '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
3683:): '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
3684:): '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
3685:): '<br /><br />'.
3686:): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
3687:): ' value="'.$url.'" /></span>'.
3688:): (' 'x2).
3689:): '<span class="LC_nobreak">'.$lt{'key'}.':'.
3690:): '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3691:): (' 'x2).
3692:): '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
3693:): '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
3694:): (' 'x2).
3695:): '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3696:): '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3697:): '<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>'.
3698:): '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3699:): '</fieldset>'.
3700:): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3701:): '<span class="LC_nobreak">'.&mt('Display target:');
3702:): my %currdisp;
3703:): if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3704:): if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3705:): $currdisp{'window'} = ' checked="checked"';
3706:): } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
3707:): $currdisp{'tab'} = ' checked="checked"';
3708:): } else {
3709:): $currdisp{'iframe'} = ' checked="checked"';
3710:): }
3711:): if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3712:): $currdisp{'width'} = $1;
3713:): }
3714:): if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3715:): $currdisp{'height'} = $1;
3716:): }
3717:): $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
3718:): $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
3719:): } else {
3720:): $currdisp{'iframe'} = ' checked="checked"';
3721:): }
3722:): foreach my $disp ('iframe','tab','window') {
3723:): $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3724:): $lt{$disp}.'</label>'.(' 'x2);
3725:): }
3726:): $datatable .= (' 'x4);
3727:): foreach my $dimen ('width','height') {
3728:): $datatable .= '<label>'.$lt{$dimen}.' '.
3729:): '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3730:): (' 'x2);
3731:): }
3732:): $datatable .= '</span><br />'.
3733:): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
3734:): '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
3735:): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
3736:): '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
3737:): '</textarea></div><div style=""></div>'.
3738:): '<div style="padding:0;clear:both;margin:0;border:0"></div>';
3739:): }
3740:): $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
3741:): if ($imgsrc) {
3742:): $datatable .= $imgsrc.
3743:): '<label><input type="checkbox" name="ltitools_image_del"'.
3744:): ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3745:): '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3746:): } else {
3747:): $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3748:): }
3749:): if ($switchserver) {
3750:): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3751:): } else {
3752:): $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3753:): }
3754:): $datatable .= '</span></fieldset>';
3755:): my (%checkedfields,%rolemaps,$userincdom);
3756:): if (ref($settings->{$item}) eq 'HASH') {
3757:): if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3758:): %checkedfields = %{$settings->{$item}->{'fields'}};
3759:): }
3760:): $userincdom = $settings->{$item}->{'incdom'};
3761:): if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3762:): %rolemaps = %{$settings->{$item}->{'roles'}};
3763:): $checkedfields{'roles'} = 1;
3764:): }
3765:): }
3766:): $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3767:): '<span class="LC_nobreak">';
3768:): my $userfieldstyle = 'display:none;';
3769:): my $seluserdom = '';
3770:): my $unseluserdom = ' selected="selected"';
3771:): foreach my $field (@fields) {
3772:): my ($checked,$onclick,$id,$spacer);
3773:): if ($checkedfields{$field}) {
3774:): $checked = ' checked="checked"';
3775:): }
3776:): if ($field eq 'user') {
3777:): $id = ' id="ltitools_user_field_'.$i.'"';
3778:): $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
3779:): if ($checked) {
3780:): $userfieldstyle = 'display:inline-block';
3781:): if ($userincdom) {
3782:): $seluserdom = $unseluserdom;
3783:): $unseluserdom = '';
3784:): }
3785:): }
3786:): } else {
3787:): $spacer = (' ' x2);
3788:): }
3789:): $datatable .= '<label>'.
3790:): '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
3791:): $lt{$field}.'</label>'.$spacer;
3792:): }
3793:): $datatable .= '</span>';
3794:): $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
3795:): '<span class="LC_nobreak"> : '.
3796:): '<select name="ltitools_userincdom_'.$i.'">'.
3797:): '<option value="">'.&mt('Select').'</option>'.
3798:): '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
3799:): '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
3800:): '</select></span></div>';
3801:): $datatable .= '</fieldset>'.
3802:): '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3803:): foreach my $role (@courseroles) {
3804:): my ($selected,$selectnone);
3805:): if (!$rolemaps{$role}) {
3806:): $selectnone = ' selected="selected"';
3807:): }
3808:): $datatable .= '<td align="center">'.
3809:): &Apache::lonnet::plaintext($role,'Course').'<br />'.
3810:): '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3811:): '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3812:): foreach my $ltirole (@ltiroles) {
3813:): unless ($selectnone) {
3814:): if ($rolemaps{$role} eq $ltirole) {
3815:): $selected = ' selected="selected"';
3816:): } else {
3817:): $selected = '';
3818:): }
3819:): }
3820:): $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3821:): }
3822:): $datatable .= '</select></td>';
3823:): }
3824:): $datatable .= '</tr></table></fieldset>';
3825:): my %courseconfig;
3826:): if (ref($settings->{$item}) eq 'HASH') {
3827:): if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3828:): %courseconfig = %{$settings->{$item}->{'crsconf'}};
3829:): }
3830:): }
3831:): $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3832:): foreach my $item ('label','title','target','linktext','explanation','append') {
3833:): my $checked;
3834:): if ($courseconfig{$item}) {
3835:): $checked = ' checked="checked"';
3836:): }
3837:): $datatable .= '<label>'.
3838:): '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3839:): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3840:): }
3841:): $datatable .= '</span></fieldset>'.
3842:): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3843:): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3844:): if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3845:): my %custom = %{$settings->{$item}->{'custom'}};
3846:): if (keys(%custom) > 0) {
3847:): foreach my $key (sort(keys(%custom))) {
3848:): $datatable .= '<tr><td><span class="LC_nobreak">'.
3849:): '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3850:): $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3851:): '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3852:): ' value="'.$custom{$key}.'" /></td></tr>';
3853:): }
3854:): }
3855:): }
3856:): $datatable .= '<tr><td><span class="LC_nobreak">'.
3857:): '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3858:): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3859:): '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3860:): $datatable .= '</table></fieldset></td></tr>'."\n";
3861:): $itemcount ++;
3862:): }
3863:): }
3864:): $css_class = $itemcount%2?' class="LC_odd_row"':'';
3865:): my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
3866:): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3867:): '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3868:): '<select name="ltitools_add_pos"'.$chgstr.'>';
3869:): for (my $k=0; $k<$maxnum+1; $k++) {
3870:): my $vpos = $k+1;
3871:): my $selstr;
3872:): if ($k == $maxnum) {
3873:): $selstr = ' selected="selected" ';
3874:): }
3875:): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3876:): }
3877:): $datatable .= '</select> '."\n".
3878:): '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
3879:): '<td colspan="2">'.
3880:): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3881:): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
3882:): (' 'x2).
3883:): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3884:): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3885:): (' 'x2).
3886:): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3887:): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3888:): '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
3889:): '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
3890:): '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
3891:): '<br />'.
3892:): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
3893:): (' 'x2).
3894:): '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3895:): (' 'x2).
3896:): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
3897:): (' 'x2).
3898:): '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3899:): '<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".
3900:): '</fieldset>'.
3901:): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3902:): '<span class="LC_nobreak">'.&mt('Display target:');
3903:): my %defaultdisp;
3904:): $defaultdisp{'iframe'} = ' checked="checked"';
3905:): foreach my $disp ('iframe','tab','window') {
3906:): $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3907:): $lt{$disp}.'</label>'.(' 'x2);
3908:): }
3909:): $datatable .= (' 'x4);
3910:): foreach my $dimen ('width','height') {
3911:): $datatable .= '<label>'.$lt{$dimen}.' '.
3912:): '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3913:): (' 'x2);
3914:): }
3915:): $datatable .= '</span><br />'.
3916:): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
3917:): '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
3918:): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
3919:): '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
3920:): '</div><div style=""></div>'.
3921:): '<div style="padding:0;clear:both;margin:0;border:0"></div>';
3922:): $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
3923:): '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3924:): if ($switchserver) {
3925:): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3926:): } else {
3927:): $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3928:): }
3929:): $datatable .= '</span></fieldset>'.
3930:): '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3931:): '<span class="LC_nobreak">';
3932:): foreach my $field (@fields) {
3933:): my ($id,$onclick,$spacer);
3934:): if ($field eq 'user') {
3935:): $id = ' id="ltitools_user_field_add"';
3936:): $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
3937:): } else {
3938:): $spacer = (' ' x2);
3939:): }
3940:): $datatable .= '<label>'.
3941:): '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
3942:): $lt{$field}.'</label>'.$spacer;
3943:): }
3944:): $datatable .= '</span>'.
3945:): '<div style="display:none;" id="ltitools_user_div_add">'.
3946:): '<span class="LC_nobreak"> : '.
3947:): '<select name="ltitools_userincdom_add">'.
3948:): '<option value="" selected="selected">'.&mt('Select').'</option>'.
3949:): '<option value="0">'.&mt('username').'</option>'.
3950:): '<option value="1">'.&mt('username:domain').'</option>'.
3951:): '</select></span></div></fieldset>';
3952:): $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3953:): foreach my $role (@courseroles) {
3954:): my ($checked,$checkednone);
3955:): $datatable .= '<td align="center">'.
3956:): &Apache::lonnet::plaintext($role,'Course').'<br />'.
3957:): '<select name="ltitools_add_roles_'.$role.'">'.
3958:): '<option value="" selected="selected">'.&mt('Select').'</option>';
3959:): foreach my $ltirole (@ltiroles) {
3960:): $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
3961:): }
3962:): $datatable .= '</select></td>';
3963:): }
3964:): $datatable .= '</tr></table></fieldset>'.
3965:): '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3966:): foreach my $item ('label','title','target','linktext','explanation','append') {
3967:): $datatable .= '<label>'.
3968:): '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
3969:): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3970:): }
3971:): $datatable .= '</span></fieldset>'.
3972:): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3973:): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
3974:): '<tr><td><span class="LC_nobreak">'.
3975:): '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
3976:): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
3977:): '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
3978:): '</table></fieldset>'."\n".
3979:): '</td>'."\n".
3980:): '</tr>'."\n";
3981:): $itemcount ++;
3982:): return $datatable;
3983:): }
3984:):
3985:): sub ltitools_names {
3986:): my %lt = &Apache::lonlocal::texthash(
3987:): 'title' => 'Title',
3988:): 'version' => 'Version',
3989:): 'msgtype' => 'Message Type',
3990:): 'sigmethod' => 'Signature Method',
3991:): 'url' => 'URL',
3992:): 'key' => 'Key',
3993:): 'lifetime' => 'Nonce lifetime (s)',
3994:): 'secret' => 'Secret',
3995:): 'icon' => 'Icon',
3996:): 'user' => 'User',
3997:): 'fullname' => 'Full Name',
3998:): 'firstname' => 'First Name',
3999:): 'lastname' => 'Last Name',
4000:): 'email' => 'E-mail',
4001:): 'roles' => 'Role',
4002:): 'window' => 'Window',
4003:): 'tab' => 'Tab',
4004:): 'iframe' => 'iFrame',
4005:): 'height' => 'Height',
4006:): 'width' => 'Width',
4007:): 'linktext' => 'Default Link Text',
4008:): 'explanation' => 'Default Explanation',
4009:): 'crstarget' => 'Display target',
4010:): 'crslabel' => 'Course label',
4011:): 'crstitle' => 'Course title',
4012:): 'crslinktext' => 'Link Text',
4013:): 'crsexplanation' => 'Explanation',
4014:): 'crsappend' => 'Provider URL',
4015:): );
4016:):
4017:): return %lt;
4018:): }
4019:):
1.121 raeburn 4020: sub print_coursedefaults {
1.139 raeburn 4021: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 4022: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4023: my $itemcount = 1;
1.160.6.16 raeburn 4024: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 4025: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 4026: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4027: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 4028: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4029: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
4030: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 4031: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 4032: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 4033: );
1.160.6.21 raeburn 4034: my %staticdefaults = (
4035: anonsurvey_threshold => 10,
4036: uploadquota => 500,
1.160.6.57 raeburn 4037: postsubmit => 60,
1.160.6.70 raeburn 4038: mysqltables => 172800,
1.160.6.21 raeburn 4039: );
1.139 raeburn 4040: if ($position eq 'top') {
1.160.6.57 raeburn 4041: %defaultchecked = (
4042: 'uselcmath' => 'on',
4043: 'usejsme' => 'on',
1.160.6.64 raeburn 4044: 'canclone' => 'none',
1.160.6.57 raeburn 4045: );
4046: @toggles = ('uselcmath','usejsme');
1.139 raeburn 4047: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4048: \%choices,$itemcount);
1.160.6.64 raeburn 4049: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4050: $datatable .=
4051: '<tr'.$css_class.'><td valign="top">'.
4052: '<span class="LC_nobreak">'.$choices{'canclone'}.
4053: '</span></td><td class="LC_left_item">';
4054: my $currcanclone = 'none';
4055: my $onclick;
4056: my @cloneoptions = ('none','domain');
4057: my %clonetitles = (
4058: none => 'No additional course requesters',
4059: domain => "Any course requester in course's domain",
4060: instcode => 'Course requests for official courses ...',
4061: );
4062: my (%codedefaults,@code_order,@posscodes);
4063: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4064: \@code_order) eq 'ok') {
4065: if (@code_order > 0) {
4066: push(@cloneoptions,'instcode');
4067: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4068: }
4069: }
4070: if (ref($settings) eq 'HASH') {
4071: if ($settings->{'canclone'}) {
4072: if (ref($settings->{'canclone'}) eq 'HASH') {
4073: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4074: if (@code_order > 0) {
4075: $currcanclone = 'instcode';
4076: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4077: }
4078: }
4079: } elsif ($settings->{'canclone'} eq 'domain') {
4080: $currcanclone = $settings->{'canclone'};
4081: }
4082: }
4083: }
4084: foreach my $option (@cloneoptions) {
4085: my ($checked,$additional);
4086: if ($currcanclone eq $option) {
4087: $checked = ' checked="checked"';
4088: }
4089: if ($option eq 'instcode') {
4090: if (@code_order) {
4091: my $show = 'none';
4092: if ($checked) {
4093: $show = 'block';
4094: }
4095: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4096: &mt('Institutional codes for new and cloned course have identical:').
4097: '<br />';
4098: foreach my $item (@code_order) {
4099: my $codechk;
4100: if ($checked) {
4101: if (grep(/^\Q$item\E$/,@posscodes)) {
4102: $codechk = ' checked="checked"';
4103: }
4104: }
4105: $additional .= '<label>'.
4106: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4107: $item.'</label>';
4108: }
4109: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4110: }
4111: }
4112: $datatable .=
4113: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4114: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4115: '</label> '.$additional.'</span><br />';
4116: }
4117: $datatable .= '</td>'.
4118: '</tr>';
4119: $itemcount ++;
1.139 raeburn 4120: } else {
4121: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 4122: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 4123: my $currusecredits = 0;
1.160.6.57 raeburn 4124: my $postsubmitclient = 1;
1.160.6.30 raeburn 4125: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 4126: if (ref($settings) eq 'HASH') {
4127: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 4128: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4129: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4130: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4131: }
4132: }
1.160.6.16 raeburn 4133: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 4134: foreach my $type (@types) {
4135: next if ($type eq 'community');
4136: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4137: if ($defcredits{$type} ne '') {
4138: $currusecredits = 1;
4139: }
4140: }
4141: }
4142: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4143: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4144: $postsubmitclient = 0;
4145: foreach my $type (@types) {
4146: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4147: }
4148: } else {
4149: foreach my $type (@types) {
4150: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4151: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
4152: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
4153: } else {
4154: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4155: }
4156: } else {
4157: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4158: }
4159: }
4160: }
4161: } else {
4162: foreach my $type (@types) {
4163: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 4164: }
4165: }
1.160.6.70 raeburn 4166: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4167: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4168: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4169: }
4170: } else {
4171: foreach my $type (@types) {
4172: $currmysql{$type} = $staticdefaults{'mysqltables'};
4173: }
4174: }
1.160.6.58 raeburn 4175: } else {
4176: foreach my $type (@types) {
4177: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4178: }
1.139 raeburn 4179: }
4180: if (!$currdefresponder) {
1.160.6.21 raeburn 4181: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4182: } elsif ($currdefresponder < 1) {
4183: $currdefresponder = 1;
4184: }
1.160.6.21 raeburn 4185: foreach my $type (@types) {
4186: if ($curruploadquota{$type} eq '') {
4187: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4188: }
4189: }
1.139 raeburn 4190: $datatable .=
1.160.6.16 raeburn 4191: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4192: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4193: '</span></td>'.
4194: '<td class="LC_right_item"><span class="LC_nobreak">'.
4195: '<input type="text" name="anonsurvey_threshold"'.
4196: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 4197: '</td></tr>'."\n";
4198: $itemcount ++;
4199: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4200: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4201: $choices{'uploadquota'}.
4202: '</span></td>'.
4203: '<td align="right" class="LC_right_item">'.
4204: '<table><tr>';
1.160.6.21 raeburn 4205: foreach my $type (@types) {
4206: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4207: '<input type="text" name="uploadquota_'.$type.'"'.
4208: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4209: }
4210: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 4211: $itemcount ++;
1.160.6.40 raeburn 4212: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 4213: my $display = 'none';
4214: if ($currusecredits) {
4215: $display = 'block';
4216: }
4217: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 4218: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4219: foreach my $type (@types) {
4220: next if ($type eq 'community');
4221: $additional .= '<td align="center">'.&mt($type).'<br />'.
4222: '<input type="text" name="'.$type.'_credits"'.
4223: ' value="'.$defcredits{$type}.'" size="3" /></td>';
4224: }
4225: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 4226: %defaultchecked = ('coursecredits' => 'off');
4227: @toggles = ('coursecredits');
4228: my $current = {
4229: 'coursecredits' => $currusecredits,
4230: };
4231: (my $table,$itemcount) =
4232: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4233: \%choices,$itemcount,$onclick,$additional,'left');
4234: $datatable .= $table;
4235: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4236: my $display = 'none';
4237: if ($postsubmitclient) {
4238: $display = 'block';
4239: }
4240: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 4241: &mt('Number of seconds submit is disabled').'<br />'.
4242: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4243: '<table><tr>';
1.160.6.57 raeburn 4244: foreach my $type (@types) {
4245: $additional .= '<td align="center">'.&mt($type).'<br />'.
4246: '<input type="text" name="'.$type.'_timeout" value="'.
4247: $deftimeout{$type}.'" size="5" /></td>';
4248: }
4249: $additional .= '</tr></table></div>'."\n";
4250: %defaultchecked = ('postsubmit' => 'on');
4251: @toggles = ('postsubmit');
1.160.6.70 raeburn 4252: $current = {
4253: 'postsubmit' => $postsubmitclient,
4254: };
1.160.6.57 raeburn 4255: ($table,$itemcount) =
4256: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4257: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 4258: $datatable .= $table;
1.160.6.70 raeburn 4259: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4260: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4261: $choices{'mysqltables'}.
4262: '</span></td>'.
4263: '<td align="right" class="LC_right_item">'.
4264: '<table><tr>';
4265: foreach my $type (@types) {
4266: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4267: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 4268: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 4269: }
4270: $datatable .= '</tr></table></td></tr>'."\n";
4271: $itemcount ++;
4272:
1.160.6.37 raeburn 4273: }
4274: $$rowtotal += $itemcount;
4275: return $datatable;
4276: }
4277:
4278: sub print_selfenrollment {
4279: my ($position,$dom,$settings,$rowtotal) = @_;
4280: my ($css_class,$datatable);
4281: my $itemcount = 1;
4282: my @types = ('official','unofficial','community','textbook');
4283: if (($position eq 'top') || ($position eq 'middle')) {
4284: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4285: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
4286: my @rows;
4287: my $key;
4288: if ($position eq 'top') {
4289: $key = 'admin';
4290: if (ref($rowsref) eq 'ARRAY') {
4291: @rows = @{$rowsref};
4292: }
4293: } elsif ($position eq 'middle') {
4294: $key = 'default';
4295: @rows = ('types','registered','approval','limit');
4296: }
4297: foreach my $row (@rows) {
4298: if (defined($titlesref->{$row})) {
4299: $itemcount ++;
4300: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4301: $datatable .= '<tr'.$css_class.'>'.
4302: '<td>'.$titlesref->{$row}.'</td>'.
4303: '<td class="LC_left_item">'.
4304: '<table><tr>';
4305: my (%current,%currentcap);
4306: if (ref($settings) eq 'HASH') {
4307: if (ref($settings->{$key}) eq 'HASH') {
4308: foreach my $type (@types) {
4309: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4310: $current{$type} = $settings->{$key}->{$type}->{$row};
4311: }
4312: if (($row eq 'limit') && ($key eq 'default')) {
4313: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4314: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4315: }
4316: }
4317: }
4318: }
4319: }
4320: my %roles = (
4321: '0' => &Apache::lonnet::plaintext('dc'),
4322: );
4323:
4324: foreach my $type (@types) {
4325: unless (($row eq 'registered') && ($key eq 'default')) {
4326: $datatable .= '<th>'.&mt($type).'</th>';
4327: }
4328: }
4329: unless (($row eq 'registered') && ($key eq 'default')) {
4330: $datatable .= '</tr><tr>';
4331: }
4332: foreach my $type (@types) {
4333: if ($type eq 'community') {
4334: $roles{'1'} = &mt('Community personnel');
4335: } else {
4336: $roles{'1'} = &mt('Course personnel');
4337: }
4338: $datatable .= '<td style="vertical-align: top">';
4339: if ($position eq 'top') {
4340: my %checked;
4341: if ($current{$type} eq '0') {
4342: $checked{'0'} = ' checked="checked"';
4343: } else {
4344: $checked{'1'} = ' checked="checked"';
4345: }
4346: foreach my $role ('1','0') {
4347: $datatable .= '<span class="LC_nobreak"><label>'.
4348: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4349: 'value="'.$role.'"'.$checked{$role}.' />'.
4350: $roles{$role}.'</label></span> ';
4351: }
4352: } else {
4353: if ($row eq 'types') {
4354: my %checked;
4355: if ($current{$type} =~ /^(all|dom)$/) {
4356: $checked{$1} = ' checked="checked"';
4357: } else {
4358: $checked{''} = ' checked="checked"';
4359: }
4360: foreach my $val ('','dom','all') {
4361: $datatable .= '<span class="LC_nobreak"><label>'.
4362: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4363: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4364: }
4365: } elsif ($row eq 'registered') {
4366: my %checked;
4367: if ($current{$type} eq '1') {
4368: $checked{'1'} = ' checked="checked"';
4369: } else {
4370: $checked{'0'} = ' checked="checked"';
4371: }
4372: foreach my $val ('0','1') {
4373: $datatable .= '<span class="LC_nobreak"><label>'.
4374: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4375: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4376: }
4377: } elsif ($row eq 'approval') {
4378: my %checked;
4379: if ($current{$type} =~ /^([12])$/) {
4380: $checked{$1} = ' checked="checked"';
4381: } else {
4382: $checked{'0'} = ' checked="checked"';
4383: }
4384: for my $val (0..2) {
4385: $datatable .= '<span class="LC_nobreak"><label>'.
4386: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4387: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4388: }
4389: } elsif ($row eq 'limit') {
4390: my %checked;
4391: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4392: $checked{$1} = ' checked="checked"';
4393: } else {
4394: $checked{'none'} = ' checked="checked"';
4395: }
4396: my $cap;
4397: if ($currentcap{$type} =~ /^\d+$/) {
4398: $cap = $currentcap{$type};
4399: }
4400: foreach my $val ('none','allstudents','selfenrolled') {
4401: $datatable .= '<span class="LC_nobreak"><label>'.
4402: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4403: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4404: }
4405: $datatable .= '<br />'.
4406: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4407: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4408: '</span>';
4409: }
4410: }
4411: $datatable .= '</td>';
4412: }
4413: $datatable .= '</tr>';
4414: }
4415: $datatable .= '</table></td></tr>';
4416: }
4417: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 4418: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4419: }
4420: $$rowtotal += $itemcount;
4421: return $datatable;
4422: }
4423:
4424: sub print_validation_rows {
4425: my ($caller,$dom,$settings,$rowtotal) = @_;
4426: my ($itemsref,$namesref,$fieldsref);
4427: if ($caller eq 'selfenroll') {
4428: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4429: } elsif ($caller eq 'requestcourses') {
4430: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4431: }
4432: my %currvalidation;
4433: if (ref($settings) eq 'HASH') {
4434: if (ref($settings->{'validation'}) eq 'HASH') {
4435: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 4436: }
1.160.6.39 raeburn 4437: }
4438: my $datatable;
4439: my $itemcount = 0;
4440: foreach my $item (@{$itemsref}) {
4441: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4442: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4443: $namesref->{$item}.
4444: '</span></td>'.
4445: '<td class="LC_left_item">';
4446: if (($item eq 'url') || ($item eq 'button')) {
4447: $datatable .= '<span class="LC_nobreak">'.
4448: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4449: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4450: } elsif ($item eq 'fields') {
4451: my @currfields;
4452: if (ref($currvalidation{$item}) eq 'ARRAY') {
4453: @currfields = @{$currvalidation{$item}};
4454: }
4455: foreach my $field (@{$fieldsref}) {
4456: my $check = '';
4457: if (grep(/^\Q$field\E$/,@currfields)) {
4458: $check = ' checked="checked"';
4459: }
4460: $datatable .= '<span class="LC_nobreak"><label>'.
4461: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4462: ' value="'.$field.'"'.$check.' />'.$field.
4463: '</label></span> ';
4464: }
4465: } elsif ($item eq 'markup') {
4466: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
4467: $currvalidation{$item}.
1.160.6.37 raeburn 4468: '</textarea>';
1.160.6.39 raeburn 4469: }
4470: $datatable .= '</td></tr>'."\n";
4471: if (ref($rowtotal)) {
1.160.6.37 raeburn 4472: $itemcount ++;
4473: }
1.139 raeburn 4474: }
1.160.6.39 raeburn 4475: if ($caller eq 'requestcourses') {
4476: my %currhash;
1.160.6.51 raeburn 4477: if (ref($settings) eq 'HASH') {
4478: if (ref($settings->{'validation'}) eq 'HASH') {
4479: if ($settings->{'validation'}{'dc'} ne '') {
4480: $currhash{$settings->{'validation'}{'dc'}} = 1;
4481: }
1.160.6.39 raeburn 4482: }
4483: }
4484: my $numinrow = 2;
4485: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4486: 'validationdc',%currhash);
1.160.6.50 raeburn 4487: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4488: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.160.6.39 raeburn 4489: if ($numdc > 1) {
1.160.6.50 raeburn 4490: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 4491: } else {
1.160.6.50 raeburn 4492: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 4493: }
1.160.6.50 raeburn 4494: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 4495: $itemcount ++;
4496: }
4497: if (ref($rowtotal)) {
4498: $$rowtotal += $itemcount;
4499: }
1.121 raeburn 4500: return $datatable;
1.118 jms 4501: }
4502:
1.137 raeburn 4503: sub print_usersessions {
4504: my ($position,$dom,$settings,$rowtotal) = @_;
4505: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 4506: my (%by_ip,%by_location,@intdoms);
4507: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 4508:
4509: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4510: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4511: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4512: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4513: my $itemcount = 1;
4514: if ($position eq 'top') {
1.152 raeburn 4515: if (keys(%serverhomes) > 1) {
1.145 raeburn 4516: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 4517: my $curroffloadnow;
4518: if (ref($settings) eq 'HASH') {
4519: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4520: $curroffloadnow = $settings->{'offloadnow'};
4521: }
4522: }
4523: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4524: } else {
1.140 raeburn 4525: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4526: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 4527: }
1.137 raeburn 4528: } else {
1.145 raeburn 4529: if (keys(%by_location) == 0) {
4530: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4531: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 4532: } else {
4533: my %lt = &usersession_titles();
4534: my $numinrow = 5;
4535: my $prefix;
4536: my @types;
4537: if ($position eq 'bottom') {
4538: $prefix = 'remote';
4539: @types = ('version','excludedomain','includedomain');
4540: } else {
4541: $prefix = 'hosted';
4542: @types = ('excludedomain','includedomain');
4543: }
4544: my (%current,%checkedon,%checkedoff);
4545: my @lcversions = &Apache::lonnet::all_loncaparevs();
4546: my @locations = sort(keys(%by_location));
4547: foreach my $type (@types) {
4548: $checkedon{$type} = '';
4549: $checkedoff{$type} = ' checked="checked"';
4550: }
4551: if (ref($settings) eq 'HASH') {
4552: if (ref($settings->{$prefix}) eq 'HASH') {
4553: foreach my $key (keys(%{$settings->{$prefix}})) {
4554: $current{$key} = $settings->{$prefix}{$key};
4555: if ($key eq 'version') {
4556: if ($current{$key} ne '') {
4557: $checkedon{$key} = ' checked="checked"';
4558: $checkedoff{$key} = '';
4559: }
4560: } elsif (ref($current{$key}) eq 'ARRAY') {
4561: $checkedon{$key} = ' checked="checked"';
4562: $checkedoff{$key} = '';
4563: }
1.137 raeburn 4564: }
4565: }
4566: }
1.145 raeburn 4567: foreach my $type (@types) {
4568: next if ($type ne 'version' && !@locations);
4569: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4570: $datatable .= '<tr'.$css_class.'>
4571: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
4572: <span class="LC_nobreak">
4573: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4574: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4575: if ($type eq 'version') {
4576: my $selector = '<select name="'.$prefix.'_version">';
4577: foreach my $version (@lcversions) {
4578: my $selected = '';
4579: if ($current{'version'} eq $version) {
4580: $selected = ' selected="selected"';
4581: }
4582: $selector .= ' <option value="'.$version.'"'.
4583: $selected.'>'.$version.'</option>';
4584: }
4585: $selector .= '</select> ';
4586: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4587: } else {
4588: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4589: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4590: ' />'.(' 'x2).
4591: '<input type="button" value="'.&mt('uncheck all').'" '.
4592: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4593: "\n".
4594: '</div><div><table>';
4595: my $rem;
4596: for (my $i=0; $i<@locations; $i++) {
4597: my ($showloc,$value,$checkedtype);
4598: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4599: my $ip = $by_location{$locations[$i]}->[0];
4600: if (ref($by_ip{$ip}) eq 'ARRAY') {
4601: $value = join(':',@{$by_ip{$ip}});
4602: $showloc = join(', ',@{$by_ip{$ip}});
4603: if (ref($current{$type}) eq 'ARRAY') {
4604: foreach my $loc (@{$by_ip{$ip}}) {
4605: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4606: $checkedtype = ' checked="checked"';
4607: last;
4608: }
4609: }
1.138 raeburn 4610: }
4611: }
4612: }
1.145 raeburn 4613: $rem = $i%($numinrow);
4614: if ($rem == 0) {
4615: if ($i > 0) {
4616: $datatable .= '</tr>';
4617: }
4618: $datatable .= '<tr>';
4619: }
4620: $datatable .= '<td class="LC_left_item">'.
4621: '<span class="LC_nobreak"><label>'.
4622: '<input type="checkbox" name="'.$prefix.'_'.$type.
4623: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4624: '</label></span></td>';
1.137 raeburn 4625: }
1.145 raeburn 4626: $rem = @locations%($numinrow);
4627: my $colsleft = $numinrow - $rem;
4628: if ($colsleft > 1 ) {
4629: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4630: ' </td>';
4631: } elsif ($colsleft == 1) {
4632: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4633: }
1.145 raeburn 4634: $datatable .= '</tr></table>';
1.137 raeburn 4635: }
1.145 raeburn 4636: $datatable .= '</td></tr>';
4637: $itemcount ++;
1.137 raeburn 4638: }
4639: }
4640: }
4641: $$rowtotal += $itemcount;
4642: return $datatable;
4643: }
4644:
1.138 raeburn 4645: sub build_location_hashes {
4646: my ($intdoms,$by_ip,$by_location) = @_;
4647: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
4648: (ref($by_location) eq 'HASH'));
4649: my %iphost = &Apache::lonnet::get_iphost();
4650: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4651: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4652: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4653: foreach my $id (@{$iphost{$primary_ip}}) {
4654: my $intdom = &Apache::lonnet::internet_dom($id);
4655: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4656: push(@{$intdoms},$intdom);
4657: }
4658: }
4659: }
4660: foreach my $ip (keys(%iphost)) {
4661: if (ref($iphost{$ip}) eq 'ARRAY') {
4662: foreach my $id (@{$iphost{$ip}}) {
4663: my $location = &Apache::lonnet::internet_dom($id);
4664: if ($location) {
4665: next if (grep(/^\Q$location\E$/,@{$intdoms}));
4666: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4667: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4668: push(@{$by_ip->{$ip}},$location);
4669: }
4670: } else {
4671: $by_ip->{$ip} = [$location];
4672: }
4673: }
4674: }
4675: }
4676: }
4677: foreach my $ip (sort(keys(%{$by_ip}))) {
4678: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4679: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4680: my $first = $by_ip->{$ip}->[0];
4681: if (ref($by_location->{$first}) eq 'ARRAY') {
4682: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4683: push(@{$by_location->{$first}},$ip);
4684: }
4685: } else {
4686: $by_location->{$first} = [$ip];
4687: }
4688: }
4689: }
4690: return;
4691: }
4692:
1.145 raeburn 4693: sub current_offloads_to {
4694: my ($dom,$settings,$servers) = @_;
4695: my (%spareid,%otherdomconfigs);
1.152 raeburn 4696: if (ref($servers) eq 'HASH') {
1.145 raeburn 4697: foreach my $lonhost (sort(keys(%{$servers}))) {
4698: my $gotspares;
1.152 raeburn 4699: if (ref($settings) eq 'HASH') {
4700: if (ref($settings->{'spares'}) eq 'HASH') {
4701: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4702: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4703: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4704: $gotspares = 1;
4705: }
1.145 raeburn 4706: }
4707: }
4708: unless ($gotspares) {
4709: my $gotspares;
4710: my $serverhomeID =
4711: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4712: my $serverhomedom =
4713: &Apache::lonnet::host_domain($serverhomeID);
4714: if ($serverhomedom ne $dom) {
4715: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4716: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4717: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4718: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4719: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4720: $gotspares = 1;
4721: }
4722: }
4723: } else {
4724: $otherdomconfigs{$serverhomedom} =
4725: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4726: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4727: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4728: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4729: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4730: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4731: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4732: $gotspares = 1;
4733: }
4734: }
4735: }
4736: }
4737: }
4738: }
4739: }
4740: unless ($gotspares) {
4741: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4742: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4743: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4744: } else {
4745: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4746: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4747: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4748: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4749: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4750: } else {
1.150 raeburn 4751: my %what = (
4752: spareid => 1,
4753: );
4754: my ($result,$returnhash) =
4755: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4756: if ($result eq 'ok') {
4757: if (ref($returnhash) eq 'HASH') {
4758: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4759: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4760: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4761: }
4762: }
1.145 raeburn 4763: }
4764: }
4765: }
4766: }
4767: }
4768: }
4769: return %spareid;
4770: }
4771:
4772: sub spares_row {
1.160.6.61 raeburn 4773: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4774: my $css_class;
4775: my $numinrow = 4;
4776: my $itemcount = 1;
4777: my $datatable;
1.152 raeburn 4778: my %typetitles = &sparestype_titles();
4779: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4780: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4781: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4782: my ($othercontrol,$serverdom);
4783: if ($serverhome ne $server) {
4784: $serverdom = &Apache::lonnet::host_domain($serverhome);
4785: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4786: } else {
4787: $serverdom = &Apache::lonnet::host_domain($server);
4788: if ($serverdom ne $dom) {
4789: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4790: }
4791: }
4792: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 4793: my $checkednow;
4794: if (ref($curroffloadnow) eq 'HASH') {
4795: if ($curroffloadnow->{$server}) {
4796: $checkednow = ' checked="checked"';
4797: }
4798: }
1.145 raeburn 4799: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4800: $datatable .= '<tr'.$css_class.'>
4801: <td rowspan="2">
1.160.6.13 raeburn 4802: <span class="LC_nobreak">'.
4803: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 4804: ,'<b>'.$server.'</b>').'</span><br />'.
4805: '<span class="LC_nobreak">'."\n".
4806: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4807: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 4808: "\n";
1.145 raeburn 4809: my (%current,%canselect);
1.152 raeburn 4810: my @choices =
4811: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4812: foreach my $type ('primary','default') {
4813: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4814: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4815: my @spares = @{$spareid->{$server}{$type}};
4816: if (@spares > 0) {
1.152 raeburn 4817: if ($othercontrol) {
4818: $current{$type} = join(', ',@spares);
4819: } else {
4820: $current{$type} .= '<table>';
4821: my $numspares = scalar(@spares);
4822: for (my $i=0; $i<@spares; $i++) {
4823: my $rem = $i%($numinrow);
4824: if ($rem == 0) {
4825: if ($i > 0) {
4826: $current{$type} .= '</tr>';
4827: }
4828: $current{$type} .= '<tr>';
1.145 raeburn 4829: }
1.152 raeburn 4830: $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'".');" /> '.
4831: $spareid->{$server}{$type}[$i].
4832: '</label></td>'."\n";
4833: }
4834: my $rem = @spares%($numinrow);
4835: my $colsleft = $numinrow - $rem;
4836: if ($colsleft > 1 ) {
4837: $current{$type} .= '<td colspan="'.$colsleft.
4838: '" class="LC_left_item">'.
4839: ' </td>';
4840: } elsif ($colsleft == 1) {
4841: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4842: }
1.152 raeburn 4843: $current{$type} .= '</tr></table>';
1.150 raeburn 4844: }
1.145 raeburn 4845: }
4846: }
4847: if ($current{$type} eq '') {
4848: $current{$type} = &mt('None specified');
4849: }
1.152 raeburn 4850: if ($othercontrol) {
4851: if ($type eq 'primary') {
4852: $canselect{$type} = $othercontrol;
4853: }
4854: } else {
4855: $canselect{$type} =
4856: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4857: '<select name="newspare_'.$type.'_'.$server.'" '.
4858: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4859: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4860: if (@choices > 0) {
4861: foreach my $lonhost (@choices) {
4862: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4863: }
4864: }
4865: $canselect{$type} .= '</select>'."\n";
4866: }
4867: } else {
4868: $current{$type} = &mt('Could not be determined');
4869: if ($type eq 'primary') {
4870: $canselect{$type} = $othercontrol;
4871: }
1.145 raeburn 4872: }
1.152 raeburn 4873: if ($type eq 'default') {
4874: $datatable .= '<tr'.$css_class.'>';
4875: }
4876: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4877: '<td>'.$current{$type}.'</td>'."\n".
4878: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4879: }
4880: $itemcount ++;
4881: }
4882: }
4883: $$rowtotal += $itemcount;
4884: return $datatable;
4885: }
4886:
1.152 raeburn 4887: sub possible_newspares {
4888: my ($server,$currspares,$serverhomes,$altids) = @_;
4889: my $serverhostname = &Apache::lonnet::hostname($server);
4890: my %excluded;
4891: if ($serverhostname ne '') {
4892: %excluded = (
4893: $serverhostname => 1,
4894: );
4895: }
4896: if (ref($currspares) eq 'HASH') {
4897: foreach my $type (keys(%{$currspares})) {
4898: if (ref($currspares->{$type}) eq 'ARRAY') {
4899: if (@{$currspares->{$type}} > 0) {
4900: foreach my $curr (@{$currspares->{$type}}) {
4901: my $hostname = &Apache::lonnet::hostname($curr);
4902: $excluded{$hostname} = 1;
4903: }
4904: }
4905: }
4906: }
4907: }
4908: my @choices;
4909: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4910: if (keys(%{$serverhomes}) > 1) {
4911: foreach my $name (sort(keys(%{$serverhomes}))) {
4912: unless ($excluded{$name}) {
4913: if (exists($altids->{$serverhomes->{$name}})) {
4914: push(@choices,$altids->{$serverhomes->{$name}});
4915: } else {
4916: push(@choices,$serverhomes->{$name});
1.145 raeburn 4917: }
4918: }
4919: }
4920: }
4921: }
1.152 raeburn 4922: return sort(@choices);
1.145 raeburn 4923: }
4924:
1.150 raeburn 4925: sub print_loadbalancing {
4926: my ($dom,$settings,$rowtotal) = @_;
4927: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4928: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4929: my $numinrow = 1;
4930: my $datatable;
4931: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 4932: my (%currbalancer,%currtargets,%currrules,%existing);
4933: if (ref($settings) eq 'HASH') {
4934: %existing = %{$settings};
4935: }
4936: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4937: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
4938: \%currtargets,\%currrules);
1.150 raeburn 4939: } else {
4940: return;
4941: }
4942: my ($othertitle,$usertypes,$types) =
4943: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 4944: my $rownum = 8;
1.150 raeburn 4945: if (ref($types) eq 'ARRAY') {
4946: $rownum += scalar(@{$types});
4947: }
1.160.6.7 raeburn 4948: my @css_class = ('LC_odd_row','LC_even_row');
4949: my $balnum = 0;
4950: my $islast;
4951: my (@toshow,$disabledtext);
4952: if (keys(%currbalancer) > 0) {
4953: @toshow = sort(keys(%currbalancer));
4954: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4955: push(@toshow,'');
4956: }
4957: } else {
4958: @toshow = ('');
4959: $disabledtext = &mt('No existing load balancer');
4960: }
4961: foreach my $lonhost (@toshow) {
4962: if ($balnum == scalar(@toshow)-1) {
4963: $islast = 1;
4964: } else {
4965: $islast = 0;
4966: }
4967: my $cssidx = $balnum%2;
4968: my $targets_div_style = 'display: none';
4969: my $disabled_div_style = 'display: block';
4970: my $homedom_div_style = 'display: none';
4971: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4972: '<td rowspan="'.$rownum.'" valign="top">'.
4973: '<p>';
4974: if ($lonhost eq '') {
4975: $datatable .= '<span class="LC_nobreak">';
4976: if (keys(%currbalancer) > 0) {
4977: $datatable .= &mt('Add balancer:');
4978: } else {
4979: $datatable .= &mt('Enable balancer:');
4980: }
4981: $datatable .= ' '.
4982: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4983: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4984: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4985: '<option value="" selected="selected">'.&mt('None').
4986: '</option>'."\n";
4987: foreach my $server (sort(keys(%servers))) {
4988: next if ($currbalancer{$server});
4989: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4990: }
4991: $datatable .=
4992: '</select>'."\n".
4993: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4994: } else {
4995: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4996: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4997: &mt('Stop balancing').'</label>'.
4998: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4999: $targets_div_style = 'display: block';
5000: $disabled_div_style = 'display: none';
5001: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5002: $homedom_div_style = 'display: block';
5003: }
5004: }
5005: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
5006: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5007: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5008: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5009: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5010: my @sparestypes = ('primary','default');
5011: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 5012: my %hostherechecked = (
5013: no => ' checked="checked"',
5014: );
1.160.6.7 raeburn 5015: foreach my $sparetype (@sparestypes) {
5016: my $targettable;
5017: for (my $i=0; $i<$numspares; $i++) {
5018: my $checked;
5019: if (ref($currtargets{$lonhost}) eq 'HASH') {
5020: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5021: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5022: $checked = ' checked="checked"';
5023: }
5024: }
5025: }
5026: my ($chkboxval,$disabled);
5027: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5028: $chkboxval = $spares[$i];
5029: }
5030: if (exists($currbalancer{$spares[$i]})) {
5031: $disabled = ' disabled="disabled"';
5032: }
5033: $targettable .=
1.160.6.55 raeburn 5034: '<td><span class="LC_nobreak"><label>'.
5035: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 5036: $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 5037: '</span></label></span></td>';
1.160.6.7 raeburn 5038: my $rem = $i%($numinrow);
5039: if ($rem == 0) {
5040: if (($i > 0) && ($i < $numspares-1)) {
5041: $targettable .= '</tr>';
5042: }
5043: if ($i < $numspares-1) {
5044: $targettable .= '<tr>';
1.150 raeburn 5045: }
5046: }
5047: }
1.160.6.7 raeburn 5048: if ($targettable ne '') {
5049: my $rem = $numspares%($numinrow);
5050: my $colsleft = $numinrow - $rem;
5051: if ($colsleft > 1 ) {
5052: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5053: ' </td>';
5054: } elsif ($colsleft == 1) {
5055: $targettable .= '<td class="LC_left_item"> </td>';
5056: }
5057: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5058: '<table><tr>'.$targettable.'</tr></table><br />';
5059: }
1.160.6.76 raeburn 5060: $hostherechecked{$sparetype} = '';
5061: if (ref($currtargets{$lonhost}) eq 'HASH') {
5062: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5063: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5064: $hostherechecked{$sparetype} = ' checked="checked"';
5065: $hostherechecked{'no'} = '';
5066: }
5067: }
5068: }
5069: }
5070: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5071: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5072: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5073: foreach my $sparetype (@sparestypes) {
5074: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5075: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5076: '</i></label><br />';
1.160.6.7 raeburn 5077: }
5078: $datatable .= '</div></td></tr>'.
5079: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5080: $othertitle,$usertypes,$types,\%servers,
5081: \%currbalancer,$lonhost,
5082: $targets_div_style,$homedom_div_style,
5083: $css_class[$cssidx],$balnum,$islast);
5084: $$rowtotal += $rownum;
5085: $balnum ++;
5086: }
5087: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5088: return $datatable;
5089: }
5090:
5091: sub get_loadbalancers_config {
5092: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
5093: return unless ((ref($servers) eq 'HASH') &&
5094: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
5095: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
5096: if (keys(%{$existing}) > 0) {
5097: my $oldlonhost;
5098: foreach my $key (sort(keys(%{$existing}))) {
5099: if ($key eq 'lonhost') {
5100: $oldlonhost = $existing->{'lonhost'};
5101: $currbalancer->{$oldlonhost} = 1;
5102: } elsif ($key eq 'targets') {
5103: if ($oldlonhost) {
5104: $currtargets->{$oldlonhost} = $existing->{'targets'};
5105: }
5106: } elsif ($key eq 'rules') {
5107: if ($oldlonhost) {
5108: $currrules->{$oldlonhost} = $existing->{'rules'};
5109: }
5110: } elsif (ref($existing->{$key}) eq 'HASH') {
5111: $currbalancer->{$key} = 1;
5112: $currtargets->{$key} = $existing->{$key}{'targets'};
5113: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 5114: }
5115: }
1.160.6.7 raeburn 5116: } else {
5117: my ($balancerref,$targetsref) =
5118: &Apache::lonnet::get_lonbalancer_config($servers);
5119: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5120: foreach my $server (sort(keys(%{$balancerref}))) {
5121: $currbalancer->{$server} = 1;
5122: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5123: }
5124: }
5125: }
1.160.6.7 raeburn 5126: return;
1.150 raeburn 5127: }
5128:
5129: sub loadbalancing_rules {
5130: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 5131: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5132: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5133: my $output;
1.160.6.7 raeburn 5134: my $num = 0;
5135: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5136: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5137: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5138: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 5139: $num ++;
1.150 raeburn 5140: my $current;
5141: if (ref($currrules) eq 'HASH') {
5142: $current = $currrules->{$type};
5143: }
1.160.6.55 raeburn 5144: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 5145: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5146: $current = '';
5147: }
5148: }
5149: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 5150: $servers,$currbalancer,$lonhost,$dom,
5151: $targets_div_style,$homedom_div_style,
5152: $css_class,$balnum,$num,$islast);
1.150 raeburn 5153: }
5154: }
5155: return $output;
5156: }
5157:
5158: sub loadbalancing_titles {
5159: my ($dom,$intdom,$usertypes,$types) = @_;
5160: my %othertypes = (
5161: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5162: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5163: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5164: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 5165: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5166: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5167: );
1.160.6.26 raeburn 5168: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 5169: if (ref($types) eq 'ARRAY') {
5170: unshift(@alltypes,@{$types},'default');
5171: }
5172: my %titles;
5173: foreach my $type (@alltypes) {
5174: if ($type =~ /^_LC_/) {
5175: $titles{$type} = $othertypes{$type};
5176: } elsif ($type eq 'default') {
5177: $titles{$type} = &mt('All users from [_1]',$dom);
5178: if (ref($types) eq 'ARRAY') {
5179: if (@{$types} > 0) {
5180: $titles{$type} = &mt('Other users from [_1]',$dom);
5181: }
5182: }
5183: } elsif (ref($usertypes) eq 'HASH') {
5184: $titles{$type} = $usertypes->{$type};
5185: }
5186: }
5187: return (\@alltypes,\%othertypes,\%titles);
5188: }
5189:
5190: sub loadbalance_rule_row {
1.160.6.7 raeburn 5191: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5192: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 5193: my @rulenames;
1.150 raeburn 5194: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 5195: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 5196: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 5197: } else {
1.160.6.26 raeburn 5198: @rulenames = ('default','homeserver');
5199: if ($type eq '_LC_external') {
5200: push(@rulenames,'externalbalancer');
5201: } else {
5202: push(@rulenames,'specific');
5203: }
5204: push(@rulenames,'none');
1.150 raeburn 5205: }
5206: my $style = $targets_div_style;
1.160.6.55 raeburn 5207: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 5208: $style = $homedom_div_style;
5209: }
1.160.6.7 raeburn 5210: my $space;
5211: if ($islast && $num == 1) {
5212: $space = '<div display="inline-block"> </div>';
5213: }
5214: my $output =
5215: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
5216: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5217: '<td valaign="top">'.$space.
5218: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 5219: for (my $i=0; $i<@rulenames; $i++) {
5220: my $rule = $rulenames[$i];
5221: my ($checked,$extra);
5222: if ($rulenames[$i] eq 'default') {
5223: $rule = '';
5224: }
5225: if ($rulenames[$i] eq 'specific') {
5226: if (ref($servers) eq 'HASH') {
5227: my $default;
5228: if (($current ne '') && (exists($servers->{$current}))) {
5229: $checked = ' checked="checked"';
5230: }
5231: unless ($checked) {
5232: $default = ' selected="selected"';
5233: }
1.160.6.7 raeburn 5234: $extra =
5235: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5236: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5237: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5238: '<option value=""'.$default.'></option>'."\n";
5239: foreach my $server (sort(keys(%{$servers}))) {
5240: if (ref($currbalancer) eq 'HASH') {
5241: next if (exists($currbalancer->{$server}));
5242: }
1.150 raeburn 5243: my $selected;
1.160.6.7 raeburn 5244: if ($server eq $current) {
1.150 raeburn 5245: $selected = ' selected="selected"';
5246: }
1.160.6.7 raeburn 5247: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 5248: }
5249: $extra .= '</select>';
5250: }
5251: } elsif ($rule eq $current) {
5252: $checked = ' checked="checked"';
5253: }
5254: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 5255: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5256: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5257: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 5258: ')"'.$checked.' /> ';
1.160.6.56 raeburn 5259: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 5260: $output .= $ruletitles{'particular'};
5261: } else {
5262: $output .= $ruletitles{$rulenames[$i]};
5263: }
5264: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 5265: }
5266: $output .= '</div></td></tr>'."\n";
5267: return $output;
5268: }
5269:
5270: sub offloadtype_text {
5271: my %ruletitles = &Apache::lonlocal::texthash (
5272: 'default' => 'Offloads to default destinations',
5273: 'homeserver' => "Offloads to user's home server",
5274: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5275: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 5276: 'none' => 'No offload',
1.160.6.26 raeburn 5277: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5278: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 5279: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 5280: );
5281: return %ruletitles;
5282: }
5283:
5284: sub sparestype_titles {
5285: my %typestitles = &Apache::lonlocal::texthash (
5286: 'primary' => 'primary',
5287: 'default' => 'default',
5288: );
5289: return %typestitles;
5290: }
5291:
1.28 raeburn 5292: sub contact_titles {
5293: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 5294: 'supportemail' => 'Support E-mail address',
5295: 'adminemail' => 'Default Server Admin E-mail address',
5296: 'errormail' => 'Error reports to be e-mailed to',
5297: 'packagesmail' => 'Package update alerts to be e-mailed to',
5298: 'helpdeskmail' => "Helpdesk requests for this domain's users",
5299: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
5300: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5301: 'requestsmail' => 'E-mail from course requests requiring approval',
5302: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 5303: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 5304: );
5305: my %short_titles = &Apache::lonlocal::texthash (
5306: adminemail => 'Admin E-mail address',
5307: supportemail => 'Support E-mail',
5308: );
5309: return (\%titles,\%short_titles);
5310: }
5311:
1.160.6.78 raeburn 5312: sub helpform_fields {
5313: my %titles = &Apache::lonlocal::texthash (
5314: 'username' => 'Name',
5315: 'user' => 'Username/domain',
5316: 'phone' => 'Phone',
5317: 'cc' => 'Cc e-mail',
5318: 'course' => 'Course Details',
5319: 'section' => 'Sections',
5320: 'screenshot' => 'File upload',
5321: );
5322: my @fields = ('username','phone','user','course','section','cc','screenshot');
5323: my %possoptions = (
5324: username => ['yes','no','req'],
5325: phone => ['yes','no','req'],
5326: user => ['yes','no'],
5327: cc => ['yes','no'],
5328: course => ['yes','no'],
5329: section => ['yes','no'],
5330: screenshot => ['yes','no'],
5331: );
5332: my %fieldoptions = &Apache::lonlocal::texthash (
5333: 'yes' => 'Optional',
5334: 'req' => 'Required',
5335: 'no' => "Not shown",
5336: );
5337: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5338: }
5339:
1.72 raeburn 5340: sub tool_titles {
5341: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 5342: aboutme => 'Personal web page',
1.86 raeburn 5343: blog => 'Blog',
1.160.6.4 raeburn 5344: webdav => 'WebDAV',
1.86 raeburn 5345: portfolio => 'Portfolio',
1.88 bisitz 5346: official => 'Official courses (with institutional codes)',
5347: unofficial => 'Unofficial courses',
1.98 raeburn 5348: community => 'Communities',
1.160.6.30 raeburn 5349: textbook => 'Textbook courses',
1.86 raeburn 5350: );
1.72 raeburn 5351: return %titles;
5352: }
5353:
1.101 raeburn 5354: sub courserequest_titles {
5355: my %titles = &Apache::lonlocal::texthash (
5356: official => 'Official',
5357: unofficial => 'Unofficial',
5358: community => 'Communities',
1.160.6.30 raeburn 5359: textbook => 'Textbook',
1.101 raeburn 5360: norequest => 'Not allowed',
1.104 raeburn 5361: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5362: validate => 'With validation',
5363: autolimit => 'Numerical limit',
1.103 raeburn 5364: unlimited => '(blank for unlimited)',
1.101 raeburn 5365: );
5366: return %titles;
5367: }
5368:
1.160.6.5 raeburn 5369: sub authorrequest_titles {
5370: my %titles = &Apache::lonlocal::texthash (
5371: norequest => 'Not allowed',
5372: approval => 'Approval by Dom. Coord.',
5373: automatic => 'Automatic approval',
5374: );
5375: return %titles;
5376: }
5377:
1.101 raeburn 5378: sub courserequest_conditions {
5379: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5380: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 5381: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 5382: );
5383: return %conditions;
5384: }
5385:
5386:
1.27 raeburn 5387: sub print_usercreation {
1.30 raeburn 5388: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 5389: my $numinrow = 4;
1.28 raeburn 5390: my $datatable;
5391: if ($position eq 'top') {
1.30 raeburn 5392: $$rowtotal ++;
1.34 raeburn 5393: my $rowcount = 0;
1.32 raeburn 5394: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 5395: if (ref($rules) eq 'HASH') {
5396: if (keys(%{$rules}) > 0) {
1.32 raeburn 5397: $datatable .= &user_formats_row('username',$settings,$rules,
5398: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 5399: $$rowtotal ++;
1.32 raeburn 5400: $rowcount ++;
5401: }
5402: }
5403: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5404: if (ref($idrules) eq 'HASH') {
5405: if (keys(%{$idrules}) > 0) {
5406: $datatable .= &user_formats_row('id',$settings,$idrules,
5407: $idruleorder,$numinrow,$rowcount);
5408: $$rowtotal ++;
5409: $rowcount ++;
1.28 raeburn 5410: }
5411: }
1.39 raeburn 5412: if ($rowcount == 0) {
5413: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5414: $$rowtotal ++;
5415: $rowcount ++;
5416: }
1.34 raeburn 5417: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 5418: my @creators = ('author','course','requestcrs');
1.37 raeburn 5419: my ($rules,$ruleorder) =
5420: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 5421: my %lt = &usercreation_types();
5422: my %checked;
5423: if (ref($settings) eq 'HASH') {
5424: if (ref($settings->{'cancreate'}) eq 'HASH') {
5425: foreach my $item (@creators) {
5426: $checked{$item} = $settings->{'cancreate'}{$item};
5427: }
5428: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5429: foreach my $item (@creators) {
5430: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5431: $checked{$item} = 'none';
5432: }
5433: }
5434: }
5435: }
5436: my $rownum = 0;
5437: foreach my $item (@creators) {
5438: $rownum ++;
1.160.6.34 raeburn 5439: if ($checked{$item} eq '') {
5440: $checked{$item} = 'any';
1.34 raeburn 5441: }
5442: my $css_class;
5443: if ($rownum%2) {
5444: $css_class = '';
5445: } else {
5446: $css_class = ' class="LC_odd_row" ';
5447: }
5448: $datatable .= '<tr'.$css_class.'>'.
5449: '<td><span class="LC_nobreak">'.$lt{$item}.
5450: '</span></td><td align="right">';
1.160.6.34 raeburn 5451: my @options = ('any');
5452: if (ref($rules) eq 'HASH') {
5453: if (keys(%{$rules}) > 0) {
5454: push(@options,('official','unofficial'));
1.37 raeburn 5455: }
5456: }
1.160.6.34 raeburn 5457: push(@options,'none');
1.37 raeburn 5458: foreach my $option (@options) {
1.50 raeburn 5459: my $type = 'radio';
1.34 raeburn 5460: my $check = ' ';
1.160.6.34 raeburn 5461: if ($checked{$item} eq $option) {
5462: $check = ' checked="checked" ';
1.34 raeburn 5463: }
5464: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5465: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5466: $item.'" value="'.$option.'"'.$check.'/> '.
5467: $lt{$option}.'</label> </span>';
5468: }
5469: $datatable .= '</td></tr>';
5470: }
1.28 raeburn 5471: } else {
5472: my @contexts = ('author','course','domain');
5473: my @authtypes = ('int','krb4','krb5','loc');
5474: my %checked;
5475: if (ref($settings) eq 'HASH') {
5476: if (ref($settings->{'authtypes'}) eq 'HASH') {
5477: foreach my $item (@contexts) {
5478: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5479: foreach my $auth (@authtypes) {
5480: if ($settings->{'authtypes'}{$item}{$auth}) {
5481: $checked{$item}{$auth} = ' checked="checked" ';
5482: }
5483: }
5484: }
5485: }
1.27 raeburn 5486: }
1.35 raeburn 5487: } else {
5488: foreach my $item (@contexts) {
1.36 raeburn 5489: foreach my $auth (@authtypes) {
1.35 raeburn 5490: $checked{$item}{$auth} = ' checked="checked" ';
5491: }
5492: }
1.27 raeburn 5493: }
1.28 raeburn 5494: my %title = &context_names();
5495: my %authname = &authtype_names();
5496: my $rownum = 0;
5497: my $css_class;
5498: foreach my $item (@contexts) {
5499: if ($rownum%2) {
5500: $css_class = '';
5501: } else {
5502: $css_class = ' class="LC_odd_row" ';
5503: }
1.30 raeburn 5504: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5505: '<td>'.$title{$item}.
5506: '</td><td class="LC_left_item">'.
5507: '<span class="LC_nobreak">';
5508: foreach my $auth (@authtypes) {
5509: $datatable .= '<label>'.
5510: '<input type="checkbox" name="'.$item.'_auth" '.
5511: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5512: $authname{$auth}.'</label> ';
5513: }
5514: $datatable .= '</span></td></tr>';
5515: $rownum ++;
1.27 raeburn 5516: }
1.30 raeburn 5517: $$rowtotal += $rownum;
1.27 raeburn 5518: }
5519: return $datatable;
5520: }
5521:
1.160.6.34 raeburn 5522: sub print_selfcreation {
5523: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 5524: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 5525: if (ref($settings) eq 'HASH') {
5526: if (ref($settings->{'cancreate'}) eq 'HASH') {
5527: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 5528: if (ref($createsettings) eq 'HASH') {
5529: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5530: @selfcreate = @{$createsettings->{'selfcreate'}};
5531: } elsif ($createsettings->{'selfcreate'} ne '') {
5532: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5533: @selfcreate = ('email','login','sso');
5534: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5535: @selfcreate = ($createsettings->{'selfcreate'});
5536: }
5537: }
5538: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5539: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 5540: }
5541: }
5542: }
5543: }
5544: my %radiohash;
5545: my $numinrow = 4;
5546: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5547: if ($position eq 'top') {
5548: my %choices = &Apache::lonlocal::texthash (
5549: cancreate_login => 'Institutional Login',
5550: cancreate_sso => 'Institutional Single Sign On',
5551: );
5552: my @toggles = sort(keys(%choices));
5553: my %defaultchecked = (
5554: 'cancreate_login' => 'off',
5555: 'cancreate_sso' => 'off',
5556: );
1.160.6.35 raeburn 5557: my ($onclick,$itemcount);
1.160.6.34 raeburn 5558: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5559: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 5560: $$rowtotal += $itemcount;
1.160.6.39 raeburn 5561:
1.160.6.34 raeburn 5562: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5563:
5564: if (ref($usertypes) eq 'HASH') {
5565: if (keys(%{$usertypes}) > 0) {
5566: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5567: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 5568: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 5569: $$rowtotal ++;
5570: }
5571: }
1.160.6.44 raeburn 5572: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5573: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5574: $fieldtitles{'inststatus'} = &mt('Institutional status');
5575: my $rem;
5576: my $numperrow = 2;
5577: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5578: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 5579: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 5580: '<td class="LC_left_item">'."\n".
5581: '<table><tr><td>'."\n";
5582: for (my $i=0; $i<@fields; $i++) {
5583: $rem = $i%($numperrow);
5584: if ($rem == 0) {
5585: if ($i > 0) {
5586: $datatable .= '</tr>';
5587: }
5588: $datatable .= '<tr>';
5589: }
5590: my $currval;
1.160.6.51 raeburn 5591: if (ref($createsettings) eq 'HASH') {
5592: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5593: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5594: }
1.160.6.44 raeburn 5595: }
5596: $datatable .= '<td class="LC_left_item">'.
5597: '<span class="LC_nobreak">'.
5598: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5599: 'value="'.$currval.'" size="10" /> '.
5600: $fieldtitles{$fields[$i]}.'</span></td>';
5601: }
5602: my $colsleft = $numperrow - $rem;
5603: if ($colsleft > 1 ) {
5604: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5605: ' </td>';
5606: } elsif ($colsleft == 1) {
5607: $datatable .= '<td class="LC_left_item"> </td>';
5608: }
5609: $datatable .= '</tr></table></td></tr>';
5610: $$rowtotal ++;
1.160.6.34 raeburn 5611: } elsif ($position eq 'middle') {
5612: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5613: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5614: $usertypes->{'default'} = $othertitle;
5615: if (ref($types) eq 'ARRAY') {
5616: push(@{$types},'default');
5617: $usertypes->{'default'} = $othertitle;
5618: foreach my $status (@{$types}) {
5619: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 5620: $numinrow,$$rowtotal,$usertypes);
1.160.6.44 raeburn 5621: $$rowtotal ++;
1.160.6.34 raeburn 5622: }
5623: }
5624: } else {
1.160.6.40 raeburn 5625: my %choices = &Apache::lonlocal::texthash (
5626: cancreate_email => 'E-mail address as username',
5627: );
5628: my @toggles = sort(keys(%choices));
5629: my %defaultchecked = (
5630: 'cancreate_email' => 'off',
5631: );
5632: my $itemcount = 0;
5633: my $display = 'none';
5634: if (grep(/^\Qemail\E$/,@selfcreate)) {
5635: $display = 'block';
5636: }
5637: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5638: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5639: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5640: my $usertypes = {};
5641: my $order = [];
5642: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
5643: $usertypes = $domdefaults{'inststatustypes'};
5644: $order = $domdefaults{'inststatusguest'};
5645: }
5646: if (ref($order) eq 'ARRAY') {
5647: push(@{$order},'default');
5648: if (@{$order} > 1) {
5649: $usertypes->{'default'} = &mt('Other users');
5650: $additional .= '<table><tr>';
5651: foreach my $status (@{$order}) {
5652: $additional .= '<th>'.$usertypes->{$status}.'</th>';
5653: }
5654: $additional .= '</tr><tr>';
5655: foreach my $status (@{$order}) {
5656: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 5657: }
1.160.6.40 raeburn 5658: $additional .= '</tr></table>';
1.160.6.34 raeburn 5659: } else {
1.160.6.40 raeburn 5660: $usertypes->{'default'} = &mt('All users');
5661: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 5662: }
5663: }
1.160.6.40 raeburn 5664: $additional .= '</div>'."\n";
5665:
5666: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 5667: \%choices,$$rowtotal,$onclick,$additional);
5668: $$rowtotal ++;
1.160.6.40 raeburn 5669: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 5670: $$rowtotal ++;
1.160.6.35 raeburn 5671: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5672: $numinrow = 1;
1.160.6.40 raeburn 5673: if (ref($order) eq 'ARRAY') {
5674: foreach my $status (@{$order}) {
1.160.6.35 raeburn 5675: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5676: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
5677: $$rowtotal ++;
5678: }
5679: }
1.160.6.34 raeburn 5680: my ($emailrules,$emailruleorder) =
5681: &Apache::lonnet::inst_userrules($dom,'email');
5682: if (ref($emailrules) eq 'HASH') {
5683: if (keys(%{$emailrules}) > 0) {
5684: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 5685: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 5686: $$rowtotal ++;
5687: }
5688: }
1.160.6.35 raeburn 5689: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 5690: }
5691: return $datatable;
5692: }
5693:
1.160.6.40 raeburn 5694: sub email_as_username {
5695: my ($rowtotal,$processing,$type) = @_;
5696: my %choices =
5697: &Apache::lonlocal::texthash (
5698: automatic => 'Automatic approval',
5699: approval => 'Queued for approval',
5700: );
5701: my $output;
5702: foreach my $option ('automatic','approval') {
5703: my $checked;
5704: if (ref($processing) eq 'HASH') {
5705: if ($type eq '') {
5706: if (!exists($processing->{'default'})) {
5707: if ($option eq 'automatic') {
5708: $checked = ' checked="checked"';
5709: }
5710: } else {
5711: if ($processing->{'default'} eq $option) {
5712: $checked = ' checked="checked"';
5713: }
5714: }
5715: } else {
5716: if (!exists($processing->{$type})) {
5717: if ($option eq 'automatic') {
5718: $checked = ' checked="checked"';
5719: }
5720: } else {
5721: if ($processing->{$type} eq $option) {
5722: $checked = ' checked="checked"';
5723: }
5724: }
5725: }
5726: } elsif ($option eq 'automatic') {
5727: $checked = ' checked="checked"';
5728: }
5729: my $name = 'cancreate_emailprocess';
5730: if (($type ne '') && ($type ne 'default')) {
5731: $name .= '_'.$type;
5732: }
5733: $output .= '<span class="LC_nobreak"><label>'.
5734: '<input type="radio" name="'.$name.'"'.
5735: $checked.' value="'.$option.'" />'.
5736: $choices{$option}.'</label></span>';
5737: if ($type eq '') {
5738: $output .= ' ';
5739: } else {
5740: $output .= '<br />';
5741: }
5742: }
5743: $$rowtotal ++;
5744: return $output;
5745: }
5746:
1.160.6.5 raeburn 5747: sub captcha_choice {
5748: my ($context,$settings,$itemcount) = @_;
1.160.6.69 raeburn 5749: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5750: $vertext,$currver);
1.160.6.5 raeburn 5751: my %lt = &captcha_phrases();
5752: $keyentry = 'hidden';
5753: if ($context eq 'cancreate') {
1.160.6.34 raeburn 5754: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 5755: } elsif ($context eq 'login') {
5756: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
5757: }
5758: if (ref($settings) eq 'HASH') {
5759: if ($settings->{'captcha'}) {
5760: $checked{$settings->{'captcha'}} = ' checked="checked"';
5761: } else {
5762: $checked{'original'} = ' checked="checked"';
5763: }
5764: if ($settings->{'captcha'} eq 'recaptcha') {
5765: $pubtext = $lt{'pub'};
5766: $privtext = $lt{'priv'};
5767: $keyentry = 'text';
1.160.6.69 raeburn 5768: $vertext = $lt{'ver'};
5769: $currver = $settings->{'recaptchaversion'};
5770: if ($currver ne '2') {
5771: $currver = 1;
5772: }
1.160.6.5 raeburn 5773: }
5774: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5775: $currpub = $settings->{'recaptchakeys'}{'public'};
5776: $currpriv = $settings->{'recaptchakeys'}{'private'};
5777: }
5778: } else {
5779: $checked{'original'} = ' checked="checked"';
5780: }
5781: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5782: my $output = '<tr'.$css_class.'>'.
5783: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
5784: '<table><tr><td>'."\n";
5785: foreach my $option ('original','recaptcha','notused') {
5786: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5787: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5788: $lt{$option}.'</label></span>';
5789: unless ($option eq 'notused') {
5790: $output .= (' 'x2)."\n";
5791: }
5792: }
5793: #
5794: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5795: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
5796: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
5797: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
5798: #
5799: $output .= '</td></tr>'."\n".
5800: '<tr><td>'."\n".
5801: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5802: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5803: $currpub.'" size="40" /></span><br />'."\n".
5804: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5805: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 5806: $currpriv.'" size="40" /></span><br />'.
5807: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5808: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5809: $currver.'" size="3" /></span><br />'.
5810: '</td></tr></table>'."\n".
1.160.6.5 raeburn 5811: '</td></tr>';
5812: return $output;
5813: }
5814:
1.32 raeburn 5815: sub user_formats_row {
5816: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5817: my $output;
5818: my %text = (
5819: 'username' => 'new usernames',
5820: 'id' => 'IDs',
1.45 raeburn 5821: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5822: );
5823: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5824: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5825: '<td><span class="LC_nobreak">';
5826: if ($type eq 'email') {
5827: $output .= &mt("Formats disallowed for $text{$type}: ");
5828: } else {
5829: $output .= &mt("Format rules to check for $text{$type}: ");
5830: }
5831: $output .= '</span></td>'.
5832: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5833: my $rem;
5834: if (ref($ruleorder) eq 'ARRAY') {
5835: for (my $i=0; $i<@{$ruleorder}; $i++) {
5836: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5837: my $rem = $i%($numinrow);
5838: if ($rem == 0) {
5839: if ($i > 0) {
5840: $output .= '</tr>';
5841: }
5842: $output .= '<tr>';
5843: }
5844: my $check = ' ';
1.39 raeburn 5845: if (ref($settings) eq 'HASH') {
5846: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5847: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5848: $check = ' checked="checked" ';
5849: }
1.27 raeburn 5850: }
5851: }
5852: $output .= '<td class="LC_left_item">'.
5853: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5854: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5855: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5856: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5857: }
5858: }
5859: $rem = @{$ruleorder}%($numinrow);
5860: }
5861: my $colsleft = $numinrow - $rem;
5862: if ($colsleft > 1 ) {
5863: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5864: ' </td>';
5865: } elsif ($colsleft == 1) {
5866: $output .= '<td class="LC_left_item"> </td>';
5867: }
5868: $output .= '</tr></table></td></tr>';
5869: return $output;
5870: }
5871:
1.34 raeburn 5872: sub usercreation_types {
5873: my %lt = &Apache::lonlocal::texthash (
5874: author => 'When adding a co-author',
5875: course => 'When adding a user to a course',
1.100 raeburn 5876: requestcrs => 'When requesting a course',
1.34 raeburn 5877: any => 'Any',
5878: official => 'Institutional only ',
5879: unofficial => 'Non-institutional only',
5880: none => 'None',
5881: );
5882: return %lt;
1.48 raeburn 5883: }
1.34 raeburn 5884:
1.160.6.34 raeburn 5885: sub selfcreation_types {
5886: my %lt = &Apache::lonlocal::texthash (
5887: selfcreate => 'User creates own account',
5888: any => 'Any',
5889: official => 'Institutional only ',
5890: unofficial => 'Non-institutional only',
5891: email => 'E-mail address',
5892: login => 'Institutional Login',
5893: sso => 'SSO',
5894: );
5895: }
5896:
1.28 raeburn 5897: sub authtype_names {
5898: my %lt = &Apache::lonlocal::texthash(
5899: int => 'Internal',
5900: krb4 => 'Kerberos 4',
5901: krb5 => 'Kerberos 5',
5902: loc => 'Local',
5903: );
5904: return %lt;
5905: }
5906:
5907: sub context_names {
5908: my %context_title = &Apache::lonlocal::texthash(
5909: author => 'Creating users when an Author',
5910: course => 'Creating users when in a course',
5911: domain => 'Creating users when a Domain Coordinator',
5912: );
5913: return %context_title;
5914: }
5915:
1.33 raeburn 5916: sub print_usermodification {
5917: my ($position,$dom,$settings,$rowtotal) = @_;
5918: my $numinrow = 4;
5919: my ($context,$datatable,$rowcount);
5920: if ($position eq 'top') {
5921: $rowcount = 0;
5922: $context = 'author';
5923: foreach my $role ('ca','aa') {
5924: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5925: $numinrow,$rowcount);
5926: $$rowtotal ++;
5927: $rowcount ++;
5928: }
1.160.6.37 raeburn 5929: } elsif ($position eq 'bottom') {
1.33 raeburn 5930: $context = 'course';
5931: $rowcount = 0;
5932: foreach my $role ('st','ep','ta','in','cr') {
5933: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5934: $numinrow,$rowcount);
5935: $$rowtotal ++;
5936: $rowcount ++;
5937: }
5938: }
5939: return $datatable;
5940: }
5941:
1.43 raeburn 5942: sub print_defaults {
1.160.6.40 raeburn 5943: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 5944: my $rownum = 0;
1.160.6.80 raeburn 5945: my ($datatable,$css_class,$titles);
5946: unless ($position eq 'bottom') {
5947: $titles = &defaults_titles($dom);
5948: }
1.160.6.40 raeburn 5949: if ($position eq 'top') {
5950: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5951: 'datelocale_def','portal_def');
5952: my %defaults;
5953: if (ref($settings) eq 'HASH') {
5954: %defaults = %{$settings};
1.43 raeburn 5955: } else {
1.160.6.40 raeburn 5956: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5957: foreach my $item (@items) {
5958: $defaults{$item} = $domdefaults{$item};
5959: }
1.43 raeburn 5960: }
1.160.6.40 raeburn 5961: foreach my $item (@items) {
5962: if ($rownum%2) {
5963: $css_class = '';
5964: } else {
5965: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 5966: }
1.160.6.40 raeburn 5967: $datatable .= '<tr'.$css_class.'>'.
5968: '<td><span class="LC_nobreak">'.$titles->{$item}.
5969: '</span></td><td class="LC_right_item" colspan="3">';
5970: if ($item eq 'auth_def') {
5971: my @authtypes = ('internal','krb4','krb5','localauth');
5972: my %shortauth = (
5973: internal => 'int',
5974: krb4 => 'krb4',
5975: krb5 => 'krb5',
5976: localauth => 'loc'
5977: );
5978: my %authnames = &authtype_names();
5979: foreach my $auth (@authtypes) {
5980: my $checked = ' ';
5981: if ($defaults{$item} eq $auth) {
5982: $checked = ' checked="checked" ';
5983: }
5984: $datatable .= '<label><input type="radio" name="'.$item.
5985: '" value="'.$auth.'"'.$checked.'/>'.
5986: $authnames{$shortauth{$auth}}.'</label> ';
5987: }
5988: } elsif ($item eq 'timezone_def') {
5989: my $includeempty = 1;
5990: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5991: } elsif ($item eq 'datelocale_def') {
5992: my $includeempty = 1;
5993: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5994: } elsif ($item eq 'lang_def') {
1.160.6.63 raeburn 5995: my $includeempty = 1;
5996: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40 raeburn 5997: } else {
5998: my $size;
5999: if ($item eq 'portal_def') {
6000: $size = ' size="25"';
6001: }
6002: $datatable .= '<input type="text" name="'.$item.'" value="'.
6003: $defaults{$item}.'"'.$size.' />';
6004: }
6005: $datatable .= '</td></tr>';
6006: $rownum ++;
6007: }
1.160.6.80 raeburn 6008: } elsif ($position eq 'middle') {
6009: my @items = ('intauth_cost','intauth_check','intauth_switch');
6010: my %defaults;
6011: if (ref($settings) eq 'HASH') {
6012: %defaults = %{$settings};
6013: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6014: $defaults{'intauth_cost'} = 10;
6015: }
6016: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6017: $defaults{'intauth_check'} = 0;
6018: }
6019: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6020: $defaults{'intauth_switch'} = 0;
6021: }
6022: } else {
6023: %defaults = (
6024: 'intauth_cost' => 10,
6025: 'intauth_check' => 0,
6026: 'intauth_switch' => 0,
6027: );
6028: }
6029: foreach my $item (@items) {
6030: if ($rownum%2) {
6031: $css_class = '';
6032: } else {
6033: $css_class = ' class="LC_odd_row" ';
6034: }
6035: $datatable .= '<tr'.$css_class.'>'.
6036: '<td><span class="LC_nobreak">'.$titles->{$item}.
6037: '</span></td><td class="LC_left_item" colspan="3">';
6038: if ($item eq 'intauth_switch') {
6039: my @options = (0,1,2);
6040: my %optiondesc = &Apache::lonlocal::texthash (
6041: 0 => 'No',
6042: 1 => 'Yes',
6043: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6044: );
6045: $datatable .= '<table width="100%">';
6046: foreach my $option (@options) {
6047: my $checked = ' ';
6048: if ($defaults{$item} eq $option) {
6049: $checked = ' checked="checked"';
6050: }
6051: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6052: '<label><input type="radio" name="'.$item.
6053: '" value="'.$option.'"'.$checked.' />'.
6054: $optiondesc{$option}.'</label></span></td></tr>';
6055: }
6056: $datatable .= '</table>';
6057: } elsif ($item eq 'intauth_check') {
6058: my @options = (0,1,2);
6059: my %optiondesc = &Apache::lonlocal::texthash (
6060: 0 => 'No',
6061: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6062: 2 => 'Yes, disallow login if stored cost is less than domain default',
6063: );
6064: $datatable .= '<table wisth="100%">';
6065: foreach my $option (@options) {
6066: my $checked = ' ';
6067: my $onclick;
6068: if ($defaults{$item} eq $option) {
6069: $checked = ' checked="checked"';
6070: }
6071: if ($option == 2) {
6072: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6073: }
6074: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6075: '<label><input type="radio" name="'.$item.
6076: '" value="'.$option.'"'.$checked.$onclick.' />'.
6077: $optiondesc{$option}.'</label></span></td></tr>';
6078: }
6079: $datatable .= '</table>';
6080: } else {
6081: $datatable .= '<input type="text" name="'.$item.'" value="'.
6082: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6083: }
6084: $datatable .= '</td></tr>';
6085: $rownum ++;
6086: }
1.160.6.40 raeburn 6087: } else {
1.160.6.80 raeburn 6088: my %defaults;
1.160.6.40 raeburn 6089: if (ref($settings) eq 'HASH') {
6090: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
6091: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
6092: my $maxnum = @{$settings->{'inststatusorder'}};
6093: for (my $i=0; $i<$maxnum; $i++) {
6094: $css_class = $rownum%2?' class="LC_odd_row"':'';
6095: my $item = $settings->{'inststatusorder'}->[$i];
6096: my $title = $settings->{'inststatustypes'}->{$item};
6097: my $guestok;
6098: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
6099: $guestok = 1;
6100: }
6101: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6102: $datatable .= '<tr'.$css_class.'>'.
6103: '<td><span class="LC_nobreak">'.
6104: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6105: for (my $k=0; $k<=$maxnum; $k++) {
6106: my $vpos = $k+1;
6107: my $selstr;
6108: if ($k == $i) {
6109: $selstr = ' selected="selected" ';
6110: }
6111: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6112: }
6113: my ($checkedon,$checkedoff);
6114: $checkedoff = ' checked="checked"';
6115: if ($guestok) {
6116: $checkedon = $checkedoff;
6117: $checkedoff = '';
6118: }
6119: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6120: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6121: &mt('delete').'</span></td>'.
6122: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
6123: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
6124: '</span></td>'.
6125: '<td class="LC_right_item"><span class="LC_nobreak">'.
6126: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
6127: &mt('Yes').'</label>'.(' 'x2).
6128: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
6129: &mt('No').'</label></span></td></tr>';
6130: }
6131: $css_class = $rownum%2?' class="LC_odd_row"':'';
6132: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6133: $datatable .= '<tr '.$css_class.'>'.
6134: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6135: for (my $k=0; $k<=$maxnum; $k++) {
6136: my $vpos = $k+1;
6137: my $selstr;
6138: if ($k == $maxnum) {
6139: $selstr = ' selected="selected" ';
6140: }
6141: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6142: }
6143: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 6144: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 6145: ' '.&mt('(new)').
6146: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
6147: &mt('Name displayed:').
6148: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6149: '<td class="LC_right_item"><span class="LC_nobreak">'.
6150: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
6151: &mt('Yes').'</label>'.(' 'x2).
6152: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
6153: &mt('No').'</label></span></td></tr>';
6154: '</tr>'."\n";
6155: $rownum ++;
1.141 raeburn 6156: }
1.43 raeburn 6157: }
6158: }
6159: $$rowtotal += $rownum;
6160: return $datatable;
6161: }
6162:
1.160.6.5 raeburn 6163: sub get_languages_hash {
6164: my %langchoices;
6165: foreach my $id (&Apache::loncommon::languageids()) {
6166: my $code = &Apache::loncommon::supportedlanguagecode($id);
6167: if ($code ne '') {
6168: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6169: }
6170: }
6171: return %langchoices;
6172: }
6173:
1.43 raeburn 6174: sub defaults_titles {
1.141 raeburn 6175: my ($dom) = @_;
1.43 raeburn 6176: my %titles = &Apache::lonlocal::texthash (
6177: 'auth_def' => 'Default authentication type',
6178: 'auth_arg_def' => 'Default authentication argument',
6179: 'lang_def' => 'Default language',
1.54 raeburn 6180: 'timezone_def' => 'Default timezone',
1.68 raeburn 6181: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6182: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 6183: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
6184: 'intauth_check' => 'Check bcrypt cost if authenticated',
6185: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 6186: );
1.141 raeburn 6187: if ($dom) {
6188: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6189: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6190: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6191: $protocol = 'http' if ($protocol ne 'https');
6192: if ($uint_dom) {
6193: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6194: $uint_dom);
6195: }
6196: }
1.43 raeburn 6197: return (\%titles);
6198: }
6199:
1.46 raeburn 6200: sub print_scantronformat {
6201: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6202: my $itemcount = 1;
1.60 raeburn 6203: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6204: %confhash);
1.46 raeburn 6205: my $switchserver = &check_switchserver($dom,$confname);
6206: my %lt = &Apache::lonlocal::texthash (
1.95 www 6207: default => 'Default bubblesheet format file error',
6208: custom => 'Custom bubblesheet format file error',
1.46 raeburn 6209: );
6210: my %scantronfiles = (
6211: default => 'default.tab',
6212: custom => 'custom.tab',
6213: );
6214: foreach my $key (keys(%scantronfiles)) {
6215: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6216: .$scantronfiles{$key};
6217: }
6218: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6219: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6220: if (!$switchserver) {
6221: my $servadm = $r->dir_config('lonAdmEMail');
6222: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6223: if ($configuserok eq 'ok') {
6224: if ($author_ok eq 'ok') {
6225: my %legacyfile = (
6226: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6227: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
6228: );
6229: my %md5chk;
6230: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6231: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6232: chomp($md5chk{$type});
1.46 raeburn 6233: }
6234: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6235: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6236: ($scantronurls{$type},my $error) =
1.46 raeburn 6237: &legacy_scantronformat($r,$dom,$confname,
6238: $type,$legacyfile{$type},
6239: $scantronurls{$type},
6240: $scantronfiles{$type});
1.60 raeburn 6241: if ($error ne '') {
6242: $error{$type} = $error;
6243: }
6244: }
6245: if (keys(%error) == 0) {
6246: $is_custom = 1;
6247: $confhash{'scantron'}{'scantronformat'} =
6248: $scantronurls{'custom'};
6249: my $putresult =
6250: &Apache::lonnet::put_dom('configuration',
6251: \%confhash,$dom);
6252: if ($putresult ne 'ok') {
6253: $error{'custom'} =
6254: '<span class="LC_error">'.
6255: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6256: }
1.46 raeburn 6257: }
6258: } else {
1.60 raeburn 6259: ($scantronurls{'default'},my $error) =
1.46 raeburn 6260: &legacy_scantronformat($r,$dom,$confname,
6261: 'default',$legacyfile{'default'},
6262: $scantronurls{'default'},
6263: $scantronfiles{'default'});
1.60 raeburn 6264: if ($error eq '') {
6265: $confhash{'scantron'}{'scantronformat'} = '';
6266: my $putresult =
6267: &Apache::lonnet::put_dom('configuration',
6268: \%confhash,$dom);
6269: if ($putresult ne 'ok') {
6270: $error{'default'} =
6271: '<span class="LC_error">'.
6272: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6273: }
6274: } else {
6275: $error{'default'} = $error;
6276: }
1.46 raeburn 6277: }
6278: }
6279: }
6280: } else {
1.95 www 6281: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 6282: }
6283: }
6284: if (ref($settings) eq 'HASH') {
6285: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6286: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
6287: if ((!@info) || ($info[0] eq 'no_such_dir')) {
6288: $scantronurl = '';
6289: } else {
6290: $scantronurl = $settings->{'scantronformat'};
6291: }
6292: $is_custom = 1;
6293: } else {
6294: $scantronurl = $scantronurls{'default'};
6295: }
6296: } else {
1.60 raeburn 6297: if ($is_custom) {
6298: $scantronurl = $scantronurls{'custom'};
6299: } else {
6300: $scantronurl = $scantronurls{'default'};
6301: }
1.46 raeburn 6302: }
6303: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6304: $datatable .= '<tr'.$css_class.'>';
6305: if (!$is_custom) {
1.65 raeburn 6306: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6307: '<span class="LC_nobreak">';
1.46 raeburn 6308: if ($scantronurl) {
1.160.6.21 raeburn 6309: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6310: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 6311: } else {
6312: $datatable = &mt('File unavailable for display');
6313: }
1.65 raeburn 6314: $datatable .= '</span></td>';
1.60 raeburn 6315: if (keys(%error) == 0) {
6316: $datatable .= '<td valign="bottom">';
6317: if (!$switchserver) {
6318: $datatable .= &mt('Upload:').'<br />';
6319: }
6320: } else {
6321: my $errorstr;
6322: foreach my $key (sort(keys(%error))) {
6323: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6324: }
6325: $datatable .= '<td>'.$errorstr;
6326: }
1.46 raeburn 6327: } else {
6328: if (keys(%error) > 0) {
6329: my $errorstr;
6330: foreach my $key (sort(keys(%error))) {
6331: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6332: }
1.60 raeburn 6333: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 6334: } elsif ($scantronurl) {
1.160.6.26 raeburn 6335: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 6336: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 6337: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 6338: $link.
6339: '<label><input type="checkbox" name="scantronformat_del"'.
6340: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 6341: '<td><span class="LC_nobreak"> '.
6342: &mt('Replace:').'</span><br />';
1.46 raeburn 6343: }
6344: }
6345: if (keys(%error) == 0) {
6346: if ($switchserver) {
6347: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6348: } else {
1.65 raeburn 6349: $datatable .='<span class="LC_nobreak"> '.
6350: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 6351: }
6352: }
6353: $datatable .= '</td></tr>';
6354: $$rowtotal ++;
6355: return $datatable;
6356: }
6357:
6358: sub legacy_scantronformat {
6359: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6360: my ($url,$error);
6361: my @statinfo = &Apache::lonnet::stat_file($newurl);
6362: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6363: (my $result,$url) =
6364: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6365: '','',$newfile);
6366: if ($result ne 'ok') {
1.130 raeburn 6367: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 6368: }
6369: }
6370: return ($url,$error);
6371: }
1.43 raeburn 6372:
1.49 raeburn 6373: sub print_coursecategories {
1.57 raeburn 6374: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6375: my $datatable;
6376: if ($position eq 'top') {
1.160.6.42 raeburn 6377: my (%checked);
6378: my @catitems = ('unauth','auth');
6379: my @cattypes = ('std','domonly','codesrch','none');
6380: $checked{'unauth'} = 'std';
6381: $checked{'auth'} = 'std';
6382: if (ref($settings) eq 'HASH') {
6383: foreach my $type (@cattypes) {
6384: if ($type eq $settings->{'unauth'}) {
6385: $checked{'unauth'} = $type;
6386: }
6387: if ($type eq $settings->{'auth'}) {
6388: $checked{'auth'} = $type;
6389: }
6390: }
6391: }
6392: my %lt = &Apache::lonlocal::texthash (
6393: unauth => 'Catalog type for unauthenticated users',
6394: auth => 'Catalog type for authenticated users',
6395: none => 'No catalog',
6396: std => 'Standard catalog',
6397: domonly => 'Domain-only catalog',
6398: codesrch => "Code search form",
6399: );
6400: my $itemcount = 0;
6401: foreach my $item (@catitems) {
6402: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6403: $datatable .= '<tr '.$css_class.'>'.
6404: '<td>'.$lt{$item}.'</td>'.
6405: '<td class="LC_right_item"><span class="LC_nobreak">';
6406: foreach my $type (@cattypes) {
6407: my $ischecked;
6408: if ($checked{$item} eq $type) {
6409: $ischecked=' checked="checked"';
6410: }
6411: $datatable .= '<label>'.
6412: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6413: ' />'.$lt{$type}.'</label> ';
6414: }
6415: $datatable .= '</td></tr>';
6416: $itemcount ++;
6417: }
6418: $$rowtotal += $itemcount;
6419: } elsif ($position eq 'middle') {
1.57 raeburn 6420: my $toggle_cats_crs = ' ';
6421: my $toggle_cats_dom = ' checked="checked" ';
6422: my $can_cat_crs = ' ';
6423: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 6424: my $toggle_catscomm_comm = ' ';
6425: my $toggle_catscomm_dom = ' checked="checked" ';
6426: my $can_catcomm_comm = ' ';
6427: my $can_catcomm_dom = ' checked="checked" ';
6428:
1.57 raeburn 6429: if (ref($settings) eq 'HASH') {
6430: if ($settings->{'togglecats'} eq 'crs') {
6431: $toggle_cats_crs = $toggle_cats_dom;
6432: $toggle_cats_dom = ' ';
6433: }
6434: if ($settings->{'categorize'} eq 'crs') {
6435: $can_cat_crs = $can_cat_dom;
6436: $can_cat_dom = ' ';
6437: }
1.120 raeburn 6438: if ($settings->{'togglecatscomm'} eq 'comm') {
6439: $toggle_catscomm_comm = $toggle_catscomm_dom;
6440: $toggle_catscomm_dom = ' ';
6441: }
6442: if ($settings->{'categorizecomm'} eq 'comm') {
6443: $can_catcomm_comm = $can_catcomm_dom;
6444: $can_catcomm_dom = ' ';
6445: }
1.57 raeburn 6446: }
6447: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 6448: togglecats => 'Show/Hide a course in catalog',
6449: togglecatscomm => 'Show/Hide a community in catalog',
6450: categorize => 'Assign a category to a course',
6451: categorizecomm => 'Assign a category to a community',
1.57 raeburn 6452: );
6453: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 6454: dom => 'Set in Domain',
6455: crs => 'Set in Course',
6456: comm => 'Set in Community',
1.57 raeburn 6457: );
6458: $datatable = '<tr class="LC_odd_row">'.
6459: '<td>'.$title{'togglecats'}.'</td>'.
6460: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6461: '<input type="radio" name="togglecats"'.
6462: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6463: '<label><input type="radio" name="togglecats"'.
6464: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
6465: '</tr><tr>'.
6466: '<td>'.$title{'categorize'}.'</td>'.
6467: '<td class="LC_right_item"><span class="LC_nobreak">'.
6468: '<label><input type="radio" name="categorize"'.
6469: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6470: '<label><input type="radio" name="categorize"'.
6471: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 6472: '</tr><tr class="LC_odd_row">'.
6473: '<td>'.$title{'togglecatscomm'}.'</td>'.
6474: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6475: '<input type="radio" name="togglecatscomm"'.
6476: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6477: '<label><input type="radio" name="togglecatscomm"'.
6478: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
6479: '</tr><tr>'.
6480: '<td>'.$title{'categorizecomm'}.'</td>'.
6481: '<td class="LC_right_item"><span class="LC_nobreak">'.
6482: '<label><input type="radio" name="categorizecomm"'.
6483: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6484: '<label><input type="radio" name="categorizecomm"'.
6485: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 6486: '</tr>';
1.120 raeburn 6487: $$rowtotal += 4;
1.57 raeburn 6488: } else {
6489: my $css_class;
6490: my $itemcount = 1;
6491: my $cathash;
6492: if (ref($settings) eq 'HASH') {
6493: $cathash = $settings->{'cats'};
6494: }
6495: if (ref($cathash) eq 'HASH') {
6496: my (@cats,@trails,%allitems,%idx,@jsarray);
6497: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
6498: \%allitems,\%idx,\@jsarray);
6499: my $maxdepth = scalar(@cats);
6500: my $colattrib = '';
6501: if ($maxdepth > 2) {
6502: $colattrib = ' colspan="2" ';
6503: }
6504: my @path;
6505: if (@cats > 0) {
6506: if (ref($cats[0]) eq 'ARRAY') {
6507: my $numtop = @{$cats[0]};
6508: my $maxnum = $numtop;
1.120 raeburn 6509: my %default_names = (
6510: instcode => &mt('Official courses'),
6511: communities => &mt('Communities'),
6512: );
6513:
6514: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6515: ($cathash->{'instcode::0'} eq '') ||
6516: (!grep(/^communities$/,@{$cats[0]})) ||
6517: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 6518: $maxnum ++;
6519: }
6520: my $lastidx;
6521: for (my $i=0; $i<$numtop; $i++) {
6522: my $parent = $cats[0][$i];
6523: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6524: my $item = &escape($parent).'::0';
6525: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6526: $lastidx = $idx{$item};
6527: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6528: .'<select name="'.$item.'"'.$chgstr.'>';
6529: for (my $k=0; $k<=$maxnum; $k++) {
6530: my $vpos = $k+1;
6531: my $selstr;
6532: if ($k == $i) {
6533: $selstr = ' selected="selected" ';
6534: }
6535: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6536: }
1.160.6.29 raeburn 6537: $datatable .= '</select></span></td><td>';
1.120 raeburn 6538: if ($parent eq 'instcode' || $parent eq 'communities') {
6539: $datatable .= '<span class="LC_nobreak">'
6540: .$default_names{$parent}.'</span>';
6541: if ($parent eq 'instcode') {
6542: $datatable .= '<br /><span class="LC_nobreak">('
6543: .&mt('with institutional codes')
6544: .')</span></td><td'.$colattrib.'>';
6545: } else {
6546: $datatable .= '<table><tr><td>';
6547: }
6548: $datatable .= '<span class="LC_nobreak">'
6549: .'<label><input type="radio" name="'
6550: .$parent.'" value="1" checked="checked" />'
6551: .&mt('Display').'</label>';
6552: if ($parent eq 'instcode') {
6553: $datatable .= ' ';
6554: } else {
6555: $datatable .= '</span></td></tr><tr><td>'
6556: .'<span class="LC_nobreak">';
6557: }
6558: $datatable .= '<label><input type="radio" name="'
6559: .$parent.'" value="0" />'
6560: .&mt('Do not display').'</label></span>';
6561: if ($parent eq 'communities') {
6562: $datatable .= '</td></tr></table>';
6563: }
6564: $datatable .= '</td>';
1.57 raeburn 6565: } else {
6566: $datatable .= $parent
1.160.6.29 raeburn 6567: .' <span class="LC_nobreak"><label>'
6568: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6569: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6570: }
6571: my $depth = 1;
6572: push(@path,$parent);
6573: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6574: pop(@path);
6575: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6576: $itemcount ++;
6577: }
1.48 raeburn 6578: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6579: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6580: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6581: for (my $k=0; $k<=$maxnum; $k++) {
6582: my $vpos = $k+1;
6583: my $selstr;
1.57 raeburn 6584: if ($k == $numtop) {
1.48 raeburn 6585: $selstr = ' selected="selected" ';
6586: }
6587: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6588: }
1.59 bisitz 6589: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6590: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6591: .'</tr>'."\n";
1.48 raeburn 6592: $itemcount ++;
1.120 raeburn 6593: foreach my $default ('instcode','communities') {
6594: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6595: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6596: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6597: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6598: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6599: for (my $k=0; $k<=$maxnum; $k++) {
6600: my $vpos = $k+1;
6601: my $selstr;
6602: if ($k == $maxnum) {
6603: $selstr = ' selected="selected" ';
6604: }
6605: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6606: }
1.120 raeburn 6607: $datatable .= '</select></span></td>'.
6608: '<td><span class="LC_nobreak">'.
6609: $default_names{$default}.'</span>';
6610: if ($default eq 'instcode') {
6611: $datatable .= '<br /><span class="LC_nobreak">('
6612: .&mt('with institutional codes').')</span>';
6613: }
6614: $datatable .= '</td>'
6615: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6616: .&mt('Display').'</label> '
6617: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6618: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6619: }
6620: }
6621: }
1.57 raeburn 6622: } else {
6623: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6624: }
6625: } else {
1.160.6.42 raeburn 6626: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6627: .&initialize_categories($itemcount);
1.48 raeburn 6628: }
1.57 raeburn 6629: $$rowtotal += $itemcount;
1.48 raeburn 6630: }
6631: return $datatable;
6632: }
6633:
1.69 raeburn 6634: sub print_serverstatuses {
6635: my ($dom,$settings,$rowtotal) = @_;
6636: my $datatable;
6637: my @pages = &serverstatus_pages();
6638: my (%namedaccess,%machineaccess);
6639: foreach my $type (@pages) {
6640: $namedaccess{$type} = '';
6641: $machineaccess{$type}= '';
6642: }
6643: if (ref($settings) eq 'HASH') {
6644: foreach my $type (@pages) {
6645: if (exists($settings->{$type})) {
6646: if (ref($settings->{$type}) eq 'HASH') {
6647: foreach my $key (keys(%{$settings->{$type}})) {
6648: if ($key eq 'namedusers') {
6649: $namedaccess{$type} = $settings->{$type}->{$key};
6650: } elsif ($key eq 'machines') {
6651: $machineaccess{$type} = $settings->{$type}->{$key};
6652: }
6653: }
6654: }
6655: }
6656: }
6657: }
1.81 raeburn 6658: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6659: my $rownum = 0;
6660: my $css_class;
6661: foreach my $type (@pages) {
6662: $rownum ++;
6663: $css_class = $rownum%2?' class="LC_odd_row"':'';
6664: $datatable .= '<tr'.$css_class.'>'.
6665: '<td><span class="LC_nobreak">'.
6666: $titles->{$type}.'</span></td>'.
6667: '<td class="LC_left_item">'.
6668: '<input type="text" name="'.$type.'_namedusers" '.
6669: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6670: '<td class="LC_right_item">'.
6671: '<span class="LC_nobreak">'.
6672: '<input type="text" name="'.$type.'_machines" '.
6673: 'value="'.$machineaccess{$type}.'" size="10" />'.
6674: '</td></tr>'."\n";
6675: }
6676: $$rowtotal += $rownum;
6677: return $datatable;
6678: }
6679:
6680: sub serverstatus_pages {
6681: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 6682: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 6683: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 6684: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6685: }
6686:
1.160.6.40 raeburn 6687: sub defaults_javascript {
6688: my ($settings) = @_;
1.160.6.80 raeburn 6689: 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.');
6690: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
6691: &js_escape(\$intauthcheck);
6692: &js_escape(\$intauthcost);
6693: my $intauthjs = <<"ENDSCRIPT";
6694:
6695: function warnIntAuth(field) {
6696: if (field.name == 'intauth_check') {
6697: if (field.value == '2') {
6698: alert('$intauthcheck');
6699: }
6700: }
6701: if (field.name == 'intauth_cost') {
6702: field.value.replace(/\s/g,'');
6703: if (field.value != '') {
6704: var regexdigit=/^\\d+\$/;
6705: if (!regexdigit.test(field.value)) {
6706: alert('$intauthcost');
6707: }
6708: }
6709: }
6710: return;
6711: }
6712:
6713: ENDSCRIPT
6714:
6715: if (ref($settings) ne 'HASH') {
6716: return &Apache::lonhtmlcommon::scripttag($intauthjs);
6717: }
1.160.6.40 raeburn 6718: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6719: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6720: if ($maxnum eq '') {
6721: $maxnum = 0;
6722: }
6723: $maxnum ++;
1.160.6.51 raeburn 6724: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 6725: return <<"ENDSCRIPT";
6726: <script type="text/javascript">
6727: // <![CDATA[
6728: function reorderTypes(form,caller) {
6729: var changedVal;
6730: $jstext
6731: var newpos = 'addinststatus_pos';
6732: var current = new Array;
6733: var maxh = $maxnum;
6734: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6735: var oldVal;
6736: if (caller == newpos) {
6737: changedVal = newitemVal;
6738: } else {
6739: var curritem = 'inststatus_pos_'+caller;
6740: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6741: current[newitemVal] = newpos;
6742: }
6743: for (var i=0; i<inststatuses.length; i++) {
6744: if (inststatuses[i] != caller) {
6745: var elementName = 'inststatus_pos_'+inststatuses[i];
6746: if (form.elements[elementName]) {
6747: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6748: current[currVal] = elementName;
6749: }
6750: }
6751: }
6752: for (var j=0; j<maxh; j++) {
6753: if (current[j] == undefined) {
6754: oldVal = j;
6755: }
6756: }
6757: if (oldVal < changedVal) {
6758: for (var k=oldVal+1; k<=changedVal ; k++) {
6759: var elementName = current[k];
6760: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6761: }
6762: } else {
6763: for (var k=changedVal; k<oldVal; k++) {
6764: var elementName = current[k];
6765: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6766: }
6767: }
6768: return;
6769: }
6770:
1.160.6.80 raeburn 6771: $intauthjs
6772:
1.160.6.40 raeburn 6773: // ]]>
6774: </script>
6775:
6776: ENDSCRIPT
1.160.6.80 raeburn 6777: } else {
6778: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.160.6.40 raeburn 6779: }
6780: }
6781:
1.49 raeburn 6782: sub coursecategories_javascript {
6783: my ($settings) = @_;
1.57 raeburn 6784: my ($output,$jstext,$cathash);
1.49 raeburn 6785: if (ref($settings) eq 'HASH') {
1.57 raeburn 6786: $cathash = $settings->{'cats'};
6787: }
6788: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6789: my (@cats,@jsarray,%idx);
1.57 raeburn 6790: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6791: if (@jsarray > 0) {
6792: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6793: for (my $i=0; $i<@jsarray; $i++) {
6794: if (ref($jsarray[$i]) eq 'ARRAY') {
6795: my $catstr = join('","',@{$jsarray[$i]});
6796: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6797: }
6798: }
6799: }
6800: } else {
6801: $jstext = ' var categories = Array(1);'."\n".
6802: ' categories[0] = Array("instcode_pos");'."\n";
6803: }
1.160.6.42 raeburn 6804: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6805: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 6806: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6807: &js_escape(\$instcode_reserved);
6808: &js_escape(\$communities_reserved);
6809: &js_escape(\$choose_again);
1.49 raeburn 6810: $output = <<"ENDSCRIPT";
6811: <script type="text/javascript">
1.109 raeburn 6812: // <![CDATA[
1.49 raeburn 6813: function reorderCats(form,parent,item,idx) {
6814: var changedVal;
6815: $jstext
6816: var newpos = 'addcategory_pos';
6817: if (parent == '') {
6818: var has_instcode = 0;
6819: var maxtop = categories[idx].length;
6820: for (var j=0; j<maxtop; j++) {
6821: if (categories[idx][j] == 'instcode::0') {
6822: has_instcode == 1;
6823: }
6824: }
6825: if (has_instcode == 0) {
6826: categories[idx][maxtop] = 'instcode_pos';
6827: }
6828: } else {
6829: newpos += '_'+parent;
6830: }
6831: var maxh = 1 + categories[idx].length;
6832: var current = new Array;
6833: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6834: if (item == newpos) {
6835: changedVal = newitemVal;
6836: } else {
6837: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6838: current[newitemVal] = newpos;
6839: }
6840: for (var i=0; i<categories[idx].length; i++) {
6841: var elementName = categories[idx][i];
6842: if (elementName != item) {
6843: if (form.elements[elementName]) {
6844: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6845: current[currVal] = elementName;
6846: }
6847: }
6848: }
6849: var oldVal;
6850: for (var j=0; j<maxh; j++) {
6851: if (current[j] == undefined) {
6852: oldVal = j;
6853: }
6854: }
6855: if (oldVal < changedVal) {
6856: for (var k=oldVal+1; k<=changedVal ; k++) {
6857: var elementName = current[k];
6858: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6859: }
6860: } else {
6861: for (var k=changedVal; k<oldVal; k++) {
6862: var elementName = current[k];
6863: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6864: }
6865: }
6866: return;
6867: }
1.120 raeburn 6868:
6869: function categoryCheck(form) {
6870: if (form.elements['addcategory_name'].value == 'instcode') {
6871: alert('$instcode_reserved\\n$choose_again');
6872: return false;
6873: }
6874: if (form.elements['addcategory_name'].value == 'communities') {
6875: alert('$communities_reserved\\n$choose_again');
6876: return false;
6877: }
6878: return true;
6879: }
6880:
1.109 raeburn 6881: // ]]>
1.49 raeburn 6882: </script>
6883:
6884: ENDSCRIPT
6885: return $output;
6886: }
6887:
1.48 raeburn 6888: sub initialize_categories {
6889: my ($itemcount) = @_;
1.120 raeburn 6890: my ($datatable,$css_class,$chgstr);
6891: my %default_names = (
6892: instcode => 'Official courses (with institutional codes)',
6893: communities => 'Communities',
6894: );
6895: my $select0 = ' selected="selected"';
6896: my $select1 = '';
6897: foreach my $default ('instcode','communities') {
6898: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6899: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
6900: if ($default eq 'communities') {
6901: $select1 = $select0;
6902: $select0 = '';
6903: }
6904: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6905: .'<select name="'.$default.'_pos">'
6906: .'<option value="0"'.$select0.'>1</option>'
6907: .'<option value="1"'.$select1.'>2</option>'
6908: .'<option value="2">3</option></select> '
6909: .$default_names{$default}
6910: .'</span></td><td><span class="LC_nobreak">'
6911: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6912: .&mt('Display').'</label> <label>'
6913: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6914: .'</label></span></td></tr>';
1.120 raeburn 6915: $itemcount ++;
6916: }
1.48 raeburn 6917: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6918: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6919: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6920: .'<select name="addcategory_pos"'.$chgstr.'>'
6921: .'<option value="0">1</option>'
6922: .'<option value="1">2</option>'
6923: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 6924: .&mt('Add category').'</td><td>'.&mt('Name:')
6925: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
6926: return $datatable;
6927: }
6928:
6929: sub build_category_rows {
1.49 raeburn 6930: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6931: my ($text,$name,$item,$chgstr);
1.48 raeburn 6932: if (ref($cats) eq 'ARRAY') {
6933: my $maxdepth = scalar(@{$cats});
6934: if (ref($cats->[$depth]) eq 'HASH') {
6935: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6936: my $numchildren = @{$cats->[$depth]{$parent}};
6937: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 6938: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6939: my ($idxnum,$parent_name,$parent_item);
6940: my $higher = $depth - 1;
6941: if ($higher == 0) {
6942: $parent_name = &escape($parent).'::'.$higher;
6943: } else {
6944: if (ref($path) eq 'ARRAY') {
6945: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6946: }
6947: }
6948: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 6949: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 6950: if ($j < $numchildren) {
1.48 raeburn 6951: $name = $cats->[$depth]{$parent}[$j];
6952: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 6953: $idxnum = $idx->{$item};
6954: } else {
6955: $name = $parent_name;
6956: $item = $parent_item;
1.48 raeburn 6957: }
1.49 raeburn 6958: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6959: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 6960: for (my $i=0; $i<=$numchildren; $i++) {
6961: my $vpos = $i+1;
6962: my $selstr;
6963: if ($j == $i) {
6964: $selstr = ' selected="selected" ';
6965: }
6966: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6967: }
6968: $text .= '</select> ';
6969: if ($j < $numchildren) {
6970: my $deeper = $depth+1;
6971: $text .= $name.' '
6972: .'<label><input type="checkbox" name="deletecategory" value="'
6973: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6974: if(ref($path) eq 'ARRAY') {
6975: push(@{$path},$name);
1.49 raeburn 6976: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 6977: pop(@{$path});
6978: }
6979: } else {
1.59 bisitz 6980: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 6981: if ($j == $numchildren) {
6982: $text .= $name;
6983: } else {
6984: $text .= $item;
6985: }
6986: $text .= '" value="" />';
6987: }
6988: $text .= '</td></tr>';
6989: }
6990: $text .= '</table></td>';
6991: } else {
6992: my $higher = $depth-1;
6993: if ($higher == 0) {
6994: $name = &escape($parent).'::'.$higher;
6995: } else {
6996: if (ref($path) eq 'ARRAY') {
6997: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6998: }
6999: }
7000: my $colspan;
7001: if ($parent ne 'instcode') {
7002: $colspan = $maxdepth - $depth - 1;
7003: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
7004: }
7005: }
7006: }
7007: }
7008: return $text;
7009: }
7010:
1.33 raeburn 7011: sub modifiable_userdata_row {
1.160.6.35 raeburn 7012: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
7013: my ($role,$rolename,$statustype);
7014: $role = $item;
1.160.6.34 raeburn 7015: if ($context eq 'cancreate') {
1.160.6.35 raeburn 7016: if ($item =~ /^emailusername_(.+)$/) {
7017: $statustype = $1;
7018: $role = 'emailusername';
7019: if (ref($usertypes) eq 'HASH') {
7020: if ($usertypes->{$statustype}) {
7021: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7022: } else {
7023: $rolename = &mt('Data provided by user');
7024: }
7025: }
1.160.6.34 raeburn 7026: }
7027: } elsif ($context eq 'selfcreate') {
1.63 raeburn 7028: if (ref($usertypes) eq 'HASH') {
7029: $rolename = $usertypes->{$role};
7030: } else {
7031: $rolename = $role;
7032: }
1.33 raeburn 7033: } else {
1.63 raeburn 7034: if ($role eq 'cr') {
7035: $rolename = &mt('Custom role');
7036: } else {
7037: $rolename = &Apache::lonnet::plaintext($role);
7038: }
1.33 raeburn 7039: }
1.160.6.34 raeburn 7040: my (@fields,%fieldtitles);
7041: if (ref($fieldsref) eq 'ARRAY') {
7042: @fields = @{$fieldsref};
7043: } else {
7044: @fields = ('lastname','firstname','middlename','generation',
7045: 'permanentemail','id');
7046: }
7047: if ((ref($titlesref) eq 'HASH')) {
7048: %fieldtitles = %{$titlesref};
7049: } else {
7050: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7051: }
1.33 raeburn 7052: my $output;
7053: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7054: $output = '<tr '.$css_class.'>'.
7055: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7056: '<td class="LC_left_item" colspan="2"><table>';
7057: my $rem;
7058: my %checks;
7059: if (ref($settings) eq 'HASH') {
7060: if (ref($settings->{$context}) eq 'HASH') {
7061: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 7062: my $hashref = $settings->{$context}->{$role};
7063: if ($role eq 'emailusername') {
7064: if ($statustype) {
7065: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7066: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 7067: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 7068: foreach my $field (@fields) {
7069: if ($hashref->{$field}) {
7070: $checks{$field} = $hashref->{$field};
7071: }
7072: }
7073: }
7074: }
7075: }
7076: } else {
7077: if (ref($hashref) eq 'HASH') {
7078: foreach my $field (@fields) {
7079: if ($hashref->{$field}) {
7080: $checks{$field} = ' checked="checked" ';
7081: }
7082: }
1.33 raeburn 7083: }
7084: }
7085: }
7086: }
7087: }
1.160.6.39 raeburn 7088:
1.33 raeburn 7089: for (my $i=0; $i<@fields; $i++) {
7090: my $rem = $i%($numinrow);
7091: if ($rem == 0) {
7092: if ($i > 0) {
7093: $output .= '</tr>';
7094: }
7095: $output .= '<tr>';
7096: }
7097: my $check = ' ';
1.160.6.35 raeburn 7098: unless ($role eq 'emailusername') {
7099: if (exists($checks{$fields[$i]})) {
7100: $check = $checks{$fields[$i]}
7101: } else {
7102: if ($role eq 'st') {
7103: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 7104: $check = ' checked="checked" ';
1.160.6.35 raeburn 7105: }
1.33 raeburn 7106: }
7107: }
7108: }
7109: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 7110: '<span class="LC_nobreak">';
7111: if ($role eq 'emailusername') {
7112: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7113: $checks{$fields[$i]} = 'omit';
7114: }
7115: foreach my $option ('required','optional','omit') {
7116: my $checked='';
7117: if ($checks{$fields[$i]} eq $option) {
7118: $checked='checked="checked" ';
7119: }
7120: $output .= '<label>'.
7121: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7122: &mt($option).'</label>'.(' ' x2);
7123: }
7124: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7125: } else {
7126: $output .= '<label>'.
7127: '<input type="checkbox" name="canmodify_'.$role.'" '.
7128: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7129: '</label>';
7130: }
7131: $output .= '</span></td>';
1.33 raeburn 7132: $rem = @fields%($numinrow);
7133: }
7134: my $colsleft = $numinrow - $rem;
7135: if ($colsleft > 1 ) {
7136: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7137: ' </td>';
7138: } elsif ($colsleft == 1) {
7139: $output .= '<td class="LC_left_item"> </td>';
7140: }
7141: $output .= '</tr></table></td></tr>';
7142: return $output;
7143: }
1.28 raeburn 7144:
1.93 raeburn 7145: sub insttypes_row {
1.160.6.34 raeburn 7146: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 7147: my %lt = &Apache::lonlocal::texthash (
7148: cansearch => 'Users allowed to search',
7149: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 7150: lockablenames => 'User preference to lock name',
1.93 raeburn 7151: );
7152: my $showdom;
7153: if ($context eq 'cansearch') {
7154: $showdom = ' ('.$dom.')';
7155: }
1.160.6.5 raeburn 7156: my $class = 'LC_left_item';
7157: if ($context eq 'statustocreate') {
7158: $class = 'LC_right_item';
7159: }
1.160.6.34 raeburn 7160: my $css_class = ' class="LC_odd_row"';
7161: if ($rownum ne '') {
7162: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
7163: }
7164: my $output = '<tr'.$css_class.'>'.
7165: '<td>'.$lt{$context}.$showdom.
7166: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7167: my $rem;
7168: if (ref($types) eq 'ARRAY') {
7169: for (my $i=0; $i<@{$types}; $i++) {
7170: if (defined($usertypes->{$types->[$i]})) {
7171: my $rem = $i%($numinrow);
7172: if ($rem == 0) {
7173: if ($i > 0) {
7174: $output .= '</tr>';
7175: }
7176: $output .= '<tr>';
1.23 raeburn 7177: }
1.26 raeburn 7178: my $check = ' ';
1.99 raeburn 7179: if (ref($settings) eq 'HASH') {
7180: if (ref($settings->{$context}) eq 'ARRAY') {
7181: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7182: $check = ' checked="checked" ';
7183: }
7184: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7185: $check = ' checked="checked" ';
7186: }
1.23 raeburn 7187: }
1.26 raeburn 7188: $output .= '<td class="LC_left_item">'.
7189: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7190: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 7191: 'value="'.$types->[$i].'"'.$check.'/>'.
7192: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7193: }
7194: }
1.26 raeburn 7195: $rem = @{$types}%($numinrow);
1.23 raeburn 7196: }
7197: my $colsleft = $numinrow - $rem;
1.131 raeburn 7198: if (($rem == 0) && (@{$types} > 0)) {
7199: $output .= '<tr>';
7200: }
1.23 raeburn 7201: if ($colsleft > 1) {
1.25 raeburn 7202: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 7203: } else {
1.25 raeburn 7204: $output .= '<td class="LC_left_item">';
1.23 raeburn 7205: }
7206: my $defcheck = ' ';
1.99 raeburn 7207: if (ref($settings) eq 'HASH') {
7208: if (ref($settings->{$context}) eq 'ARRAY') {
7209: if (grep(/^default$/,@{$settings->{$context}})) {
7210: $defcheck = ' checked="checked" ';
7211: }
7212: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7213: $defcheck = ' checked="checked" ';
7214: }
1.23 raeburn 7215: }
1.25 raeburn 7216: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 7217: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 7218: 'value="default"'.$defcheck.'/>'.
7219: $othertitle.'</label></span></td>'.
7220: '</tr></table></td></tr>';
7221: return $output;
1.23 raeburn 7222: }
7223:
7224: sub sorted_searchtitles {
7225: my %searchtitles = &Apache::lonlocal::texthash(
7226: 'uname' => 'username',
7227: 'lastname' => 'last name',
7228: 'lastfirst' => 'last name, first name',
7229: );
7230: my @titleorder = ('uname','lastname','lastfirst');
7231: return (\%searchtitles,\@titleorder);
7232: }
7233:
1.25 raeburn 7234: sub sorted_searchtypes {
7235: my %srchtypes_desc = (
7236: exact => 'is exact match',
7237: contains => 'contains ..',
7238: begins => 'begins with ..',
7239: );
7240: my @srchtypeorder = ('exact','begins','contains');
7241: return (\%srchtypes_desc,\@srchtypeorder);
7242: }
7243:
1.3 raeburn 7244: sub usertype_update_row {
7245: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7246: my $datatable;
7247: my $numinrow = 4;
7248: foreach my $type (@{$types}) {
7249: if (defined($usertypes->{$type})) {
7250: $$rownums ++;
7251: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7252: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7253: '</td><td class="LC_left_item"><table>';
7254: for (my $i=0; $i<@{$fields}; $i++) {
7255: my $rem = $i%($numinrow);
7256: if ($rem == 0) {
7257: if ($i > 0) {
7258: $datatable .= '</tr>';
7259: }
7260: $datatable .= '<tr>';
7261: }
7262: my $check = ' ';
1.39 raeburn 7263: if (ref($settings) eq 'HASH') {
7264: if (ref($settings->{'fields'}) eq 'HASH') {
7265: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7266: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7267: $check = ' checked="checked" ';
7268: }
1.3 raeburn 7269: }
7270: }
7271: }
7272:
7273: if ($i == @{$fields}-1) {
7274: my $colsleft = $numinrow - $rem;
7275: if ($colsleft > 1) {
7276: $datatable .= '<td colspan="'.$colsleft.'">';
7277: } else {
7278: $datatable .= '<td>';
7279: }
7280: } else {
7281: $datatable .= '<td>';
7282: }
1.8 raeburn 7283: $datatable .= '<span class="LC_nobreak"><label>'.
7284: '<input type="checkbox" name="updateable_'.$type.
7285: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7286: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 7287: }
7288: $datatable .= '</tr></table></td></tr>';
7289: }
7290: }
7291: return $datatable;
1.1 raeburn 7292: }
7293:
7294: sub modify_login {
1.160.6.24 raeburn 7295: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 7296: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7297: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7298: %title = ( coursecatalog => 'Display course catalog',
7299: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 7300: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 7301: newuser => 'Link for visitors to create a user account',
7302: loginheader => 'Log-in box header');
7303: @offon = ('off','on');
1.112 raeburn 7304: if (ref($domconfig{login}) eq 'HASH') {
7305: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7306: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7307: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7308: }
7309: }
7310: }
1.9 raeburn 7311: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7312: \%domconfig,\%loginhash);
1.160.6.14 raeburn 7313: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7314: foreach my $item (@toggles) {
7315: $loginhash{login}{$item} = $env{'form.'.$item};
7316: }
1.41 raeburn 7317: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 7318: if (ref($colchanges{'login'}) eq 'HASH') {
7319: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7320: \%loginhash);
7321: }
1.110 raeburn 7322:
1.149 raeburn 7323: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 7324: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 7325: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 7326: if (keys(%servers) > 1) {
7327: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 7328: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7329: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7330: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7331: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7332: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7333: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7334: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7335: $changes{'loginvia'}{$lonhost} = 1;
7336: } else {
7337: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7338: $changes{'loginvia'}{$lonhost} = 1;
7339: }
7340: } else {
7341: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7342: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7343: $changes{'loginvia'}{$lonhost} = 1;
7344: }
7345: }
7346: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7347: foreach my $item (@loginvia_attribs) {
7348: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7349: }
7350: } else {
7351: foreach my $item (@loginvia_attribs) {
7352: my $new = $env{'form.'.$lonhost.'_'.$item};
7353: if (($item eq 'serverpath') && ($new eq 'custom')) {
7354: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7355: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7356: $new = '/';
7357: }
7358: }
7359: if (($item eq 'custompath') &&
7360: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7361: $new = '';
7362: }
7363: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7364: $changes{'loginvia'}{$lonhost} = 1;
7365: }
7366: if ($item eq 'exempt') {
1.160.6.56 raeburn 7367: $new = &check_exempt_addresses($new);
1.128 raeburn 7368: }
7369: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7370: }
7371: }
1.112 raeburn 7372: } else {
1.128 raeburn 7373: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7374: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 7375: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 7376: foreach my $item (@loginvia_attribs) {
7377: my $new = $env{'form.'.$lonhost.'_'.$item};
7378: if (($item eq 'serverpath') && ($new eq 'custom')) {
7379: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7380: $new = '/';
7381: }
7382: }
7383: if (($item eq 'custompath') &&
7384: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7385: $new = '';
7386: }
7387: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7388: }
1.110 raeburn 7389: }
7390: }
7391: }
7392: }
1.119 raeburn 7393:
1.160.6.5 raeburn 7394: my $servadm = $r->dir_config('lonAdmEMail');
7395: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
7396: if (ref($domconfig{'login'}) eq 'HASH') {
7397: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
7398: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
7399: if ($lang eq 'nolang') {
7400: push(@currlangs,$lang);
7401: } elsif (defined($langchoices{$lang})) {
7402: push(@currlangs,$lang);
7403: } else {
7404: next;
7405: }
7406: }
7407: }
7408: }
7409: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
7410: if (@currlangs > 0) {
7411: foreach my $lang (@currlangs) {
7412: if (grep(/^\Q$lang\E$/,@delurls)) {
7413: $changes{'helpurl'}{$lang} = 1;
7414: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
7415: $changes{'helpurl'}{$lang} = 1;
7416: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
7417: push(@newlangs,$lang);
7418: } else {
7419: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7420: }
7421: }
7422: }
7423: unless (grep(/^nolang$/,@currlangs)) {
7424: if ($env{'form.loginhelpurl_nolang.filename'}) {
7425: $changes{'helpurl'}{'nolang'} = 1;
7426: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
7427: push(@newlangs,'nolang');
7428: }
7429: }
7430: if ($env{'form.loginhelpurl_add_lang'}) {
7431: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
7432: ($env{'form.loginhelpurl_add_file.filename'})) {
7433: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
7434: $addedfile = $env{'form.loginhelpurl_add_lang'};
7435: }
7436: }
7437: if ((@newlangs > 0) || ($addedfile)) {
7438: my $error;
7439: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7440: if ($configuserok eq 'ok') {
7441: if ($switchserver) {
7442: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7443: } elsif ($author_ok eq 'ok') {
7444: my @allnew = @newlangs;
7445: if ($addedfile ne '') {
7446: push(@allnew,$addedfile);
7447: }
7448: foreach my $lang (@allnew) {
7449: my $formelem = 'loginhelpurl_'.$lang;
7450: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
7451: $formelem = 'loginhelpurl_add_file';
7452: }
7453: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7454: "help/$lang",'','',$newfile{$lang});
7455: if ($result eq 'ok') {
7456: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
7457: $changes{'helpurl'}{$lang} = 1;
7458: } else {
7459: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
7460: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7461: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
7462: (!grep(/^\Q$lang\E$/,@delurls))) {
7463: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7464: }
7465: }
7466: }
7467: } else {
7468: $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);
7469: }
7470: } else {
7471: $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);
7472: }
7473: if ($error) {
7474: &Apache::lonnet::logthis($error);
7475: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7476: }
7477: }
1.160.6.56 raeburn 7478:
7479: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
7480: if (ref($domconfig{'login'}) eq 'HASH') {
7481: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
7482: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
7483: if ($domservers{$lonhost}) {
7484: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7485: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 7486: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 7487: }
7488: }
7489: }
7490: }
7491: }
7492: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
7493: foreach my $lonhost (sort(keys(%domservers))) {
7494: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7495: $changes{'headtag'}{$lonhost} = 1;
7496: } else {
7497: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
7498: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
7499: }
7500: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
7501: push(@newhosts,$lonhost);
7502: } elsif ($currheadtagurls{$lonhost}) {
7503: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
7504: if ($currexempt{$lonhost}) {
7505: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
7506: $changes{'headtag'}{$lonhost} = 1;
7507: }
7508: } elsif ($possexempt{$lonhost}) {
7509: $changes{'headtag'}{$lonhost} = 1;
7510: }
7511: if ($possexempt{$lonhost}) {
7512: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7513: }
7514: }
7515: }
7516: }
7517: if (@newhosts) {
7518: my $error;
7519: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7520: if ($configuserok eq 'ok') {
7521: if ($switchserver) {
7522: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
7523: } elsif ($author_ok eq 'ok') {
7524: foreach my $lonhost (@newhosts) {
7525: my $formelem = 'loginheadtag_'.$lonhost;
7526: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7527: "login/headtag/$lonhost",'','',
7528: $env{'form.loginheadtag_'.$lonhost.'.filename'});
7529: if ($result eq 'ok') {
7530: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
7531: $changes{'headtag'}{$lonhost} = 1;
7532: if ($possexempt{$lonhost}) {
7533: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7534: }
7535: } else {
7536: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7537: $newheadtagurls{$lonhost},$result);
7538: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7539: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7540: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7541: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7542: }
7543: }
7544: }
7545: } else {
7546: $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);
7547: }
7548: } else {
7549: $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);
7550: }
7551: if ($error) {
7552: &Apache::lonnet::logthis($error);
7553: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7554: }
7555: }
1.160.6.5 raeburn 7556: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
7557:
7558: my $defaulthelpfile = '/adm/loginproblems.html';
7559: my $defaulttext = &mt('Default in use');
7560:
1.1 raeburn 7561: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7562: $dom);
7563: if ($putresult eq 'ok') {
1.160.6.14 raeburn 7564: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7565: my %defaultchecked = (
7566: 'coursecatalog' => 'on',
1.160.6.14 raeburn 7567: 'helpdesk' => 'on',
1.42 raeburn 7568: 'adminmail' => 'off',
1.43 raeburn 7569: 'newuser' => 'off',
1.42 raeburn 7570: );
1.55 raeburn 7571: if (ref($domconfig{'login'}) eq 'HASH') {
7572: foreach my $item (@toggles) {
7573: if ($defaultchecked{$item} eq 'on') {
7574: if (($domconfig{'login'}{$item} eq '0') &&
7575: ($env{'form.'.$item} eq '1')) {
7576: $changes{$item} = 1;
7577: } elsif (($domconfig{'login'}{$item} eq '' ||
7578: $domconfig{'login'}{$item} eq '1') &&
7579: ($env{'form.'.$item} eq '0')) {
7580: $changes{$item} = 1;
7581: }
7582: } elsif ($defaultchecked{$item} eq 'off') {
7583: if (($domconfig{'login'}{$item} eq '1') &&
7584: ($env{'form.'.$item} eq '0')) {
7585: $changes{$item} = 1;
7586: } elsif (($domconfig{'login'}{$item} eq '' ||
7587: $domconfig{'login'}{$item} eq '0') &&
7588: ($env{'form.'.$item} eq '1')) {
7589: $changes{$item} = 1;
7590: }
1.42 raeburn 7591: }
7592: }
1.41 raeburn 7593: }
1.6 raeburn 7594: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7595: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7596: if (ref($lastactref) eq 'HASH') {
7597: $lastactref->{'domainconfig'} = 1;
7598: }
1.1 raeburn 7599: $resulttext = &mt('Changes made:').'<ul>';
7600: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7601: if ($item eq 'loginvia') {
1.112 raeburn 7602: if (ref($changes{$item}) eq 'HASH') {
7603: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7604: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7605: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7606: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7607: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7608: $protocol = 'http' if ($protocol ne 'https');
7609: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7610:
7611: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7612: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7613: } else {
7614: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7615: }
7616: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7617: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7618: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7619: }
7620: $resulttext .= '</li>';
7621: } else {
7622: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7623: }
1.112 raeburn 7624: } else {
1.128 raeburn 7625: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7626: }
7627: }
1.128 raeburn 7628: $resulttext .= '</ul></li>';
1.112 raeburn 7629: }
1.160.6.5 raeburn 7630: } elsif ($item eq 'helpurl') {
7631: if (ref($changes{$item}) eq 'HASH') {
7632: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7633: if (grep(/^\Q$lang\E$/,@delurls)) {
7634: my ($chg,$link);
7635: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7636: if ($lang eq 'nolang') {
7637: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7638: } else {
7639: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7640: }
7641: $resulttext .= '<li>'.$chg.'</li>';
7642: } else {
7643: my $chg;
7644: if ($lang eq 'nolang') {
7645: $chg = &mt('custom log-in help file for no preferred language');
7646: } else {
7647: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7648: }
7649: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7650: $loginhash{'login'}{'helpurl'}{$lang}.
7651: '?inhibitmenu=yes',$chg,600,500).
7652: '</li>';
7653: }
7654: }
7655: }
1.160.6.56 raeburn 7656: } elsif ($item eq 'headtag') {
7657: if (ref($changes{$item}) eq 'HASH') {
7658: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7659: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7660: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7661: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7662: $resulttext .= '<li><a href="'.
7663: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7664: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7665: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7666: if ($possexempt{$lonhost}) {
7667: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7668: } else {
7669: $resulttext .= &mt('included for any client IP');
7670: }
7671: $resulttext .= '</li>';
7672: }
7673: }
7674: }
1.160.6.5 raeburn 7675: } elsif ($item eq 'captcha') {
7676: if (ref($loginhash{'login'}) eq 'HASH') {
7677: my $chgtxt;
7678: if ($loginhash{'login'}{$item} eq 'notused') {
7679: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7680: } else {
7681: my %captchas = &captcha_phrases();
7682: if ($captchas{$loginhash{'login'}{$item}}) {
7683: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7684: } else {
7685: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7686: }
7687: }
7688: $resulttext .= '<li>'.$chgtxt.'</li>';
7689: }
7690: } elsif ($item eq 'recaptchakeys') {
7691: if (ref($loginhash{'login'}) eq 'HASH') {
7692: my ($privkey,$pubkey);
7693: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7694: $pubkey = $loginhash{'login'}{$item}{'public'};
7695: $privkey = $loginhash{'login'}{$item}{'private'};
7696: }
7697: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7698: if (!$pubkey) {
7699: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7700: } else {
7701: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7702: }
7703: if (!$privkey) {
7704: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7705: } else {
1.160.6.53 raeburn 7706: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 7707: }
7708: $chgtxt .= '</ul>';
7709: $resulttext .= '<li>'.$chgtxt.'</li>';
7710: }
1.160.6.69 raeburn 7711: } elsif ($item eq 'recaptchaversion') {
7712: if (ref($loginhash{'login'}) eq 'HASH') {
7713: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
7714: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
7715: '</li>';
7716: }
7717: }
1.41 raeburn 7718: } else {
7719: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7720: }
1.1 raeburn 7721: }
1.6 raeburn 7722: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7723: } else {
7724: $resulttext = &mt('No changes made to log-in page settings');
7725: }
7726: } else {
1.11 albertel 7727: $resulttext = '<span class="LC_error">'.
7728: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7729: }
1.6 raeburn 7730: if ($errors) {
1.9 raeburn 7731: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7732: $errors.'</ul>';
7733: }
7734: return $resulttext;
7735: }
7736:
1.160.6.56 raeburn 7737: sub check_exempt_addresses {
7738: my ($iplist) = @_;
7739: $iplist =~ s/^\s+//;
7740: $iplist =~ s/\s+$//;
7741: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7742: my (@okips,$new);
7743: foreach my $ip (@poss_ips) {
7744: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7745: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7746: push(@okips,$ip);
7747: }
7748: }
7749: }
7750: if (@okips > 0) {
7751: $new = join(',',@okips);
7752: } else {
7753: $new = '';
7754: }
7755: return $new;
7756: }
7757:
1.6 raeburn 7758: sub color_font_choices {
7759: my %choices =
7760: &Apache::lonlocal::texthash (
7761: img => "Header",
7762: bgs => "Background colors",
7763: links => "Link colors",
1.55 raeburn 7764: images => "Images",
1.6 raeburn 7765: font => "Font color",
1.160.6.22 raeburn 7766: fontmenu => "Font menu",
1.76 raeburn 7767: pgbg => "Page",
1.6 raeburn 7768: tabbg => "Header",
7769: sidebg => "Border",
7770: link => "Link",
7771: alink => "Active link",
7772: vlink => "Visited link",
7773: );
7774: return %choices;
7775: }
7776:
7777: sub modify_rolecolors {
1.160.6.24 raeburn 7778: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7779: my ($resulttext,%rolehash);
7780: $rolehash{'rolecolors'} = {};
1.55 raeburn 7781: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7782: if ($domconfig{'rolecolors'} eq '') {
7783: $domconfig{'rolecolors'} = {};
7784: }
7785: }
1.9 raeburn 7786: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7787: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7788: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7789: $dom);
7790: if ($putresult eq 'ok') {
7791: if (keys(%changes) > 0) {
1.41 raeburn 7792: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7793: if (ref($lastactref) eq 'HASH') {
7794: $lastactref->{'domainconfig'} = 1;
7795: }
1.6 raeburn 7796: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7797: $rolehash{'rolecolors'});
7798: } else {
7799: $resulttext = &mt('No changes made to default color schemes');
7800: }
7801: } else {
1.11 albertel 7802: $resulttext = '<span class="LC_error">'.
7803: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7804: }
7805: if ($errors) {
7806: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7807: $errors.'</ul>';
7808: }
7809: return $resulttext;
7810: }
7811:
7812: sub modify_colors {
1.9 raeburn 7813: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7814: my (%changes,%choices);
1.51 raeburn 7815: my @bgs;
1.6 raeburn 7816: my @links = ('link','alink','vlink');
1.41 raeburn 7817: my @logintext;
1.6 raeburn 7818: my @images;
7819: my $servadm = $r->dir_config('lonAdmEMail');
7820: my $errors;
1.160.6.22 raeburn 7821: my %defaults;
1.6 raeburn 7822: foreach my $role (@{$roles}) {
7823: if ($role eq 'login') {
1.12 raeburn 7824: %choices = &login_choices();
1.41 raeburn 7825: @logintext = ('textcol','bgcol');
1.12 raeburn 7826: } else {
7827: %choices = &color_font_choices();
7828: }
7829: if ($role eq 'login') {
1.41 raeburn 7830: @images = ('img','logo','domlogo','login');
1.51 raeburn 7831: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7832: } else {
7833: @images = ('img');
1.160.6.22 raeburn 7834: @bgs = ('pgbg','tabbg','sidebg');
7835: }
7836: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7837: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7838: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7839: }
7840: if ($role eq 'login') {
7841: foreach my $item (@logintext) {
1.160.6.39 raeburn 7842: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7843: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7844: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7845: }
7846: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 7847: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7848: }
7849: }
7850: } else {
1.160.6.39 raeburn 7851: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7852: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7853: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7854: }
7855: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 7856: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7857: }
1.6 raeburn 7858: }
1.160.6.22 raeburn 7859: foreach my $item (@bgs) {
1.160.6.39 raeburn 7860: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7861: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7862: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7863: }
7864: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 7865: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7866: }
7867: }
7868: foreach my $item (@links) {
1.160.6.39 raeburn 7869: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7870: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7871: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7872: }
7873: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 7874: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7875: }
1.6 raeburn 7876: }
1.46 raeburn 7877: my ($configuserok,$author_ok,$switchserver) =
7878: &config_check($dom,$confname,$servadm);
1.9 raeburn 7879: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7880: if (ref($domconfig->{$role}) ne 'HASH') {
7881: $domconfig->{$role} = {};
7882: }
1.8 raeburn 7883: foreach my $img (@images) {
1.70 raeburn 7884: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7885: if (defined($env{'form.login_showlogo_'.$img})) {
7886: $confhash->{$role}{'showlogo'}{$img} = 1;
7887: } else {
7888: $confhash->{$role}{'showlogo'}{$img} = 0;
7889: }
7890: }
1.18 albertel 7891: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7892: && !defined($domconfig->{$role}{$img})
7893: && !$env{'form.'.$role.'_del_'.$img}
7894: && $env{'form.'.$role.'_import_'.$img}) {
7895: # import the old configured image from the .tab setting
7896: # if they haven't provided a new one
7897: $domconfig->{$role}{$img} =
7898: $env{'form.'.$role.'_import_'.$img};
7899: }
1.6 raeburn 7900: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7901: my $error;
1.6 raeburn 7902: if ($configuserok eq 'ok') {
1.9 raeburn 7903: if ($switchserver) {
1.12 raeburn 7904: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7905: } else {
7906: if ($author_ok eq 'ok') {
7907: my ($result,$logourl) =
7908: &publishlogo($r,'upload',$role.'_'.$img,
7909: $dom,$confname,$img,$width,$height);
7910: if ($result eq 'ok') {
7911: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7912: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7913: } else {
1.12 raeburn 7914: $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 7915: }
7916: } else {
1.46 raeburn 7917: $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 7918: }
7919: }
7920: } else {
1.46 raeburn 7921: $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 7922: }
7923: if ($error) {
1.8 raeburn 7924: &Apache::lonnet::logthis($error);
1.11 albertel 7925: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7926: }
7927: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7928: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7929: my $error;
7930: if ($configuserok eq 'ok') {
7931: # is confname an author?
7932: if ($switchserver eq '') {
7933: if ($author_ok eq 'ok') {
7934: my ($result,$logourl) =
7935: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7936: $dom,$confname,$img,$width,$height);
7937: if ($result eq 'ok') {
7938: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7939: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7940: }
7941: }
7942: }
7943: }
1.6 raeburn 7944: }
7945: }
7946: }
7947: if (ref($domconfig) eq 'HASH') {
7948: if (ref($domconfig->{$role}) eq 'HASH') {
7949: foreach my $img (@images) {
7950: if ($domconfig->{$role}{$img} ne '') {
7951: if ($env{'form.'.$role.'_del_'.$img}) {
7952: $confhash->{$role}{$img} = '';
1.12 raeburn 7953: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7954: } else {
1.9 raeburn 7955: if ($confhash->{$role}{$img} eq '') {
7956: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7957: }
1.6 raeburn 7958: }
7959: } else {
7960: if ($env{'form.'.$role.'_del_'.$img}) {
7961: $confhash->{$role}{$img} = '';
1.12 raeburn 7962: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7963: }
7964: }
1.70 raeburn 7965: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
7966: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
7967: if ($confhash->{$role}{'showlogo'}{$img} ne
7968: $domconfig->{$role}{'showlogo'}{$img}) {
7969: $changes{$role}{'showlogo'}{$img} = 1;
7970: }
7971: } else {
7972: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7973: $changes{$role}{'showlogo'}{$img} = 1;
7974: }
7975: }
7976: }
7977: }
1.6 raeburn 7978: if ($domconfig->{$role}{'font'} ne '') {
7979: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
7980: $changes{$role}{'font'} = 1;
7981: }
7982: } else {
7983: if ($confhash->{$role}{'font'}) {
7984: $changes{$role}{'font'} = 1;
7985: }
7986: }
1.107 raeburn 7987: if ($role ne 'login') {
7988: if ($domconfig->{$role}{'fontmenu'} ne '') {
7989: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
7990: $changes{$role}{'fontmenu'} = 1;
7991: }
7992: } else {
7993: if ($confhash->{$role}{'fontmenu'}) {
7994: $changes{$role}{'fontmenu'} = 1;
7995: }
1.97 tempelho 7996: }
7997: }
1.6 raeburn 7998: foreach my $item (@bgs) {
7999: if ($domconfig->{$role}{$item} ne '') {
8000: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8001: $changes{$role}{'bgs'}{$item} = 1;
8002: }
8003: } else {
8004: if ($confhash->{$role}{$item}) {
8005: $changes{$role}{'bgs'}{$item} = 1;
8006: }
8007: }
8008: }
8009: foreach my $item (@links) {
8010: if ($domconfig->{$role}{$item} ne '') {
8011: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8012: $changes{$role}{'links'}{$item} = 1;
8013: }
8014: } else {
8015: if ($confhash->{$role}{$item}) {
8016: $changes{$role}{'links'}{$item} = 1;
8017: }
8018: }
8019: }
1.41 raeburn 8020: foreach my $item (@logintext) {
8021: if ($domconfig->{$role}{$item} ne '') {
8022: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8023: $changes{$role}{'logintext'}{$item} = 1;
8024: }
8025: } else {
8026: if ($confhash->{$role}{$item}) {
8027: $changes{$role}{'logintext'}{$item} = 1;
8028: }
8029: }
8030: }
1.6 raeburn 8031: } else {
8032: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8033: \@logintext,$confhash,\%changes);
1.6 raeburn 8034: }
8035: } else {
8036: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8037: \@logintext,$confhash,\%changes);
1.6 raeburn 8038: }
8039: }
8040: return ($errors,%changes);
8041: }
8042:
1.46 raeburn 8043: sub config_check {
8044: my ($dom,$confname,$servadm) = @_;
8045: my ($configuserok,$author_ok,$switchserver,%currroles);
8046: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8047: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8048: $confname,$servadm);
8049: if ($configuserok eq 'ok') {
8050: $switchserver = &check_switchserver($dom,$confname);
8051: if ($switchserver eq '') {
8052: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8053: }
8054: }
8055: return ($configuserok,$author_ok,$switchserver);
8056: }
8057:
1.6 raeburn 8058: sub default_change_checker {
1.41 raeburn 8059: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8060: foreach my $item (@{$links}) {
8061: if ($confhash->{$role}{$item}) {
8062: $changes->{$role}{'links'}{$item} = 1;
8063: }
8064: }
8065: foreach my $item (@{$bgs}) {
8066: if ($confhash->{$role}{$item}) {
8067: $changes->{$role}{'bgs'}{$item} = 1;
8068: }
8069: }
1.41 raeburn 8070: foreach my $item (@{$logintext}) {
8071: if ($confhash->{$role}{$item}) {
8072: $changes->{$role}{'logintext'}{$item} = 1;
8073: }
8074: }
1.6 raeburn 8075: foreach my $img (@{$images}) {
8076: if ($env{'form.'.$role.'_del_'.$img}) {
8077: $confhash->{$role}{$img} = '';
1.12 raeburn 8078: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8079: }
1.70 raeburn 8080: if ($role eq 'login') {
8081: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8082: $changes->{$role}{'showlogo'}{$img} = 1;
8083: }
8084: }
1.6 raeburn 8085: }
8086: if ($confhash->{$role}{'font'}) {
8087: $changes->{$role}{'font'} = 1;
8088: }
1.48 raeburn 8089: }
1.6 raeburn 8090:
8091: sub display_colorchgs {
8092: my ($dom,$changes,$roles,$confhash) = @_;
8093: my (%choices,$resulttext);
8094: if (!grep(/^login$/,@{$roles})) {
8095: $resulttext = &mt('Changes made:').'<br />';
8096: }
8097: foreach my $role (@{$roles}) {
8098: if ($role eq 'login') {
8099: %choices = &login_choices();
8100: } else {
8101: %choices = &color_font_choices();
8102: }
8103: if (ref($changes->{$role}) eq 'HASH') {
8104: if ($role ne 'login') {
8105: $resulttext .= '<h4>'.&mt($role).'</h4>';
8106: }
8107: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8108: if ($role ne 'login') {
8109: $resulttext .= '<ul>';
8110: }
8111: if (ref($changes->{$role}{$key}) eq 'HASH') {
8112: if ($role ne 'login') {
8113: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8114: }
8115: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8116: if (($role eq 'login') && ($key eq 'showlogo')) {
8117: if ($confhash->{$role}{$key}{$item}) {
8118: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8119: } else {
8120: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8121: }
8122: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8123: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8124: } else {
1.12 raeburn 8125: my $newitem = $confhash->{$role}{$item};
8126: if ($key eq 'images') {
8127: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
8128: }
8129: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8130: }
8131: }
8132: if ($role ne 'login') {
8133: $resulttext .= '</ul></li>';
8134: }
8135: } else {
8136: if ($confhash->{$role}{$key} eq '') {
8137: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8138: } else {
8139: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8140: }
8141: }
8142: if ($role ne 'login') {
8143: $resulttext .= '</ul>';
8144: }
8145: }
8146: }
8147: }
1.3 raeburn 8148: return $resulttext;
1.1 raeburn 8149: }
8150:
1.9 raeburn 8151: sub thumb_dimensions {
8152: return ('200','50');
8153: }
8154:
1.16 raeburn 8155: sub check_dimensions {
8156: my ($inputfile) = @_;
8157: my ($fullwidth,$fullheight);
8158: if ($inputfile =~ m|^[/\w.\-]+$|) {
8159: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8160: my $imageinfo = <PIPE>;
8161: if (!close(PIPE)) {
8162: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8163: }
8164: chomp($imageinfo);
8165: my ($fullsize) =
1.21 raeburn 8166: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8167: if ($fullsize) {
8168: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8169: }
8170: }
8171: }
8172: return ($fullwidth,$fullheight);
8173: }
8174:
1.9 raeburn 8175: sub check_configuser {
8176: my ($uhome,$dom,$confname,$servadm) = @_;
8177: my ($configuserok,%currroles);
8178: if ($uhome eq 'no_host') {
8179: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
8180: my $configpass = &LONCAPA::Enrollment::create_password();
8181: $configuserok =
8182: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8183: $configpass,'','','','','',undef,$servadm);
8184: } else {
8185: $configuserok = 'ok';
8186: %currroles =
8187: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8188: }
8189: return ($configuserok,%currroles);
8190: }
8191:
8192: sub check_authorstatus {
8193: my ($dom,$confname,%currroles) = @_;
8194: my $author_ok;
1.40 raeburn 8195: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8196: my $start = time;
8197: my $end = 0;
8198: $author_ok =
8199: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8200: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8201: } else {
8202: $author_ok = 'ok';
8203: }
8204: return $author_ok;
8205: }
8206:
8207: sub publishlogo {
1.46 raeburn 8208: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 8209: my ($output,$fname,$logourl);
8210: if ($action eq 'upload') {
8211: $fname=$env{'form.'.$formname.'.filename'};
8212: chop($env{'form.'.$formname});
8213: } else {
8214: ($fname) = ($formname =~ /([^\/]+)$/);
8215: }
1.46 raeburn 8216: if ($savefileas ne '') {
8217: $fname = $savefileas;
8218: }
1.9 raeburn 8219: $fname=&Apache::lonnet::clean_filename($fname);
8220: # See if there is anything left
8221: unless ($fname) { return ('error: no uploaded file'); }
8222: $fname="$subdir/$fname";
1.160.6.5 raeburn 8223: my $docroot=$r->dir_config('lonDocRoot');
8224: my $filepath="$docroot/priv";
8225: my $relpath = "$dom/$confname";
1.9 raeburn 8226: my ($fnamepath,$file,$fetchthumb);
8227: $file=$fname;
8228: if ($fname=~m|/|) {
8229: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8230: }
1.160.6.26 raeburn 8231: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8232: my $count;
1.160.6.5 raeburn 8233: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8234: $filepath.="/$parts[$count]";
8235: if ((-e $filepath)!=1) {
8236: mkdir($filepath,02770);
8237: }
8238: }
8239: # Check for bad extension and disallow upload
8240: if ($file=~/\.(\w+)$/ &&
8241: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8242: $output =
1.160.6.25 raeburn 8243: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8244: } elsif ($file=~/\.(\w+)$/ &&
8245: !defined(&Apache::loncommon::fileembstyle($1))) {
8246: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8247: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 8248: $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 8249: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 8250: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8251: } else {
8252: my $source = $filepath.'/'.$file;
8253: my $logfile;
8254: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 8255: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8256: }
8257: print $logfile
8258: "\n================= Publish ".localtime()." ================\n".
8259: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8260: # Save the file
8261: if (!open(FH,'>'.$source)) {
8262: &Apache::lonnet::logthis('Failed to create '.$source);
8263: return (&mt('Failed to create file'));
8264: }
8265: if ($action eq 'upload') {
8266: if (!print FH ($env{'form.'.$formname})) {
8267: &Apache::lonnet::logthis('Failed to write to '.$source);
8268: return (&mt('Failed to write file'));
8269: }
8270: } else {
8271: my $original = &Apache::lonnet::filelocation('',$formname);
8272: if(!copy($original,$source)) {
8273: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8274: return (&mt('Failed to write file'));
8275: }
8276: }
8277: close(FH);
8278: chmod(0660, $source); # Permissions to rw-rw---.
8279:
8280: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8281: my $copyfile=$targetdir.'/'.$file;
8282:
8283: my @parts=split(/\//,$targetdir);
8284: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8285: for (my $count=5;$count<=$#parts;$count++) {
8286: $path.="/$parts[$count]";
8287: if (!-e $path) {
8288: print $logfile "\nCreating directory ".$path;
8289: mkdir($path,02770);
8290: }
8291: }
8292: my $versionresult;
8293: if (-e $copyfile) {
8294: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8295: } else {
8296: $versionresult = 'ok';
8297: }
8298: if ($versionresult eq 'ok') {
8299: if (copy($source,$copyfile)) {
8300: print $logfile "\nCopied original source to ".$copyfile."\n";
8301: $output = 'ok';
8302: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8303: push(@{$modified_urls},[$copyfile,$source]);
8304: my $metaoutput =
8305: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8306: unless ($registered_cleanup) {
8307: my $handlers = $r->get_handlers('PerlCleanupHandler');
8308: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8309: $registered_cleanup=1;
8310: }
1.9 raeburn 8311: } else {
8312: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8313: $output = &mt('Failed to copy file to RES space').", $!";
8314: }
8315: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8316: my $inputfile = $filepath.'/'.$file;
8317: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8318: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8319: if ($fullwidth ne '' && $fullheight ne '') {
8320: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8321: my $thumbsize = $thumbwidth.'x'.$thumbheight;
8322: system("convert -sample $thumbsize $inputfile $outfile");
8323: chmod(0660, $filepath.'/tn-'.$file);
8324: if (-e $outfile) {
8325: my $copyfile=$targetdir.'/tn-'.$file;
8326: if (copy($outfile,$copyfile)) {
8327: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8328: my $thumb_metaoutput =
8329: &write_metadata($dom,$confname,$formname,
8330: $targetdir,'tn-'.$file,$logfile);
8331: push(@{$modified_urls},[$copyfile,$outfile]);
8332: unless ($registered_cleanup) {
8333: my $handlers = $r->get_handlers('PerlCleanupHandler');
8334: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8335: $registered_cleanup=1;
8336: }
1.16 raeburn 8337: } else {
8338: print $logfile "\nUnable to write ".$copyfile.
8339: ':'.$!."\n";
8340: }
8341: }
1.9 raeburn 8342: }
8343: }
8344: }
8345: } else {
8346: $output = $versionresult;
8347: }
8348: }
8349: return ($output,$logourl);
8350: }
8351:
8352: sub logo_versioning {
8353: my ($targetdir,$file,$logfile) = @_;
8354: my $target = $targetdir.'/'.$file;
8355: my ($maxversion,$fn,$extn,$output);
8356: $maxversion = 0;
8357: if ($file =~ /^(.+)\.(\w+)$/) {
8358: $fn=$1;
8359: $extn=$2;
8360: }
8361: opendir(DIR,$targetdir);
8362: while (my $filename=readdir(DIR)) {
8363: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8364: $maxversion=($1>$maxversion)?$1:$maxversion;
8365: }
8366: }
8367: $maxversion++;
8368: print $logfile "\nCreating old version ".$maxversion."\n";
8369: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8370: if (copy($target,$copyfile)) {
8371: print $logfile "Copied old target to ".$copyfile."\n";
8372: $copyfile=$copyfile.'.meta';
8373: if (copy($target.'.meta',$copyfile)) {
8374: print $logfile "Copied old target metadata to ".$copyfile."\n";
8375: $output = 'ok';
8376: } else {
8377: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8378: $output = &mt('Failed to copy old meta').", $!, ";
8379: }
8380: } else {
8381: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8382: $output = &mt('Failed to copy old target').", $!, ";
8383: }
8384: return $output;
8385: }
8386:
8387: sub write_metadata {
8388: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
8389: my (%metadatafields,%metadatakeys,$output);
8390: $metadatafields{'title'}=$formname;
8391: $metadatafields{'creationdate'}=time;
8392: $metadatafields{'lastrevisiondate'}=time;
8393: $metadatafields{'copyright'}='public';
8394: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
8395: $env{'user.domain'};
8396: $metadatafields{'authorspace'}=$confname.':'.$dom;
8397: $metadatafields{'domain'}=$dom;
8398: {
8399: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
8400: my $mfh;
1.155 raeburn 8401: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 8402: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 8403: unless ($_=~/\./) {
8404: my $unikey=$_;
8405: $unikey=~/^([A-Za-z]+)/;
8406: my $tag=$1;
8407: $tag=~tr/A-Z/a-z/;
8408: print $mfh "\n\<$tag";
8409: foreach (split(/\,/,$metadatakeys{$unikey})) {
8410: my $value=$metadatafields{$unikey.'.'.$_};
8411: $value=~s/\"/\'\'/g;
8412: print $mfh ' '.$_.'="'.$value.'"';
8413: }
8414: print $mfh '>'.
8415: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
8416: .'</'.$tag.'>';
8417: }
8418: }
8419: $output = 'ok';
8420: print $logfile "\nWrote metadata";
8421: close($mfh);
8422: } else {
8423: print $logfile "\nFailed to open metadata file";
1.9 raeburn 8424: $output = &mt('Could not write metadata');
8425: }
8426: }
1.155 raeburn 8427: return $output;
8428: }
8429:
8430: sub notifysubscribed {
8431: foreach my $targetsource (@{$modified_urls}){
8432: next unless (ref($targetsource) eq 'ARRAY');
8433: my ($target,$source)=@{$targetsource};
8434: if ($source ne '') {
8435: if (open(my $logfh,'>>'.$source.'.log')) {
8436: print $logfh "\nCleanup phase: Notifications\n";
8437: my @subscribed=&subscribed_hosts($target);
8438: foreach my $subhost (@subscribed) {
8439: print $logfh "\nNotifying host ".$subhost.':';
8440: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
8441: print $logfh $reply;
8442: }
8443: my @subscribedmeta=&subscribed_hosts("$target.meta");
8444: foreach my $subhost (@subscribedmeta) {
8445: print $logfh "\nNotifying host for metadata only ".$subhost.':';
8446: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
8447: $subhost);
8448: print $logfh $reply;
8449: }
8450: print $logfh "\n============ Done ============\n";
1.160 raeburn 8451: close($logfh);
1.155 raeburn 8452: }
8453: }
8454: }
8455: return OK;
8456: }
8457:
8458: sub subscribed_hosts {
8459: my ($target) = @_;
8460: my @subscribed;
8461: if (open(my $fh,"<$target.subscription")) {
8462: while (my $subline=<$fh>) {
8463: if ($subline =~ /^($match_lonid):/) {
8464: my $host = $1;
8465: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
8466: unless (grep(/^\Q$host\E$/,@subscribed)) {
8467: push(@subscribed,$host);
8468: }
8469: }
8470: }
8471: }
8472: }
8473: return @subscribed;
1.9 raeburn 8474: }
8475:
8476: sub check_switchserver {
8477: my ($dom,$confname) = @_;
8478: my ($allowed,$switchserver);
8479: my $home = &Apache::lonnet::homeserver($confname,$dom);
8480: if ($home eq 'no_host') {
8481: $home = &Apache::lonnet::domain($dom,'primary');
8482: }
8483: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 8484: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
8485: if (!$allowed) {
1.160.6.11 raeburn 8486: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 8487: }
8488: return $switchserver;
8489: }
8490:
1.1 raeburn 8491: sub modify_quotas {
1.160.6.30 raeburn 8492: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 8493: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 8494: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 8495: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8496: $validationfieldsref);
1.86 raeburn 8497: if ($action eq 'quotas') {
8498: $context = 'tools';
1.160.6.26 raeburn 8499: } else {
1.86 raeburn 8500: $context = $action;
8501: }
8502: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 8503: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 8504: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 8505: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8506: %titles = &courserequest_titles();
8507: $toolregexp = join('|',@usertools);
8508: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 8509: $confname = $dom.'-domainconfig';
8510: my $servadm = $r->dir_config('lonAdmEMail');
8511: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 8512: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8513: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 8514: } elsif ($context eq 'requestauthor') {
8515: @usertools = ('author');
8516: %titles = &authorrequest_titles();
1.86 raeburn 8517: } else {
1.160.6.4 raeburn 8518: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 8519: %titles = &tool_titles();
1.86 raeburn 8520: }
1.160.6.27 raeburn 8521: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 8522: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8523: foreach my $key (keys(%env)) {
1.101 raeburn 8524: if ($context eq 'requestcourses') {
8525: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8526: my $item = $1;
8527: my $type = $2;
8528: if ($type =~ /^limit_(.+)/) {
8529: $limithash{$item}{$1} = $env{$key};
8530: } else {
8531: $confhash{$item}{$type} = $env{$key};
8532: }
8533: }
1.160.6.5 raeburn 8534: } elsif ($context eq 'requestauthor') {
8535: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8536: $confhash{$1} = $env{$key};
8537: }
1.101 raeburn 8538: } else {
1.86 raeburn 8539: if ($key =~ /^form\.quota_(.+)$/) {
8540: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 8541: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8542: $confhash{'authorquota'}{$1} = $env{$key};
8543: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8544: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8545: }
1.72 raeburn 8546: }
8547: }
1.160.6.5 raeburn 8548: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 8549: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8550: @approvalnotify = sort(@approvalnotify);
8551: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 8552: my @crstypes = ('official','unofficial','community','textbook');
8553: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8554: foreach my $type (@hasuniquecode) {
8555: if (grep(/^\Q$type\E$/,@crstypes)) {
8556: $confhash{'uniquecode'}{$type} = 1;
8557: }
8558: }
1.160.6.46 raeburn 8559: my (%newbook,%allpos);
1.160.6.30 raeburn 8560: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8561: foreach my $type ('textbooks','templates') {
8562: @{$allpos{$type}} = ();
8563: my $invalid;
8564: if ($type eq 'textbooks') {
8565: $invalid = &mt('Invalid LON-CAPA course for textbook');
8566: } else {
8567: $invalid = &mt('Invalid LON-CAPA course for template');
8568: }
8569: if ($env{'form.'.$type.'_addbook'}) {
8570: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8571: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8572: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8573: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8574: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8575: } else {
8576: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8577: my $position = $env{'form.'.$type.'_addbook_pos'};
8578: $position =~ s/\D+//g;
8579: if ($position ne '') {
8580: $allpos{$type}[$position] = $newbook{$type};
8581: }
1.160.6.30 raeburn 8582: }
1.160.6.46 raeburn 8583: } else {
8584: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 8585: }
8586: }
1.160.6.46 raeburn 8587: }
1.160.6.30 raeburn 8588: }
1.102 raeburn 8589: if (ref($domconfig{$action}) eq 'HASH') {
8590: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8591: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8592: $changes{'notify'}{'approval'} = 1;
8593: }
8594: } else {
1.144 raeburn 8595: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8596: $changes{'notify'}{'approval'} = 1;
8597: }
8598: }
1.160.6.30 raeburn 8599: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8600: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8601: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8602: unless ($confhash{'uniquecode'}{$crstype}) {
8603: $changes{'uniquecode'} = 1;
8604: }
8605: }
8606: unless ($changes{'uniquecode'}) {
8607: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8608: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8609: $changes{'uniquecode'} = 1;
8610: }
8611: }
8612: }
8613: } else {
8614: $changes{'uniquecode'} = 1;
8615: }
8616: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8617: $changes{'uniquecode'} = 1;
8618: }
8619: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8620: foreach my $type ('textbooks','templates') {
8621: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8622: my %deletions;
8623: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8624: if (@todelete) {
8625: map { $deletions{$_} = 1; } @todelete;
8626: }
8627: my %imgdeletions;
8628: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8629: if (@todeleteimages) {
8630: map { $imgdeletions{$_} = 1; } @todeleteimages;
8631: }
8632: my $maxnum = $env{'form.'.$type.'_maxnum'};
8633: for (my $i=0; $i<=$maxnum; $i++) {
8634: my $itemid = $env{'form.'.$type.'_id_'.$i};
8635: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8636: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8637: if ($deletions{$key}) {
8638: if ($domconfig{$action}{$type}{$key}{'image'}) {
8639: #FIXME need to obsolete item in RES space
8640: }
8641: next;
8642: } else {
8643: my $newpos = $env{'form.'.$itemid};
8644: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 8645: foreach my $item ('subject','title','publisher','author') {
8646: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8647: ($type eq 'templates'));
1.160.6.46 raeburn 8648: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8649: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8650: $changes{$type}{$key} = 1;
8651: }
8652: }
8653: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 8654: }
1.160.6.46 raeburn 8655: if ($imgdeletions{$key}) {
8656: $changes{$type}{$key} = 1;
8657: #FIXME need to obsolete item in RES space
8658: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8659: my ($cdom,$cnum) = split(/_/,$key);
8660: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8661: $cdom,$cnum,$type,$configuserok,
8662: $switchserver,$author_ok);
8663: if ($imgurl) {
8664: $confhash{$type}{$key}{'image'} = $imgurl;
8665: $changes{$type}{$key} = 1;
1.160.6.30 raeburn 8666: }
1.160.6.46 raeburn 8667: if ($error) {
8668: &Apache::lonnet::logthis($error);
8669: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8670: }
8671: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8672: $confhash{$type}{$key}{'image'} =
8673: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 8674: }
8675: }
8676: }
8677: }
8678: }
8679: }
1.102 raeburn 8680: } else {
1.144 raeburn 8681: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8682: $changes{'notify'}{'approval'} = 1;
8683: }
1.160.6.30 raeburn 8684: if (ref($confhash{'uniquecode'} eq 'HASH')) {
8685: $changes{'uniquecode'} = 1;
8686: }
8687: }
8688: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8689: foreach my $type ('textbooks','templates') {
8690: if ($newbook{$type}) {
8691: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 8692: foreach my $item ('subject','title','publisher','author') {
8693: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8694: ($type eq 'template'));
1.160.6.46 raeburn 8695: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8696: if ($env{'form.'.$type.'_addbook_'.$item}) {
8697: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8698: }
8699: }
8700: if ($type eq 'textbooks') {
8701: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8702: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8703: my ($imageurl,$error) =
8704: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8705: $configuserok,$switchserver,$author_ok);
8706: if ($imageurl) {
8707: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8708: }
8709: if ($error) {
8710: &Apache::lonnet::logthis($error);
8711: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8712: }
8713: }
1.160.6.30 raeburn 8714: }
8715: }
1.160.6.46 raeburn 8716: if (@{$allpos{$type}} > 0) {
8717: my $idx = 0;
8718: foreach my $item (@{$allpos{$type}}) {
8719: if ($item ne '') {
8720: $confhash{$type}{$item}{'order'} = $idx;
8721: if (ref($domconfig{$action}) eq 'HASH') {
8722: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8723: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8724: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8725: $changes{$type}{$item} = 1;
8726: }
1.160.6.30 raeburn 8727: }
8728: }
8729: }
1.160.6.46 raeburn 8730: $idx ++;
1.160.6.30 raeburn 8731: }
8732: }
8733: }
8734: }
1.160.6.39 raeburn 8735: if (ref($validationitemsref) eq 'ARRAY') {
8736: foreach my $item (@{$validationitemsref}) {
8737: if ($item eq 'fields') {
8738: my @changed;
8739: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8740: if (@{$confhash{'validation'}{$item}} > 0) {
8741: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8742: }
1.160.6.65 raeburn 8743: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8744: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8745: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8746: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8747: $domconfig{'requestcourses'}{'validation'}{$item});
8748: } else {
8749: @changed = @{$confhash{'validation'}{$item}};
8750: }
1.160.6.39 raeburn 8751: } else {
8752: @changed = @{$confhash{'validation'}{$item}};
8753: }
8754: } else {
8755: @changed = @{$confhash{'validation'}{$item}};
8756: }
8757: if (@changed) {
8758: if ($confhash{'validation'}{$item}) {
8759: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8760: } else {
8761: $changes{'validation'}{$item} = &mt('None');
8762: }
8763: }
8764: } else {
8765: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8766: if ($item eq 'markup') {
8767: if ($env{'form.requestcourses_validation_'.$item}) {
8768: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8769: }
8770: }
1.160.6.65 raeburn 8771: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8772: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8773: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8774: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8775: }
8776: } else {
8777: if ($confhash{'validation'}{$item} ne '') {
8778: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8779: }
1.160.6.39 raeburn 8780: }
8781: } else {
8782: if ($confhash{'validation'}{$item} ne '') {
8783: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8784: }
8785: }
8786: }
8787: }
8788: }
8789: if ($env{'form.validationdc'}) {
8790: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 8791: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 8792: if (exists($domcoords{$newval})) {
8793: $confhash{'validation'}{'dc'} = $newval;
8794: }
8795: }
8796: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 8797: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8798: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8799: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8800: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8801: if ($confhash{'validation'}{'dc'} eq '') {
8802: $changes{'validation'}{'dc'} = &mt('None');
8803: } else {
8804: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8805: }
1.160.6.39 raeburn 8806: }
1.160.6.65 raeburn 8807: } elsif ($confhash{'validation'}{'dc'} ne '') {
8808: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 8809: }
8810: } elsif ($confhash{'validation'}{'dc'} ne '') {
8811: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8812: }
8813: } elsif ($confhash{'validation'}{'dc'} ne '') {
8814: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8815: }
1.160.6.65 raeburn 8816: } else {
8817: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8818: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8819: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8820: $changes{'validation'}{'dc'} = &mt('None');
8821: }
8822: }
1.160.6.39 raeburn 8823: }
8824: }
1.102 raeburn 8825: }
8826: } else {
1.86 raeburn 8827: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 8828: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8829: }
1.72 raeburn 8830: foreach my $item (@usertools) {
8831: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8832: my $unset;
1.101 raeburn 8833: if ($context eq 'requestcourses') {
1.104 raeburn 8834: $unset = '0';
8835: if ($type eq '_LC_adv') {
8836: $unset = '';
8837: }
1.101 raeburn 8838: if ($confhash{$item}{$type} eq 'autolimit') {
8839: $confhash{$item}{$type} .= '=';
8840: unless ($limithash{$item}{$type} =~ /\D/) {
8841: $confhash{$item}{$type} .= $limithash{$item}{$type};
8842: }
8843: }
1.160.6.5 raeburn 8844: } elsif ($context eq 'requestauthor') {
8845: $unset = '0';
8846: if ($type eq '_LC_adv') {
8847: $unset = '';
8848: }
1.72 raeburn 8849: } else {
1.101 raeburn 8850: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8851: $confhash{$item}{$type} = 1;
8852: } else {
8853: $confhash{$item}{$type} = 0;
8854: }
1.72 raeburn 8855: }
1.86 raeburn 8856: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 8857: if ($action eq 'requestauthor') {
8858: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8859: $changes{$type} = 1;
8860: }
8861: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8862: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8863: $changes{$item}{$type} = 1;
8864: }
8865: } else {
8866: if ($context eq 'requestcourses') {
1.104 raeburn 8867: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8868: $changes{$item}{$type} = 1;
8869: }
8870: } else {
8871: if (!$confhash{$item}{$type}) {
8872: $changes{$item}{$type} = 1;
8873: }
8874: }
8875: }
8876: } else {
8877: if ($context eq 'requestcourses') {
1.104 raeburn 8878: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8879: $changes{$item}{$type} = 1;
8880: }
1.160.6.5 raeburn 8881: } elsif ($context eq 'requestauthor') {
8882: if ($confhash{$type} ne $unset) {
8883: $changes{$type} = 1;
8884: }
1.72 raeburn 8885: } else {
8886: if (!$confhash{$item}{$type}) {
8887: $changes{$item}{$type} = 1;
8888: }
8889: }
8890: }
1.1 raeburn 8891: }
8892: }
1.160.6.5 raeburn 8893: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8894: if (ref($domconfig{'quotas'}) eq 'HASH') {
8895: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8896: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8897: if (exists($confhash{'defaultquota'}{$key})) {
8898: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8899: $changes{'defaultquota'}{$key} = 1;
8900: }
8901: } else {
8902: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8903: }
8904: }
1.86 raeburn 8905: } else {
8906: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8907: if (exists($confhash{'defaultquota'}{$key})) {
8908: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8909: $changes{'defaultquota'}{$key} = 1;
8910: }
8911: } else {
8912: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8913: }
1.1 raeburn 8914: }
8915: }
1.160.6.20 raeburn 8916: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8917: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8918: if (exists($confhash{'authorquota'}{$key})) {
8919: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8920: $changes{'authorquota'}{$key} = 1;
8921: }
8922: } else {
8923: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8924: }
8925: }
8926: }
1.1 raeburn 8927: }
1.86 raeburn 8928: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8929: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8930: if (ref($domconfig{'quotas'}) eq 'HASH') {
8931: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8932: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8933: $changes{'defaultquota'}{$key} = 1;
8934: }
8935: } else {
8936: if (!exists($domconfig{'quotas'}{$key})) {
8937: $changes{'defaultquota'}{$key} = 1;
8938: }
1.72 raeburn 8939: }
8940: } else {
1.86 raeburn 8941: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8942: }
1.1 raeburn 8943: }
8944: }
1.160.6.20 raeburn 8945: if (ref($confhash{'authorquota'}) eq 'HASH') {
8946: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8947: if (ref($domconfig{'quotas'}) eq 'HASH') {
8948: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8949: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
8950: $changes{'authorquota'}{$key} = 1;
8951: }
8952: } else {
8953: $changes{'authorquota'}{$key} = 1;
8954: }
8955: } else {
8956: $changes{'authorquota'}{$key} = 1;
8957: }
8958: }
8959: }
1.1 raeburn 8960: }
1.72 raeburn 8961:
1.160.6.5 raeburn 8962: if ($context eq 'requestauthor') {
8963: $domdefaults{'requestauthor'} = \%confhash;
8964: } else {
8965: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 8966: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 8967: $domdefaults{$key} = $confhash{$key};
8968: }
1.160.6.5 raeburn 8969: }
1.72 raeburn 8970: }
1.160.6.5 raeburn 8971:
1.1 raeburn 8972: my %quotahash = (
1.86 raeburn 8973: $action => { %confhash }
1.1 raeburn 8974: );
8975: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
8976: $dom);
8977: if ($putresult eq 'ok') {
8978: if (keys(%changes) > 0) {
1.72 raeburn 8979: my $cachetime = 24*60*60;
8980: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 8981: if (ref($lastactref) eq 'HASH') {
8982: $lastactref->{'domdefaults'} = 1;
8983: }
1.1 raeburn 8984: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 8985: unless (($context eq 'requestcourses') ||
8986: ($context eq 'requestauthor')) {
1.86 raeburn 8987: if (ref($changes{'defaultquota'}) eq 'HASH') {
8988: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
8989: foreach my $type (@{$types},'default') {
8990: if (defined($changes{'defaultquota'}{$type})) {
8991: my $typetitle = $usertypes->{$type};
8992: if ($type eq 'default') {
8993: $typetitle = $othertitle;
8994: }
1.160.6.28 raeburn 8995: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 8996: }
8997: }
1.86 raeburn 8998: $resulttext .= '</ul></li>';
1.72 raeburn 8999: }
1.160.6.20 raeburn 9000: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 9001: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 9002: foreach my $type (@{$types},'default') {
9003: if (defined($changes{'authorquota'}{$type})) {
9004: my $typetitle = $usertypes->{$type};
9005: if ($type eq 'default') {
9006: $typetitle = $othertitle;
9007: }
1.160.6.28 raeburn 9008: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 9009: }
9010: }
9011: $resulttext .= '</ul></li>';
9012: }
1.72 raeburn 9013: }
1.80 raeburn 9014: my %newenv;
1.72 raeburn 9015: foreach my $item (@usertools) {
1.160.6.5 raeburn 9016: my (%haschgs,%inconf);
9017: if ($context eq 'requestauthor') {
9018: %haschgs = %changes;
9019: %inconf = %confhash;
9020: } else {
9021: if (ref($changes{$item}) eq 'HASH') {
9022: %haschgs = %{$changes{$item}};
9023: }
9024: if (ref($confhash{$item}) eq 'HASH') {
9025: %inconf = %{$confhash{$item}};
9026: }
9027: }
9028: if (keys(%haschgs) > 0) {
1.80 raeburn 9029: my $newacc =
9030: &Apache::lonnet::usertools_access($env{'user.name'},
9031: $env{'user.domain'},
1.86 raeburn 9032: $item,'reload',$context);
1.160.6.5 raeburn 9033: if (($context eq 'requestcourses') ||
9034: ($context eq 'requestauthor')) {
1.108 raeburn 9035: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9036: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9037: }
9038: } else {
9039: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9040: $newenv{'environment.availabletools.'.$item} = $newacc;
9041: }
1.80 raeburn 9042: }
1.160.6.5 raeburn 9043: unless ($context eq 'requestauthor') {
9044: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9045: }
1.72 raeburn 9046: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 9047: if ($haschgs{$type}) {
1.72 raeburn 9048: my $typetitle = $usertypes->{$type};
9049: if ($type eq 'default') {
9050: $typetitle = $othertitle;
9051: } elsif ($type eq '_LC_adv') {
9052: $typetitle = 'LON-CAPA Advanced Users';
9053: }
1.160.6.5 raeburn 9054: if ($inconf{$type}) {
1.101 raeburn 9055: if ($context eq 'requestcourses') {
9056: my $cond;
1.160.6.5 raeburn 9057: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9058: if ($1 eq '') {
9059: $cond = &mt('(Automatic processing of any request).');
9060: } else {
9061: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9062: }
9063: } else {
1.160.6.5 raeburn 9064: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9065: }
9066: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 9067: } elsif ($context eq 'requestauthor') {
9068: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9069: $titles{$inconf{$type}},$typetitle);
9070:
1.101 raeburn 9071: } else {
9072: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9073: }
1.72 raeburn 9074: } else {
1.104 raeburn 9075: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 9076: if ($inconf{$type} eq '0') {
1.104 raeburn 9077: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9078: } else {
9079: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9080: }
9081: } else {
9082: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9083: }
1.72 raeburn 9084: }
9085: }
1.26 raeburn 9086: }
1.160.6.5 raeburn 9087: unless ($context eq 'requestauthor') {
9088: $resulttext .= '</ul></li>';
9089: }
1.26 raeburn 9090: }
1.1 raeburn 9091: }
1.160.6.5 raeburn 9092: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9093: if (ref($changes{'notify'}) eq 'HASH') {
9094: if ($changes{'notify'}{'approval'}) {
9095: if (ref($confhash{'notify'}) eq 'HASH') {
9096: if ($confhash{'notify'}{'approval'}) {
9097: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9098: } else {
1.160.6.5 raeburn 9099: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9100: }
9101: }
9102: }
9103: }
9104: }
1.160.6.30 raeburn 9105: if ($action eq 'requestcourses') {
9106: my @offon = ('off','on');
9107: if ($changes{'uniquecode'}) {
9108: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9109: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9110: $resulttext .= '<li>'.
9111: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9112: '</li>';
9113: } else {
9114: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9115: '</li>';
9116: }
9117: }
1.160.6.46 raeburn 9118: foreach my $type ('textbooks','templates') {
9119: if (ref($changes{$type}) eq 'HASH') {
9120: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9121: foreach my $key (sort(keys(%{$changes{$type}}))) {
9122: my %coursehash = &Apache::lonnet::coursedescription($key);
9123: my $coursetitle = $coursehash{'description'};
9124: my $position = $confhash{$type}{$key}{'order'} + 1;
9125: $resulttext .= '<li>';
1.160.6.47 raeburn 9126: foreach my $item ('subject','title','publisher','author') {
9127: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9128: ($type eq 'templates'));
1.160.6.46 raeburn 9129: my $name = $item.':';
9130: $name =~ s/^(\w)/\U$1/;
9131: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9132: }
9133: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9134: if ($type eq 'textbooks') {
9135: if ($confhash{$type}{$key}{'image'}) {
9136: $resulttext .= ' '.&mt('Image: [_1]',
9137: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9138: ' alt="Textbook cover" />').'<br />';
9139: }
9140: }
9141: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 9142: }
1.160.6.46 raeburn 9143: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 9144: }
9145: }
1.160.6.39 raeburn 9146: if (ref($changes{'validation'}) eq 'HASH') {
9147: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9148: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9149: foreach my $item (@{$validationitemsref}) {
9150: if (exists($changes{'validation'}{$item})) {
9151: if ($item eq 'markup') {
9152: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9153: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9154: } else {
9155: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9156: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9157: }
9158: }
9159: }
9160: if (exists($changes{'validation'}{'dc'})) {
9161: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9162: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9163: }
9164: }
9165: }
1.160.6.30 raeburn 9166: }
1.1 raeburn 9167: $resulttext .= '</ul>';
1.80 raeburn 9168: if (keys(%newenv)) {
9169: &Apache::lonnet::appenv(\%newenv);
9170: }
1.1 raeburn 9171: } else {
1.86 raeburn 9172: if ($context eq 'requestcourses') {
9173: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 9174: } elsif ($context eq 'requestauthor') {
9175: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9176: } else {
1.90 weissno 9177: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9178: }
1.1 raeburn 9179: }
9180: } else {
1.11 albertel 9181: $resulttext = '<span class="LC_error">'.
9182: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9183: }
1.160.6.30 raeburn 9184: if ($errors) {
9185: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9186: '<ul>'.$errors.'</ul></p>';
9187: }
1.3 raeburn 9188: return $resulttext;
1.1 raeburn 9189: }
9190:
1.160.6.30 raeburn 9191: sub process_textbook_image {
1.160.6.46 raeburn 9192: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 9193: my $filename = $env{'form.'.$caller.'.filename'};
9194: my ($error,$url);
9195: my ($width,$height) = (50,50);
9196: if ($configuserok eq 'ok') {
9197: if ($switchserver) {
9198: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9199: $switchserver);
9200: } elsif ($author_ok eq 'ok') {
9201: my ($result,$imageurl) =
9202: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.46 raeburn 9203: "$type/$dom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 9204: if ($result eq 'ok') {
9205: $url = $imageurl;
9206: } else {
9207: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9208: }
9209: } else {
9210: $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);
9211: }
9212: } else {
9213: $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);
9214: }
9215: return ($url,$error);
9216: }
9217:
1.160.6.84.6. (raeburn 9218:): sub modify_ltitools {
9219:): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
9220:): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9221:): my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
9222:): my $confname = $dom.'-domainconfig';
9223:): my $servadm = $r->dir_config('lonAdmEMail');
9224:): my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9225:): my (%posslti,%possfield);
9226:): my @courseroles = ('cc','in','ta','ep','st');
9227:): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
9228:): map { $posslti{$_} = 1; } @ltiroles;
9229:): my @allfields = ('fullname','firstname','lastname','email','user','roles');
9230:): map { $possfield{$_} = 1; } @allfields;
9231:): my %lt = <itools_names();
9232:): if ($env{'form.ltitools_add'}) {
9233:): my $title = $env{'form.ltitools_add_title'};
9234:): $title =~ s/(`)/'/g;
9235:): ($newid,my $error) = &get_ltitools_id($dom,$title);
9236:): if ($newid) {
9237:): my $position = $env{'form.ltitools_add_pos'};
9238:): $position =~ s/\D+//g;
9239:): if ($position ne '') {
9240:): $allpos[$position] = $newid;
9241:): }
9242:): $changes{$newid} = 1;
9243:): foreach my $item ('title','url','key','secret','lifetime') {
9244:): $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
9245:): if ($item eq 'lifetime') {
9246:): $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
9247:): }
9248:): if ($env{'form.ltitools_add_'.$item}) {
9249:): if (($item eq 'key') || ($item eq 'secret')) {
9250:): $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9251:): } else {
9252:): $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9253:): }
9254:): }
9255:): }
9256:): if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
9257:): $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
9258:): }
9259:): if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
9260:): $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
9261:): }
9262:): if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
9263:): $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
9264:): } else {
9265:): $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
9266:): }
9267:): foreach my $item ('width','height','linktext','explanation') {
9268:): $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
9269:): $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
9270:): if (($item eq 'width') || ($item eq 'height')) {
9271:): if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
9272:): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9273:): }
9274:): } else {
9275:): if ($env{'form.ltitools_add_'.$item} ne '') {
9276:): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9277:): }
9278:): }
9279:): }
9280:): if ($env{'form.ltitools_add_target'} eq 'window') {
9281:): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
9282:): } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
9283:): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
9284:): } else {
9285:): $confhash{$newid}{'display'}{'target'} = 'iframe';
9286:): }
9287:): if ($env{'form.ltitools_add_image.filename'} ne '') {
9288:): my ($imageurl,$error) =
9289:): &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
9290:): $configuserok,$switchserver,$author_ok);
9291:): if ($imageurl) {
9292:): $confhash{$newid}{'image'} = $imageurl;
9293:): }
9294:): if ($error) {
9295:): &Apache::lonnet::logthis($error);
9296:): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9297:): }
9298:): }
9299:): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
9300:): foreach my $field (@fields) {
9301:): if ($possfield{$field}) {
9302:): if ($field eq 'roles') {
9303:): foreach my $role (@courseroles) {
9304:): my $choice = $env{'form.ltitools_add_roles_'.$role};
9305:): if (($choice ne '') && ($posslti{$choice})) {
9306:): $confhash{$newid}{'roles'}{$role} = $choice;
9307:): if ($role eq 'cc') {
9308:): $confhash{$newid}{'roles'}{'co'} = $choice;
9309:): }
9310:): }
9311:): }
9312:): } else {
9313:): $confhash{$newid}{'fields'}{$field} = 1;
9314:): }
9315:): }
9316:): }
9317:): if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
9318:): if ($confhash{$newid}{'fields'}{'user'}) {
9319:): if ($env{'form.ltitools_userincdom_add'}) {
9320:): $confhash{$newid}{'incdom'} = 1;
9321:): }
9322:): }
9323:): }
9324:): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
9325:): foreach my $item (@courseconfig) {
9326:): $confhash{$newid}{'crsconf'}{$item} = 1;
9327:): }
9328:): if ($env{'form.ltitools_add_custom'}) {
9329:): my $name = $env{'form.ltitools_add_custom_name'};
9330:): my $value = $env{'form.ltitools_add_custom_value'};
9331:): $value =~ s/(`)/'/g;
9332:): $name =~ s/(`)/'/g;
9333:): $confhash{$newid}{'custom'}{$name} = $value;
9334:): }
9335:): } else {
9336:): my $error = &mt('Failed to acquire unique ID for new external tool');
9337:): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9338:): }
9339:): }
9340:): if (ref($domconfig{$action}) eq 'HASH') {
9341:): my %deletions;
9342:): my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
9343:): if (@todelete) {
9344:): map { $deletions{$_} = 1; } @todelete;
9345:): }
9346:): my %customadds;
9347:): my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
9348:): if (@newcustom) {
9349:): map { $customadds{$_} = 1; } @newcustom;
9350:): }
9351:): my %imgdeletions;
9352:): my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
9353:): if (@todeleteimages) {
9354:): map { $imgdeletions{$_} = 1; } @todeleteimages;
9355:): }
9356:): my $maxnum = $env{'form.ltitools_maxnum'};
9357:): for (my $i=0; $i<=$maxnum; $i++) {
9358:): my $itemid = $env{'form.ltitools_id_'.$i};
9359:): $itemid =~ s/\D+//g;
9360:): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9361:): if ($deletions{$itemid}) {
9362:): if ($domconfig{$action}{$itemid}{'image'}) {
9363:): #FIXME need to obsolete item in RES space
9364:): }
9365:): $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
9366:): next;
9367:): } else {
9368:): my $newpos = $env{'form.ltitools_'.$itemid};
9369:): $newpos =~ s/\D+//g;
9370:): foreach my $item ('title','url','lifetime') {
9371:): $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9372:): if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
9373:): $changes{$itemid} = 1;
9374:): }
9375:): }
9376:): foreach my $item ('key','secret') {
9377:): $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9378:): if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
9379:): $changes{$itemid} = 1;
9380:): }
9381:): }
9382:): if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
9383:): $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
9384:): }
9385:): if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
9386:): $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
9387:): }
9388:): if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
9389:): $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
9390:): } else {
9391:): $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
9392:): }
9393:): if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
9394:): if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
9395:): $changes{$itemid} = 1;
9396:): }
9397:): } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
9398:): $changes{$itemid} = 1;
9399:): }
9400:): foreach my $size ('width','height') {
9401:): $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
9402:): $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
9403:): if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
9404:): $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
9405:): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9406:): if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
9407:): $changes{$itemid} = 1;
9408:): }
9409:): } else {
9410:): $changes{$itemid} = 1;
9411:): }
9412:): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9413:): if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
9414:): $changes{$itemid} = 1;
9415:): }
9416:): }
9417:): }
9418:): foreach my $item ('linktext','explanation') {
9419:): $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
9420:): $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
9421:): if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
9422:): $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9423:): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9424:): if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
9425:): $changes{$itemid} = 1;
9426:): }
9427:): } else {
9428:): $changes{$itemid} = 1;
9429:): }
9430:): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9431:): if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
9432:): $changes{$itemid} = 1;
9433:): }
9434:): }
9435:): }
9436:): if ($env{'form.ltitools_target_'.$i} eq 'window') {
9437:): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
9438:): } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
9439:): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
9440:): } else {
9441:): $confhash{$itemid}{'display'}{'target'} = 'iframe';
9442:): }
9443:): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9444:): if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
9445:): $changes{$itemid} = 1;
9446:): }
9447:): } else {
9448:): $changes{$itemid} = 1;
9449:): }
9450:): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
9451:): foreach my $item ('label','title','target','linktext','explanation','append') {
9452:): if (grep(/^\Q$item\E$/,@courseconfig)) {
9453:): $confhash{$itemid}{'crsconf'}{$item} = 1;
9454:): if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
9455:): if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
9456:): $changes{$itemid} = 1;
9457:): }
9458:): } else {
9459:): $changes{$itemid} = 1;
9460:): }
9461:): }
9462:): }
9463:): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
9464:): foreach my $field (@fields) {
9465:): if ($possfield{$field}) {
9466:): if ($field eq 'roles') {
9467:): foreach my $role (@courseroles) {
9468:): my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
9469:): if (($choice ne '') && ($posslti{$choice})) {
9470:): $confhash{$itemid}{'roles'}{$role} = $choice;
9471:): if ($role eq 'cc') {
9472:): $confhash{$itemid}{'roles'}{'co'} = $choice;
9473:): }
9474:): }
9475:): if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
9476:): if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
9477:): $changes{$itemid} = 1;
9478:): }
9479:): } elsif ($confhash{$itemid}{'roles'}{$role}) {
9480:): $changes{$itemid} = 1;
9481:): }
9482:): }
9483:): } else {
9484:): $confhash{$itemid}{'fields'}{$field} = 1;
9485:): if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
9486:): if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
9487:): $changes{$itemid} = 1;
9488:): }
9489:): } else {
9490:): $changes{$itemid} = 1;
9491:): }
9492:): }
9493:): }
9494:): }
9495:): if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
9496:): if ($confhash{$itemid}{'fields'}{'user'}) {
9497:): if ($env{'form.ltitools_userincdom_'.$i}) {
9498:): $confhash{$itemid}{'incdom'} = 1;
9499:): }
9500:): if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
9501:): $changes{$itemid} = 1;
9502:): }
9503:): }
9504:): }
9505:): $allpos[$newpos] = $itemid;
9506:): }
9507:): if ($imgdeletions{$itemid}) {
9508:): $changes{$itemid} = 1;
9509:): #FIXME need to obsolete item in RES space
9510:): } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
9511:): my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
9512:): $itemid,$configuserok,$switchserver,
9513:): $author_ok);
9514:): if ($imgurl) {
9515:): $confhash{$itemid}{'image'} = $imgurl;
9516:): $changes{$itemid} = 1;
9517:): }
9518:): if ($error) {
9519:): &Apache::lonnet::logthis($error);
9520:): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9521:): }
9522:): } elsif ($domconfig{$action}{$itemid}{'image'}) {
9523:): $confhash{$itemid}{'image'} =
9524:): $domconfig{$action}{$itemid}{'image'};
9525:): }
9526:): if ($customadds{$i}) {
9527:): my $name = $env{'form.ltitools_custom_name_'.$i};
9528:): $name =~ s/(`)/'/g;
9529:): $name =~ s/^\s+//;
9530:): $name =~ s/\s+$//;
9531:): my $value = $env{'form.ltitools_custom_value_'.$i};
9532:): $value =~ s/(`)/'/g;
9533:): $value =~ s/^\s+//;
9534:): $value =~ s/\s+$//;
9535:): if ($name ne '') {
9536:): $confhash{$itemid}{'custom'}{$name} = $value;
9537:): $changes{$itemid} = 1;
9538:): }
9539:): }
9540:): my %customdels;
9541:): my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
9542:): if (@customdeletions) {
9543:): $changes{$itemid} = 1;
9544:): }
9545:): map { $customdels{$_} = 1; } @customdeletions;
9546:): if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
9547:): foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
9548:): unless ($customdels{$key}) {
9549:): if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
9550:): $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
9551:): }
9552:): if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
9553:): $changes{$itemid} = 1;
9554:): }
9555:): }
9556:): }
9557:): }
9558:): unless ($changes{$itemid}) {
9559:): foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
9560:): if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
9561:): if (ref($confhash{$itemid}{$key}) eq 'HASH') {
9562:): foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
9563:): unless (exists($confhash{$itemid}{$key}{$innerkey})) {
9564:): $changes{$itemid} = 1;
9565:): last;
9566:): }
9567:): }
9568:): } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
9569:): $changes{$itemid} = 1;
9570:): }
9571:): }
9572:): last if ($changes{$itemid});
9573:): }
9574:): }
9575:): }
9576:): }
9577:): }
9578:): if (@allpos > 0) {
9579:): my $idx = 0;
9580:): foreach my $itemid (@allpos) {
9581:): if ($itemid ne '') {
9582:): $confhash{$itemid}{'order'} = $idx;
9583:): if (ref($domconfig{$action}) eq 'HASH') {
9584:): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9585:): if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
9586:): $changes{$itemid} = 1;
9587:): }
9588:): }
9589:): }
9590:): $idx ++;
9591:): }
9592:): }
9593:): }
9594:): my %ltitoolshash = (
9595:): $action => { %confhash }
9596:): );
9597:): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
9598:): $dom);
9599:): if ($putresult eq 'ok') {
9600:): my %ltienchash = (
9601:): $action => { %encconfig }
9602:): );
9603:): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
9604:): if (keys(%changes) > 0) {
9605:): my $cachetime = 24*60*60;
9606:): my %ltiall = %confhash;
9607:): foreach my $id (keys(%ltiall)) {
9608:): if (ref($encconfig{$id}) eq 'HASH') {
9609:): foreach my $item ('key','secret') {
9610:): $ltiall{$id}{$item} = $encconfig{$id}{$item};
9611:): }
9612:): }
9613:): }
9614:): &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
9615:): if (ref($lastactref) eq 'HASH') {
9616:): $lastactref->{'ltitools'} = 1;
9617:): }
9618:): $resulttext = &mt('Changes made:').'<ul>';
9619:): my %bynum;
9620:): foreach my $itemid (sort(keys(%changes))) {
9621:): my $position = $confhash{$itemid}{'order'};
9622:): $bynum{$position} = $itemid;
9623:): }
9624:): foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9625:): my $itemid = $bynum{$pos};
9626:): if (ref($confhash{$itemid}) ne 'HASH') {
9627:): $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9628:): } else {
9629:): $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
9630:): if ($confhash{$itemid}{'image'}) {
9631:): $resulttext .= ' '.
9632:): '<img src="'.$confhash{$itemid}{'image'}.'"'.
9633:): ' alt="'.&mt('Tool Provider icon').'" />';
9634:): }
9635:): $resulttext .= '</li><ul>';
9636:): my $position = $pos + 1;
9637:): $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
9638:): foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
9639:): if ($confhash{$itemid}{$item} ne '') {
9640:): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
9641:): }
9642:): }
9643:): if ($encconfig{$itemid}{'key'} ne '') {
9644:): $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
9645:): }
9646:): if ($encconfig{$itemid}{'secret'} ne '') {
9647:): $resulttext .= '<li>'.$lt{'secret'}.': ';
9648:): my $num = length($encconfig{$itemid}{'secret'});
9649:): $resulttext .= ('*'x$num).'</li>';
9650:): }
9651:): $resulttext .= '<li>'.&mt('Configurable in course:');
9652:): my @possconfig = ('label','title','target','linktext','explanation','append');
9653:): my $numconfig = 0;
9654:): if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
9655:): foreach my $item (@possconfig) {
9656:): if ($confhash{$itemid}{'crsconf'}{$item}) {
9657:): $numconfig ++;
9658:): $resulttext .= ' "'.$lt{'crs'.$item}.'"';
9659:): }
9660:): }
9661:): }
9662:): if (!$numconfig) {
9663:): $resulttext .= &mt('None');
9664:): }
9665:): $resulttext .= '</li>';
9666:): if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
9667:): my $displaylist;
9668:): if ($confhash{$itemid}{'display'}{'target'}) {
9669:): $displaylist = &mt('Display target').': '.
9670:): $confhash{$itemid}{'display'}{'target'}.',';
9671:): }
9672:): foreach my $size ('width','height') {
9673:): if ($confhash{$itemid}{'display'}{$size}) {
9674:): $displaylist .= (' 'x2).$lt{$size}.': '.
9675:): $confhash{$itemid}{'display'}{$size}.',';
9676:): }
9677:): }
9678:): if ($displaylist) {
9679:): $displaylist =~ s/,$//;
9680:): $resulttext .= '<li>'.$displaylist.'</li>';
9681:): }
9682:): foreach my $item ('linktext','explanation') {
9683:): if ($confhash{$itemid}{'display'}{$item}) {
9684:): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
9685:): }
9686:): }
9687:): }
9688:): if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
9689:): my $fieldlist;
9690:): foreach my $field (@allfields) {
9691:): if ($confhash{$itemid}{'fields'}{$field}) {
9692:): $fieldlist .= (' 'x2).$lt{$field}.',';
9693:): }
9694:): }
9695:): if ($fieldlist) {
9696:): $fieldlist =~ s/,$//;
9697:): if ($confhash{$itemid}{'fields'}{'user'}) {
9698:): if ($confhash{$itemid}{'incdom'}) {
9699:): $fieldlist .= ' ('.&mt('username:domain').')';
9700:): } else {
9701:): $fieldlist .= ' ('.&mt('username').')';
9702:): }
9703:): }
9704:): $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
9705:): }
9706:): }
9707:): if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
9708:): my $rolemaps;
9709:): foreach my $role (@courseroles) {
9710:): if ($confhash{$itemid}{'roles'}{$role}) {
9711:): $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
9712:): $confhash{$itemid}{'roles'}{$role}.',';
9713:): }
9714:): }
9715:): if ($rolemaps) {
9716:): $rolemaps =~ s/,$//;
9717:): $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
9718:): }
9719:): }
9720:): if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
9721:): my $customlist;
9722:): if (keys(%{$confhash{$itemid}{'custom'}})) {
9723:): foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
9724:): $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
9725:): }
9726:): }
9727:): if ($customlist) {
9728:): $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
9729:): }
9730:): }
9731:): $resulttext .= '</ul></li>';
9732:): }
9733:): }
9734:): $resulttext .= '</ul>';
9735:): } else {
9736:): $resulttext = &mt('No changes made.');
9737:): }
9738:): } else {
9739:): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9740:): }
9741:): if ($errors) {
9742:): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9743:): $errors.'</ul>';
9744:): }
9745:): return $resulttext;
9746:): }
9747:):
9748:): sub process_ltitools_image {
9749:): my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
9750:): my $filename = $env{'form.'.$caller.'.filename'};
9751:): my ($error,$url);
9752:): my ($width,$height) = (21,21);
9753:): if ($configuserok eq 'ok') {
9754:): if ($switchserver) {
9755:): $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
9756:): $switchserver);
9757:): } elsif ($author_ok eq 'ok') {
9758:): my ($result,$imageurl,$madethumb) =
9759:): &publishlogo($r,'upload',$caller,$dom,$confname,
9760:): "ltitools/$itemid/icon",$width,$height);
9761:): if ($result eq 'ok') {
9762:): if ($madethumb) {
9763:): my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
9764:): my $imagethumb = "$path/tn-".$imagefile;
9765:): $url = $imagethumb;
9766:): } else {
9767:): $url = $imageurl;
9768:): }
9769:): } else {
9770:): $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9771:): }
9772:): } else {
9773:): $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);
9774:): }
9775:): } else {
9776:): $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);
9777:): }
9778:): return ($url,$error);
9779:): }
9780:):
9781:): sub get_ltitools_id {
9782:): my ($cdom,$title) = @_;
9783:): # get lock on ltitools db
9784:): my $lockhash = {
9785:): lock => $env{'user.name'}.
9786:): ':'.$env{'user.domain'},
9787:): };
9788:): my $tries = 0;
9789:): my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9790:): my ($id,$error);
9791:):
9792:): while (($gotlock ne 'ok') && ($tries<10)) {
9793:): $tries ++;
9794:): sleep (0.1);
9795:): $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9796:): }
9797:): if ($gotlock eq 'ok') {
9798:): my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
9799:): if ($currids{'lock'}) {
9800:): delete($currids{'lock'});
9801:): if (keys(%currids)) {
9802:): my @curr = sort { $a <=> $b } keys(%currids);
9803:): if ($curr[-1] =~ /^\d+$/) {
9804:): $id = 1 + $curr[-1];
9805:): }
9806:): } else {
9807:): $id = 1;
9808:): }
9809:): if ($id) {
9810:): unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
9811:): $error = 'nostore';
9812:): }
9813:): } else {
9814:): $error = 'nonumber';
9815:): }
9816:): }
9817:): my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
9818:): } else {
9819:): $error = 'nolock';
9820:): }
9821:): return ($id,$error);
9822:): }
9823:):
1.3 raeburn 9824: sub modify_autoenroll {
1.160.6.24 raeburn 9825: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 9826: my ($resulttext,%changes);
9827: my %currautoenroll;
9828: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9829: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9830: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9831: }
9832: }
9833: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9834: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 9835: sender => 'Sender for notification messages',
1.160.6.68 raeburn 9836: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9837: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 9838: my @offon = ('off','on');
1.17 raeburn 9839: my $sender_uname = $env{'form.sender_uname'};
9840: my $sender_domain = $env{'form.sender_domain'};
9841: if ($sender_domain eq '') {
9842: $sender_uname = '';
9843: } elsif ($sender_uname eq '') {
9844: $sender_domain = '';
9845: }
1.129 raeburn 9846: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 9847: my $failsafe = $env{'form.autoenroll_failsafe'};
9848: $failsafe =~ s{^\s+|\s+$}{}g;
9849: if ($failsafe =~ /\D/) {
9850: undef($failsafe);
9851: }
1.1 raeburn 9852: my %autoenrollhash = (
1.129 raeburn 9853: autoenroll => { 'run' => $env{'form.autoenroll_run'},
9854: 'sender_uname' => $sender_uname,
9855: 'sender_domain' => $sender_domain,
9856: 'co-owners' => $coowners,
1.160.6.68 raeburn 9857: 'autofailsafe' => $failsafe,
1.1 raeburn 9858: }
9859: );
1.4 raeburn 9860: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
9861: $dom);
1.1 raeburn 9862: if ($putresult eq 'ok') {
9863: if (exists($currautoenroll{'run'})) {
9864: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
9865: $changes{'run'} = 1;
9866: }
9867: } elsif ($autorun) {
9868: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 9869: $changes{'run'} = 1;
1.1 raeburn 9870: }
9871: }
1.17 raeburn 9872: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 9873: $changes{'sender'} = 1;
9874: }
1.17 raeburn 9875: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 9876: $changes{'sender'} = 1;
9877: }
1.129 raeburn 9878: if ($currautoenroll{'co-owners'} ne '') {
9879: if ($currautoenroll{'co-owners'} ne $coowners) {
9880: $changes{'coowners'} = 1;
9881: }
9882: } elsif ($coowners) {
9883: $changes{'coowners'} = 1;
1.160.6.68 raeburn 9884: }
9885: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
9886: $changes{'autofailsafe'} = 1;
9887: }
1.1 raeburn 9888: if (keys(%changes) > 0) {
9889: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 9890: if ($changes{'run'}) {
1.1 raeburn 9891: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
9892: }
9893: if ($changes{'sender'}) {
1.17 raeburn 9894: if ($sender_uname eq '' || $sender_domain eq '') {
9895: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
9896: } else {
9897: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
9898: }
1.1 raeburn 9899: }
1.129 raeburn 9900: if ($changes{'coowners'}) {
9901: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
9902: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9903: if (ref($lastactref) eq 'HASH') {
9904: $lastactref->{'domainconfig'} = 1;
9905: }
1.129 raeburn 9906: }
1.160.6.68 raeburn 9907: if ($changes{'autofailsafe'}) {
9908: if ($failsafe ne '') {
1.160.6.82 raeburn 9909: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 9910: } else {
1.160.6.82 raeburn 9911: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 9912: }
9913: &Apache::lonnet::get_domain_defaults($dom,1);
9914: if (ref($lastactref) eq 'HASH') {
9915: $lastactref->{'domdefaults'} = 1;
9916: }
9917: }
1.1 raeburn 9918: $resulttext .= '</ul>';
9919: } else {
9920: $resulttext = &mt('No changes made to auto-enrollment settings');
9921: }
9922: } else {
1.11 albertel 9923: $resulttext = '<span class="LC_error">'.
9924: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9925: }
1.3 raeburn 9926: return $resulttext;
1.1 raeburn 9927: }
9928:
9929: sub modify_autoupdate {
1.3 raeburn 9930: my ($dom,%domconfig) = @_;
1.1 raeburn 9931: my ($resulttext,%currautoupdate,%fields,%changes);
9932: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
9933: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
9934: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
9935: }
9936: }
9937: my @offon = ('off','on');
9938: my %title = &Apache::lonlocal::texthash (
9939: run => 'Auto-update:',
9940: classlists => 'Updates to user information in classlists?'
9941: );
1.44 raeburn 9942: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9943: my %fieldtitles = &Apache::lonlocal::texthash (
9944: id => 'Student/Employee ID',
1.20 raeburn 9945: permanentemail => 'E-mail address',
1.1 raeburn 9946: lastname => 'Last Name',
9947: firstname => 'First Name',
9948: middlename => 'Middle Name',
1.132 raeburn 9949: generation => 'Generation',
1.1 raeburn 9950: );
1.142 raeburn 9951: $othertitle = &mt('All users');
1.1 raeburn 9952: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 9953: $othertitle = &mt('Other users');
1.1 raeburn 9954: }
9955: foreach my $key (keys(%env)) {
9956: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 9957: my ($usertype,$item) = ($1,$2);
9958: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
9959: if ($usertype eq 'default') {
9960: push(@{$fields{$1}},$2);
9961: } elsif (ref($types) eq 'ARRAY') {
9962: if (grep(/^\Q$usertype\E$/,@{$types})) {
9963: push(@{$fields{$1}},$2);
9964: }
9965: }
9966: }
1.1 raeburn 9967: }
9968: }
1.131 raeburn 9969: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
9970: @lockablenames = sort(@lockablenames);
9971: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
9972: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9973: if (@changed) {
9974: $changes{'lockablenames'} = 1;
9975: }
9976: } else {
9977: if (@lockablenames) {
9978: $changes{'lockablenames'} = 1;
9979: }
9980: }
1.1 raeburn 9981: my %updatehash = (
9982: autoupdate => { run => $env{'form.autoupdate_run'},
9983: classlists => $env{'form.classlists'},
9984: fields => {%fields},
1.131 raeburn 9985: lockablenames => \@lockablenames,
1.1 raeburn 9986: }
9987: );
9988: foreach my $key (keys(%currautoupdate)) {
9989: if (($key eq 'run') || ($key eq 'classlists')) {
9990: if (exists($updatehash{autoupdate}{$key})) {
9991: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
9992: $changes{$key} = 1;
9993: }
9994: }
9995: } elsif ($key eq 'fields') {
9996: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 9997: foreach my $item (@{$types},'default') {
1.1 raeburn 9998: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
9999: my $change = 0;
10000: foreach my $type (@{$currautoupdate{$key}{$item}}) {
10001: if (!exists($fields{$item})) {
10002: $change = 1;
1.132 raeburn 10003: last;
1.1 raeburn 10004: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 10005: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 10006: $change = 1;
1.132 raeburn 10007: last;
1.1 raeburn 10008: }
10009: }
10010: }
10011: if ($change) {
10012: push(@{$changes{$key}},$item);
10013: }
1.26 raeburn 10014: }
1.1 raeburn 10015: }
10016: }
1.131 raeburn 10017: } elsif ($key eq 'lockablenames') {
10018: if (ref($currautoupdate{$key}) eq 'ARRAY') {
10019: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10020: if (@changed) {
10021: $changes{'lockablenames'} = 1;
10022: }
10023: } else {
10024: if (@lockablenames) {
10025: $changes{'lockablenames'} = 1;
10026: }
10027: }
10028: }
10029: }
10030: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10031: if (@lockablenames) {
10032: $changes{'lockablenames'} = 1;
1.1 raeburn 10033: }
10034: }
1.26 raeburn 10035: foreach my $item (@{$types},'default') {
10036: if (defined($fields{$item})) {
10037: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 10038: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10039: my $change = 0;
10040: if (ref($fields{$item}) eq 'ARRAY') {
10041: foreach my $type (@{$fields{$item}}) {
10042: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10043: $change = 1;
10044: last;
10045: }
10046: }
10047: }
10048: if ($change) {
10049: push(@{$changes{'fields'}},$item);
10050: }
10051: } else {
1.26 raeburn 10052: push(@{$changes{'fields'}},$item);
10053: }
10054: } else {
10055: push(@{$changes{'fields'}},$item);
1.1 raeburn 10056: }
10057: }
10058: }
10059: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10060: $dom);
10061: if ($putresult eq 'ok') {
10062: if (keys(%changes) > 0) {
10063: $resulttext = &mt('Changes made:').'<ul>';
10064: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 10065: if ($key eq 'lockablenames') {
10066: $resulttext .= '<li>';
10067: if (@lockablenames) {
10068: $usertypes->{'default'} = $othertitle;
10069: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10070: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10071: } else {
10072: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10073: }
10074: $resulttext .= '</li>';
10075: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 10076: foreach my $item (@{$changes{$key}}) {
10077: my @newvalues;
10078: foreach my $type (@{$fields{$item}}) {
10079: push(@newvalues,$fieldtitles{$type});
10080: }
1.3 raeburn 10081: my $newvaluestr;
10082: if (@newvalues > 0) {
10083: $newvaluestr = join(', ',@newvalues);
10084: } else {
10085: $newvaluestr = &mt('none');
1.6 raeburn 10086: }
1.1 raeburn 10087: if ($item eq 'default') {
1.26 raeburn 10088: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 10089: } else {
1.26 raeburn 10090: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 10091: }
10092: }
10093: } else {
10094: my $newvalue;
10095: if ($key eq 'run') {
10096: $newvalue = $offon[$env{'form.autoupdate_run'}];
10097: } else {
10098: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 10099: }
1.1 raeburn 10100: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
10101: }
10102: }
10103: $resulttext .= '</ul>';
10104: } else {
1.3 raeburn 10105: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 10106: }
10107: } else {
1.11 albertel 10108: $resulttext = '<span class="LC_error">'.
10109: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10110: }
1.3 raeburn 10111: return $resulttext;
1.1 raeburn 10112: }
10113:
1.125 raeburn 10114: sub modify_autocreate {
10115: my ($dom,%domconfig) = @_;
10116: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10117: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10118: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10119: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10120: }
10121: }
10122: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10123: req => 'Auto-creation of validated requests for official courses',
10124: xmldc => 'Identity of course creator of courses from XML files',
10125: );
10126: my @types = ('xml','req');
10127: foreach my $item (@types) {
10128: $newvals{$item} = $env{'form.autocreate_'.$item};
10129: $newvals{$item} =~ s/\D//g;
10130: $newvals{$item} = 0 if ($newvals{$item} eq '');
10131: }
10132: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 10133: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 10134: unless (exists($domcoords{$newvals{'xmldc'}})) {
10135: $newvals{'xmldc'} = '';
10136: }
10137: %autocreatehash = (
10138: autocreate => { xml => $newvals{'xml'},
10139: req => $newvals{'req'},
10140: }
10141: );
10142: if ($newvals{'xmldc'} ne '') {
10143: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10144: }
10145: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10146: $dom);
10147: if ($putresult eq 'ok') {
10148: my @items = @types;
10149: if ($newvals{'xml'}) {
10150: push(@items,'xmldc');
10151: }
10152: foreach my $item (@items) {
10153: if (exists($currautocreate{$item})) {
10154: if ($currautocreate{$item} ne $newvals{$item}) {
10155: $changes{$item} = 1;
10156: }
10157: } elsif ($newvals{$item}) {
10158: $changes{$item} = 1;
10159: }
10160: }
10161: if (keys(%changes) > 0) {
10162: my @offon = ('off','on');
10163: $resulttext = &mt('Changes made:').'<ul>';
10164: foreach my $item (@types) {
10165: if ($changes{$item}) {
10166: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 10167: $resulttext .= '<li>'.
10168: &mt("$title{$item} set to [_1]$newtxt [_2]",
10169: '<b>','</b>').
10170: '</li>';
1.125 raeburn 10171: }
10172: }
10173: if ($changes{'xmldc'}) {
10174: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10175: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 10176: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 10177: }
10178: $resulttext .= '</ul>';
10179: } else {
10180: $resulttext = &mt('No changes made to auto-creation settings');
10181: }
10182: } else {
10183: $resulttext = '<span class="LC_error">'.
10184: &mt('An error occurred: [_1]',$putresult).'</span>';
10185: }
10186: return $resulttext;
10187: }
10188:
1.23 raeburn 10189: sub modify_directorysrch {
1.160.6.81 raeburn 10190: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 10191: my ($resulttext,%changes);
10192: my %currdirsrch;
10193: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10194: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10195: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10196: }
10197: }
1.160.6.72 raeburn 10198: my %title = ( available => 'Institutional directory search available',
10199: localonly => 'Other domains can search institution',
10200: lcavailable => 'LON-CAPA directory search available',
10201: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 10202: searchby => 'Search types',
10203: searchtypes => 'Search latitude');
10204: my @offon = ('off','on');
1.24 raeburn 10205: my @otherdoms = ('Yes','No');
1.23 raeburn 10206:
1.25 raeburn 10207: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 10208: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10209: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10210:
1.44 raeburn 10211: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 10212: if (keys(%{$usertypes}) == 0) {
10213: @cansearch = ('default');
10214: } else {
10215: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10216: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10217: if (!grep(/^\Q$type\E$/,@cansearch)) {
10218: push(@{$changes{'cansearch'}},$type);
10219: }
1.23 raeburn 10220: }
1.26 raeburn 10221: foreach my $type (@cansearch) {
10222: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10223: push(@{$changes{'cansearch'}},$type);
10224: }
1.23 raeburn 10225: }
1.26 raeburn 10226: } else {
10227: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 10228: }
10229: }
10230:
10231: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10232: foreach my $by (@{$currdirsrch{'searchby'}}) {
10233: if (!grep(/^\Q$by\E$/,@searchby)) {
10234: push(@{$changes{'searchby'}},$by);
10235: }
10236: }
10237: foreach my $by (@searchby) {
10238: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10239: push(@{$changes{'searchby'}},$by);
10240: }
10241: }
10242: } else {
10243: push(@{$changes{'searchby'}},@searchby);
10244: }
1.25 raeburn 10245:
10246: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10247: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10248: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10249: push(@{$changes{'searchtypes'}},$type);
10250: }
10251: }
10252: foreach my $type (@searchtypes) {
10253: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10254: push(@{$changes{'searchtypes'}},$type);
10255: }
10256: }
10257: } else {
10258: if (exists($currdirsrch{'searchtypes'})) {
10259: foreach my $type (@searchtypes) {
10260: if ($type ne $currdirsrch{'searchtypes'}) {
10261: push(@{$changes{'searchtypes'}},$type);
10262: }
10263: }
10264: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10265: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10266: }
10267: } else {
10268: push(@{$changes{'searchtypes'}},@searchtypes);
10269: }
10270: }
10271:
1.23 raeburn 10272: my %dirsrch_hash = (
10273: directorysrch => { available => $env{'form.dirsrch_available'},
10274: cansearch => \@cansearch,
1.160.6.72 raeburn 10275: localonly => $env{'form.dirsrch_instlocalonly'},
10276: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10277: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 10278: searchby => \@searchby,
1.25 raeburn 10279: searchtypes => \@searchtypes,
1.23 raeburn 10280: }
10281: );
10282: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10283: $dom);
10284: if ($putresult eq 'ok') {
10285: if (exists($currdirsrch{'available'})) {
10286: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10287: $changes{'available'} = 1;
10288: }
10289: } else {
10290: if ($env{'form.dirsrch_available'} eq '1') {
10291: $changes{'available'} = 1;
10292: }
10293: }
1.160.6.72 raeburn 10294: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 10295: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
10296: $changes{'lcavailable'} = 1;
10297: }
1.24 raeburn 10298: } else {
1.160.6.72 raeburn 10299: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10300: $changes{'lcavailable'} = 1;
10301: }
10302: }
10303: if (exists($currdirsrch{'localonly'})) {
10304: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 10305: $changes{'localonly'} = 1;
10306: }
1.160.6.72 raeburn 10307: } else {
10308: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
10309: $changes{'localonly'} = 1;
10310: }
10311: }
10312: if (exists($currdirsrch{'lclocalonly'})) {
10313: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
10314: $changes{'lclocalonly'} = 1;
10315: }
10316: } else {
10317: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10318: $changes{'lclocalonly'} = 1;
10319: }
1.24 raeburn 10320: }
1.23 raeburn 10321: if (keys(%changes) > 0) {
10322: $resulttext = &mt('Changes made:').'<ul>';
10323: if ($changes{'available'}) {
10324: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10325: }
1.160.6.72 raeburn 10326: if ($changes{'lcavailable'}) {
10327: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10328: }
1.24 raeburn 10329: if ($changes{'localonly'}) {
1.160.6.72 raeburn 10330: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
10331: }
10332: if ($changes{'lclocalonly'}) {
10333: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 10334: }
1.23 raeburn 10335: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10336: my $chgtext;
1.26 raeburn 10337: if (ref($usertypes) eq 'HASH') {
10338: if (keys(%{$usertypes}) > 0) {
10339: foreach my $type (@{$types}) {
10340: if (grep(/^\Q$type\E$/,@cansearch)) {
10341: $chgtext .= $usertypes->{$type}.'; ';
10342: }
10343: }
10344: if (grep(/^default$/,@cansearch)) {
10345: $chgtext .= $othertitle;
10346: } else {
10347: $chgtext =~ s/\; $//;
10348: }
1.160.6.13 raeburn 10349: $resulttext .=
10350: '<li>'.
10351: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10352: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10353: '</li>';
1.23 raeburn 10354: }
10355: }
10356: }
10357: if (ref($changes{'searchby'}) eq 'ARRAY') {
10358: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10359: my $chgtext;
10360: foreach my $type (@{$titleorder}) {
10361: if (grep(/^\Q$type\E$/,@searchby)) {
10362: if (defined($searchtitles->{$type})) {
10363: $chgtext .= $searchtitles->{$type}.'; ';
10364: }
10365: }
10366: }
10367: $chgtext =~ s/\; $//;
10368: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10369: }
1.25 raeburn 10370: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10371: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10372: my $chgtext;
10373: foreach my $type (@{$srchtypeorder}) {
10374: if (grep(/^\Q$type\E$/,@searchtypes)) {
10375: if (defined($srchtypes_desc->{$type})) {
10376: $chgtext .= $srchtypes_desc->{$type}.'; ';
10377: }
10378: }
10379: }
10380: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 10381: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 10382: }
10383: $resulttext .= '</ul>';
1.160.6.81 raeburn 10384: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
10385: if (ref($lastactref) eq 'HASH') {
10386: $lastactref->{'directorysrch'} = 1;
10387: }
1.23 raeburn 10388: } else {
1.160.6.72 raeburn 10389: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 10390: }
10391: } else {
10392: $resulttext = '<span class="LC_error">'.
1.27 raeburn 10393: &mt('An error occurred: [_1]',$putresult).'</span>';
10394: }
10395: return $resulttext;
10396: }
10397:
1.28 raeburn 10398: sub modify_contacts {
1.160.6.24 raeburn 10399: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 10400: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10401: if (ref($domconfig{'contacts'}) eq 'HASH') {
10402: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10403: $currsetting{$key} = $domconfig{'contacts'}{$key};
10404: }
10405: }
1.160.6.78 raeburn 10406: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 10407: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 10408: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
10409: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.160.6.23 raeburn 10410: my @toggles = ('reporterrors','reportupdates');
1.160.6.78 raeburn 10411: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 10412: foreach my $type (@mailings) {
10413: @{$newsetting{$type}} =
10414: &Apache::loncommon::get_env_multiple('form.'.$type);
10415: foreach my $item (@contacts) {
10416: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
10417: $contacts_hash{contacts}{$type}{$item} = 1;
10418: } else {
10419: $contacts_hash{contacts}{$type}{$item} = 0;
10420: }
1.160.6.78 raeburn 10421: }
1.28 raeburn 10422: $others{$type} = $env{'form.'.$type.'_others'};
10423: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 10424: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10425: $bcc{$type} = $env{'form.'.$type.'_bcc'};
10426: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 10427: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
10428: $includestr{$type} = $env{'form.'.$type.'_includestr'};
10429: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
10430: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10431: }
1.134 raeburn 10432: }
1.28 raeburn 10433: }
10434: foreach my $item (@contacts) {
10435: $to{$item} = $env{'form.'.$item};
10436: $contacts_hash{'contacts'}{$item} = $to{$item};
10437: }
1.160.6.23 raeburn 10438: foreach my $item (@toggles) {
10439: if ($env{'form.'.$item} =~ /^(0|1)$/) {
10440: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
10441: }
10442: }
1.160.6.78 raeburn 10443: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
10444: foreach my $field (@{$fields}) {
10445: if (ref($possoptions->{$field}) eq 'ARRAY') {
10446: my $value = $env{'form.helpform_'.$field};
10447: $value =~ s/^\s+|\s+$//g;
10448: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
10449: $contacts_hash{contacts}{'helpform'}{$field} = $value;
10450: if ($field eq 'screenshot') {
10451: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
10452: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
10453: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
10454: }
10455: }
10456: }
10457: }
10458: }
10459: }
1.28 raeburn 10460: if (keys(%currsetting) > 0) {
10461: foreach my $item (@contacts) {
10462: if ($to{$item} ne $currsetting{$item}) {
10463: $changes{$item} = 1;
10464: }
10465: }
10466: foreach my $type (@mailings) {
10467: foreach my $item (@contacts) {
10468: if (ref($currsetting{$type}) eq 'HASH') {
10469: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
10470: push(@{$changes{$type}},$item);
10471: }
10472: } else {
10473: push(@{$changes{$type}},@{$newsetting{$type}});
10474: }
10475: }
10476: if ($others{$type} ne $currsetting{$type}{'others'}) {
10477: push(@{$changes{$type}},'others');
10478: }
1.160.6.78 raeburn 10479: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10480: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
10481: push(@{$changes{$type}},'bcc');
10482: }
1.160.6.78 raeburn 10483: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
10484: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
10485: push(@{$changes{$type}},'include');
10486: }
10487: }
10488: }
10489: if (ref($fields) eq 'ARRAY') {
10490: if (ref($currsetting{'helpform'}) eq 'HASH') {
10491: foreach my $field (@{$fields}) {
10492: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
10493: push(@{$changes{'helpform'}},$field);
10494: }
10495: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10496: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
10497: push(@{$changes{'helpform'}},'maxsize');
10498: }
10499: }
10500: }
10501: } else {
10502: foreach my $field (@{$fields}) {
10503: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10504: push(@{$changes{'helpform'}},$field);
10505: }
10506: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10507: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10508: push(@{$changes{'helpform'}},'maxsize');
10509: }
10510: }
10511: }
1.134 raeburn 10512: }
1.28 raeburn 10513: }
10514: } else {
10515: my %default;
10516: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
10517: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
10518: $default{'errormail'} = 'adminemail';
10519: $default{'packagesmail'} = 'adminemail';
10520: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 10521: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 10522: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 10523: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 10524: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 10525: foreach my $item (@contacts) {
10526: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 10527: $changes{$item} = 1;
1.160.6.23 raeburn 10528: }
1.28 raeburn 10529: }
10530: foreach my $type (@mailings) {
10531: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
10532: push(@{$changes{$type}},@{$newsetting{$type}});
10533: }
10534: if ($others{$type} ne '') {
10535: push(@{$changes{$type}},'others');
1.134 raeburn 10536: }
1.160.6.78 raeburn 10537: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10538: if ($bcc{$type} ne '') {
10539: push(@{$changes{$type}},'bcc');
10540: }
1.160.6.78 raeburn 10541: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
10542: push(@{$changes{$type}},'include');
10543: }
10544: }
10545: }
10546: if (ref($fields) eq 'ARRAY') {
10547: foreach my $field (@{$fields}) {
10548: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10549: push(@{$changes{'helpform'}},$field);
10550: }
10551: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10552: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10553: push(@{$changes{'helpform'}},'maxsize');
10554: }
10555: }
1.134 raeburn 10556: }
1.28 raeburn 10557: }
10558: }
1.160.6.23 raeburn 10559: foreach my $item (@toggles) {
10560: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
10561: $changes{$item} = 1;
10562: } elsif ((!$env{'form.'.$item}) &&
10563: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
10564: $changes{$item} = 1;
10565: }
10566: }
1.28 raeburn 10567: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
10568: $dom);
10569: if ($putresult eq 'ok') {
10570: if (keys(%changes) > 0) {
1.160.6.24 raeburn 10571: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10572: if (ref($lastactref) eq 'HASH') {
10573: $lastactref->{'domainconfig'} = 1;
10574: }
1.28 raeburn 10575: my ($titles,$short_titles) = &contact_titles();
10576: $resulttext = &mt('Changes made:').'<ul>';
10577: foreach my $item (@contacts) {
10578: if ($changes{$item}) {
10579: $resulttext .= '<li>'.$titles->{$item}.
10580: &mt(' set to: ').
10581: '<span class="LC_cusr_emph">'.
10582: $to{$item}.'</span></li>';
10583: }
10584: }
10585: foreach my $type (@mailings) {
10586: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 10587: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
10588: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
10589: } else {
10590: $resulttext .= '<li>'.$titles->{$type}.': ';
10591: }
1.28 raeburn 10592: my @text;
10593: foreach my $item (@{$newsetting{$type}}) {
10594: push(@text,$short_titles->{$item});
10595: }
10596: if ($others{$type} ne '') {
10597: push(@text,$others{$type});
10598: }
1.160.6.78 raeburn 10599: if (@text) {
10600: $resulttext .= '<span class="LC_cusr_emph">'.
10601: join(', ',@text).'</span>';
10602: }
10603: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10604: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 10605: my $bcctext;
10606: if (@text) {
10607: $bcctext = ' '.&mt('with Bcc to');
10608: } else {
10609: $bcctext = '(Bcc)';
10610: }
10611: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10612: } elsif (!@text) {
10613: $resulttext .= &mt('No one');
1.134 raeburn 10614: }
1.160.6.78 raeburn 10615: if ($includestr{$type} ne '') {
10616: if ($includeloc{$type} eq 'b') {
10617: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
10618: } elsif ($includeloc{$type} eq 's') {
10619: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
10620: }
10621: }
10622: } elsif (!@text) {
10623: $resulttext .= &mt('No recipients');
1.134 raeburn 10624: }
10625: $resulttext .= '</li>';
1.28 raeburn 10626: }
10627: }
1.160.6.23 raeburn 10628: my @offon = ('off','on');
10629: if ($changes{'reporterrors'}) {
10630: $resulttext .= '<li>'.
10631: &mt('E-mail error reports to [_1] set to "'.
10632: $offon[$env{'form.reporterrors'}].'".',
10633: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10634: &mt('LON-CAPA core group - MSU'),600,500)).
10635: '</li>';
10636: }
10637: if ($changes{'reportupdates'}) {
10638: $resulttext .= '<li>'.
10639: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
10640: $offon[$env{'form.reportupdates'}].'".',
10641: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10642: &mt('LON-CAPA core group - MSU'),600,500)).
10643: '</li>';
10644: }
1.160.6.78 raeburn 10645: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
10646: my (@optional,@required,@unused,$maxsizechg);
10647: foreach my $field (@{$changes{'helpform'}}) {
10648: if ($field eq 'maxsize') {
10649: $maxsizechg = 1;
10650: next;
10651: }
10652: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
10653: push(@optional,$field);
10654: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
10655: push(@unused,$field);
10656: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
10657: push(@required,$field);
10658: }
10659: }
10660: if (@optional) {
10661: $resulttext .= '<li>'.
10662: &mt('Help form fields changed to "Optional": [_1].',
10663: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
10664: '</li>';
10665: }
10666: if (@required) {
10667: $resulttext .= '<li>'.
10668: &mt('Help form fields changed to "Required": [_1].',
10669: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
10670: '</li>';
10671: }
10672: if (@unused) {
10673: $resulttext .= '<li>'.
10674: &mt('Help form fields changed to "Not shown": [_1].',
10675: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
10676: '</li>';
10677: }
10678: if ($maxsizechg) {
10679: $resulttext .= '<li>'.
10680: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
10681: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
10682: '</li>';
10683:
10684: }
10685: }
1.28 raeburn 10686: $resulttext .= '</ul>';
10687: } else {
1.160.6.78 raeburn 10688: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 10689: }
10690: } else {
10691: $resulttext = '<span class="LC_error">'.
10692: &mt('An error occurred: [_1].',$putresult).'</span>';
10693: }
10694: return $resulttext;
10695: }
10696:
10697: sub modify_usercreation {
1.27 raeburn 10698: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 10699: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 10700: my $warningmsg;
1.27 raeburn 10701: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10702: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 10703: if ($key eq 'cancreate') {
10704: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10705: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10706: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.69 raeburn 10707: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
10708: ($item eq 'recaptchaversion')) {
1.160.6.34 raeburn 10709: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10710: } else {
10711: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10712: }
1.50 raeburn 10713: }
1.43 raeburn 10714: }
1.160.6.34 raeburn 10715: } elsif ($key eq 'email_rule') {
10716: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10717: } else {
10718: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 10719: }
10720: }
1.34 raeburn 10721: }
1.160.6.34 raeburn 10722: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
10723: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
10724: my @contexts = ('author','course','requestcrs');
10725: foreach my $item(@contexts) {
10726: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 10727: }
1.34 raeburn 10728: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10729: foreach my $item (@contexts) {
1.160.6.34 raeburn 10730: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
10731: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 10732: }
1.27 raeburn 10733: }
1.34 raeburn 10734: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
10735: foreach my $item (@contexts) {
1.43 raeburn 10736: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 10737: if ($cancreate{$item} ne 'any') {
10738: push(@{$changes{'cancreate'}},$item);
10739: }
10740: } else {
10741: if ($cancreate{$item} ne 'none') {
10742: push(@{$changes{'cancreate'}},$item);
10743: }
1.27 raeburn 10744: }
10745: }
10746: } else {
1.43 raeburn 10747: foreach my $item (@contexts) {
1.34 raeburn 10748: push(@{$changes{'cancreate'}},$item);
10749: }
1.27 raeburn 10750: }
1.34 raeburn 10751:
1.27 raeburn 10752: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
10753: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
10754: if (!grep(/^\Q$type\E$/,@username_rule)) {
10755: push(@{$changes{'username_rule'}},$type);
10756: }
10757: }
10758: foreach my $type (@username_rule) {
10759: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
10760: push(@{$changes{'username_rule'}},$type);
10761: }
10762: }
10763: } else {
10764: push(@{$changes{'username_rule'}},@username_rule);
10765: }
10766:
1.32 raeburn 10767: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
10768: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
10769: if (!grep(/^\Q$type\E$/,@id_rule)) {
10770: push(@{$changes{'id_rule'}},$type);
10771: }
10772: }
10773: foreach my $type (@id_rule) {
10774: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
10775: push(@{$changes{'id_rule'}},$type);
10776: }
10777: }
10778: } else {
10779: push(@{$changes{'id_rule'}},@id_rule);
10780: }
10781:
1.43 raeburn 10782: my @authen_contexts = ('author','course','domain');
1.28 raeburn 10783: my @authtypes = ('int','krb4','krb5','loc');
10784: my %authhash;
1.43 raeburn 10785: foreach my $item (@authen_contexts) {
1.28 raeburn 10786: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
10787: foreach my $auth (@authtypes) {
10788: if (grep(/^\Q$auth\E$/,@authallowed)) {
10789: $authhash{$item}{$auth} = 1;
10790: } else {
10791: $authhash{$item}{$auth} = 0;
10792: }
10793: }
10794: }
10795: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 10796: foreach my $item (@authen_contexts) {
1.28 raeburn 10797: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
10798: foreach my $auth (@authtypes) {
10799: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
10800: push(@{$changes{'authtypes'}},$item);
10801: last;
10802: }
10803: }
10804: }
10805: }
10806: } else {
1.43 raeburn 10807: foreach my $item (@authen_contexts) {
1.28 raeburn 10808: push(@{$changes{'authtypes'}},$item);
10809: }
10810: }
10811:
1.160.6.34 raeburn 10812: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
10813: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
10814: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
10815: $save_usercreate{'id_rule'} = \@id_rule;
10816: $save_usercreate{'username_rule'} = \@username_rule,
10817: $save_usercreate{'authtypes'} = \%authhash;
10818:
1.27 raeburn 10819: my %usercreation_hash = (
1.160.6.34 raeburn 10820: usercreation => \%save_usercreate,
10821: );
1.27 raeburn 10822:
10823: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
10824: $dom);
1.50 raeburn 10825:
1.160.6.34 raeburn 10826: if ($putresult eq 'ok') {
10827: if (keys(%changes) > 0) {
10828: $resulttext = &mt('Changes made:').'<ul>';
10829: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10830: my %lt = &usercreation_types();
10831: foreach my $type (@{$changes{'cancreate'}}) {
10832: my $chgtext = $lt{$type}.', ';
10833: if ($cancreate{$type} eq 'none') {
10834: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
10835: } elsif ($cancreate{$type} eq 'any') {
10836: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
10837: } elsif ($cancreate{$type} eq 'official') {
10838: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
10839: } elsif ($cancreate{$type} eq 'unofficial') {
10840: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
10841: }
10842: $resulttext .= '<li>'.$chgtext.'</li>';
10843: }
10844: }
10845: if (ref($changes{'username_rule'}) eq 'ARRAY') {
10846: my ($rules,$ruleorder) =
10847: &Apache::lonnet::inst_userrules($dom,'username');
10848: my $chgtext = '<ul>';
10849: foreach my $type (@username_rule) {
10850: if (ref($rules->{$type}) eq 'HASH') {
10851: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
10852: }
10853: }
10854: $chgtext .= '</ul>';
10855: if (@username_rule > 0) {
10856: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10857: } else {
10858: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
10859: }
10860: }
10861: if (ref($changes{'id_rule'}) eq 'ARRAY') {
10862: my ($idrules,$idruleorder) =
10863: &Apache::lonnet::inst_userrules($dom,'id');
10864: my $chgtext = '<ul>';
10865: foreach my $type (@id_rule) {
10866: if (ref($idrules->{$type}) eq 'HASH') {
10867: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
10868: }
10869: }
10870: $chgtext .= '</ul>';
10871: if (@id_rule > 0) {
10872: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10873: } else {
10874: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
10875: }
10876: }
10877: my %authname = &authtype_names();
10878: my %context_title = &context_names();
10879: if (ref($changes{'authtypes'}) eq 'ARRAY') {
10880: my $chgtext = '<ul>';
10881: foreach my $type (@{$changes{'authtypes'}}) {
10882: my @allowed;
10883: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
10884: foreach my $auth (@authtypes) {
10885: if ($authhash{$type}{$auth}) {
10886: push(@allowed,$authname{$auth});
10887: }
10888: }
10889: if (@allowed > 0) {
10890: $chgtext .= join(', ',@allowed).'</li>';
10891: } else {
10892: $chgtext .= &mt('none').'</li>';
10893: }
10894: }
10895: $chgtext .= '</ul>';
10896: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
10897: $resulttext .= '</li>';
10898: }
10899: $resulttext .= '</ul>';
10900: } else {
10901: $resulttext = &mt('No changes made to user creation settings');
10902: }
10903: } else {
10904: $resulttext = '<span class="LC_error">'.
10905: &mt('An error occurred: [_1]',$putresult).'</span>';
10906: }
10907: if ($warningmsg ne '') {
10908: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10909: }
10910: return $resulttext;
10911: }
10912:
10913: sub modify_selfcreation {
10914: my ($dom,%domconfig) = @_;
10915: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
10916: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 10917: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10918: if (ref($types) eq 'ARRAY') {
10919: $usertypes->{'default'} = $othertitle;
10920: push(@{$types},'default');
10921: }
1.160.6.34 raeburn 10922: #
10923: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
10924: #
10925: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10926: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
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') ||
10931: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.69 raeburn 10932: ($item eq 'recaptchaversion') ||
1.160.6.40 raeburn 10933: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 10934: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 10935: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10936: } else {
10937: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10938: }
10939: }
10940: }
10941: } elsif ($key eq 'email_rule') {
10942: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10943: } else {
10944: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10945: }
10946: }
10947: }
10948: #
10949: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
10950: #
10951: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10952: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
10953: if ($key eq 'selfcreate') {
10954: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
10955: } else {
10956: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
10957: }
10958: }
10959: }
10960:
10961: my @contexts = ('selfcreate');
10962: @{$cancreate{'selfcreate'}} = ();
10963: %{$cancreate{'emailusername'}} = ();
10964: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 10965: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 10966: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 10967: my %selfcreatetypes = (
10968: sso => 'users authenticated by institutional single sign on',
10969: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 10970: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 10971: );
1.160.6.34 raeburn 10972: #
10973: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
10974: # is permitted.
10975: #
1.160.6.40 raeburn 10976:
10977: my @statuses;
10978: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10979: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
10980: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
10981: }
10982: }
10983: push(@statuses,'default');
10984:
1.160.6.35 raeburn 10985: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 10986: if ($item eq 'email') {
1.160.6.40 raeburn 10987: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 10988: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 10989: push(@contexts,'selfcreateprocessing');
10990: foreach my $type (@statuses) {
10991: if ($type eq 'default') {
10992: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
10993: } else {
10994: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
10995: }
10996: }
1.160.6.34 raeburn 10997: }
10998: } else {
10999: if ($env{'form.cancreate_'.$item}) {
11000: push(@{$cancreate{'selfcreate'}},$item);
11001: }
11002: }
11003: }
11004: my (@email_rule,%userinfo,%savecaptcha);
11005: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
11006: #
1.160.6.35 raeburn 11007: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
11008: # 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 11009: #
1.160.6.40 raeburn 11010:
1.160.6.48 raeburn 11011: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 11012: push(@contexts,'emailusername');
1.160.6.35 raeburn 11013: if (ref($types) eq 'ARRAY') {
11014: foreach my $type (@{$types}) {
11015: if (ref($infofields) eq 'ARRAY') {
11016: foreach my $field (@{$infofields}) {
11017: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
11018: $cancreate{'emailusername'}{$type}{$field} = $1;
11019: }
11020: }
1.160.6.34 raeburn 11021: }
11022: }
11023: }
11024: #
11025: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
11026: # queued requests for self-creation of account using e-mail address as username
11027: #
11028:
11029: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
11030: @approvalnotify = sort(@approvalnotify);
11031: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
11032: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11033: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11034: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11035: push(@{$changes{'cancreate'}},'notify');
11036: }
11037: } else {
11038: if ($cancreate{'notify'}{'approval'}) {
11039: push(@{$changes{'cancreate'}},'notify');
11040: }
11041: }
11042: } elsif ($cancreate{'notify'}{'approval'}) {
11043: push(@{$changes{'cancreate'}},'notify');
11044: }
11045:
11046: #
11047: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
11048: #
11049: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
11050: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11051: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11052: if (@{$curr_usercreation{'email_rule'}} > 0) {
11053: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
11054: if (!grep(/^\Q$type\E$/,@email_rule)) {
11055: push(@{$changes{'email_rule'}},$type);
11056: }
11057: }
11058: }
11059: if (@email_rule > 0) {
11060: foreach my $type (@email_rule) {
11061: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
11062: push(@{$changes{'email_rule'}},$type);
11063: }
11064: }
11065: }
11066: } elsif (@email_rule > 0) {
11067: push(@{$changes{'email_rule'}},@email_rule);
11068: }
11069: }
11070: #
1.160.6.40 raeburn 11071: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 11072: # institutional log-in.
11073: #
11074: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11075: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11076: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11077: ($domdefaults{'auth_def'} eq 'localauth'))) {
11078: $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.').' '.
11079: &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.');
11080: }
11081: }
11082: my @fields = ('lastname','firstname','middlename','generation',
11083: 'permanentemail','id');
1.160.6.44 raeburn 11084: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 11085: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11086: #
11087: # Where usernames may created for institutional log-in and/or institutional single sign on:
11088: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11089: # may self-create accounts
11090: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11091: # which the user may supply, if institutional data is unavailable.
11092: #
11093: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
11094: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 11095: if (@{$types} > 1) {
1.160.6.34 raeburn 11096: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11097: push(@contexts,'statustocreate');
11098: } else {
11099: undef($cancreate{'statustocreate'});
11100: }
11101: foreach my $type (@{$types}) {
11102: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11103: foreach my $field (@fields) {
11104: if (grep(/^\Q$field\E$/,@modifiable)) {
11105: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11106: } else {
11107: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11108: }
11109: }
11110: }
11111: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
11112: foreach my $type (@{$types}) {
11113: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11114: foreach my $field (@fields) {
11115: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11116: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11117: push(@{$changes{'selfcreate'}},$type);
11118: last;
11119: }
11120: }
11121: }
11122: }
11123: } else {
11124: foreach my $type (@{$types}) {
11125: push(@{$changes{'selfcreate'}},$type);
11126: }
11127: }
11128: }
1.160.6.44 raeburn 11129: foreach my $field (@shibfields) {
11130: if ($env{'form.shibenv_'.$field} ne '') {
11131: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11132: }
11133: }
11134: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11135: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11136: foreach my $field (@shibfields) {
11137: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11138: push(@{$changes{'cancreate'}},'shibenv');
11139: }
11140: }
11141: } else {
11142: foreach my $field (@shibfields) {
11143: if ($env{'form.shibenv_'.$field}) {
11144: push(@{$changes{'cancreate'}},'shibenv');
11145: last;
11146: }
11147: }
11148: }
11149: }
1.160.6.34 raeburn 11150: }
11151: foreach my $item (@contexts) {
11152: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11153: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11154: if (ref($cancreate{$item}) eq 'ARRAY') {
11155: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11156: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11157: push(@{$changes{'cancreate'}},$item);
11158: }
11159: }
11160: }
11161: }
11162: if (ref($cancreate{$item}) eq 'ARRAY') {
11163: foreach my $type (@{$cancreate{$item}}) {
11164: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11165: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11166: push(@{$changes{'cancreate'}},$item);
11167: }
11168: }
11169: }
11170: }
11171: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11172: if (ref($cancreate{$item}) eq 'HASH') {
11173: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 11174: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
11175: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
11176: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
11177: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11178: push(@{$changes{'cancreate'}},$item);
11179: }
11180: }
11181: }
1.160.6.40 raeburn 11182: } elsif ($item eq 'selfcreateprocessing') {
11183: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
11184: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11185: push(@{$changes{'cancreate'}},$item);
11186: }
11187: }
1.160.6.35 raeburn 11188: } else {
11189: if (!$cancreate{$item}{$curr}) {
11190: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11191: push(@{$changes{'cancreate'}},$item);
11192: }
1.160.6.34 raeburn 11193: }
11194: }
11195: }
11196: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 11197: if (ref($cancreate{$item}{$field}) eq 'HASH') {
11198: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
11199: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
11200: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
11201: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11202: push(@{$changes{'cancreate'}},$item);
11203: }
11204: }
11205: } else {
11206: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11207: push(@{$changes{'cancreate'}},$item);
11208: }
11209: }
11210: }
1.160.6.40 raeburn 11211: } elsif ($item eq 'selfcreateprocessing') {
11212: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
11213: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11214: push(@{$changes{'cancreate'}},$item);
11215: }
11216: }
1.160.6.35 raeburn 11217: } else {
11218: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
11219: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11220: push(@{$changes{'cancreate'}},$item);
11221: }
1.160.6.34 raeburn 11222: }
11223: }
11224: }
11225: }
11226: } elsif ($curr_usercreation{'cancreate'}{$item}) {
11227: if (ref($cancreate{$item}) eq 'ARRAY') {
11228: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
11229: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11230: push(@{$changes{'cancreate'}},$item);
11231: }
11232: }
11233: } elsif (ref($cancreate{$item}) eq 'HASH') {
11234: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
11235: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11236: push(@{$changes{'cancreate'}},$item);
11237: }
11238: }
11239: }
11240: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 11241: if (ref($cancreate{$item}) eq 'HASH') {
11242: foreach my $type (keys(%{$cancreate{$item}})) {
11243: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11244: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11245: if ($cancreate{$item}{$type}{$field}) {
11246: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11247: push(@{$changes{'cancreate'}},$item);
11248: }
11249: last;
11250: }
11251: }
11252: }
11253: }
1.160.6.34 raeburn 11254: }
11255: }
11256: }
11257: #
11258: # Populate %save_usercreate hash with updates to self-creation configuration.
11259: #
11260: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
11261: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 11262: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 11263: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
11264: if (ref($cancreate{'notify'}) eq 'HASH') {
11265: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
11266: }
1.160.6.40 raeburn 11267: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
11268: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
11269: }
1.160.6.34 raeburn 11270: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11271: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
11272: }
1.160.6.44 raeburn 11273: if (ref($cancreate{'shibenv'}) eq 'HASH') {
11274: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
11275: }
1.160.6.34 raeburn 11276: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
11277: $save_usercreate{'emailrule'} = \@email_rule;
11278:
11279: my %userconfig_hash = (
11280: usercreation => \%save_usercreate,
11281: usermodification => \%save_usermodify,
11282: );
11283: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
11284: $dom);
11285: #
11286: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
11287: #
1.27 raeburn 11288: if ($putresult eq 'ok') {
11289: if (keys(%changes) > 0) {
11290: $resulttext = &mt('Changes made:').'<ul>';
11291: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 11292: my %lt = &selfcreation_types();
1.34 raeburn 11293: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 11294: my $chgtext;
1.45 raeburn 11295: if ($type eq 'selfcreate') {
1.50 raeburn 11296: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 11297: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 11298: } else {
1.160.6.34 raeburn 11299: $chgtext .= &mt('Self-creation of a new account is permitted for:').
11300: '<ul>';
1.50 raeburn 11301: foreach my $case (@{$cancreate{$type}}) {
11302: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
11303: }
11304: $chgtext .= '</ul>';
1.100 raeburn 11305: if (ref($cancreate{$type}) eq 'ARRAY') {
11306: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
11307: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11308: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 11309: $chgtext .= '<br />'.
11310: '<span class="LC_warning">'.
11311: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11312: '</span>';
1.100 raeburn 11313: }
11314: }
11315: }
11316: }
1.43 raeburn 11317: }
1.160.6.44 raeburn 11318: } elsif ($type eq 'shibenv') {
11319: if (keys(%{$cancreate{$type}}) == 0) {
11320: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
11321: } else {
11322: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
11323: '<ul>';
11324: foreach my $field (@shibfields) {
11325: next if ($cancreate{$type}{$field} eq '');
11326: if ($field eq 'inststatus') {
11327: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
11328: } else {
11329: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
11330: }
11331: }
11332: $chgtext .= '</ul>';
11333: }
1.93 raeburn 11334: } elsif ($type eq 'statustocreate') {
1.96 raeburn 11335: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
11336: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
11337: if (@{$cancreate{'selfcreate'}} > 0) {
11338: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 11339: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 11340: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 11341: $chgtext .= '<br />'.
11342: '<span class="LC_warning">'.
11343: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11344: '</span>';
11345: }
1.96 raeburn 11346: } elsif (ref($usertypes) eq 'HASH') {
11347: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 11348: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
11349: } else {
11350: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
11351: }
11352: $chgtext .= '<ul>';
11353: foreach my $case (@{$cancreate{$type}}) {
11354: if ($case eq 'default') {
11355: $chgtext .= '<li>'.$othertitle.'</li>';
11356: } else {
11357: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 11358: }
11359: }
1.100 raeburn 11360: $chgtext .= '</ul>';
11361: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 11362: $chgtext .= '<br /><span class="LC_warning">'.
11363: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
11364: '</span>';
1.100 raeburn 11365: }
11366: }
11367: } else {
11368: if (@{$cancreate{$type}} == 0) {
11369: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
11370: } else {
11371: $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 11372: }
11373: }
11374: }
1.160.6.40 raeburn 11375: } elsif ($type eq 'selfcreateprocessing') {
11376: my %choices = &Apache::lonlocal::texthash (
11377: automatic => 'Automatic approval',
11378: approval => 'Queued for approval',
11379: );
11380: if (@statuses > 1) {
11381: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
11382: '<ul>';
11383: foreach my $type (@statuses) {
11384: if ($type eq 'default') {
11385: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11386: } else {
11387: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11388: }
11389: }
11390: $chgtext .= '</ul>';
11391: } else {
11392: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
11393: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
11394: }
1.160.6.5 raeburn 11395: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 11396: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 11397: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
11398: } else {
11399: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 11400: if ($captchas{$savecaptcha{$type}}) {
11401: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 11402: } else {
11403: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
11404: }
11405: }
11406: } elsif ($type eq 'recaptchakeys') {
11407: my ($privkey,$pubkey);
1.160.6.34 raeburn 11408: if (ref($savecaptcha{$type}) eq 'HASH') {
11409: $pubkey = $savecaptcha{$type}{'public'};
11410: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 11411: }
11412: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
11413: if (!$pubkey) {
11414: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
11415: } else {
11416: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11417: }
11418: if (!$privkey) {
11419: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
11420: } else {
11421: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
11422: }
11423: $chgtext .= '</ul>';
1.160.6.69 raeburn 11424: } elsif ($type eq 'recaptchaversion') {
11425: if ($savecaptcha{'captcha'} eq 'recaptcha') {
11426: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
11427: }
1.160.6.34 raeburn 11428: } elsif ($type eq 'emailusername') {
11429: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 11430: if (ref($types) eq 'ARRAY') {
11431: foreach my $type (@{$types}) {
11432: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
11433: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50 raeburn 11434: $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 11435: '<ul>';
11436: foreach my $field (@{$infofields}) {
11437: if ($cancreate{'emailusername'}{$type}{$field}) {
11438: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
11439: }
11440: }
1.160.6.50 raeburn 11441: $chgtext .= '</ul>';
11442: } else {
11443: $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 11444: }
11445: } else {
1.160.6.50 raeburn 11446: $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 11447: }
11448: }
11449: }
11450: }
11451: } elsif ($type eq 'notify') {
11452: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
11453: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11454: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
11455: if ($cancreate{'notify'}{'approval'}) {
11456: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
11457: }
11458: }
1.43 raeburn 11459: }
1.34 raeburn 11460: }
1.160.6.34 raeburn 11461: if ($chgtext) {
11462: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 11463: }
11464: }
11465: }
1.43 raeburn 11466: if (ref($changes{'email_rule'}) eq 'ARRAY') {
11467: my ($emailrules,$emailruleorder) =
11468: &Apache::lonnet::inst_userrules($dom,'email');
11469: my $chgtext = '<ul>';
11470: foreach my $type (@email_rule) {
11471: if (ref($emailrules->{$type}) eq 'HASH') {
11472: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
11473: }
11474: }
11475: $chgtext .= '</ul>';
11476: if (@email_rule > 0) {
1.160.6.34 raeburn 11477: $resulttext .= '<li>'.
11478: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
11479: $chgtext.
11480: '</li>';
1.43 raeburn 11481: } else {
1.160.6.34 raeburn 11482: $resulttext .= '<li>'.
11483: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
11484: '</li>';
1.43 raeburn 11485: }
11486: }
1.160.6.34 raeburn 11487: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
11488: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
11489: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11490: foreach my $type (@{$changes{'selfcreate'}}) {
11491: my $typename = $type;
11492: if (ref($usertypes) eq 'HASH') {
11493: if ($usertypes->{$type} ne '') {
11494: $typename = $usertypes->{$type};
1.28 raeburn 11495: }
11496: }
1.160.6.34 raeburn 11497: my @modifiable;
11498: $resulttext .= '<li>'.
11499: &mt('Self-creation of account by users with status: [_1]',
11500: '<span class="LC_cusr_emph">'.$typename.'</span>').
11501: ' - '.&mt('modifiable fields (if institutional data blank): ');
11502: foreach my $field (@fields) {
11503: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
11504: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
11505: }
11506: }
11507: if (@modifiable > 0) {
11508: $resulttext .= join(', ',@modifiable);
1.43 raeburn 11509: } else {
1.160.6.34 raeburn 11510: $resulttext .= &mt('none');
1.43 raeburn 11511: }
1.160.6.34 raeburn 11512: $resulttext .= '</li>';
1.28 raeburn 11513: }
1.160.6.34 raeburn 11514: $resulttext .= '</ul></li>';
1.28 raeburn 11515: }
1.27 raeburn 11516: $resulttext .= '</ul>';
11517: } else {
1.160.6.34 raeburn 11518: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 11519: }
11520: } else {
11521: $resulttext = '<span class="LC_error">'.
1.23 raeburn 11522: &mt('An error occurred: [_1]',$putresult).'</span>';
11523: }
1.43 raeburn 11524: if ($warningmsg ne '') {
11525: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11526: }
1.23 raeburn 11527: return $resulttext;
11528: }
11529:
1.160.6.5 raeburn 11530: sub process_captcha {
11531: my ($container,$changes,$newsettings,$current) = @_;
11532: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
11533: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
11534: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
11535: $newsettings->{'captcha'} = 'original';
11536: }
11537: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
11538: if ($container eq 'cancreate') {
11539: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11540: push(@{$changes->{'cancreate'}},'captcha');
11541: } elsif (!defined($changes->{'cancreate'})) {
11542: $changes->{'cancreate'} = ['captcha'];
11543: }
11544: } else {
11545: $changes->{'captcha'} = 1;
11546: }
11547: }
1.160.6.69 raeburn 11548: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 11549: if ($newsettings->{'captcha'} eq 'recaptcha') {
11550: $newpub = $env{'form.'.$container.'_recaptchapub'};
11551: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 11552: $newpub =~ s/[^\w\-]//g;
11553: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 11554: $newsettings->{'recaptchakeys'} = {
11555: public => $newpub,
11556: private => $newpriv,
11557: };
1.160.6.69 raeburn 11558: $newversion = $env{'form.'.$container.'_recaptchaversion'};
11559: $newversion =~ s/\D//g;
11560: if ($newversion ne '2') {
11561: $newversion = 1;
11562: }
11563: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 11564: }
11565: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
11566: $currpub = $current->{'recaptchakeys'}{'public'};
11567: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 11568: unless ($newsettings->{'captcha'} eq 'recaptcha') {
11569: $newsettings->{'recaptchakeys'} = {
11570: public => '',
11571: private => '',
11572: }
11573: }
1.160.6.5 raeburn 11574: }
1.160.6.69 raeburn 11575: if ($current->{'captcha'} eq 'recaptcha') {
11576: $currversion = $current->{'recaptchaversion'};
11577: if ($currversion ne '2') {
11578: $currversion = 1;
11579: }
11580: }
11581: if ($currversion ne $newversion) {
11582: if ($container eq 'cancreate') {
11583: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11584: push(@{$changes->{'cancreate'}},'recaptchaversion');
11585: } elsif (!defined($changes->{'cancreate'})) {
11586: $changes->{'cancreate'} = ['recaptchaversion'];
11587: }
11588: } else {
11589: $changes->{'recaptchaversion'} = 1;
11590: }
11591: }
1.160.6.5 raeburn 11592: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
11593: if ($container eq 'cancreate') {
11594: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11595: push(@{$changes->{'cancreate'}},'recaptchakeys');
11596: } elsif (!defined($changes->{'cancreate'})) {
11597: $changes->{'cancreate'} = ['recaptchakeys'];
11598: }
11599: } else {
11600: $changes->{'recaptchakeys'} = 1;
11601: }
11602: }
11603: return;
11604: }
11605:
1.33 raeburn 11606: sub modify_usermodification {
11607: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 11608: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 11609: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11610: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 11611: if ($key eq 'selfcreate') {
11612: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
11613: } else {
11614: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
11615: }
1.33 raeburn 11616: }
11617: }
1.160.6.34 raeburn 11618: my @contexts = ('author','course');
1.33 raeburn 11619: my %context_title = (
11620: author => 'In author context',
11621: course => 'In course context',
11622: );
11623: my @fields = ('lastname','firstname','middlename','generation',
11624: 'permanentemail','id');
11625: my %roles = (
11626: author => ['ca','aa'],
11627: course => ['st','ep','ta','in','cr'],
11628: );
11629: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11630: foreach my $context (@contexts) {
11631: foreach my $role (@{$roles{$context}}) {
11632: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
11633: foreach my $item (@fields) {
11634: if (grep(/^\Q$item\E$/,@modifiable)) {
11635: $modifyhash{$context}{$role}{$item} = 1;
11636: } else {
11637: $modifyhash{$context}{$role}{$item} = 0;
11638: }
11639: }
11640: }
11641: if (ref($curr_usermodification{$context}) eq 'HASH') {
11642: foreach my $role (@{$roles{$context}}) {
11643: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
11644: foreach my $field (@fields) {
11645: if ($modifyhash{$context}{$role}{$field} ne
11646: $curr_usermodification{$context}{$role}{$field}) {
11647: push(@{$changes{$context}},$role);
11648: last;
11649: }
11650: }
11651: }
11652: }
11653: } else {
11654: foreach my $context (@contexts) {
11655: foreach my $role (@{$roles{$context}}) {
11656: push(@{$changes{$context}},$role);
11657: }
11658: }
11659: }
11660: }
11661: my %usermodification_hash = (
11662: usermodification => \%modifyhash,
11663: );
11664: my $putresult = &Apache::lonnet::put_dom('configuration',
11665: \%usermodification_hash,$dom);
11666: if ($putresult eq 'ok') {
11667: if (keys(%changes) > 0) {
11668: $resulttext = &mt('Changes made: ').'<ul>';
11669: foreach my $context (@contexts) {
11670: if (ref($changes{$context}) eq 'ARRAY') {
11671: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
11672: if (ref($changes{$context}) eq 'ARRAY') {
11673: foreach my $role (@{$changes{$context}}) {
11674: my $rolename;
1.160.6.34 raeburn 11675: if ($role eq 'cr') {
11676: $rolename = &mt('Custom');
1.33 raeburn 11677: } else {
1.160.6.34 raeburn 11678: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 11679: }
11680: my @modifiable;
1.160.6.34 raeburn 11681: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 11682: foreach my $field (@fields) {
11683: if ($modifyhash{$context}{$role}{$field}) {
11684: push(@modifiable,$fieldtitles{$field});
11685: }
11686: }
11687: if (@modifiable > 0) {
11688: $resulttext .= join(', ',@modifiable);
11689: } else {
11690: $resulttext .= &mt('none');
11691: }
11692: $resulttext .= '</li>';
11693: }
11694: $resulttext .= '</ul></li>';
11695: }
11696: }
11697: }
11698: $resulttext .= '</ul>';
11699: } else {
11700: $resulttext = &mt('No changes made to user modification settings');
11701: }
11702: } else {
11703: $resulttext = '<span class="LC_error">'.
11704: &mt('An error occurred: [_1]',$putresult).'</span>';
11705: }
11706: return $resulttext;
11707: }
11708:
1.43 raeburn 11709: sub modify_defaults {
1.160.6.27 raeburn 11710: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 11711: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 11712: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 11713: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
11714: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 11715: my @authtypes = ('internal','krb4','krb5','localauth');
11716: foreach my $item (@items) {
11717: $newvalues{$item} = $env{'form.'.$item};
11718: if ($item eq 'auth_def') {
11719: if ($newvalues{$item} ne '') {
11720: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
11721: push(@errors,$item);
11722: }
11723: }
11724: } elsif ($item eq 'lang_def') {
11725: if ($newvalues{$item} ne '') {
11726: if ($newvalues{$item} =~ /^(\w+)/) {
11727: my $langcode = $1;
1.103 raeburn 11728: if ($langcode ne 'x_chef') {
11729: if (code2language($langcode) eq '') {
11730: push(@errors,$item);
11731: }
1.43 raeburn 11732: }
11733: } else {
11734: push(@errors,$item);
11735: }
11736: }
1.54 raeburn 11737: } elsif ($item eq 'timezone_def') {
11738: if ($newvalues{$item} ne '') {
1.62 raeburn 11739: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 11740: push(@errors,$item);
11741: }
11742: }
1.68 raeburn 11743: } elsif ($item eq 'datelocale_def') {
11744: if ($newvalues{$item} ne '') {
11745: my @datelocale_ids = DateTime::Locale->ids();
11746: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
11747: push(@errors,$item);
11748: }
11749: }
1.141 raeburn 11750: } elsif ($item eq 'portal_def') {
11751: if ($newvalues{$item} ne '') {
11752: 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])\/?$/) {
11753: push(@errors,$item);
11754: }
11755: }
1.160.6.80 raeburn 11756: } elsif ($item eq 'intauth_cost') {
11757: if ($newvalues{$item} ne '') {
11758: if ($newvalues{$item} =~ /\D/) {
11759: push(@errors,$item);
11760: }
11761: }
11762: } elsif ($item eq 'intauth_check') {
11763: if ($newvalues{$item} ne '') {
11764: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
11765: push(@errors,$item);
11766: }
11767: }
11768: } elsif ($item eq 'intauth_switch') {
11769: if ($newvalues{$item} ne '') {
11770: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
11771: push(@errors,$item);
11772: }
11773: }
1.43 raeburn 11774: }
11775: if (grep(/^\Q$item\E$/,@errors)) {
11776: $newvalues{$item} = $domdefaults{$item};
11777: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
11778: $changes{$item} = 1;
11779: }
1.72 raeburn 11780: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 11781: }
11782: my %defaults_hash = (
1.72 raeburn 11783: defaults => \%newvalues,
11784: );
1.43 raeburn 11785: my $title = &defaults_titles();
1.160.6.40 raeburn 11786:
11787: my $currinststatus;
11788: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11789: $currinststatus = $domconfig{'inststatus'};
11790: } else {
11791: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11792: $currinststatus = {
11793: inststatustypes => $usertypes,
11794: inststatusorder => $types,
11795: inststatusguest => [],
11796: };
11797: }
11798: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
11799: my @allpos;
11800: my %guests;
11801: my %alltypes;
11802: my ($currtitles,$currguests,$currorder);
11803: if (ref($currinststatus) eq 'HASH') {
11804: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
11805: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
11806: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
11807: if ($currinststatus->{inststatustypes}->{$type} ne '') {
11808: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
11809: }
11810: }
11811: unless (grep(/^\Q$type\E$/,@todelete)) {
11812: my $position = $env{'form.inststatus_pos_'.$type};
11813: $position =~ s/\D+//g;
11814: $allpos[$position] = $type;
11815: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
11816: $alltypes{$type} =~ s/`//g;
11817: if ($env{'form.inststatus_guest_'.$type}) {
11818: $guests{$type} = 1;
11819: }
11820: }
11821: }
11822: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
11823: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
11824: }
11825: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
11826: $currtitles =~ s/,$//;
11827: }
11828: }
11829: if ($env{'form.addinststatus'}) {
11830: my $newtype = $env{'form.addinststatus'};
11831: $newtype =~ s/\W//g;
11832: unless (exists($alltypes{$newtype})) {
11833: if ($env{'form.addinststatus_guest'}) {
11834: $guests{$newtype} = 1;
11835: }
11836: $alltypes{$newtype} = $env{'form.addinststatus_title'};
11837: $alltypes{$newtype} =~ s/`//g;
11838: my $position = $env{'form.addinststatus_pos'};
11839: $position =~ s/\D+//g;
11840: if ($position ne '') {
11841: $allpos[$position] = $newtype;
11842: }
11843: }
11844: }
11845: my (@orderedstatus,@orderedguests);
11846: foreach my $type (@allpos) {
11847: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
11848: push(@orderedstatus,$type);
11849: if ($guests{$type}) {
11850: push(@orderedguests,$type);
11851: }
11852: }
11853: }
11854: foreach my $type (keys(%alltypes)) {
11855: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
11856: delete($alltypes{$type});
11857: }
11858: }
11859: $defaults_hash{'inststatus'} = {
11860: inststatustypes => \%alltypes,
11861: inststatusorder => \@orderedstatus,
11862: inststatusguest => \@orderedguests,
11863: };
11864: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
11865: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
11866: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
11867: }
11868: }
11869: if ($currorder ne join(',',@orderedstatus)) {
11870: $changes{'inststatus'}{'inststatusorder'} = 1;
11871: }
11872: if ($currguests ne join(',',@orderedguests)) {
11873: $changes{'inststatus'}{'inststatusguest'} = 1;
11874: }
11875: my $newtitles;
11876: foreach my $item (@orderedstatus) {
11877: $newtitles .= $alltypes{$item}.',';
11878: }
11879: $newtitles =~ s/,$//;
11880: if ($currtitles ne $newtitles) {
11881: $changes{'inststatus'}{'inststatustypes'} = 1;
11882: }
1.43 raeburn 11883: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
11884: $dom);
11885: if ($putresult eq 'ok') {
11886: if (keys(%changes) > 0) {
11887: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 11888: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 11889: 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";
11890: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 11891: if ($item eq 'inststatus') {
11892: if (ref($changes{'inststatus'}) eq 'HASH') {
11893: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
11894: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
11895: foreach my $type (@orderedstatus) {
11896: $resulttext .= $alltypes{$type}.', ';
11897: }
11898: $resulttext =~ s/, $//;
11899: $resulttext .= '</li>';
11900: }
11901: if ($changes{'inststatus'}{'inststatusguest'}) {
11902: $resulttext .= '<li>';
11903: if (@orderedguests) {
11904: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
11905: foreach my $type (@orderedguests) {
11906: $resulttext .= $alltypes{$type}.', ';
11907: }
11908: $resulttext =~ s/, $//;
11909: } else {
11910: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
11911: }
11912: $resulttext .= '</li>';
11913: }
11914: }
11915: } else {
11916: my $value = $env{'form.'.$item};
11917: if ($value eq '') {
11918: $value = &mt('none');
11919: } elsif ($item eq 'auth_def') {
11920: my %authnames = &authtype_names();
11921: my %shortauth = (
11922: internal => 'int',
11923: krb4 => 'krb4',
11924: krb5 => 'krb5',
11925: localauth => 'loc',
11926: );
11927: $value = $authnames{$shortauth{$value}};
1.160.6.80 raeburn 11928: } elsif ($item eq 'intauth_switch') {
11929: my %optiondesc = &Apache::lonlocal::texthash (
11930: 0 => 'No',
11931: 1 => 'Yes',
11932: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
11933: );
11934: if ($value =~ /^(0|1|2)$/) {
11935: $value = $optiondesc{$value};
11936: } else {
11937: $value = &mt('none -- defaults to No');
11938: }
11939: } elsif ($item eq 'intauth_check') {
11940: my %optiondesc = &Apache::lonlocal::texthash (
11941: 0 => 'No',
11942: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
11943: 2 => 'Yes, disallow login if stored cost is less than domain default',
11944: );
11945: if ($value =~ /^(0|1|2)$/) {
11946: $value = $optiondesc{$value};
11947: } else {
11948: $value = &mt('none -- defaults to No');
11949: }
1.160.6.40 raeburn 11950: }
11951: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
11952: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 11953: }
11954: }
11955: $resulttext .= '</ul>';
11956: $mailmsgtext .= "\n";
11957: my $cachetime = 24*60*60;
1.72 raeburn 11958: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11959: if (ref($lastactref) eq 'HASH') {
11960: $lastactref->{'domdefaults'} = 1;
11961: }
1.68 raeburn 11962: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 11963: my $notify = 1;
11964: if (ref($domconfig{'contacts'}) eq 'HASH') {
11965: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
11966: $notify = 0;
11967: }
11968: }
11969: if ($notify) {
11970: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
11971: "LON-CAPA Domain Settings Change - $dom",
11972: $mailmsgtext);
11973: }
1.54 raeburn 11974: }
1.43 raeburn 11975: } else {
1.54 raeburn 11976: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 11977: }
11978: } else {
11979: $resulttext = '<span class="LC_error">'.
11980: &mt('An error occurred: [_1]',$putresult).'</span>';
11981: }
11982: if (@errors > 0) {
11983: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
11984: foreach my $item (@errors) {
11985: $resulttext .= ' "'.$title->{$item}.'",';
11986: }
11987: $resulttext =~ s/,$//;
11988: }
11989: return $resulttext;
11990: }
11991:
1.46 raeburn 11992: sub modify_scantron {
1.160.6.24 raeburn 11993: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 11994: my ($resulttext,%confhash,%changes,$errors);
11995: my $custom = 'custom.tab';
11996: my $default = 'default.tab';
11997: my $servadm = $r->dir_config('lonAdmEMail');
11998: my ($configuserok,$author_ok,$switchserver) =
11999: &config_check($dom,$confname,$servadm);
12000: if ($env{'form.scantronformat.filename'} ne '') {
12001: my $error;
12002: if ($configuserok eq 'ok') {
12003: if ($switchserver) {
1.130 raeburn 12004: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 12005: } else {
12006: if ($author_ok eq 'ok') {
12007: my ($result,$scantronurl) =
12008: &publishlogo($r,'upload','scantronformat',$dom,
12009: $confname,'scantron','','',$custom);
12010: if ($result eq 'ok') {
12011: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 12012: $changes{'scantronformat'} = 1;
1.46 raeburn 12013: } else {
12014: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
12015: }
12016: } else {
12017: $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);
12018: }
12019: }
12020: } else {
12021: $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);
12022: }
12023: if ($error) {
12024: &Apache::lonnet::logthis($error);
12025: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12026: }
12027: }
1.48 raeburn 12028: if (ref($domconfig{'scantron'}) eq 'HASH') {
12029: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
12030: if ($env{'form.scantronformat_del'}) {
12031: $confhash{'scantron'}{'scantronformat'} = '';
12032: $changes{'scantronformat'} = 1;
1.46 raeburn 12033: }
12034: }
12035: }
12036: if (keys(%confhash) > 0) {
12037: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
12038: $dom);
12039: if ($putresult eq 'ok') {
12040: if (keys(%changes) > 0) {
1.48 raeburn 12041: if (ref($confhash{'scantron'}) eq 'HASH') {
12042: $resulttext = &mt('Changes made:').'<ul>';
12043: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 12044: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 12045: } else {
1.130 raeburn 12046: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 12047: }
1.48 raeburn 12048: $resulttext .= '</ul>';
12049: } else {
1.130 raeburn 12050: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 12051: }
12052: $resulttext .= '</ul>';
12053: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 12054: if (ref($lastactref) eq 'HASH') {
12055: $lastactref->{'domainconfig'} = 1;
12056: }
1.46 raeburn 12057: } else {
1.130 raeburn 12058: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12059: }
12060: } else {
12061: $resulttext = '<span class="LC_error">'.
12062: &mt('An error occurred: [_1]',$putresult).'</span>';
12063: }
12064: } else {
1.130 raeburn 12065: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12066: }
12067: if ($errors) {
12068: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12069: $errors.'</ul>';
12070: }
12071: return $resulttext;
12072: }
12073:
1.48 raeburn 12074: sub modify_coursecategories {
1.160.6.43 raeburn 12075: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 12076: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
12077: $cathash);
1.48 raeburn 12078: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 12079: my @catitems = ('unauth','auth');
12080: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 12081: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 12082: $cathash = $domconfig{'coursecategories'}{'cats'};
12083: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
12084: $changes{'togglecats'} = 1;
12085: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
12086: }
12087: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
12088: $changes{'categorize'} = 1;
12089: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
12090: }
1.120 raeburn 12091: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
12092: $changes{'togglecatscomm'} = 1;
12093: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
12094: }
12095: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
12096: $changes{'categorizecomm'} = 1;
12097: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
12098: }
1.160.6.42 raeburn 12099: foreach my $item (@catitems) {
12100: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12101: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
12102: $changes{$item} = 1;
12103: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12104: }
12105: }
12106: }
1.57 raeburn 12107: } else {
12108: $changes{'togglecats'} = 1;
12109: $changes{'categorize'} = 1;
1.124 raeburn 12110: $changes{'togglecatscomm'} = 1;
12111: $changes{'categorizecomm'} = 1;
1.87 raeburn 12112: $domconfig{'coursecategories'} = {
12113: togglecats => $env{'form.togglecats'},
12114: categorize => $env{'form.categorize'},
1.124 raeburn 12115: togglecatscomm => $env{'form.togglecatscomm'},
12116: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 12117: };
1.160.6.42 raeburn 12118: foreach my $item (@catitems) {
12119: if ($env{'form.coursecat_'.$item} ne 'std') {
12120: $changes{$item} = 1;
12121: }
12122: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12123: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12124: }
12125: }
1.57 raeburn 12126: }
12127: if (ref($cathash) eq 'HASH') {
12128: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 12129: push (@deletecategory,'instcode::0');
12130: }
1.120 raeburn 12131: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
12132: push(@deletecategory,'communities::0');
12133: }
1.48 raeburn 12134: }
1.57 raeburn 12135: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
12136: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12137: if (@deletecategory > 0) {
12138: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 12139: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 12140: foreach my $item (@deletecategory) {
1.57 raeburn 12141: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
12142: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 12143: $deletions{$item} = 1;
1.57 raeburn 12144: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 12145: }
12146: }
12147: }
1.57 raeburn 12148: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 12149: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 12150: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 12151: $reorderings{$item} = 1;
1.57 raeburn 12152: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 12153: }
12154: if ($env{'form.addcategory_name_'.$item} ne '') {
12155: my $newcat = $env{'form.addcategory_name_'.$item};
12156: my $newdepth = $depth+1;
12157: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12158: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 12159: $adds{$newitem} = 1;
12160: }
12161: if ($env{'form.subcat_'.$item} ne '') {
12162: my $newcat = $env{'form.subcat_'.$item};
12163: my $newdepth = $depth+1;
12164: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12165: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 12166: $adds{$newitem} = 1;
12167: }
12168: }
12169: }
12170: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 12171: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12172: my $newitem = 'instcode::0';
1.57 raeburn 12173: if ($cathash->{$newitem} eq '') {
12174: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12175: $adds{$newitem} = 1;
12176: }
12177: } else {
12178: my $newitem = 'instcode::0';
1.57 raeburn 12179: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12180: $adds{$newitem} = 1;
12181: }
12182: }
1.120 raeburn 12183: if ($env{'form.communities'} eq '1') {
12184: if (ref($cathash) eq 'HASH') {
12185: my $newitem = 'communities::0';
12186: if ($cathash->{$newitem} eq '') {
12187: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12188: $adds{$newitem} = 1;
12189: }
12190: } else {
12191: my $newitem = 'communities::0';
12192: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12193: $adds{$newitem} = 1;
12194: }
12195: }
1.48 raeburn 12196: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 12197: if (($env{'form.addcategory_name'} ne 'instcode') &&
12198: ($env{'form.addcategory_name'} ne 'communities')) {
12199: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
12200: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
12201: $adds{$newitem} = 1;
12202: }
1.48 raeburn 12203: }
1.57 raeburn 12204: my $putresult;
1.48 raeburn 12205: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12206: if (keys(%deletions) > 0) {
12207: foreach my $key (keys(%deletions)) {
12208: if ($predelallitems{$key} ne '') {
12209: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
12210: }
12211: }
12212: }
12213: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 12214: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 12215: if (ref($chkcats[0]) eq 'ARRAY') {
12216: my $depth = 0;
12217: my $chg = 0;
12218: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
12219: my $name = $chkcats[0][$i];
12220: my $item;
12221: if ($name eq '') {
12222: $chg ++;
12223: } else {
12224: $item = &escape($name).'::0';
12225: if ($chg) {
1.57 raeburn 12226: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 12227: }
12228: $depth ++;
1.57 raeburn 12229: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 12230: $depth --;
12231: }
12232: }
12233: }
1.57 raeburn 12234: }
12235: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12236: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 12237: if ($putresult eq 'ok') {
1.57 raeburn 12238: my %title = (
1.120 raeburn 12239: togglecats => 'Show/Hide a course in catalog',
12240: categorize => 'Assign a category to a course',
12241: togglecatscomm => 'Show/Hide a community in catalog',
12242: categorizecomm => 'Assign a category to a community',
1.57 raeburn 12243: );
12244: my %level = (
1.120 raeburn 12245: dom => 'set in Domain ("Modify Course/Community")',
12246: crs => 'set in Course ("Course Configuration")',
12247: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 12248: none => 'No catalog',
12249: std => 'Standard catalog',
12250: domonly => 'Domain-only catalog',
12251: codesrch => 'Code search form',
1.57 raeburn 12252: );
1.48 raeburn 12253: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 12254: if ($changes{'togglecats'}) {
12255: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
12256: }
12257: if ($changes{'categorize'}) {
12258: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 12259: }
1.120 raeburn 12260: if ($changes{'togglecatscomm'}) {
12261: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
12262: }
12263: if ($changes{'categorizecomm'}) {
12264: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
12265: }
1.160.6.42 raeburn 12266: if ($changes{'unauth'}) {
12267: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
12268: }
12269: if ($changes{'auth'}) {
12270: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
12271: }
1.57 raeburn 12272: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12273: my $cathash;
12274: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
12275: $cathash = $domconfig{'coursecategories'}{'cats'};
12276: } else {
12277: $cathash = {};
12278: }
12279: my (@cats,@trails,%allitems);
12280: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
12281: if (keys(%deletions) > 0) {
12282: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
12283: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
12284: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
12285: }
12286: $resulttext .= '</ul></li>';
12287: }
12288: if (keys(%reorderings) > 0) {
12289: my %sort_by_trail;
12290: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
12291: foreach my $key (keys(%reorderings)) {
12292: if ($allitems{$key} ne '') {
12293: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12294: }
1.48 raeburn 12295: }
1.57 raeburn 12296: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12297: $resulttext .= '<li>'.$trails[$trail].'</li>';
12298: }
12299: $resulttext .= '</ul></li>';
1.48 raeburn 12300: }
1.57 raeburn 12301: if (keys(%adds) > 0) {
12302: my %sort_by_trail;
12303: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
12304: foreach my $key (keys(%adds)) {
12305: if ($allitems{$key} ne '') {
12306: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12307: }
12308: }
12309: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12310: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 12311: }
1.57 raeburn 12312: $resulttext .= '</ul></li>';
1.48 raeburn 12313: }
12314: }
12315: $resulttext .= '</ul>';
1.160.6.43 raeburn 12316: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 12317: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12318: if ($changes{'auth'}) {
12319: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
12320: }
12321: if ($changes{'unauth'}) {
12322: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
12323: }
12324: my $cachetime = 24*60*60;
12325: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 12326: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 12327: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 12328: }
12329: }
1.48 raeburn 12330: } else {
12331: $resulttext = '<span class="LC_error">'.
1.57 raeburn 12332: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 12333: }
12334: } else {
1.120 raeburn 12335: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 12336: }
12337: return $resulttext;
12338: }
12339:
1.69 raeburn 12340: sub modify_serverstatuses {
12341: my ($dom,%domconfig) = @_;
12342: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
12343: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
12344: %currserverstatus = %{$domconfig{'serverstatuses'}};
12345: }
12346: my @pages = &serverstatus_pages();
12347: foreach my $type (@pages) {
12348: $newserverstatus{$type}{'namedusers'} = '';
12349: $newserverstatus{$type}{'machines'} = '';
12350: if (defined($env{'form.'.$type.'_namedusers'})) {
12351: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
12352: my @okusers;
12353: foreach my $user (@users) {
12354: my ($uname,$udom) = split(/:/,$user);
12355: if (($udom =~ /^$match_domain$/) &&
12356: (&Apache::lonnet::domain($udom)) &&
12357: ($uname =~ /^$match_username$/)) {
12358: if (!grep(/^\Q$user\E/,@okusers)) {
12359: push(@okusers,$user);
12360: }
12361: }
12362: }
12363: if (@okusers > 0) {
12364: @okusers = sort(@okusers);
12365: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
12366: }
12367: }
12368: if (defined($env{'form.'.$type.'_machines'})) {
12369: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
12370: my @okmachines;
12371: foreach my $ip (@machines) {
12372: my @parts = split(/\./,$ip);
12373: next if (@parts < 4);
12374: my $badip = 0;
12375: for (my $i=0; $i<4; $i++) {
12376: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
12377: $badip = 1;
12378: last;
12379: }
12380: }
12381: if (!$badip) {
12382: push(@okmachines,$ip);
12383: }
12384: }
12385: @okmachines = sort(@okmachines);
12386: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
12387: }
12388: }
12389: my %serverstatushash = (
12390: serverstatuses => \%newserverstatus,
12391: );
12392: foreach my $type (@pages) {
1.83 raeburn 12393: foreach my $setting ('namedusers','machines') {
1.84 raeburn 12394: my (@current,@new);
1.83 raeburn 12395: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 12396: if ($currserverstatus{$type}{$setting} ne '') {
12397: @current = split(/,/,$currserverstatus{$type}{$setting});
12398: }
12399: }
12400: if ($newserverstatus{$type}{$setting} ne '') {
12401: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 12402: }
12403: if (@current > 0) {
12404: if (@new > 0) {
12405: foreach my $item (@current) {
12406: if (!grep(/^\Q$item\E$/,@new)) {
12407: $changes{$type}{$setting} = 1;
1.82 raeburn 12408: last;
12409: }
12410: }
1.84 raeburn 12411: foreach my $item (@new) {
12412: if (!grep(/^\Q$item\E$/,@current)) {
12413: $changes{$type}{$setting} = 1;
12414: last;
1.82 raeburn 12415: }
12416: }
12417: } else {
1.83 raeburn 12418: $changes{$type}{$setting} = 1;
1.69 raeburn 12419: }
1.83 raeburn 12420: } elsif (@new > 0) {
12421: $changes{$type}{$setting} = 1;
1.69 raeburn 12422: }
12423: }
12424: }
12425: if (keys(%changes) > 0) {
1.81 raeburn 12426: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 12427: my $putresult = &Apache::lonnet::put_dom('configuration',
12428: \%serverstatushash,$dom);
12429: if ($putresult eq 'ok') {
12430: $resulttext .= &mt('Changes made:').'<ul>';
12431: foreach my $type (@pages) {
1.84 raeburn 12432: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 12433: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 12434: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 12435: if ($newserverstatus{$type}{'namedusers'} eq '') {
12436: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
12437: } else {
12438: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
12439: }
1.84 raeburn 12440: }
12441: if ($changes{$type}{'machines'}) {
1.69 raeburn 12442: if ($newserverstatus{$type}{'machines'} eq '') {
12443: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
12444: } else {
12445: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
12446: }
12447:
12448: }
12449: $resulttext .= '</ul></li>';
12450: }
12451: }
12452: $resulttext .= '</ul>';
12453: } else {
12454: $resulttext = '<span class="LC_error">'.
12455: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
12456:
12457: }
12458: } else {
12459: $resulttext = &mt('No changes made to access to server status pages');
12460: }
12461: return $resulttext;
12462: }
12463:
1.118 jms 12464: sub modify_helpsettings {
1.160.6.77 raeburn 12465: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 12466: my ($resulttext,$errors,%changes,%helphash);
12467: my %defaultchecked = ('submitbugs' => 'on');
12468: my @offon = ('off','on');
1.118 jms 12469: my @toggles = ('submitbugs');
1.160.6.77 raeburn 12470: my %current = ('submitbugs' => '',
12471: 'adhoc' => {},
12472: );
1.118 jms 12473: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 12474: %current = %{$domconfig{'helpsettings'}};
12475: }
1.160.6.77 raeburn 12476: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 12477: foreach my $item (@toggles) {
12478: if ($defaultchecked{$item} eq 'on') {
12479: if ($current{$item} eq '') {
12480: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 12481: $changes{$item} = 1;
12482: }
1.160.6.73 raeburn 12483: } elsif ($current{$item} ne $env{'form.'.$item}) {
12484: $changes{$item} = 1;
12485: }
12486: } elsif ($defaultchecked{$item} eq 'off') {
12487: if ($current{$item} eq '') {
12488: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 12489: $changes{$item} = 1;
12490: }
1.160.6.73 raeburn 12491: } elsif ($current{$item} ne $env{'form.'.$item}) {
12492: $changes{$item} = 1;
12493: }
12494: }
12495: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
12496: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
12497: }
12498: }
1.160.6.77 raeburn 12499: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 12500: my $confname = $dom.'-domainconfig';
12501: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 12502: my (@allpos,%newsettings,%changedprivs,$newrole);
12503: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 12504: my @accesstypes = ('all','dh','da','none','status','inc','exc');
12505: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 12506: my %lt = &Apache::lonlocal::texthash(
12507: s => 'system',
12508: d => 'domain',
12509: order => 'Display order',
12510: access => 'Role usage',
1.160.6.79 raeburn 12511: all => 'All with domain helpdesk or helpdesk assistant role',
12512: dh => 'All with domain helpdesk role',
12513: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 12514: none => 'None',
12515: status => 'Determined based on institutional status',
12516: inc => 'Include all, but exclude specific personnel',
12517: exc => 'Exclude all, but include specific personnel',
12518: );
12519: for (my $num=0; $num<=$maxnum; $num++) {
12520: my ($prefix,$identifier,$rolename,%curr);
12521: if ($num == $maxnum) {
12522: next unless ($env{'form.newcusthelp'} == $maxnum);
12523: $identifier = 'custhelp'.$num;
12524: $prefix = 'helproles_'.$num;
12525: $rolename = $env{'form.custhelpname'.$num};
12526: $rolename=~s/[^A-Za-z0-9]//gs;
12527: next if ($rolename eq '');
12528: next if (exists($existing{'rolesdef_'.$rolename}));
12529: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12530: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12531: $newprivs{'c'},$confname,$dom);
12532: if ($result ne 'ok') {
12533: $errors .= '<li><span class="LC_error">'.
12534: &mt('An error occurred storing the new custom role: [_1]',
12535: $result).'</span></li>';
12536: next;
12537: } else {
12538: $changedprivs{$rolename} = \%newprivs;
12539: $newrole = $rolename;
12540: }
12541: } else {
12542: $prefix = 'helproles_'.$num;
12543: $rolename = $env{'form.'.$prefix};
12544: next if ($rolename eq '');
12545: next unless (exists($existing{'rolesdef_'.$rolename}));
12546: $identifier = 'custhelp'.$num;
12547: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12548: my %currprivs;
12549: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
12550: split(/\_/,$existing{'rolesdef_'.$rolename});
12551: foreach my $level ('c','d','s') {
12552: if ($newprivs{$level} ne $currprivs{$level}) {
12553: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12554: $newprivs{'c'},$confname,$dom);
12555: if ($result ne 'ok') {
12556: $errors .= '<li><span class="LC_error">'.
12557: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
12558: $rolename,$result).'</span></li>';
12559: } else {
12560: $changedprivs{$rolename} = \%newprivs;
12561: }
12562: last;
12563: }
12564: }
12565: if (ref($current{'adhoc'}) eq 'HASH') {
12566: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12567: %curr = %{$current{'adhoc'}{$rolename}};
12568: }
12569: }
12570: }
12571: my $newpos = $env{'form.'.$prefix.'_pos'};
12572: $newpos =~ s/\D+//g;
12573: $allpos[$newpos] = $rolename;
12574: my $newdesc = $env{'form.'.$prefix.'_desc'};
12575: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
12576: if ($curr{'desc'}) {
12577: if ($curr{'desc'} ne $newdesc) {
12578: $changes{'customrole'}{$rolename}{'desc'} = 1;
12579: $newsettings{$rolename}{'desc'} = $newdesc;
12580: }
12581: } elsif ($newdesc ne '') {
12582: $changes{'customrole'}{$rolename}{'desc'} = 1;
12583: $newsettings{$rolename}{'desc'} = $newdesc;
12584: }
12585: my $access = $env{'form.'.$prefix.'_access'};
12586: if (grep(/^\Q$access\E$/,@accesstypes)) {
12587: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
12588: if ($access eq 'status') {
12589: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
12590: if (scalar(@statuses) == 0) {
12591: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
12592: } else {
12593: my (@shownstatus,$numtypes);
12594: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12595: if (ref($types) eq 'ARRAY') {
12596: $numtypes = scalar(@{$types});
12597: foreach my $type (sort(@statuses)) {
12598: if ($type eq 'default') {
12599: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12600: } elsif (grep(/^\Q$type\E$/,@{$types})) {
12601: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12602: push(@shownstatus,$usertypes->{$type});
12603: }
1.160.6.73 raeburn 12604: }
12605: }
1.160.6.77 raeburn 12606: if (grep(/^default$/,@statuses)) {
12607: push(@shownstatus,$othertitle);
12608: }
12609: if (scalar(@shownstatus) == 1+$numtypes) {
12610: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
12611: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
12612: } else {
12613: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
12614: if (ref($curr{'status'}) eq 'ARRAY') {
12615: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12616: if (@diffs) {
12617: $changes{'customrole'}{$rolename}{$access} = 1;
12618: }
12619: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12620: $changes{'customrole'}{$rolename}{$access} = 1;
12621: }
12622: }
12623: }
12624: } elsif (($access eq 'inc') || ($access eq 'exc')) {
12625: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
12626: my @newspecstaff;
12627: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12628: foreach my $person (sort(@personnel)) {
12629: if ($domhelpdesk{$person}) {
12630: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
12631: }
12632: }
12633: if (ref($curr{$access}) eq 'ARRAY') {
12634: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12635: if (@diffs) {
12636: $changes{'customrole'}{$rolename}{$access} = 1;
12637: }
12638: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12639: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 12640: }
1.160.6.77 raeburn 12641: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12642: my ($uname,$udom) = split(/:/,$person);
12643: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
12644: }
12645: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 12646: }
1.160.6.77 raeburn 12647: } else {
12648: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
12649: }
12650: unless ($curr{'access'} eq $access) {
12651: $changes{'customrole'}{$rolename}{'access'} = 1;
12652: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 12653: }
12654: }
1.160.6.77 raeburn 12655: if (@allpos > 0) {
12656: my $idx = 0;
12657: foreach my $rolename (@allpos) {
12658: if ($rolename ne '') {
12659: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
12660: if (ref($current{'adhoc'}) eq 'HASH') {
12661: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12662: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
12663: $changes{'customrole'}{$rolename}{'order'} = 1;
12664: $newsettings{$rolename}{'order'} = $idx+1;
12665: }
12666: }
1.160.6.73 raeburn 12667: }
1.160.6.77 raeburn 12668: $idx ++;
1.122 jms 12669: }
12670: }
1.118 jms 12671: }
1.123 jms 12672: my $putresult;
12673: if (keys(%changes) > 0) {
1.160.6.5 raeburn 12674: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
12675: if ($putresult eq 'ok') {
1.160.6.77 raeburn 12676: if (ref($helphash{'helpsettings'}) eq 'HASH') {
12677: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
12678: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
12679: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
12680: }
12681: }
12682: my $cachetime = 24*60*60;
12683: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12684: if (ref($lastactref) eq 'HASH') {
12685: $lastactref->{'domdefaults'} = 1;
12686: }
12687: } else {
12688: $errors .= '<li><span class="LC_error">'.
12689: &mt('An error occurred storing the settings: [_1]',
12690: $putresult).'</span></li>';
12691: }
12692: }
12693: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
12694: $resulttext = &mt('Changes made:').'<ul>';
12695: my (%shownprivs,@levelorder);
12696: @levelorder = ('c','d','s');
12697: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 12698: foreach my $item (sort(keys(%changes))) {
12699: if ($item eq 'submitbugs') {
12700: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
12701: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
12702: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 12703: } elsif ($item eq 'customrole') {
12704: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 12705: my @keyorder = ('order','desc','access','status','exc','inc');
12706: my %keytext = &Apache::lonlocal::texthash(
12707: order => 'Order',
12708: desc => 'Role description',
12709: access => 'Role usage',
1.160.6.83 raeburn 12710: status => 'Allowed institutional types',
1.160.6.77 raeburn 12711: exc => 'Allowed personnel',
12712: inc => 'Disallowed personnel',
12713: );
1.160.6.73 raeburn 12714: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 12715: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
12716: if ($role eq $newrole) {
12717: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
12718: $role).'<ul>';
12719: } else {
12720: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12721: $role).'<ul>';
12722: }
12723: foreach my $key (@keyorder) {
12724: if ($changes{'customrole'}{$role}{$key}) {
12725: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
12726: $keytext{$key},$newsettings{$role}{$key}).
12727: '</li>';
12728: }
12729: }
12730: if (ref($changedprivs{$role}) eq 'HASH') {
12731: $shownprivs{$role} = 1;
12732: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
12733: foreach my $level (@levelorder) {
12734: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12735: next if ($item eq '');
12736: my ($priv) = split(/\&/,$item,2);
12737: if (&Apache::lonnet::plaintext($priv)) {
12738: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12739: unless ($level eq 'c') {
12740: $resulttext .= ' ('.$lt{$level}.')';
12741: }
12742: $resulttext .= '</li>';
12743: }
12744: }
12745: }
12746: $resulttext .= '</ul>';
12747: }
12748: $resulttext .= '</ul></li>';
12749: }
1.160.6.73 raeburn 12750: }
12751: }
1.160.6.5 raeburn 12752: }
12753: }
12754: }
1.160.6.77 raeburn 12755: if (keys(%changedprivs)) {
12756: foreach my $role (sort(keys(%changedprivs))) {
12757: unless ($shownprivs{$role}) {
12758: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12759: $role).'<ul>'.
12760: '<li>'.&mt('Privileges set to :').'<ul>';
12761: foreach my $level (@levelorder) {
12762: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12763: next if ($item eq '');
12764: my ($priv) = split(/\&/,$item,2);
12765: if (&Apache::lonnet::plaintext($priv)) {
12766: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12767: unless ($level eq 'c') {
12768: $resulttext .= ' ('.$lt{$level}.')';
12769: }
12770: $resulttext .= '</li>';
12771: }
12772: }
12773: }
12774: $resulttext .= '</ul></li></ul></li>';
12775: }
12776: }
12777: }
12778: $resulttext .= '</ul>';
12779: } else {
12780: $resulttext = &mt('No changes made to help settings');
1.118 jms 12781: }
12782: if ($errors) {
1.160.6.5 raeburn 12783: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 12784: $errors.'</ul>';
1.118 jms 12785: }
12786: return $resulttext;
12787: }
12788:
1.121 raeburn 12789: sub modify_coursedefaults {
1.160.6.27 raeburn 12790: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 12791: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 12792: my %defaultchecked = (
12793: 'uselcmath' => 'on',
12794: 'usejsme' => 'on'
12795: );
12796: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 12797: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 12798: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
12799: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 12800: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 12801: my %staticdefaults = (
12802: anonsurvey_threshold => 10,
12803: uploadquota => 500,
1.160.6.57 raeburn 12804: postsubmit => 60,
1.160.6.70 raeburn 12805: mysqltables => 172800,
1.160.6.21 raeburn 12806: );
1.121 raeburn 12807:
12808: $defaultshash{'coursedefaults'} = {};
12809:
12810: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
12811: if ($domconfig{'coursedefaults'} eq '') {
12812: $domconfig{'coursedefaults'} = {};
12813: }
12814: }
12815:
12816: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
12817: foreach my $item (@toggles) {
12818: if ($defaultchecked{$item} eq 'on') {
12819: if (($domconfig{'coursedefaults'}{$item} eq '') &&
12820: ($env{'form.'.$item} eq '0')) {
12821: $changes{$item} = 1;
1.160.6.16 raeburn 12822: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 12823: $changes{$item} = 1;
12824: }
12825: } elsif ($defaultchecked{$item} eq 'off') {
12826: if (($domconfig{'coursedefaults'}{$item} eq '') &&
12827: ($env{'form.'.$item} eq '1')) {
12828: $changes{$item} = 1;
12829: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
12830: $changes{$item} = 1;
12831: }
12832: }
12833: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
12834: }
1.160.6.21 raeburn 12835: foreach my $item (@numbers) {
12836: my ($currdef,$newdef);
1.160.6.26 raeburn 12837: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 12838: if ($item eq 'anonsurvey_threshold') {
12839: $currdef = $domconfig{'coursedefaults'}{$item};
12840: $newdef =~ s/\D//g;
12841: if ($newdef eq '' || $newdef < 1) {
12842: $newdef = 1;
12843: }
12844: $defaultshash{'coursedefaults'}{$item} = $newdef;
12845: } else {
1.160.6.70 raeburn 12846: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
12847: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
12848: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 12849: }
12850: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 12851: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 12852: }
12853: if ($currdef ne $newdef) {
12854: my $staticdef;
12855: if ($item eq 'anonsurvey_threshold') {
12856: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
12857: $changes{$item} = 1;
12858: }
1.160.6.70 raeburn 12859: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
12860: my $setting = $1;
12861: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
12862: $changes{$setting} = 1;
1.160.6.21 raeburn 12863: }
12864: }
1.139 raeburn 12865: }
12866: }
1.160.6.64 raeburn 12867: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
12868: my @currclonecode;
12869: if (ref($currclone) eq 'HASH') {
12870: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
12871: @currclonecode = @{$currclone->{'instcode'}};
12872: }
12873: }
12874: my $newclone;
12875: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
12876: $newclone = $env{'form.canclone'};
12877: }
12878: if ($newclone eq 'instcode') {
12879: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
12880: my (%codedefaults,@code_order,@clonecode);
12881: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
12882: \@code_order);
12883: foreach my $item (@code_order) {
12884: if (grep(/^\Q$item\E$/,@newcodes)) {
12885: push(@clonecode,$item);
12886: }
12887: }
12888: if (@clonecode) {
12889: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
12890: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
12891: if (@diffs) {
12892: $changes{'canclone'} = 1;
12893: }
12894: } else {
12895: $newclone eq '';
12896: }
12897: } elsif ($newclone ne '') {
12898: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
12899: }
12900: if ($newclone ne $currclone) {
12901: $changes{'canclone'} = 1;
12902: }
1.160.6.57 raeburn 12903: my %credits;
12904: foreach my $type (@types) {
12905: unless ($type eq 'community') {
12906: $credits{$type} = $env{'form.'.$type.'_credits'};
12907: $credits{$type} =~ s/[^\d.]+//g;
12908: }
12909: }
12910: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
12911: ($env{'form.coursecredits'} eq '1')) {
12912: $changes{'coursecredits'} = 1;
12913: foreach my $type (keys(%credits)) {
12914: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
12915: }
12916: } else {
12917: if ($env{'form.coursecredits'} eq '1') {
12918: foreach my $type (@types) {
12919: unless ($type eq 'community') {
12920: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
12921: $changes{'coursecredits'} = 1;
12922: }
12923: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
12924: }
12925: }
12926: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
12927: foreach my $type (@types) {
12928: unless ($type eq 'community') {
12929: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
12930: $changes{'coursecredits'} = 1;
12931: last;
12932: }
12933: }
12934: }
12935: }
12936: }
12937: if ($env{'form.postsubmit'} eq '1') {
12938: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
12939: my %currtimeout;
12940: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12941: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
12942: $changes{'postsubmit'} = 1;
12943: }
12944: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12945: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
12946: }
12947: } else {
12948: $changes{'postsubmit'} = 1;
12949: }
12950: foreach my $type (@types) {
12951: my $timeout = $env{'form.'.$type.'_timeout'};
12952: $timeout =~ s/\D//g;
12953: if ($timeout == $staticdefaults{'postsubmit'}) {
12954: $timeout = '';
12955: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
12956: $timeout = '0';
12957: }
12958: unless ($timeout eq '') {
12959: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
12960: }
12961: if (exists($currtimeout{$type})) {
12962: if ($timeout ne $currtimeout{$type}) {
12963: $changes{'postsubmit'} = 1;
12964: }
12965: } elsif ($timeout ne '') {
12966: $changes{'postsubmit'} = 1;
12967: }
12968: }
12969: } else {
12970: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
12971: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12972: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
12973: $changes{'postsubmit'} = 1;
12974: }
12975: } else {
12976: $changes{'postsubmit'} = 1;
12977: }
1.160.6.16 raeburn 12978: }
1.121 raeburn 12979: }
12980: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12981: $dom);
12982: if ($putresult eq 'ok') {
12983: if (keys(%changes) > 0) {
1.160.6.27 raeburn 12984: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 12985: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 12986: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.70 raeburn 12987: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.160.6.57 raeburn 12988: foreach my $item ('uselcmath','usejsme') {
12989: if ($changes{$item}) {
12990: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
12991: }
1.160.6.16 raeburn 12992: }
12993: if ($changes{'coursecredits'}) {
12994: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 12995: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
12996: $domdefaults{$type.'credits'} =
12997: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
12998: }
12999: }
13000: }
13001: if ($changes{'postsubmit'}) {
13002: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13003: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
13004: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13005: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
13006: $domdefaults{$type.'postsubtimeout'} =
13007: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13008: }
13009: }
1.160.6.16 raeburn 13010: }
13011: }
1.160.6.21 raeburn 13012: if ($changes{'uploadquota'}) {
13013: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13014: foreach my $type (@types) {
13015: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
13016: }
13017: }
13018: }
1.160.6.64 raeburn 13019: if ($changes{'canclone'}) {
13020: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13021: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13022: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
13023: if (@clonecodes) {
13024: $domdefaults{'canclone'} = join('+',@clonecodes);
13025: }
13026: }
13027: } else {
13028: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
13029: }
13030: }
1.121 raeburn 13031: my $cachetime = 24*60*60;
13032: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 13033: if (ref($lastactref) eq 'HASH') {
13034: $lastactref->{'domdefaults'} = 1;
13035: }
1.121 raeburn 13036: }
13037: $resulttext = &mt('Changes made:').'<ul>';
13038: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 13039: if ($item eq 'uselcmath') {
1.121 raeburn 13040: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 13041: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 13042: } else {
1.160.6.57 raeburn 13043: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
13044: }
13045: } elsif ($item eq 'usejsme') {
13046: if ($env{'form.'.$item} eq '1') {
13047: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
13048: } else {
13049: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 13050: }
1.139 raeburn 13051: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 13052: $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 13053: } elsif ($item eq 'uploadquota') {
13054: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13055: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
13056: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
13057: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 13058: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
13059:
1.160.6.21 raeburn 13060: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
13061: '</ul>'.
13062: '</li>';
13063: } else {
13064: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
13065: }
1.160.6.70 raeburn 13066: } elsif ($item eq 'mysqltables') {
13067: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
13068: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
13069: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
13070: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
13071: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
13072: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
13073: '</ul>'.
13074: '</li>';
13075: } else {
13076: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
13077: }
1.160.6.57 raeburn 13078: } elsif ($item eq 'postsubmit') {
13079: if ($domdefaults{'postsubmit'} eq 'off') {
13080: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
13081: } else {
13082: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
13083: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13084: $resulttext .= &mt('durations:').'<ul>';
13085: foreach my $type (@types) {
13086: $resulttext .= '<li>';
13087: my $timeout;
13088: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13089: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13090: }
13091: my $display;
13092: if ($timeout eq '0') {
13093: $display = &mt('unlimited');
13094: } elsif ($timeout eq '') {
13095: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
13096: } else {
13097: $display = &mt('[quant,_1,second]',$timeout);
13098: }
13099: if ($type eq 'community') {
13100: $resulttext .= &mt('Communities');
13101: } elsif ($type eq 'official') {
13102: $resulttext .= &mt('Official courses');
13103: } elsif ($type eq 'unofficial') {
13104: $resulttext .= &mt('Unofficial courses');
13105: } elsif ($type eq 'textbook') {
13106: $resulttext .= &mt('Textbook courses');
13107: }
13108: $resulttext .= ' -- '.$display.'</li>';
13109: }
13110: $resulttext .= '</ul>';
13111: }
13112: $resulttext .= '</li>';
13113: }
1.160.6.16 raeburn 13114: } elsif ($item eq 'coursecredits') {
13115: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13116: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 13117: ($domdefaults{'unofficialcredits'} eq '') &&
13118: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 13119: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13120: } else {
13121: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
13122: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
13123: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 13124: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 13125: '</ul>'.
13126: '</li>';
13127: }
13128: } else {
13129: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13130: }
1.160.6.64 raeburn 13131: } elsif ($item eq 'canclone') {
13132: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13133: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13134: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
13135: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
13136: }
13137: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
13138: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
13139: } else {
13140: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
13141: }
1.140 raeburn 13142: }
1.121 raeburn 13143: }
13144: $resulttext .= '</ul>';
13145: } else {
13146: $resulttext = &mt('No changes made to course defaults');
13147: }
13148: } else {
13149: $resulttext = '<span class="LC_error">'.
13150: &mt('An error occurred: [_1]',$putresult).'</span>';
13151: }
13152: return $resulttext;
13153: }
13154:
1.160.6.37 raeburn 13155: sub modify_selfenrollment {
13156: my ($dom,$lastactref,%domconfig) = @_;
13157: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
13158: my @types = ('official','unofficial','community','textbook');
13159: my %titles = &tool_titles();
13160: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
13161: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
13162: $ordered{'default'} = ['types','registered','approval','limit'];
13163:
13164: my (%roles,%shown,%toplevel);
13165: $roles{'0'} = &Apache::lonnet::plaintext('dc');
13166:
13167: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
13168: if ($domconfig{'selfenrollment'} eq '') {
13169: $domconfig{'selfenrollment'} = {};
13170: }
13171: }
13172: %toplevel = (
13173: admin => 'Configuration Rights',
13174: default => 'Default settings',
13175: validation => 'Validation of self-enrollment requests',
13176: );
13177: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
13178:
13179: if (ref($ordered{'admin'}) eq 'ARRAY') {
13180: foreach my $item (@{$ordered{'admin'}}) {
13181: foreach my $type (@types) {
13182: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
13183: $selfenrollhash{'admin'}{$type}{$item} = 1;
13184: } else {
13185: $selfenrollhash{'admin'}{$type}{$item} = 0;
13186: }
13187: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
13188: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
13189: if ($selfenrollhash{'admin'}{$type}{$item} ne
13190: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
13191: push(@{$changes{'admin'}{$type}},$item);
13192: }
13193: } else {
13194: if (!$selfenrollhash{'admin'}{$type}{$item}) {
13195: push(@{$changes{'admin'}{$type}},$item);
13196: }
13197: }
13198: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
13199: push(@{$changes{'admin'}{$type}},$item);
13200: }
13201: }
13202: }
13203: }
13204:
13205: foreach my $item (@{$ordered{'default'}}) {
13206: foreach my $type (@types) {
13207: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
13208: if ($item eq 'types') {
13209: unless (($value eq 'all') || ($value eq 'dom')) {
13210: $value = '';
13211: }
13212: } elsif ($item eq 'registered') {
13213: unless ($value eq '1') {
13214: $value = 0;
13215: }
13216: } elsif ($item eq 'approval') {
13217: unless ($value =~ /^[012]$/) {
13218: $value = 0;
13219: }
13220: } else {
13221: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13222: $value = 'none';
13223: }
13224: }
13225: $selfenrollhash{'default'}{$type}{$item} = $value;
13226: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
13227: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13228: if ($selfenrollhash{'default'}{$type}{$item} ne
13229: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
13230: push(@{$changes{'default'}{$type}},$item);
13231: }
13232: } else {
13233: push(@{$changes{'default'}{$type}},$item);
13234: }
13235: } else {
13236: push(@{$changes{'default'}{$type}},$item);
13237: }
13238: if ($item eq 'limit') {
13239: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13240: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
13241: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
13242: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
13243: }
13244: } else {
13245: $selfenrollhash{'default'}{$type}{'cap'} = '';
13246: }
13247: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13248: if ($selfenrollhash{'default'}{$type}{'cap'} ne
13249: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
13250: push(@{$changes{'default'}{$type}},'cap');
13251: }
13252: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
13253: push(@{$changes{'default'}{$type}},'cap');
13254: }
13255: }
13256: }
13257: }
13258:
13259: foreach my $item (@{$itemsref}) {
13260: if ($item eq 'fields') {
13261: my @changed;
13262: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
13263: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
13264: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
13265: }
13266: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13267: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
13268: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
13269: $domconfig{'selfenrollment'}{'validation'}{$item});
13270: } else {
13271: @changed = @{$selfenrollhash{'validation'}{$item}};
13272: }
13273: } else {
13274: @changed = @{$selfenrollhash{'validation'}{$item}};
13275: }
13276: if (@changed) {
13277: if ($selfenrollhash{'validation'}{$item}) {
13278: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
13279: } else {
13280: $changes{'validation'}{$item} = &mt('None');
13281: }
13282: }
13283: } else {
13284: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
13285: if ($item eq 'markup') {
13286: if ($env{'form.selfenroll_validation_'.$item}) {
13287: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13288: }
13289: }
13290: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13291: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
13292: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
13293: }
13294: }
13295: }
13296: }
13297:
13298: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
13299: $dom);
13300: if ($putresult eq 'ok') {
13301: if (keys(%changes) > 0) {
13302: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13303: $resulttext = &mt('Changes made:').'<ul>';
13304: foreach my $key ('admin','default','validation') {
13305: if (ref($changes{$key}) eq 'HASH') {
13306: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
13307: if ($key eq 'validation') {
13308: foreach my $item (@{$itemsref}) {
13309: if (exists($changes{$key}{$item})) {
13310: if ($item eq 'markup') {
13311: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13312: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
13313: } else {
13314: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13315: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
13316: }
13317: }
13318: }
13319: } else {
13320: foreach my $type (@types) {
13321: if ($type eq 'community') {
13322: $roles{'1'} = &mt('Community personnel');
13323: } else {
13324: $roles{'1'} = &mt('Course personnel');
13325: }
13326: if (ref($changes{$key}{$type}) eq 'ARRAY') {
13327: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13328: if ($key eq 'admin') {
13329: my @mgrdc = ();
13330: if (ref($ordered{$key}) eq 'ARRAY') {
13331: foreach my $item (@{$ordered{'admin'}}) {
13332: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13333: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
13334: push(@mgrdc,$item);
13335: }
13336: }
13337: }
13338: if (@mgrdc) {
13339: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
13340: } else {
13341: delete($domdefaults{$type.'selfenrolladmdc'});
13342: }
13343: }
13344: } else {
13345: if (ref($ordered{$key}) eq 'ARRAY') {
13346: foreach my $item (@{$ordered{$key}}) {
13347: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13348: $domdefaults{$type.'selfenroll'.$item} =
13349: $selfenrollhash{$key}{$type}{$item};
13350: }
13351: }
13352: }
13353: }
13354: }
13355: $resulttext .= '<li>'.$titles{$type}.'<ul>';
13356: foreach my $item (@{$ordered{$key}}) {
13357: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13358: $resulttext .= '<li>';
13359: if ($key eq 'admin') {
13360: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
13361: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
13362: } else {
13363: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
13364: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
13365: }
13366: $resulttext .= '</li>';
13367: }
13368: }
13369: $resulttext .= '</ul></li>';
13370: }
13371: }
13372: $resulttext .= '</ul></li>';
13373: }
13374: }
13375: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
13376: my $cachetime = 24*60*60;
13377: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13378: if (ref($lastactref) eq 'HASH') {
13379: $lastactref->{'domdefaults'} = 1;
13380: }
13381: }
13382: }
13383: $resulttext .= '</ul>';
13384: } else {
13385: $resulttext = &mt('No changes made to self-enrollment settings');
13386: }
13387: } else {
13388: $resulttext = '<span class="LC_error">'.
13389: &mt('An error occurred: [_1]',$putresult).'</span>';
13390: }
13391: return $resulttext;
13392: }
13393:
1.137 raeburn 13394: sub modify_usersessions {
1.160.6.27 raeburn 13395: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 13396: my @hostingtypes = ('version','excludedomain','includedomain');
13397: my @offloadtypes = ('primary','default');
13398: my %types = (
13399: remote => \@hostingtypes,
13400: hosted => \@hostingtypes,
13401: spares => \@offloadtypes,
13402: );
13403: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 13404: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 13405: my (%by_ip,%by_location,@intdoms);
13406: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
13407: my @locations = sort(keys(%by_location));
1.137 raeburn 13408: my (%defaultshash,%changes);
13409: foreach my $prefix (@prefixes) {
13410: $defaultshash{'usersessions'}{$prefix} = {};
13411: }
1.160.6.27 raeburn 13412: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 13413: my $resulttext;
1.138 raeburn 13414: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 13415: foreach my $prefix (@prefixes) {
1.145 raeburn 13416: next if ($prefix eq 'spares');
13417: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 13418: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13419: if ($type eq 'version') {
13420: my $value = $env{'form.'.$prefix.'_'.$type};
13421: my $okvalue;
13422: if ($value ne '') {
13423: if (grep(/^\Q$value\E$/,@lcversions)) {
13424: $okvalue = $value;
13425: }
13426: }
13427: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13428: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13429: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
13430: if ($inuse == 0) {
13431: $changes{$prefix}{$type} = 1;
13432: } else {
13433: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
13434: $changes{$prefix}{$type} = 1;
13435: }
13436: if ($okvalue ne '') {
13437: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13438: }
13439: }
13440: } else {
13441: if (($inuse == 1) && ($okvalue ne '')) {
13442: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13443: $changes{$prefix}{$type} = 1;
13444: }
13445: }
13446: } else {
13447: if (($inuse == 1) && ($okvalue ne '')) {
13448: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13449: $changes{$prefix}{$type} = 1;
13450: }
13451: }
13452: } else {
13453: if (($inuse == 1) && ($okvalue ne '')) {
13454: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13455: $changes{$prefix}{$type} = 1;
13456: }
13457: }
13458: } else {
13459: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13460: my @okvals;
13461: foreach my $val (@vals) {
1.138 raeburn 13462: if ($val =~ /:/) {
13463: my @items = split(/:/,$val);
13464: foreach my $item (@items) {
13465: if (ref($by_location{$item}) eq 'ARRAY') {
13466: push(@okvals,$item);
13467: }
13468: }
13469: } else {
13470: if (ref($by_location{$val}) eq 'ARRAY') {
13471: push(@okvals,$val);
13472: }
1.137 raeburn 13473: }
13474: }
13475: @okvals = sort(@okvals);
13476: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13477: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13478: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13479: if ($inuse == 0) {
13480: $changes{$prefix}{$type} = 1;
13481: } else {
13482: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13483: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
13484: if (@changed > 0) {
13485: $changes{$prefix}{$type} = 1;
13486: }
13487: }
13488: } else {
13489: if ($inuse == 1) {
13490: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13491: $changes{$prefix}{$type} = 1;
13492: }
13493: }
13494: } else {
13495: if ($inuse == 1) {
13496: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13497: $changes{$prefix}{$type} = 1;
13498: }
13499: }
13500: } else {
13501: if ($inuse == 1) {
13502: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13503: $changes{$prefix}{$type} = 1;
13504: }
13505: }
13506: }
13507: }
13508: }
1.145 raeburn 13509:
13510: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 13511: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 13512: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
13513: my $savespares;
13514:
13515: foreach my $lonhost (sort(keys(%servers))) {
13516: my $serverhomeID =
13517: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 13518: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 13519: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
13520: my %spareschg;
13521: foreach my $type (@{$types{'spares'}}) {
13522: my @okspares;
13523: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
13524: foreach my $server (@checked) {
1.152 raeburn 13525: if (&Apache::lonnet::hostname($server) ne '') {
13526: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
13527: unless (grep(/^\Q$server\E$/,@okspares)) {
13528: push(@okspares,$server);
13529: }
1.145 raeburn 13530: }
13531: }
13532: }
13533: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
13534: my $newspare;
1.152 raeburn 13535: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
13536: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 13537: $newspare = $new;
13538: }
13539: }
1.152 raeburn 13540: my @spares;
13541: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
13542: @spares = sort(@okspares,$newspare);
13543: } else {
13544: @spares = sort(@okspares);
13545: }
13546: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 13547: if (ref($spareid{$lonhost}) eq 'HASH') {
13548: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 13549: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 13550: if (@diffs > 0) {
13551: $spareschg{$type} = 1;
13552: }
13553: }
13554: }
13555: }
13556: if (keys(%spareschg) > 0) {
13557: $changes{'spares'}{$lonhost} = \%spareschg;
13558: }
13559: }
1.160.6.61 raeburn 13560: $defaultshash{'usersessions'}{'offloadnow'} = {};
13561: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
13562: my @okoffload;
13563: if (@offloadnow) {
13564: foreach my $server (@offloadnow) {
13565: if (&Apache::lonnet::hostname($server) ne '') {
13566: unless (grep(/^\Q$server\E$/,@okoffload)) {
13567: push(@okoffload,$server);
13568: }
13569: }
13570: }
13571: if (@okoffload) {
13572: foreach my $lonhost (@okoffload) {
13573: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
13574: }
13575: }
13576: }
1.145 raeburn 13577: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13578: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
13579: if (ref($changes{'spares'}) eq 'HASH') {
13580: if (keys(%{$changes{'spares'}}) > 0) {
13581: $savespares = 1;
13582: }
13583: }
13584: } else {
13585: $savespares = 1;
13586: }
1.160.6.61 raeburn 13587: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
13588: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
13589: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
13590: $changes{'offloadnow'} = 1;
13591: last;
13592: }
13593: }
13594: unless ($changes{'offloadnow'}) {
13595: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
13596: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
13597: $changes{'offloadnow'} = 1;
13598: last;
13599: }
13600: }
13601: }
13602: } elsif (@okoffload) {
13603: $changes{'offloadnow'} = 1;
13604: }
13605: } elsif (@okoffload) {
13606: $changes{'offloadnow'} = 1;
1.145 raeburn 13607: }
1.147 raeburn 13608: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
13609: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 13610: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13611: $dom);
13612: if ($putresult eq 'ok') {
13613: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13614: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
13615: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
13616: }
13617: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
13618: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
13619: }
1.160.6.61 raeburn 13620: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13621: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
13622: }
1.137 raeburn 13623: }
13624: my $cachetime = 24*60*60;
13625: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 13626: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 13627: if (ref($lastactref) eq 'HASH') {
13628: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 13629: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 13630: }
1.147 raeburn 13631: if (keys(%changes) > 0) {
13632: my %lt = &usersession_titles();
13633: $resulttext = &mt('Changes made:').'<ul>';
13634: foreach my $prefix (@prefixes) {
13635: if (ref($changes{$prefix}) eq 'HASH') {
13636: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
13637: if ($prefix eq 'spares') {
13638: if (ref($changes{$prefix}) eq 'HASH') {
13639: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
13640: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 13641: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 13642: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
13643: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 13644: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
13645: foreach my $type (@{$types{$prefix}}) {
13646: if ($changes{$prefix}{$lonhost}{$type}) {
13647: my $offloadto = &mt('None');
13648: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
13649: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
13650: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
13651: }
1.145 raeburn 13652: }
1.147 raeburn 13653: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 13654: }
1.137 raeburn 13655: }
13656: }
1.147 raeburn 13657: $resulttext .= '</li>';
1.137 raeburn 13658: }
13659: }
1.147 raeburn 13660: } else {
13661: foreach my $type (@{$types{$prefix}}) {
13662: if (defined($changes{$prefix}{$type})) {
13663: my $newvalue;
13664: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13665: if (ref($defaultshash{'usersessions'}{$prefix})) {
13666: if ($type eq 'version') {
13667: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
13668: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13669: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
13670: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
13671: }
1.145 raeburn 13672: }
13673: }
13674: }
1.147 raeburn 13675: if ($newvalue eq '') {
13676: if ($type eq 'version') {
13677: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
13678: } else {
13679: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
13680: }
1.145 raeburn 13681: } else {
1.147 raeburn 13682: if ($type eq 'version') {
13683: $newvalue .= ' '.&mt('(or later)');
13684: }
13685: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 13686: }
1.137 raeburn 13687: }
13688: }
13689: }
1.147 raeburn 13690: $resulttext .= '</ul>';
1.137 raeburn 13691: }
13692: }
1.160.6.61 raeburn 13693: if ($changes{'offloadnow'}) {
13694: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13695: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
13696: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
13697: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
13698: $resulttext .= '<li>'.$lonhost.'</li>';
13699: }
13700: $resulttext .= '</ul>';
13701: } else {
13702: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
13703: }
13704: } else {
13705: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
13706: }
13707: }
1.147 raeburn 13708: $resulttext .= '</ul>';
13709: } else {
13710: $resulttext = $nochgmsg;
1.137 raeburn 13711: }
13712: } else {
13713: $resulttext = '<span class="LC_error">'.
13714: &mt('An error occurred: [_1]',$putresult).'</span>';
13715: }
13716: } else {
1.147 raeburn 13717: $resulttext = $nochgmsg;
1.137 raeburn 13718: }
13719: return $resulttext;
13720: }
13721:
1.150 raeburn 13722: sub modify_loadbalancing {
13723: my ($dom,%domconfig) = @_;
13724: my $primary_id = &Apache::lonnet::domain($dom,'primary');
13725: my $intdom = &Apache::lonnet::internet_dom($primary_id);
13726: my ($othertitle,$usertypes,$types) =
13727: &Apache::loncommon::sorted_inst_types($dom);
13728: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 13729: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 13730: my @sparestypes = ('primary','default');
13731: my %typetitles = &sparestype_titles();
13732: my $resulttext;
1.160.6.7 raeburn 13733: my (%currbalancer,%currtargets,%currrules,%existing);
13734: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13735: %existing = %{$domconfig{'loadbalancing'}};
13736: }
13737: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
13738: \%currtargets,\%currrules);
13739: my ($saveloadbalancing,%defaultshash,%changes);
13740: my ($alltypes,$othertypes,$titles) =
13741: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
13742: my %ruletitles = &offloadtype_text();
13743: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
13744: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
13745: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
13746: if ($balancer eq '') {
13747: next;
13748: }
13749: if (!exists($servers{$balancer})) {
13750: if (exists($currbalancer{$balancer})) {
13751: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 13752: }
1.160.6.7 raeburn 13753: next;
13754: }
13755: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
13756: push(@{$changes{'delete'}},$balancer);
13757: next;
13758: }
13759: if (!exists($currbalancer{$balancer})) {
13760: push(@{$changes{'add'}},$balancer);
13761: }
13762: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
13763: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
13764: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
13765: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13766: $saveloadbalancing = 1;
13767: }
13768: foreach my $sparetype (@sparestypes) {
13769: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
13770: my @offloadto;
13771: foreach my $target (@targets) {
13772: if (($servers{$target}) && ($target ne $balancer)) {
13773: if ($sparetype eq 'default') {
13774: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
13775: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 13776: }
13777: }
1.160.6.7 raeburn 13778: unless(grep(/^\Q$target\E$/,@offloadto)) {
13779: push(@offloadto,$target);
13780: }
1.150 raeburn 13781: }
13782: }
1.160.6.76 raeburn 13783: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
13784: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
13785: push(@offloadto,$balancer);
13786: }
13787: }
13788: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 13789: }
1.160.6.7 raeburn 13790: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 13791: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 13792: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
13793: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 13794: if (@targetdiffs > 0) {
1.160.6.7 raeburn 13795: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 13796: }
1.160.6.7 raeburn 13797: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13798: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13799: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 13800: }
13801: }
13802: }
13803: } else {
1.160.6.7 raeburn 13804: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
13805: foreach my $sparetype (@sparestypes) {
13806: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13807: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13808: $changes{'curr'}{$balancer}{'targets'} = 1;
13809: }
1.150 raeburn 13810: }
13811: }
1.160.6.7 raeburn 13812: }
1.150 raeburn 13813: }
13814: my $ishomedom;
1.160.6.7 raeburn 13815: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
13816: $ishomedom = 1;
1.150 raeburn 13817: }
13818: if (ref($alltypes) eq 'ARRAY') {
13819: foreach my $type (@{$alltypes}) {
13820: my $rule;
1.160.6.7 raeburn 13821: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 13822: (!$ishomedom)) {
1.160.6.7 raeburn 13823: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
13824: }
13825: if ($rule eq 'specific') {
1.160.6.55 raeburn 13826: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
13827: if (exists($servers{$specifiedhost})) {
13828: $rule = $specifiedhost;
13829: }
1.150 raeburn 13830: }
1.160.6.7 raeburn 13831: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
13832: if (ref($currrules{$balancer}) eq 'HASH') {
13833: if ($rule ne $currrules{$balancer}{$type}) {
13834: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 13835: }
13836: } elsif ($rule ne '') {
1.160.6.7 raeburn 13837: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 13838: }
13839: }
13840: }
1.160.6.7 raeburn 13841: }
13842: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
13843: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
13844: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
13845: $defaultshash{'loadbalancing'} = {};
13846: }
13847: my $putresult = &Apache::lonnet::put_dom('configuration',
13848: \%defaultshash,$dom);
13849: if ($putresult eq 'ok') {
13850: if (keys(%changes) > 0) {
1.160.6.54 raeburn 13851: my %toupdate;
1.160.6.7 raeburn 13852: if (ref($changes{'delete'}) eq 'ARRAY') {
13853: foreach my $balancer (sort(@{$changes{'delete'}})) {
13854: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 13855: $toupdate{$balancer} = 1;
1.150 raeburn 13856: }
1.160.6.7 raeburn 13857: }
13858: if (ref($changes{'add'}) eq 'ARRAY') {
13859: foreach my $balancer (sort(@{$changes{'add'}})) {
13860: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 13861: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 13862: }
13863: }
13864: if (ref($changes{'curr'}) eq 'HASH') {
13865: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 13866: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 13867: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
13868: if ($changes{'curr'}{$balancer}{'targets'}) {
13869: my %offloadstr;
13870: foreach my $sparetype (@sparestypes) {
13871: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13872: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13873: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
13874: }
13875: }
1.150 raeburn 13876: }
1.160.6.7 raeburn 13877: if (keys(%offloadstr) == 0) {
13878: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 13879: } else {
1.160.6.7 raeburn 13880: my $showoffload;
13881: foreach my $sparetype (@sparestypes) {
13882: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
13883: if (defined($offloadstr{$sparetype})) {
13884: $showoffload .= $offloadstr{$sparetype};
13885: } else {
13886: $showoffload .= &mt('None');
13887: }
13888: $showoffload .= (' 'x3);
13889: }
13890: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 13891: }
13892: }
13893: }
1.160.6.7 raeburn 13894: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
13895: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
13896: foreach my $type (@{$alltypes}) {
13897: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
13898: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
13899: my $balancetext;
13900: if ($rule eq '') {
13901: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 13902: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 13903: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
13904: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 13905: foreach my $sparetype (@sparestypes) {
13906: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13907: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
13908: }
13909: }
1.160.6.55 raeburn 13910: foreach my $item (@{$alltypes}) {
13911: next if ($item =~ /^_LC_ipchange/);
13912: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
13913: if ($hasrule eq 'homeserver') {
13914: map { $toupdate{$_} = 1; } (keys(%libraryservers));
13915: } else {
13916: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
13917: if ($servers{$hasrule}) {
13918: $toupdate{$hasrule} = 1;
13919: }
13920: }
13921: }
13922: }
13923: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
13924: $balancetext = $ruletitles{$rule};
13925: } else {
13926: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
13927: $balancetext = $ruletitles{'particular'}.' '.$receiver;
13928: if ($receiver) {
13929: $toupdate{$receiver};
13930: }
13931: }
13932: } else {
13933: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 13934: }
1.160.6.7 raeburn 13935: } else {
13936: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
13937: }
1.160.6.26 raeburn 13938: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 13939: }
13940: }
13941: }
13942: }
1.160.6.54 raeburn 13943: if (keys(%toupdate)) {
13944: my %thismachine;
13945: my $updatedhere;
13946: my $cachetime = 60*60*24;
13947: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
13948: foreach my $lonhost (keys(%toupdate)) {
13949: if ($thismachine{$lonhost}) {
13950: unless ($updatedhere) {
13951: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
13952: $defaultshash{'loadbalancing'},
13953: $cachetime);
13954: $updatedhere = 1;
13955: }
13956: } else {
13957: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
13958: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
13959: }
13960: }
13961: }
1.150 raeburn 13962: }
1.160.6.7 raeburn 13963: }
13964: if ($resulttext ne '') {
13965: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 13966: } else {
13967: $resulttext = $nochgmsg;
13968: }
13969: } else {
1.160.6.7 raeburn 13970: $resulttext = $nochgmsg;
1.150 raeburn 13971: }
13972: } else {
1.160.6.7 raeburn 13973: $resulttext = '<span class="LC_error">'.
13974: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 13975: }
13976: } else {
1.160.6.7 raeburn 13977: $resulttext = $nochgmsg;
1.150 raeburn 13978: }
13979: return $resulttext;
13980: }
13981:
1.48 raeburn 13982: sub recurse_check {
13983: my ($chkcats,$categories,$depth,$name) = @_;
13984: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
13985: my $chg = 0;
13986: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
13987: my $category = $chkcats->[$depth]{$name}[$j];
13988: my $item;
13989: if ($category eq '') {
13990: $chg ++;
13991: } else {
13992: my $deeper = $depth + 1;
13993: $item = &escape($category).':'.&escape($name).':'.$depth;
13994: if ($chg) {
13995: $categories->{$item} -= $chg;
13996: }
13997: &recurse_check($chkcats,$categories,$deeper,$category);
13998: $deeper --;
13999: }
14000: }
14001: }
14002: return;
14003: }
14004:
14005: sub recurse_cat_deletes {
14006: my ($item,$coursecategories,$deletions) = @_;
14007: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14008: my $subdepth = $depth + 1;
14009: if (ref($coursecategories) eq 'HASH') {
14010: foreach my $subitem (keys(%{$coursecategories})) {
14011: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
14012: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
14013: delete($coursecategories->{$subitem});
14014: $deletions->{$subitem} = 1;
14015: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 14016: }
1.48 raeburn 14017: }
14018: }
14019: return;
14020: }
14021:
1.125 raeburn 14022: sub active_dc_picker {
1.160.6.16 raeburn 14023: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 14024: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 14025: my @domcoord = keys(%domcoords);
14026: if (keys(%currhash)) {
14027: foreach my $dc (keys(%currhash)) {
14028: unless (exists($domcoords{$dc})) {
14029: push(@domcoord,$dc);
14030: }
14031: }
14032: }
14033: @domcoord = sort(@domcoord);
14034: my $numdcs = scalar(@domcoord);
14035: my $rows = 0;
14036: my $table;
1.125 raeburn 14037: if ($numdcs > 1) {
1.160.6.16 raeburn 14038: $table = '<table>';
14039: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 14040: my $rem = $i%($numinrow);
14041: if ($rem == 0) {
14042: if ($i > 0) {
1.160.6.16 raeburn 14043: $table .= '</tr>';
1.125 raeburn 14044: }
1.160.6.16 raeburn 14045: $table .= '<tr>';
14046: $rows ++;
1.125 raeburn 14047: }
1.160.6.16 raeburn 14048: my $check = '';
14049: if ($inputtype eq 'radio') {
14050: if (keys(%currhash) == 0) {
14051: if (!$i) {
14052: $check = ' checked="checked"';
14053: }
14054: } elsif (exists($currhash{$domcoord[$i]})) {
14055: $check = ' checked="checked"';
14056: }
14057: } else {
14058: if (exists($currhash{$domcoord[$i]})) {
14059: $check = ' checked="checked"';
1.125 raeburn 14060: }
14061: }
1.160.6.16 raeburn 14062: if ($i == @domcoord - 1) {
1.125 raeburn 14063: my $colsleft = $numinrow - $rem;
14064: if ($colsleft > 1) {
1.160.6.16 raeburn 14065: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 14066: } else {
1.160.6.16 raeburn 14067: $table .= '<td class="LC_left_item">';
1.125 raeburn 14068: }
14069: } else {
1.160.6.16 raeburn 14070: $table .= '<td class="LC_left_item">';
14071: }
14072: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
14073: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
14074: $table .= '<span class="LC_nobreak"><label>'.
14075: '<input type="'.$inputtype.'" name="'.$name.'"'.
14076: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
14077: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 14078: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 14079: }
1.160.6.33 raeburn 14080: $table .= '</label></span></td>';
1.125 raeburn 14081: }
1.160.6.16 raeburn 14082: $table .= '</tr></table>';
14083: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 14084: my ($dcname,$dcdom) = split(':',$domcoord[0]);
14085: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 14086: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 14087: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 14088: if ($user ne $dcname.':'.$dcdom) {
14089: $table .= ' ('.$dcname.':'.$dcdom.')';
14090: }
1.160.6.16 raeburn 14091: } else {
14092: my $check;
14093: if (exists($currhash{$domcoord[0]})) {
14094: $check = ' checked="checked"';
14095: }
1.160.6.50 raeburn 14096: $table = '<span class="LC_nobreak"><label>'.
14097: '<input type="checkbox" name="'.$name.'" '.
14098: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 14099: if ($user ne $dcname.':'.$dcdom) {
14100: $table .= ' ('.$dcname.':'.$dcdom.')';
14101: }
14102: $table .= '</label></span>';
1.160.6.16 raeburn 14103: $rows ++;
14104: }
1.125 raeburn 14105: }
1.160.6.16 raeburn 14106: return ($numdcs,$table,$rows);
1.125 raeburn 14107: }
14108:
1.137 raeburn 14109: sub usersession_titles {
14110: return &Apache::lonlocal::texthash(
14111: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
14112: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 14113: spares => 'Servers offloaded to, when busy',
1.137 raeburn 14114: version => 'LON-CAPA version requirement',
1.138 raeburn 14115: excludedomain => 'Allow all, but exclude specific domains',
14116: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 14117: primary => 'Primary (checked first)',
1.154 raeburn 14118: default => 'Default',
1.137 raeburn 14119: );
14120: }
14121:
1.152 raeburn 14122: sub id_for_thisdom {
14123: my (%servers) = @_;
14124: my %altids;
14125: foreach my $server (keys(%servers)) {
14126: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
14127: if ($serverhome ne $server) {
14128: $altids{$serverhome} = $server;
14129: }
14130: }
14131: return %altids;
14132: }
14133:
1.150 raeburn 14134: sub count_servers {
14135: my ($currbalancer,%servers) = @_;
14136: my (@spares,$numspares);
14137: foreach my $lonhost (sort(keys(%servers))) {
14138: next if ($currbalancer eq $lonhost);
14139: push(@spares,$lonhost);
14140: }
14141: if ($currbalancer) {
14142: $numspares = scalar(@spares);
14143: } else {
14144: $numspares = scalar(@spares) - 1;
14145: }
14146: return ($numspares,@spares);
14147: }
14148:
14149: sub lonbalance_targets_js {
1.160.6.7 raeburn 14150: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 14151: my $select = &mt('Select');
14152: my ($alltargets,$allishome,$allinsttypes,@alltypes);
14153: if (ref($servers) eq 'HASH') {
14154: $alltargets = join("','",sort(keys(%{$servers})));
14155: my @homedoms;
14156: foreach my $server (sort(keys(%{$servers}))) {
14157: if (&Apache::lonnet::host_domain($server) eq $dom) {
14158: push(@homedoms,'1');
14159: } else {
14160: push(@homedoms,'0');
14161: }
14162: }
14163: $allishome = join("','",@homedoms);
14164: }
14165: if (ref($types) eq 'ARRAY') {
14166: if (@{$types} > 0) {
14167: @alltypes = @{$types};
14168: }
14169: }
14170: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
14171: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 14172: my (%currbalancer,%currtargets,%currrules,%existing);
14173: if (ref($settings) eq 'HASH') {
14174: %existing = %{$settings};
14175: }
14176: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
14177: \%currtargets,\%currrules);
14178: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 14179: return <<"END";
14180:
14181: <script type="text/javascript">
14182: // <![CDATA[
14183:
1.160.6.7 raeburn 14184: currBalancers = new Array('$balancers');
14185:
14186: function toggleTargets(balnum) {
14187: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14188: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
14189: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
14190: var prevbalancer = prevhostitem.value;
14191: var baltotal = document.getElementById('loadbalancing_total').value;
14192: prevhostitem.value = balancer;
14193: if (prevbalancer != '') {
14194: var prevIdx = currBalancers.indexOf(prevbalancer);
14195: if (prevIdx != -1) {
14196: currBalancers.splice(prevIdx,1);
14197: }
14198: }
1.150 raeburn 14199: if (balancer == '') {
1.160.6.7 raeburn 14200: hideSpares(balnum);
1.150 raeburn 14201: } else {
1.160.6.7 raeburn 14202: var currIdx = currBalancers.indexOf(balancer);
14203: if (currIdx == -1) {
14204: currBalancers.push(balancer);
14205: }
1.150 raeburn 14206: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 14207: var ishomedom = homedoms[lonhostitem.selectedIndex];
14208: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 14209: }
1.160.6.7 raeburn 14210: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 14211: return;
14212: }
14213:
1.160.6.7 raeburn 14214: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 14215: var alltargets = new Array('$alltargets');
14216: var insttypes = new Array('$allinsttypes');
1.151 raeburn 14217: var offloadtypes = new Array('primary','default');
14218:
1.160.6.7 raeburn 14219: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
14220: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 14221:
1.151 raeburn 14222: for (var i=0; i<offloadtypes.length; i++) {
14223: var count = 0;
14224: for (var j=0; j<alltargets.length; j++) {
14225: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 14226: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
14227: item.value = alltargets[j];
14228: item.style.textAlign='left';
14229: item.style.textFace='normal';
14230: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
14231: if (currBalancers.indexOf(alltargets[j]) == -1) {
14232: item.disabled = '';
14233: } else {
14234: item.disabled = 'disabled';
14235: item.checked = false;
14236: }
1.151 raeburn 14237: count ++;
14238: }
1.150 raeburn 14239: }
14240: }
1.151 raeburn 14241: for (var k=0; k<insttypes.length; k++) {
14242: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 14243: if (ishomedom == 1) {
1.160.6.7 raeburn 14244: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14245: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14246: } else {
1.160.6.7 raeburn 14247: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14248: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 14249: }
14250: } else {
1.160.6.7 raeburn 14251: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14252: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14253: }
1.151 raeburn 14254: if ((insttypes[k] != '_LC_external') &&
14255: ((insttypes[k] != '_LC_internetdom') ||
14256: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 14257: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
14258: item.options.length = 0;
14259: item.options[0] = new Option("","",true,true);
14260: var idx = 0;
1.151 raeburn 14261: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 14262: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
14263: idx ++;
14264: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 14265: }
14266: }
14267: }
14268: }
14269: return;
14270: }
14271:
1.160.6.7 raeburn 14272: function hideSpares(balnum) {
1.150 raeburn 14273: var alltargets = new Array('$alltargets');
14274: var insttypes = new Array('$allinsttypes');
14275: var offloadtypes = new Array('primary','default');
14276:
1.160.6.7 raeburn 14277: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
14278: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 14279:
14280: var total = alltargets.length - 1;
14281: for (var i=0; i<offloadtypes; i++) {
14282: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 14283: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
14284: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
14285: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 14286: }
1.150 raeburn 14287: }
14288: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 14289: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14290: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 14291: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 14292: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
14293: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 14294: }
14295: }
14296: return;
14297: }
14298:
1.160.6.7 raeburn 14299: function checkOffloads(item,balnum,type) {
1.150 raeburn 14300: var alltargets = new Array('$alltargets');
14301: var offloadtypes = new Array('primary','default');
14302: if (item.checked) {
14303: var total = alltargets.length - 1;
14304: var other;
14305: if (type == offloadtypes[0]) {
1.151 raeburn 14306: other = offloadtypes[1];
1.150 raeburn 14307: } else {
1.151 raeburn 14308: other = offloadtypes[0];
1.150 raeburn 14309: }
14310: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 14311: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 14312: if (server == item.value) {
1.160.6.7 raeburn 14313: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
14314: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 14315: }
14316: }
14317: }
14318: }
14319: return;
14320: }
14321:
1.160.6.7 raeburn 14322: function singleServerToggle(balnum,type) {
14323: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 14324: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 14325: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
14326: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14327:
14328: } else {
1.160.6.7 raeburn 14329: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
14330: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 14331: }
14332: return;
14333: }
14334:
1.160.6.7 raeburn 14335: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 14336: if (type == '_LC_external') {
1.160.6.26 raeburn 14337: return;
1.150 raeburn 14338: }
1.160.6.7 raeburn 14339: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 14340: for (var i=0; i<typesRules.length; i++) {
14341: if (formname.elements[typesRules[i]].checked) {
14342: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 14343: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
14344: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14345: } else {
1.160.6.7 raeburn 14346: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
14347: }
14348: }
14349: }
14350: return;
14351: }
14352:
14353: function balancerDeleteChange(balnum) {
14354: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14355: var baltotal = document.getElementById('loadbalancing_total').value;
14356: var addtarget;
14357: var removetarget;
14358: var action = 'delete';
14359: if (document.getElementById('loadbalancing_delete_'+balnum)) {
14360: var lonhost = hostitem.value;
14361: var currIdx = currBalancers.indexOf(lonhost);
14362: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
14363: if (currIdx != -1) {
14364: currBalancers.splice(currIdx,1);
14365: }
14366: addtarget = lonhost;
14367: } else {
14368: if (currIdx == -1) {
14369: currBalancers.push(lonhost);
14370: }
14371: removetarget = lonhost;
14372: action = 'undelete';
14373: }
14374: balancerChange(balnum,baltotal,action,addtarget,removetarget);
14375: }
14376: return;
14377: }
14378:
14379: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
14380: if (baltotal > 1) {
14381: var offloadtypes = new Array('primary','default');
14382: var alltargets = new Array('$alltargets');
14383: var insttypes = new Array('$allinsttypes');
14384: for (var i=0; i<baltotal; i++) {
14385: if (i != balnum) {
14386: for (var j=0; j<offloadtypes.length; j++) {
14387: var total = alltargets.length - 1;
14388: for (var k=0; k<total; k++) {
14389: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
14390: var server = serveritem.value;
14391: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14392: if (server == addtarget) {
14393: serveritem.disabled = '';
14394: }
14395: }
14396: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14397: if (server == removetarget) {
14398: serveritem.disabled = 'disabled';
14399: serveritem.checked = false;
14400: }
14401: }
14402: }
14403: }
14404: for (var j=0; j<insttypes.length; j++) {
14405: if (insttypes[j] != '_LC_external') {
14406: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
14407: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
14408: var currSel = singleserver.selectedIndex;
14409: var currVal = singleserver.options[currSel].value;
14410: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14411: var numoptions = singleserver.options.length;
14412: var needsnew = 1;
14413: for (var k=0; k<numoptions; k++) {
14414: if (singleserver.options[k] == addtarget) {
14415: needsnew = 0;
14416: break;
14417: }
14418: }
14419: if (needsnew == 1) {
14420: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
14421: }
14422: }
14423: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14424: singleserver.options.length = 0;
14425: if ((currVal) && (currVal != removetarget)) {
14426: singleserver.options[0] = new Option("","",false,false);
14427: } else {
14428: singleserver.options[0] = new Option("","",true,true);
14429: }
14430: var idx = 0;
14431: for (var m=0; m<alltargets.length; m++) {
14432: if (currBalancers.indexOf(alltargets[m]) == -1) {
14433: idx ++;
14434: if (currVal == alltargets[m]) {
14435: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
14436: } else {
14437: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
14438: }
14439: }
14440: }
14441: }
14442: }
14443: }
14444: }
1.150 raeburn 14445: }
14446: }
14447: }
14448: return;
14449: }
14450:
1.152 raeburn 14451: // ]]>
14452: </script>
14453:
14454: END
14455: }
14456:
14457: sub new_spares_js {
14458: my @sparestypes = ('primary','default');
14459: my $types = join("','",@sparestypes);
14460: my $select = &mt('Select');
14461: return <<"END";
14462:
14463: <script type="text/javascript">
14464: // <![CDATA[
14465:
14466: function updateNewSpares(formname,lonhost) {
14467: var types = new Array('$types');
14468: var include = new Array();
14469: var exclude = new Array();
14470: for (var i=0; i<types.length; i++) {
14471: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
14472: for (var j=0; j<spareboxes.length; j++) {
14473: if (formname.elements[spareboxes[j]].checked) {
14474: exclude.push(formname.elements[spareboxes[j]].value);
14475: } else {
14476: include.push(formname.elements[spareboxes[j]].value);
14477: }
14478: }
14479: }
14480: for (var i=0; i<types.length; i++) {
14481: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
14482: var selIdx = newSpare.selectedIndex;
14483: var currnew = newSpare.options[selIdx].value;
14484: var okSpares = new Array();
14485: for (var j=0; j<newSpare.options.length; j++) {
14486: var possible = newSpare.options[j].value;
14487: if (possible != '') {
14488: if (exclude.indexOf(possible) == -1) {
14489: okSpares.push(possible);
14490: } else {
14491: if (currnew == possible) {
14492: selIdx = 0;
14493: }
14494: }
14495: }
14496: }
14497: for (var k=0; k<include.length; k++) {
14498: if (okSpares.indexOf(include[k]) == -1) {
14499: okSpares.push(include[k]);
14500: }
14501: }
14502: okSpares.sort();
14503: newSpare.options.length = 0;
14504: if (selIdx == 0) {
14505: newSpare.options[0] = new Option("$select","",true,true);
14506: } else {
14507: newSpare.options[0] = new Option("$select","",false,false);
14508: }
14509: for (var m=0; m<okSpares.length; m++) {
14510: var idx = m+1;
14511: var selThis = 0;
14512: if (selIdx != 0) {
14513: if (okSpares[m] == currnew) {
14514: selThis = 1;
14515: }
14516: }
14517: if (selThis == 1) {
14518: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
14519: } else {
14520: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
14521: }
14522: }
14523: }
14524: return;
14525: }
14526:
14527: function checkNewSpares(lonhost,type) {
14528: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
14529: var chosen = newSpare.options[newSpare.selectedIndex].value;
14530: if (chosen != '') {
14531: var othertype;
14532: var othernewSpare;
14533: if (type == 'primary') {
14534: othernewSpare = document.getElementById('newspare_default_'+lonhost);
14535: }
14536: if (type == 'default') {
14537: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
14538: }
14539: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
14540: othernewSpare.selectedIndex = 0;
14541: }
14542: }
14543: return;
14544: }
14545:
14546: // ]]>
14547: </script>
14548:
14549: END
14550:
14551: }
14552:
14553: sub common_domprefs_js {
14554: return <<"END";
14555:
14556: <script type="text/javascript">
14557: // <![CDATA[
14558:
1.150 raeburn 14559: function getIndicesByName(formname,item) {
1.152 raeburn 14560: var group = new Array();
1.150 raeburn 14561: for (var i=0;i<formname.elements.length;i++) {
14562: if (formname.elements[i].name == item) {
1.152 raeburn 14563: group.push(formname.elements[i].id);
1.150 raeburn 14564: }
14565: }
1.152 raeburn 14566: return group;
1.150 raeburn 14567: }
14568:
14569: // ]]>
14570: </script>
14571:
14572: END
1.152 raeburn 14573:
1.150 raeburn 14574: }
14575:
1.160.6.5 raeburn 14576: sub recaptcha_js {
14577: my %lt = &captcha_phrases();
14578: return <<"END";
14579:
14580: <script type="text/javascript">
14581: // <![CDATA[
14582:
14583: function updateCaptcha(caller,context) {
14584: var privitem;
14585: var pubitem;
14586: var privtext;
14587: var pubtext;
1.160.6.69 raeburn 14588: var versionitem;
14589: var versiontext;
1.160.6.5 raeburn 14590: if (document.getElementById(context+'_recaptchapub')) {
14591: pubitem = document.getElementById(context+'_recaptchapub');
14592: } else {
14593: return;
14594: }
14595: if (document.getElementById(context+'_recaptchapriv')) {
14596: privitem = document.getElementById(context+'_recaptchapriv');
14597: } else {
14598: return;
14599: }
14600: if (document.getElementById(context+'_recaptchapubtxt')) {
14601: pubtext = document.getElementById(context+'_recaptchapubtxt');
14602: } else {
14603: return;
14604: }
14605: if (document.getElementById(context+'_recaptchaprivtxt')) {
14606: privtext = document.getElementById(context+'_recaptchaprivtxt');
14607: } else {
14608: return;
14609: }
1.160.6.69 raeburn 14610: if (document.getElementById(context+'_recaptchaversion')) {
14611: versionitem = document.getElementById(context+'_recaptchaversion');
14612: } else {
14613: return;
14614: }
14615: if (document.getElementById(context+'_recaptchavertxt')) {
14616: versiontext = document.getElementById(context+'_recaptchavertxt');
14617: } else {
14618: return;
14619: }
1.160.6.5 raeburn 14620: if (caller.checked) {
14621: if (caller.value == 'recaptcha') {
14622: pubitem.type = 'text';
14623: privitem.type = 'text';
14624: pubitem.size = '40';
14625: privitem.size = '40';
14626: pubtext.innerHTML = "$lt{'pub'}";
14627: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 14628: versionitem.type = 'text';
14629: versionitem.size = '3';
14630: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 14631: } else {
14632: pubitem.type = 'hidden';
14633: privitem.type = 'hidden';
1.160.6.69 raeburn 14634: versionitem.type = 'hidden';
1.160.6.5 raeburn 14635: pubtext.innerHTML = '';
14636: privtext.innerHTML = '';
1.160.6.69 raeburn 14637: versiontext.innerHTML = '';
1.160.6.5 raeburn 14638: }
14639: }
14640: return;
14641: }
14642:
14643: // ]]>
14644: </script>
14645:
14646: END
14647:
14648: }
14649:
1.160.6.40 raeburn 14650: sub toggle_display_js {
1.160.6.16 raeburn 14651: return <<"END";
14652:
14653: <script type="text/javascript">
14654: // <![CDATA[
14655:
1.160.6.40 raeburn 14656: function toggleDisplay(domForm,caller) {
14657: if (document.getElementById(caller)) {
14658: var divitem = document.getElementById(caller);
14659: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 14660: var checkval = 1;
14661: var dispval = 'block';
1.160.6.40 raeburn 14662: if (caller == 'emailoptions') {
14663: optionsElement = domForm.cancreate_email;
14664: }
1.160.6.57 raeburn 14665: if (caller == 'studentsubmission') {
14666: optionsElement = domForm.postsubmit;
14667: }
1.160.6.64 raeburn 14668: if (caller == 'cloneinstcode') {
14669: optionsElement = domForm.canclone;
14670: checkval = 'instcode';
14671: }
1.160.6.40 raeburn 14672: if (optionsElement.length) {
1.160.6.16 raeburn 14673: var currval;
1.160.6.40 raeburn 14674: for (var i=0; i<optionsElement.length; i++) {
14675: if (optionsElement[i].checked) {
14676: currval = optionsElement[i].value;
1.160.6.16 raeburn 14677: }
14678: }
1.160.6.64 raeburn 14679: if (currval == checkval) {
14680: divitem.style.display = dispval;
1.160.6.16 raeburn 14681: } else {
1.160.6.40 raeburn 14682: divitem.style.display = 'none';
1.160.6.16 raeburn 14683: }
14684: }
14685: }
14686: return;
14687: }
14688:
14689: // ]]>
14690: </script>
14691:
14692: END
14693:
14694: }
14695:
1.160.6.5 raeburn 14696: sub captcha_phrases {
14697: return &Apache::lonlocal::texthash (
14698: priv => 'Private key',
14699: pub => 'Public key',
14700: original => 'original (CAPTCHA)',
14701: recaptcha => 'successor (ReCAPTCHA)',
14702: notused => 'unused',
1.160.6.69 raeburn 14703: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 14704: );
14705: }
14706:
1.160.6.24 raeburn 14707: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 14708: my ($dom,$cachekeys) = @_;
14709: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 14710: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14711: my %thismachine;
14712: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.84.6. (raeburn 14713:): my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.160.6.61 raeburn 14714: if (keys(%servers)) {
1.160.6.24 raeburn 14715: foreach my $server (keys(%servers)) {
14716: next if ($thismachine{$server});
1.160.6.27 raeburn 14717: my @cached;
14718: foreach my $name (@posscached) {
14719: if ($cachekeys->{$name}) {
14720: push(@cached,&escape($name).':'.&escape($dom));
14721: }
14722: }
14723: if (@cached) {
14724: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
14725: }
1.160.6.24 raeburn 14726: }
14727: }
14728: return;
14729: }
14730:
1.3 raeburn 14731: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>