Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.84.2.10
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.84.2. 0(raebur 4:9): # $Id: domainprefs.pm,v 1.160.6.84.2.9 2017/11/16 23:33:05 raeburn Exp $
1.160.6.40 raeburn 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.160.6.78 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.160.6.84.2. (raeburn 30:): ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.160.6.13 raeburn 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.160.6.27 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20 raeburn 98: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 99: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 100:
1.101 raeburn 101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.160.6.30 raeburn 107: (official, unofficial, community, and textbook). In each case the radio buttons
108: allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.160.6.37 raeburn 168: use Apache::lonuserutils();
1.160.6.39 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.9 raeburn 173: use File::Copy;
1.43 raeburn 174: use Locale::Language;
1.62 raeburn 175: use DateTime::TimeZone;
1.68 raeburn 176: use DateTime::Locale;
1.1 raeburn 177:
1.155 raeburn 178: my $registered_cleanup;
179: my $modified_urls;
180:
1.1 raeburn 181: sub handler {
182: my $r=shift;
183: if ($r->header_only) {
184: &Apache::loncommon::content_type($r,'text/html');
185: $r->send_http_header;
186: return OK;
187: }
188:
1.91 raeburn 189: my $context = 'domain';
1.1 raeburn 190: my $dom = $env{'request.role.domain'};
1.5 albertel 191: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 192: if (&Apache::lonnet::allowed('mau',$dom)) {
193: &Apache::loncommon::content_type($r,'text/html');
194: $r->send_http_header;
195: } else {
196: $env{'user.error.msg'}=
197: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
198: return HTTP_NOT_ACCEPTABLE;
199: }
1.155 raeburn 200:
201: $registered_cleanup=0;
202: @{$modified_urls}=();
203:
1.1 raeburn 204: &Apache::lonhtmlcommon::clear_breadcrumbs();
205: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 206: ['phase','actions']);
1.30 raeburn 207: my $phase = 'pickactions';
1.3 raeburn 208: if ( exists($env{'form.phase'}) ) {
209: $phase = $env{'form.phase'};
210: }
1.150 raeburn 211: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 212: my %domconfig =
1.6 raeburn 213: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 214: 'quotas','autoenroll','autoupdate','autocreate',
215: 'directorysrch','usercreation','usermodification',
216: 'contacts','defaults','scantron','coursecategories',
1.160.6.73 raeburn 217: 'serverstatuses','requestcourses','helpsettings',
218: 'coursedefaults','usersessions','loadbalancing',
1.160.6.84.2. (raeburn 219:): 'requestauthor','selfenrollment','inststatus',
220:): 'ltitools'],$dom);
221:): if (ref($domconfig{'ltitools'}) eq 'HASH') {
222:): my %encconfig =
223:): &Apache::lonnet::get_dom('encconfig',['ltitools'],$dom);
224:): if (ref($encconfig{'ltitools'}) eq 'HASH') {
225:): foreach my $id (keys(%{$domconfig{'ltitools'}})) {
226:): if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
227:): foreach my $item ('key','secret') {
228:): $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
229:): }
230:): }
231:): }
232:): }
233:): }
1.43 raeburn 234: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 235: 'autoupdate','autocreate','directorysrch','contacts',
1.160.6.34 raeburn 236: 'usercreation','selfcreation','usermodification','scantron',
1.160.6.5 raeburn 237: 'requestcourses','requestauthor','coursecategories',
1.160.6.73 raeburn 238: 'serverstatuses','helpsettings','coursedefaults',
1.160.6.84.2. (raeburn 239:): 'ltitools','selfenrollment','usersessions');
1.160.6.7 raeburn 240: my %existing;
241: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
242: %existing = %{$domconfig{'loadbalancing'}};
243: }
244: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 245: push(@prefs_order,'loadbalancing');
246: }
1.30 raeburn 247: my %prefs = (
248: 'rolecolors' =>
249: { text => 'Default color schemes',
1.67 raeburn 250: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 251: header => [{col1 => 'Student Settings',
252: col2 => '',},
253: {col1 => 'Coordinator Settings',
254: col2 => '',},
255: {col1 => 'Author Settings',
256: col2 => '',},
257: {col1 => 'Administrator Settings',
258: col2 => '',}],
1.160.6.37 raeburn 259: print => \&print_rolecolors,
260: modify => \&modify_rolecolors,
1.30 raeburn 261: },
1.110 raeburn 262: 'login' =>
1.30 raeburn 263: { text => 'Log-in page options',
1.67 raeburn 264: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 265: header => [{col1 => 'Log-in Page Items',
266: col2 => '',},
267: {col1 => 'Log-in Help',
1.160.6.56 raeburn 268: col2 => 'Value'},
269: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 270: col2 => 'Value'}],
1.160.6.37 raeburn 271: print => \&print_login,
272: modify => \&modify_login,
1.30 raeburn 273: },
1.43 raeburn 274: 'defaults' =>
1.160.6.40 raeburn 275: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 276: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 277: header => [{col1 => 'Setting',
1.160.6.40 raeburn 278: col2 => 'Value'},
1.160.6.80 raeburn 279: {col1 => 'Internal Authentication',
280: col2 => 'Value'},
1.160.6.40 raeburn 281: {col1 => 'Institutional user types',
282: col2 => 'Assignable to e-mail usernames'}],
1.160.6.37 raeburn 283: print => \&print_defaults,
284: modify => \&modify_defaults,
1.43 raeburn 285: },
1.30 raeburn 286: 'quotas' =>
1.160.6.20 raeburn 287: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 288: help => 'Domain_Configuration_Quotas',
1.77 raeburn 289: header => [{col1 => 'User affiliation',
1.72 raeburn 290: col2 => 'Available tools',
1.160.6.28 raeburn 291: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 292: print => \&print_quotas,
293: modify => \&modify_quotas,
1.30 raeburn 294: },
295: 'autoenroll' =>
296: { text => 'Auto-enrollment settings',
1.67 raeburn 297: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 298: header => [{col1 => 'Configuration setting',
299: col2 => 'Value(s)'}],
1.160.6.37 raeburn 300: print => \&print_autoenroll,
301: modify => \&modify_autoenroll,
1.30 raeburn 302: },
303: 'autoupdate' =>
304: { text => 'Auto-update settings',
1.67 raeburn 305: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 306: header => [{col1 => 'Setting',
307: col2 => 'Value',},
1.131 raeburn 308: {col1 => 'Setting',
309: col2 => 'Affiliation'},
1.43 raeburn 310: {col1 => 'User population',
1.160.6.35 raeburn 311: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 312: print => \&print_autoupdate,
313: modify => \&modify_autoupdate,
1.30 raeburn 314: },
1.125 raeburn 315: 'autocreate' =>
316: { text => 'Auto-course creation settings',
317: help => 'Domain_Configuration_Auto_Creation',
318: header => [{col1 => 'Configuration Setting',
319: col2 => 'Value',}],
1.160.6.37 raeburn 320: print => \&print_autocreate,
321: modify => \&modify_autocreate,
1.125 raeburn 322: },
1.30 raeburn 323: 'directorysrch' =>
1.160.6.72 raeburn 324: { text => 'Directory searches',
1.67 raeburn 325: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72 raeburn 326: header => [{col1 => 'Institutional Directory Setting',
327: col2 => 'Value',},
328: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 329: col2 => 'Value',}],
1.160.6.37 raeburn 330: print => \&print_directorysrch,
331: modify => \&modify_directorysrch,
1.30 raeburn 332: },
333: 'contacts' =>
1.160.6.78 raeburn 334: { text => 'E-mail addresses and helpform',
1.67 raeburn 335: help => 'Domain_Configuration_Contact_Info',
1.160.6.78 raeburn 336: header => [{col1 => 'Default e-mail addresses',
337: col2 => 'Value',},
338: {col1 => 'Recipient(s) for notifications',
339: col2 => 'Value',},
340: {col1 => 'Ask helpdesk form settings',
341: col2 => 'Value',},],
1.160.6.37 raeburn 342: print => \&print_contacts,
343: modify => \&modify_contacts,
1.30 raeburn 344: },
345: 'usercreation' =>
346: { text => 'User creation',
1.67 raeburn 347: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 348: header => [{col1 => 'Format rule type',
349: col2 => 'Format rules in force'},
1.34 raeburn 350: {col1 => 'User account creation',
351: col2 => 'Usernames which may be created',},
1.30 raeburn 352: {col1 => 'Context',
1.43 raeburn 353: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 354: print => \&print_usercreation,
355: modify => \&modify_usercreation,
1.30 raeburn 356: },
1.160.6.34 raeburn 357: 'selfcreation' =>
358: { text => 'Users self-creating accounts',
359: help => 'Domain_Configuration_Self_Creation',
360: header => [{col1 => 'Self-creation with institutional username',
361: col2 => 'Enabled?'},
362: {col1 => 'Institutional user type (login/SSO self-creation)',
363: col2 => 'Information user can enter'},
364: {col1 => 'Self-creation with e-mail as username',
365: col2 => 'Settings'}],
1.160.6.37 raeburn 366: print => \&print_selfcreation,
367: modify => \&modify_selfcreation,
1.160.6.34 raeburn 368: },
1.69 raeburn 369: 'usermodification' =>
1.33 raeburn 370: { text => 'User modification',
1.67 raeburn 371: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 372: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 373: col2 => 'User information updatable in author context'},
1.33 raeburn 374: {col1 => 'Target user has role',
1.160.6.35 raeburn 375: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 376: print => \&print_usermodification,
377: modify => \&modify_usermodification,
1.33 raeburn 378: },
1.69 raeburn 379: 'scantron' =>
1.160.6.84.2. 0(raebur 380:9): { text => 'Bubblesheet format',
1.67 raeburn 381: help => 'Domain_Configuration_Scantron_Format',
1.160.6.84.2. 0(raebur 382:9): header => [ {col1 => 'Bubblesheet format file',
383:9): col2 => ''},
384:9): {col1 => 'Bubblesheet data upload formats',
385:9): col2 => 'Settings'}],
1.160.6.37 raeburn 386: print => \&print_scantron,
387: modify => \&modify_scantron,
1.46 raeburn 388: },
1.86 raeburn 389: 'requestcourses' =>
390: {text => 'Request creation of courses',
391: help => 'Domain_Configuration_Request_Courses',
392: header => [{col1 => 'User affiliation',
1.102 raeburn 393: col2 => 'Availability/Processing of requests',},
394: {col1 => 'Setting',
1.160.6.30 raeburn 395: col2 => 'Value'},
396: {col1 => 'Available textbooks',
1.160.6.39 raeburn 397: col2 => ''},
1.160.6.46 raeburn 398: {col1 => 'Available templates',
399: col2 => ''},
1.160.6.39 raeburn 400: {col1 => 'Validation (not official courses)',
401: col2 => 'Value'},],
1.160.6.37 raeburn 402: print => \&print_quotas,
403: modify => \&modify_quotas,
1.86 raeburn 404: },
1.160.6.5 raeburn 405: 'requestauthor' =>
1.160.6.34 raeburn 406: {text => 'Request Authoring Space',
1.160.6.5 raeburn 407: help => 'Domain_Configuration_Request_Author',
408: header => [{col1 => 'User affiliation',
409: col2 => 'Availability/Processing of requests',},
410: {col1 => 'Setting',
411: col2 => 'Value'}],
1.160.6.37 raeburn 412: print => \&print_quotas,
413: modify => \&modify_quotas,
1.160.6.5 raeburn 414: },
1.69 raeburn 415: 'coursecategories' =>
1.120 raeburn 416: { text => 'Cataloging of courses/communities',
1.67 raeburn 417: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 418: header => [{col1 => 'Catalog type/availability',
419: col2 => '',},
420: {col1 => 'Category settings for standard catalog',
1.57 raeburn 421: col2 => '',},
422: {col1 => 'Categories',
423: col2 => '',
424: }],
1.160.6.37 raeburn 425: print => \&print_coursecategories,
426: modify => \&modify_coursecategories,
1.69 raeburn 427: },
428: 'serverstatuses' =>
1.77 raeburn 429: {text => 'Access to server status pages',
1.69 raeburn 430: help => 'Domain_Configuration_Server_Status',
431: header => [{col1 => 'Status Page',
432: col2 => 'Other named users',
433: col3 => 'Specific IPs',
434: }],
1.160.6.37 raeburn 435: print => \&print_serverstatuses,
436: modify => \&modify_serverstatuses,
1.69 raeburn 437: },
1.160.6.73 raeburn 438: 'helpsettings' =>
439: {text => 'Support settings',
440: help => 'Domain_Configuration_Help_Settings',
441: header => [{col1 => 'Help Page Settings (logged-in users)',
442: col2 => 'Value'},
443: {col1 => 'Helpdesk Roles',
444: col2 => 'Settings'},],
445: print => \&print_helpsettings,
446: modify => \&modify_helpsettings,
447: },
1.160.6.39 raeburn 448: 'coursedefaults' =>
1.160.6.16 raeburn 449: {text => 'Course/Community defaults',
450: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 451: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
452: col2 => 'Value',},
453: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 454: col2 => 'Value',},],
1.160.6.37 raeburn 455: print => \&print_coursedefaults,
456: modify => \&modify_coursedefaults,
457: },
1.160.6.39 raeburn 458: 'selfenrollment' =>
1.160.6.37 raeburn 459: {text => 'Self-enrollment in Course/Community',
460: help => 'Domain_Configuration_Selfenrollment',
461: header => [{col1 => 'Configuration Rights',
462: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
463: {col1 => 'Defaults',
464: col2 => 'Value'},
465: {col1 => 'Self-enrollment validation (optional)',
466: col2 => 'Value'},],
467: print => \&print_selfenrollment,
468: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 469: },
1.141 raeburn 470: 'usersessions' =>
1.145 raeburn 471: {text => 'User session hosting/offloading',
1.137 raeburn 472: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 473: header => [{col1 => 'Domain server',
474: col2 => 'Servers to offload sessions to when busy'},
475: {col1 => 'Hosting of users from other domains',
1.137 raeburn 476: col2 => 'Rules'},
477: {col1 => "Hosting domain's own users elsewhere",
478: col2 => 'Rules'}],
1.160.6.37 raeburn 479: print => \&print_usersessions,
480: modify => \&modify_usersessions,
1.137 raeburn 481: },
1.160.6.78 raeburn 482: 'loadbalancing' =>
1.160.6.7 raeburn 483: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 484: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 485: header => [{col1 => 'Balancers',
1.150 raeburn 486: col2 => 'Default destinations',
1.160.6.13 raeburn 487: col3 => 'User affiliation',
1.150 raeburn 488: col4 => 'Overrides'},
489: ],
1.160.6.37 raeburn 490: print => \&print_loadbalancing,
491: modify => \&modify_loadbalancing,
1.150 raeburn 492: },
1.160.6.84.2. (raeburn 493:): 'ltitools' =>
494:): {text => 'External Tools (LTI)',
495:): help => 'Domain_Configuration_LTI_Tools',
496:): header => [{col1 => 'Setting',
497:): col2 => 'Value',}],
498:): print => \&print_ltitools,
499:): modify => \&modify_ltitools,
500:): },
1.3 raeburn 501: );
1.110 raeburn 502: if (keys(%servers) > 1) {
503: $prefs{'login'} = { text => 'Log-in page options',
504: help => 'Domain_Configuration_Login_Page',
505: header => [{col1 => 'Log-in Service',
506: col2 => 'Server Setting',},
507: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 508: col2 => ''},
509: {col1 => 'Log-in Help',
1.160.6.56 raeburn 510: col2 => 'Value'},
511: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 512: col2 => 'Value'}],
1.160.6.37 raeburn 513: print => \&print_login,
514: modify => \&modify_login,
1.110 raeburn 515: };
516: }
1.160.6.13 raeburn 517:
1.6 raeburn 518: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 519: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 520: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 521: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 522: text=>"Settings to display/modify"});
1.9 raeburn 523: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 524:
1.3 raeburn 525: if ($phase eq 'process') {
1.160.6.27 raeburn 526: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
527: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 528: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 529: $r->rflush();
1.160.6.27 raeburn 530: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 531: }
1.30 raeburn 532: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 533: my $js = &recaptcha_js().
1.160.6.40 raeburn 534: &toggle_display_js();
1.160.6.7 raeburn 535: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 536: my ($othertitle,$usertypes,$types) =
537: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 538: $js .= &lonbalance_targets_js($dom,$types,\%servers,
539: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 540: &new_spares_js().
541: &common_domprefs_js().
542: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 543: }
1.160.6.30 raeburn 544: if (grep(/^requestcourses$/,@actions)) {
545: my $javascript_validations;
546: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
547: $js .= <<END;
548: <script type="text/javascript">
549: $javascript_validations
550: </script>
551: $coursebrowserjs
552: END
553: }
1.160.6.78 raeburn 554: if (grep(/^contacts$/,@actions)) {
555: $js .= &contacts_javascript();
556: }
1.160.6.84.2. 0(raebur 557:9): if (grep(/^scantron$/,@actions)) {
558:9): $js .= &scantron_javascript();
559:9): }
1.150 raeburn 560: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 561: } else {
1.160.6.11 raeburn 562: # check if domconfig user exists for the domain.
563: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 564: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 565: &config_check($dom,$confname,$servadm);
566: unless ($configuserok eq 'ok') {
567: &Apache::lonconfigsettings::print_header($r,$phase,$context);
568: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
569: $confname).
570: '<br />'
571: );
572: if ($switchserver) {
573: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
574: '<br />'.
575: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
576: '<br />'.
577: &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).
578: '<br />'.
579: &mt('To do that now, use the following link: [_1]',$switchserver)
580: );
581: } else {
582: $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.').
583: '<br />'.
584: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
585: );
586: }
587: $r->print(&Apache::loncommon::end_page());
588: return OK;
589: }
1.21 raeburn 590: if (keys(%domconfig) == 0) {
591: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 592: my @ids=&Apache::lonnet::current_machine_ids();
593: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 594: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 595: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 596: my $custom_img_count = 0;
597: foreach my $img (@loginimages) {
598: if ($designhash{$dom.'.login.'.$img} ne '') {
599: $custom_img_count ++;
600: }
601: }
602: foreach my $role (@roles) {
603: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
604: $custom_img_count ++;
605: }
606: }
607: if ($custom_img_count > 0) {
1.94 raeburn 608: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 609: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 610: $r->print(
611: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
612: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
613: &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 />'.
614: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
615: if ($switch_server) {
1.30 raeburn 616: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 617: }
1.91 raeburn 618: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 619: return OK;
620: }
621: }
622: }
1.91 raeburn 623: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 624: }
625: return OK;
626: }
627:
628: sub process_changes {
1.160.6.24 raeburn 629: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 630: my %domconfig;
631: if (ref($values) eq 'HASH') {
632: %domconfig = %{$values};
633: }
1.3 raeburn 634: my $output;
635: if ($action eq 'login') {
1.160.6.24 raeburn 636: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 637: } elsif ($action eq 'rolecolors') {
1.9 raeburn 638: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 639: $lastactref,%domconfig);
1.3 raeburn 640: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 641: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 642: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 643: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 644: } elsif ($action eq 'autoupdate') {
645: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 646: } elsif ($action eq 'autocreate') {
647: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 648: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 649: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 650: } elsif ($action eq 'usercreation') {
1.28 raeburn 651: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 652: } elsif ($action eq 'selfcreation') {
653: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 654: } elsif ($action eq 'usermodification') {
655: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 656: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 657: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 658: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 659: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 660: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 661: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 662: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 663: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 664: } elsif ($action eq 'serverstatuses') {
665: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 666: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 667: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 668: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 669: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 670: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 671: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 672: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 673: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 674: } elsif ($action eq 'selfenrollment') {
675: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 676: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 677: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 678: } elsif ($action eq 'loadbalancing') {
679: $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.84.2. (raeburn 680:): } elsif ($action eq 'ltitools') {
681:): $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 682: }
683: return $output;
684: }
685:
686: sub print_config_box {
1.9 raeburn 687: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 688: my $rowtotal = 0;
1.49 raeburn 689: my $output;
690: if ($action eq 'coursecategories') {
691: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 692: } elsif ($action eq 'defaults') {
693: $output = &defaults_javascript($settings);
1.160.6.73 raeburn 694: } elsif ($action eq 'helpsettings') {
695: my (%privs,%levelscurrent);
696: my %full=();
697: my %levels=(
698: course => {},
699: domain => {},
700: system => {},
701: );
702: my $context = 'domain';
703: my $crstype = 'Course';
704: my $formname = 'display';
705: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
706: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
707: $output =
708: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
709: \@templateroles);
1.91 raeburn 710: }
1.160.6.40 raeburn 711: $output .=
1.30 raeburn 712: '<table class="LC_nested_outer">
1.3 raeburn 713: <tr>
1.66 raeburn 714: <th align="left" valign="middle"><span class="LC_nobreak">'.
715: &mt($item->{text}).' '.
716: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
717: '</tr>';
1.30 raeburn 718: $rowtotal ++;
1.110 raeburn 719: my $numheaders = 1;
720: if (ref($item->{'header'}) eq 'ARRAY') {
721: $numheaders = scalar(@{$item->{'header'}});
722: }
723: if ($numheaders > 1) {
1.64 raeburn 724: my $colspan = '';
1.145 raeburn 725: my $rightcolspan = '';
1.160.6.42 raeburn 726: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 727: ($action eq 'directorysrch') ||
1.160.6.56 raeburn 728: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 729: $colspan = ' colspan="2"';
730: }
1.145 raeburn 731: if ($action eq 'usersessions') {
732: $rightcolspan = ' colspan="3"';
733: }
1.30 raeburn 734: $output .= '
1.3 raeburn 735: <tr>
736: <td>
737: <table class="LC_nested">
738: <tr class="LC_info_row">
1.59 bisitz 739: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 740: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 741: </tr>';
1.69 raeburn 742: $rowtotal ++;
1.160.6.37 raeburn 743: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 744: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 745: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.78 raeburn 746: ($action eq 'helpsettings') || ($action eq 'contacts')) {
1.160.6.37 raeburn 747: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 748: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 749: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.84.2. 0(raebur 750:9): } elsif ($action eq 'scantron') {
751:9): $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 752: } elsif ($action eq 'login') {
1.160.6.56 raeburn 753: if ($numheaders == 4) {
1.160.6.5 raeburn 754: $colspan = ' colspan="2"';
755: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
756: } else {
757: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
758: }
1.160.6.37 raeburn 759: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 760: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 761: } elsif ($action eq 'rolecolors') {
1.30 raeburn 762: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 763: }
1.30 raeburn 764: $output .= '
1.6 raeburn 765: </table>
766: </td>
767: </tr>
768: <tr>
769: <td>
770: <table class="LC_nested">
771: <tr class="LC_info_row">
1.160.6.37 raeburn 772: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 773: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 774: </tr>';
775: $rowtotal ++;
1.160.6.37 raeburn 776: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
777: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 778: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.80 raeburn 779: ($action eq 'contacts') || ($action eq 'defaults')) {
1.160.6.42 raeburn 780: if ($action eq 'coursecategories') {
781: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
782: $colspan = ' colspan="2"';
783: } else {
784: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
785: }
786: $output .= '
1.63 raeburn 787: </table>
788: </td>
789: </tr>
790: <tr>
791: <td>
792: <table class="LC_nested">
793: <tr class="LC_info_row">
794: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 795: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 796: </tr>'."\n";
797: if ($action eq 'coursecategories') {
798: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
799: } else {
800: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
801: }
1.63 raeburn 802: $rowtotal ++;
1.160.6.57 raeburn 803: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 804: ($action eq 'defaults') || ($action eq 'directorysrch') ||
805: ($action eq 'helpsettings')) {
1.160.6.37 raeburn 806: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.84.2. 0(raebur 807:9): } elsif ($action eq 'scantron') {
808:9): $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 809: } elsif ($action eq 'login') {
1.160.6.56 raeburn 810: if ($numheaders == 4) {
1.160.6.5 raeburn 811: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
812: </table>
813: </td>
814: </tr>
815: <tr>
816: <td>
817: <table class="LC_nested">
818: <tr class="LC_info_row">
819: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 820: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 821: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
822: $rowtotal ++;
823: } else {
824: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
825: }
1.160.6.56 raeburn 826: $output .= '
827: </table>
828: </td>
829: </tr>
830: <tr>
831: <td>
832: <table class="LC_nested">
833: <tr class="LC_info_row">';
834: if ($numheaders == 4) {
835: $output .= '
836: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
837: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
838: </tr>';
839: } else {
840: $output .= '
841: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
842: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
843: </tr>';
844: }
845: $rowtotal ++;
846: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 847: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 848: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
849: $rowtotal ++;
850: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 851: </table>
852: </td>
853: </tr>
854: <tr>
855: <td>
856: <table class="LC_nested">
857: <tr class="LC_info_row">
858: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
859: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 860: &textbookcourses_javascript($settings).
861: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
862: </table>
863: </td>
864: </tr>
865: <tr>
866: <td>
867: <table class="LC_nested">
868: <tr class="LC_info_row">
869: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
870: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
871: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 872: </table>
873: </td>
874: </tr>
875: <tr>
876: <td>
877: <table class="LC_nested">
878: <tr class="LC_info_row">
1.160.6.46 raeburn 879: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
880: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 881: </tr>'.
882: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 883: } elsif ($action eq 'requestauthor') {
884: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 885: $rowtotal ++;
1.122 jms 886: } elsif ($action eq 'rolecolors') {
1.30 raeburn 887: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 888: </table>
889: </td>
890: </tr>
891: <tr>
892: <td>
893: <table class="LC_nested">
894: <tr class="LC_info_row">
1.69 raeburn 895: <td class="LC_left_item"'.$colspan.' valign="top">'.
896: &mt($item->{'header'}->[2]->{'col1'}).'</td>
897: <td class="LC_right_item" valign="top">'.
898: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 899: </tr>'.
1.30 raeburn 900: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 901: </table>
902: </td>
903: </tr>
904: <tr>
905: <td>
906: <table class="LC_nested">
907: <tr class="LC_info_row">
1.59 bisitz 908: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
909: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 910: </tr>'.
1.30 raeburn 911: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
912: $rowtotal += 2;
1.6 raeburn 913: }
1.3 raeburn 914: } else {
1.30 raeburn 915: $output .= '
1.3 raeburn 916: <tr>
917: <td>
918: <table class="LC_nested">
1.30 raeburn 919: <tr class="LC_info_row">';
1.160.6.72 raeburn 920: if ($action eq 'login') {
1.30 raeburn 921: $output .= '
1.59 bisitz 922: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 923: } elsif ($action eq 'serverstatuses') {
924: $output .= '
925: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
926: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
927:
1.6 raeburn 928: } else {
1.30 raeburn 929: $output .= '
1.69 raeburn 930: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
931: }
1.72 raeburn 932: if (defined($item->{'header'}->[0]->{'col3'})) {
933: $output .= '<td class="LC_left_item" valign="top">'.
934: &mt($item->{'header'}->[0]->{'col2'});
935: if ($action eq 'serverstatuses') {
936: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
937: }
1.69 raeburn 938: } else {
939: $output .= '<td class="LC_right_item" valign="top">'.
940: &mt($item->{'header'}->[0]->{'col2'});
941: }
942: $output .= '</td>';
943: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 944: if (defined($item->{'header'}->[0]->{'col4'})) {
945: $output .= '<td class="LC_left_item" valign="top">'.
946: &mt($item->{'header'}->[0]->{'col3'});
947: } else {
948: $output .= '<td class="LC_right_item" valign="top">'.
949: &mt($item->{'header'}->[0]->{'col3'});
950: }
1.69 raeburn 951: if ($action eq 'serverstatuses') {
952: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
953: }
954: $output .= '</td>';
1.6 raeburn 955: }
1.150 raeburn 956: if ($item->{'header'}->[0]->{'col4'}) {
957: $output .= '<td class="LC_right_item" valign="top">'.
958: &mt($item->{'header'}->[0]->{'col4'});
959: }
1.69 raeburn 960: $output .= '</tr>';
1.48 raeburn 961: $rowtotal ++;
1.160.6.5 raeburn 962: if ($action eq 'quotas') {
1.86 raeburn 963: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 964: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.84.2. (raeburn 965:): ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
966:): ($action eq 'ltitools')) {
1.160.6.37 raeburn 967: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 968: }
1.3 raeburn 969: }
1.30 raeburn 970: $output .= '
1.3 raeburn 971: </table>
972: </td>
973: </tr>
1.30 raeburn 974: </table><br />';
975: return ($output,$rowtotal);
1.1 raeburn 976: }
977:
1.3 raeburn 978: sub print_login {
1.160.6.5 raeburn 979: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 980: my ($css_class,$datatable);
1.6 raeburn 981: my %choices = &login_choices();
1.110 raeburn 982:
1.160.6.5 raeburn 983: if ($caller eq 'service') {
1.149 raeburn 984: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 985: my $choice = $choices{'disallowlogin'};
986: $css_class = ' class="LC_odd_row"';
1.128 raeburn 987: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 988: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 989: '<th>'.$choices{'server'}.'</th>'.
990: '<th>'.$choices{'serverpath'}.'</th>'.
991: '<th>'.$choices{'custompath'}.'</th>'.
992: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 993: my %disallowed;
994: if (ref($settings) eq 'HASH') {
995: if (ref($settings->{'loginvia'}) eq 'HASH') {
996: %disallowed = %{$settings->{'loginvia'}};
997: }
998: }
999: foreach my $lonhost (sort(keys(%servers))) {
1000: my $direct = 'selected="selected"';
1.128 raeburn 1001: if (ref($disallowed{$lonhost}) eq 'HASH') {
1002: if ($disallowed{$lonhost}{'server'} ne '') {
1003: $direct = '';
1004: }
1.110 raeburn 1005: }
1.115 raeburn 1006: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1007: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1008: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1009: '</option>';
1.160.6.13 raeburn 1010: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1011: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1012: my $selected = '';
1.128 raeburn 1013: if (ref($disallowed{$lonhost}) eq 'HASH') {
1014: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1015: $selected = 'selected="selected"';
1016: }
1.110 raeburn 1017: }
1018: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1019: $servers{$hostid}.'</option>';
1020: }
1.128 raeburn 1021: $datatable .= '</select></td>'.
1022: '<td><select name="'.$lonhost.'_serverpath">';
1023: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1024: my $pathname = $path;
1025: if ($path eq 'custom') {
1026: $pathname = &mt('Custom Path').' ->';
1027: }
1028: my $selected = '';
1029: if (ref($disallowed{$lonhost}) eq 'HASH') {
1030: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1031: $selected = 'selected="selected"';
1032: }
1033: } elsif ($path eq '') {
1034: $selected = 'selected="selected"';
1035: }
1036: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1037: }
1038: $datatable .= '</select></td>';
1039: my ($custom,$exempt);
1040: if (ref($disallowed{$lonhost}) eq 'HASH') {
1041: $custom = $disallowed{$lonhost}{'custompath'};
1042: $exempt = $disallowed{$lonhost}{'exempt'};
1043: }
1044: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1045: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1046: '</tr>';
1.110 raeburn 1047: }
1048: $datatable .= '</table></td></tr>';
1049: return $datatable;
1.160.6.5 raeburn 1050: } elsif ($caller eq 'page') {
1051: my %defaultchecked = (
1052: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1053: 'helpdesk' => 'on',
1.160.6.5 raeburn 1054: 'adminmail' => 'off',
1055: 'newuser' => 'off',
1056: );
1.160.6.14 raeburn 1057: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1058: my (%checkedon,%checkedoff);
1.42 raeburn 1059: foreach my $item (@toggles) {
1.160.6.5 raeburn 1060: if ($defaultchecked{$item} eq 'on') {
1061: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1062: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1063: } elsif ($defaultchecked{$item} eq 'off') {
1064: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1065: $checkedon{$item} = ' ';
1066: }
1.1 raeburn 1067: }
1.160.6.5 raeburn 1068: my @images = ('img','logo','domlogo','login');
1069: my @logintext = ('textcol','bgcol');
1070: my @bgs = ('pgbg','mainbg','sidebg');
1071: my @links = ('link','alink','vlink');
1072: my %designhash = &Apache::loncommon::get_domainconf($dom);
1073: my %defaultdesign = %Apache::loncommon::defaultdesign;
1074: my (%is_custom,%designs);
1075: my %defaults = (
1076: font => $defaultdesign{'login.font'},
1077: );
1.6 raeburn 1078: foreach my $item (@images) {
1.160.6.5 raeburn 1079: $defaults{$item} = $defaultdesign{'login.'.$item};
1080: $defaults{'showlogo'}{$item} = 1;
1081: }
1082: foreach my $item (@bgs) {
1083: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1084: }
1.41 raeburn 1085: foreach my $item (@logintext) {
1.160.6.5 raeburn 1086: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1087: }
1.160.6.5 raeburn 1088: foreach my $item (@links) {
1089: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1090: }
1.160.6.5 raeburn 1091: if (ref($settings) eq 'HASH') {
1092: foreach my $item (@toggles) {
1093: if ($settings->{$item} eq '1') {
1094: $checkedon{$item} = ' checked="checked" ';
1095: $checkedoff{$item} = ' ';
1096: } elsif ($settings->{$item} eq '0') {
1097: $checkedoff{$item} = ' checked="checked" ';
1098: $checkedon{$item} = ' ';
1099: }
1.6 raeburn 1100: }
1.160.6.5 raeburn 1101: foreach my $item (@images) {
1102: if (defined($settings->{$item})) {
1103: $designs{$item} = $settings->{$item};
1104: $is_custom{$item} = 1;
1105: }
1106: if (defined($settings->{'showlogo'}{$item})) {
1107: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1108: }
1109: }
1110: foreach my $item (@logintext) {
1111: if ($settings->{$item} ne '') {
1112: $designs{'logintext'}{$item} = $settings->{$item};
1113: $is_custom{$item} = 1;
1114: }
1115: }
1116: if ($settings->{'font'} ne '') {
1117: $designs{'font'} = $settings->{'font'};
1118: $is_custom{'font'} = 1;
1119: }
1120: foreach my $item (@bgs) {
1121: if ($settings->{$item} ne '') {
1122: $designs{'bgs'}{$item} = $settings->{$item};
1123: $is_custom{$item} = 1;
1124: }
1125: }
1126: foreach my $item (@links) {
1127: if ($settings->{$item} ne '') {
1128: $designs{'links'}{$item} = $settings->{$item};
1129: $is_custom{$item} = 1;
1130: }
1131: }
1132: } else {
1133: if ($designhash{$dom.'.login.font'} ne '') {
1134: $designs{'font'} = $designhash{$dom.'.login.font'};
1135: $is_custom{'font'} = 1;
1136: }
1137: foreach my $item (@images) {
1138: if ($designhash{$dom.'.login.'.$item} ne '') {
1139: $designs{$item} = $designhash{$dom.'.login.'.$item};
1140: $is_custom{$item} = 1;
1141: }
1142: }
1143: foreach my $item (@bgs) {
1144: if ($designhash{$dom.'.login.'.$item} ne '') {
1145: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1146: $is_custom{$item} = 1;
1147: }
1148: }
1149: foreach my $item (@links) {
1150: if ($designhash{$dom.'.login.'.$item} ne '') {
1151: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1152: $is_custom{$item} = 1;
1153: }
1.6 raeburn 1154: }
1155: }
1.160.6.5 raeburn 1156: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1157: logo => 'Institution Logo',
1158: domlogo => 'Domain Logo',
1159: login => 'Login box');
1160: my $itemcount = 1;
1161: foreach my $item (@toggles) {
1162: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1163: $datatable .=
1164: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1165: '</td><td>'.
1166: '<span class="LC_nobreak"><label><input type="radio" name="'.
1167: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1168: '</label> <label><input type="radio" name="'.$item.'"'.
1169: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1170: '</tr>';
1171: $itemcount ++;
1.6 raeburn 1172: }
1.160.6.5 raeburn 1173: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1174: $datatable .= '</tr></table></td></tr>';
1175: } elsif ($caller eq 'help') {
1176: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1177: my $switchserver = &check_switchserver($dom,$confname);
1178: my $itemcount = 1;
1179: $defaulturl = '/adm/loginproblems.html';
1180: $defaulttype = 'default';
1181: %lt = &Apache::lonlocal::texthash (
1182: del => 'Delete?',
1183: rep => 'Replace:',
1184: upl => 'Upload:',
1185: default => 'Default',
1186: custom => 'Custom',
1187: );
1188: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1189: my @currlangs;
1190: if (ref($settings) eq 'HASH') {
1191: if (ref($settings->{'helpurl'}) eq 'HASH') {
1192: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1193: next if ($settings->{'helpurl'}{$key} eq '');
1194: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1195: $type{$key} = 'custom';
1196: unless ($key eq 'nolang') {
1197: push(@currlangs,$key);
1198: }
1199: }
1200: } elsif ($settings->{'helpurl'} ne '') {
1201: $type{'nolang'} = 'custom';
1202: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1203: }
1204: }
1.160.6.5 raeburn 1205: foreach my $lang ('nolang',sort(@currlangs)) {
1206: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1207: $datatable .= '<tr'.$css_class.'>';
1208: if ($url{$lang} eq '') {
1209: $url{$lang} = $defaulturl;
1210: }
1211: if ($type{$lang} eq '') {
1212: $type{$lang} = $defaulttype;
1213: }
1214: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1215: if ($lang eq 'nolang') {
1216: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1217: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1218: } else {
1219: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1220: $langchoices{$lang},
1221: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1222: }
1223: $datatable .= '</span></td>'."\n".
1224: '<td class="LC_left_item">';
1225: if ($type{$lang} eq 'custom') {
1226: $datatable .= '<span class="LC_nobreak"><label>'.
1227: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1228: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1229: } else {
1230: $datatable .= $lt{'upl'};
1231: }
1232: $datatable .='<br />';
1233: if ($switchserver) {
1234: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1235: } else {
1236: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1237: }
1.160.6.5 raeburn 1238: $datatable .= '</td></tr>';
1239: $itemcount ++;
1.6 raeburn 1240: }
1.160.6.5 raeburn 1241: my @addlangs;
1242: foreach my $lang (sort(keys(%langchoices))) {
1243: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1244: push(@addlangs,$lang);
1245: }
1246: if (@addlangs > 0) {
1247: my %toadd;
1248: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1249: $toadd{''} = &mt('Select');
1250: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1251: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1252: &mt('Add log-in help page for a specific language:').' '.
1253: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1254: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1255: if ($switchserver) {
1256: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1257: } else {
1258: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1259: }
1.160.6.5 raeburn 1260: $datatable .= '</td></tr>';
1261: $itemcount ++;
1.6 raeburn 1262: }
1.160.6.5 raeburn 1263: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1264: } elsif ($caller eq 'headtag') {
1265: my %domservers = &Apache::lonnet::get_servers($dom);
1266: my $choice = $choices{'headtag'};
1267: $css_class = ' class="LC_odd_row"';
1268: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1269: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1270: '<th>'.$choices{'current'}.'</th>'.
1271: '<th>'.$choices{'action'}.'</th>'.
1272: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1273: my (%currurls,%currexempt);
1274: if (ref($settings) eq 'HASH') {
1275: if (ref($settings->{'headtag'}) eq 'HASH') {
1276: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1277: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1278: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1279: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1280: }
1281: }
1282: }
1283: }
1284: my %lt = &Apache::lonlocal::texthash(
1285: del => 'Delete?',
1286: rep => 'Replace:',
1287: upl => 'Upload:',
1288: curr => 'View contents',
1289: none => 'None',
1290: );
1291: my $switchserver = &check_switchserver($dom,$confname);
1292: foreach my $lonhost (sort(keys(%domservers))) {
1293: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1294: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1295: if ($currurls{$lonhost}) {
1296: $datatable .= '<td class="LC_right_item"><a href="'.
1297: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1298: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1299: '">'.$lt{'curr'}.'</a></td>'.
1300: '<td><span class="LC_nobreak"><label>'.
1301: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1302: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1303: } else {
1304: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1305: }
1306: $datatable .='<br />';
1307: if ($switchserver) {
1308: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1309: } else {
1310: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1311: }
1312: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1313: }
1314: $datatable .= '</table></td></tr>';
1.1 raeburn 1315: }
1.6 raeburn 1316: return $datatable;
1317: }
1318:
1319: sub login_choices {
1320: my %choices =
1321: &Apache::lonlocal::texthash (
1.116 bisitz 1322: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1323: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1324: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1325: disallowlogin => "Login page requests redirected",
1326: hostid => "Server",
1.128 raeburn 1327: server => "Redirect to:",
1328: serverpath => "Path",
1329: custompath => "Custom",
1330: exempt => "Exempt IP(s)",
1.110 raeburn 1331: directlogin => "No redirect",
1332: newuser => "Link to create a user account",
1333: img => "Header",
1334: logo => "Main Logo",
1335: domlogo => "Domain Logo",
1336: login => "Log-in Header",
1337: textcol => "Text color",
1338: bgcol => "Box color",
1339: bgs => "Background colors",
1340: links => "Link colors",
1341: font => "Font color",
1342: pgbg => "Header",
1343: mainbg => "Page",
1344: sidebg => "Login box",
1345: link => "Link",
1346: alink => "Active link",
1347: vlink => "Visited link",
1.160.6.56 raeburn 1348: headtag => "Custom markup",
1349: action => "Action",
1350: current => "Current",
1.6 raeburn 1351: );
1352: return %choices;
1353: }
1354:
1355: sub print_rolecolors {
1.30 raeburn 1356: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1357: my %choices = &color_font_choices();
1358: my @bgs = ('pgbg','tabbg','sidebg');
1359: my @links = ('link','alink','vlink');
1360: my @images = ('img');
1361: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1362: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1363: my %defaultdesign = %Apache::loncommon::defaultdesign;
1364: my (%is_custom,%designs);
1.160.6.22 raeburn 1365: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1366: if (ref($settings) eq 'HASH') {
1367: if (ref($settings->{$role}) eq 'HASH') {
1368: if ($settings->{$role}->{'img'} ne '') {
1369: $designs{'img'} = $settings->{$role}->{'img'};
1370: $is_custom{'img'} = 1;
1371: }
1372: if ($settings->{$role}->{'font'} ne '') {
1373: $designs{'font'} = $settings->{$role}->{'font'};
1374: $is_custom{'font'} = 1;
1375: }
1.97 tempelho 1376: if ($settings->{$role}->{'fontmenu'} ne '') {
1377: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1378: $is_custom{'fontmenu'} = 1;
1379: }
1.6 raeburn 1380: foreach my $item (@bgs) {
1381: if ($settings->{$role}->{$item} ne '') {
1382: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1383: $is_custom{$item} = 1;
1384: }
1385: }
1386: foreach my $item (@links) {
1387: if ($settings->{$role}->{$item} ne '') {
1388: $designs{'links'}{$item} = $settings->{$role}->{$item};
1389: $is_custom{$item} = 1;
1390: }
1391: }
1392: }
1393: } else {
1394: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1395: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1396: $is_custom{'img'} = 1;
1397: }
1.97 tempelho 1398: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1399: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1400: $is_custom{'fontmenu'} = 1;
1401: }
1.6 raeburn 1402: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1403: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1404: $is_custom{'font'} = 1;
1405: }
1406: foreach my $item (@bgs) {
1407: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1408: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1409: $is_custom{$item} = 1;
1410:
1411: }
1412: }
1413: foreach my $item (@links) {
1414: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1415: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1416: $is_custom{$item} = 1;
1417: }
1418: }
1419: }
1420: my $itemcount = 1;
1.30 raeburn 1421: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1422: $datatable .= '</tr></table></td></tr>';
1423: return $datatable;
1424: }
1425:
1.160.6.22 raeburn 1426: sub role_defaults {
1427: my ($role,$bgs,$links,$images,$logintext) = @_;
1428: my %defaults;
1429: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1430: return %defaults;
1431: }
1432: my %defaultdesign = %Apache::loncommon::defaultdesign;
1433: if ($role eq 'login') {
1434: %defaults = (
1435: font => $defaultdesign{$role.'.font'},
1436: );
1437: if (ref($logintext) eq 'ARRAY') {
1438: foreach my $item (@{$logintext}) {
1439: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1440: }
1441: }
1442: foreach my $item (@{$images}) {
1443: $defaults{'showlogo'}{$item} = 1;
1444: }
1445: } else {
1446: %defaults = (
1447: img => $defaultdesign{$role.'.img'},
1448: font => $defaultdesign{$role.'.font'},
1449: fontmenu => $defaultdesign{$role.'.fontmenu'},
1450: );
1451: }
1452: foreach my $item (@{$bgs}) {
1453: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1454: }
1455: foreach my $item (@{$links}) {
1456: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1457: }
1458: foreach my $item (@{$images}) {
1459: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1460: }
1461: return %defaults;
1462: }
1463:
1.6 raeburn 1464: sub display_color_options {
1.9 raeburn 1465: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1466: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1467: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1468: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1469: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1470: '<td>'.$choices->{'font'}.'</td>';
1471: if (!$is_custom->{'font'}) {
1.30 raeburn 1472: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1473: } else {
1474: $datatable .= '<td> </td>';
1475: }
1.160.6.9 raeburn 1476: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1477:
1.8 raeburn 1478: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1479: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1480: ' value="'.$current_color.'" /> '.
1481: ' </td></tr>';
1.107 raeburn 1482: unless ($role eq 'login') {
1483: $datatable .= '<tr'.$css_class.'>'.
1484: '<td>'.$choices->{'fontmenu'}.'</td>';
1485: if (!$is_custom->{'fontmenu'}) {
1486: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1487: } else {
1488: $datatable .= '<td> </td>';
1489: }
1.160.6.22 raeburn 1490: $current_color = $designs->{'fontmenu'} ?
1491: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1492: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1493: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1494: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1495: ' value="'.$current_color.'" /> '.
1496: ' </td></tr>';
1.97 tempelho 1497: }
1.9 raeburn 1498: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1499: foreach my $img (@{$images}) {
1.18 albertel 1500: $itemcount ++;
1.6 raeburn 1501: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1502: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1503: '<td>'.$choices->{$img};
1.41 raeburn 1504: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1505: if ($role eq 'login') {
1506: if ($img eq 'login') {
1507: $login_hdr_pick =
1.135 bisitz 1508: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1509: $logincolors =
1510: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1511: $designs,$defaults);
1.70 raeburn 1512: } elsif ($img ne 'domlogo') {
1513: $datatable.= &logo_display_options($img,$defaults,$designs);
1514: }
1515: }
1516: $datatable .= '</td>';
1.6 raeburn 1517: if ($designs->{$img} ne '') {
1518: $imgfile = $designs->{$img};
1.18 albertel 1519: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1520: } else {
1521: $imgfile = $defaults->{$img};
1522: }
1523: if ($imgfile) {
1.9 raeburn 1524: my ($showfile,$fullsize);
1525: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1526: my $urldir = $1;
1527: my $filename = $2;
1528: my @info = &Apache::lonnet::stat_file($designs->{$img});
1529: if (@info) {
1530: my $thumbfile = 'tn-'.$filename;
1531: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1532: if (@thumb) {
1533: $showfile = $urldir.'/'.$thumbfile;
1534: } else {
1535: $showfile = $imgfile;
1536: }
1537: } else {
1538: $showfile = '';
1539: }
1540: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1541: $showfile = $imgfile;
1.6 raeburn 1542: my $imgdir = $1;
1543: my $filename = $2;
1.159 raeburn 1544: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1545: $showfile = "/$imgdir/tn-".$filename;
1546: } else {
1.159 raeburn 1547: my $input = $londocroot.$imgfile;
1548: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1549: if (!-e $output) {
1.9 raeburn 1550: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1551: my ($fullwidth,$fullheight) = &check_dimensions($input);
1552: if ($fullwidth ne '' && $fullheight ne '') {
1553: if ($fullwidth > $width && $fullheight > $height) {
1554: my $size = $width.'x'.$height;
1.160.6.84.2. (raeburn 1555:): my @args = ('convert','-sample',$size,$input,$output);
1556:): system({$args[0]} @args);
1.159 raeburn 1557: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1558: }
1559: }
1.6 raeburn 1560: }
1561: }
1.16 raeburn 1562: }
1.6 raeburn 1563: if ($showfile) {
1.40 raeburn 1564: if ($showfile =~ m{^/(adm|res)/}) {
1565: if ($showfile =~ m{^/res/}) {
1566: my $local_showfile =
1567: &Apache::lonnet::filelocation('',$showfile);
1568: &Apache::lonnet::repcopy($local_showfile);
1569: }
1570: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1571: }
1572: if ($imgfile) {
1573: if ($imgfile =~ m{^/(adm|res)/}) {
1574: if ($imgfile =~ m{^/res/}) {
1575: my $local_imgfile =
1576: &Apache::lonnet::filelocation('',$imgfile);
1577: &Apache::lonnet::repcopy($local_imgfile);
1578: }
1579: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1580: } else {
1581: $fullsize = $imgfile;
1582: }
1583: }
1.41 raeburn 1584: $datatable .= '<td>';
1585: if ($img eq 'login') {
1.135 bisitz 1586: $datatable .= $login_hdr_pick;
1587: }
1.41 raeburn 1588: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1589: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1590: } else {
1.160.6.22 raeburn 1591: $datatable .= '<td> </td><td class="LC_left_item">'.
1592: &mt('Upload:').'<br />';
1.6 raeburn 1593: }
1594: } else {
1.160.6.22 raeburn 1595: $datatable .= '<td> </td><td class="LC_left_item">'.
1596: &mt('Upload:').'<br />';
1.6 raeburn 1597: }
1.9 raeburn 1598: if ($switchserver) {
1599: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1600: } else {
1.135 bisitz 1601: if ($img ne 'login') { # suppress file selection for Log-in header
1602: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1603: }
1.9 raeburn 1604: }
1605: $datatable .= '</td></tr>';
1.6 raeburn 1606: }
1607: $itemcount ++;
1608: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1609: $datatable .= '<tr'.$css_class.'>'.
1610: '<td>'.$choices->{'bgs'}.'</td>';
1611: my $bgs_def;
1612: foreach my $item (@{$bgs}) {
1613: if (!$is_custom->{$item}) {
1.70 raeburn 1614: $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 1615: }
1616: }
1617: if ($bgs_def) {
1.8 raeburn 1618: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1619: } else {
1620: $datatable .= '<td> </td>';
1621: }
1622: $datatable .= '<td class="LC_right_item">'.
1623: '<table border="0"><tr>';
1.160.6.13 raeburn 1624:
1.6 raeburn 1625: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1626: $datatable .= '<td align="center">'.$choices->{$item};
1627: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1628: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1629: $datatable .= ' ';
1.6 raeburn 1630: }
1.160.6.9 raeburn 1631: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1632: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1633: }
1634: $datatable .= '</tr></table></td></tr>';
1635: $itemcount ++;
1636: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1637: $datatable .= '<tr'.$css_class.'>'.
1638: '<td>'.$choices->{'links'}.'</td>';
1639: my $links_def;
1640: foreach my $item (@{$links}) {
1641: if (!$is_custom->{$item}) {
1.30 raeburn 1642: $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 1643: }
1644: }
1645: if ($links_def) {
1.8 raeburn 1646: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1647: } else {
1648: $datatable .= '<td> </td>';
1649: }
1650: $datatable .= '<td class="LC_right_item">'.
1651: '<table border="0"><tr>';
1652: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1653: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1654: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1655: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1656: $datatable.=' ';
1.6 raeburn 1657: }
1.160.6.9 raeburn 1658: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1659: '" /></td>';
1660: }
1.30 raeburn 1661: $$rowtotal += $itemcount;
1.3 raeburn 1662: return $datatable;
1663: }
1664:
1.70 raeburn 1665: sub logo_display_options {
1666: my ($img,$defaults,$designs) = @_;
1667: my $checkedon;
1668: if (ref($defaults) eq 'HASH') {
1669: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1670: if ($defaults->{'showlogo'}{$img}) {
1671: $checkedon = 'checked="checked" ';
1672: }
1673: }
1674: }
1675: if (ref($designs) eq 'HASH') {
1676: if (ref($designs->{'showlogo'}) eq 'HASH') {
1677: if (defined($designs->{'showlogo'}{$img})) {
1678: if ($designs->{'showlogo'}{$img} == 0) {
1679: $checkedon = '';
1680: } elsif ($designs->{'showlogo'}{$img} == 1) {
1681: $checkedon = 'checked="checked" ';
1682: }
1683: }
1684: }
1685: }
1686: return '<br /><label> <input type="checkbox" name="'.
1687: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1688: &mt('show').'</label>'."\n";
1689: }
1690:
1.41 raeburn 1691: sub login_header_options {
1.135 bisitz 1692: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1693: my $output = '';
1.41 raeburn 1694: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1695: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1696: if (!$is_custom->{'textcol'}) {
1697: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1698: ' ';
1699: }
1700: if (!$is_custom->{'bgcol'}) {
1701: $output .= $choices->{'bgcol'}.': '.
1702: '<span id="css_'.$role.'_font" style="background-color: '.
1703: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1704: }
1705: $output .= '<br />';
1706: }
1707: $output .='<br />';
1708: return $output;
1709: }
1710:
1711: sub login_text_colors {
1.160.6.22 raeburn 1712: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1713: my $color_menu = '<table border="0"><tr>';
1714: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1715: $color_menu .= '<td align="center">'.$choices->{$item};
1716: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1717: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1718: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1719: }
1720: $color_menu .= '</tr></table><br />';
1721: return $color_menu;
1722: }
1723:
1724: sub image_changes {
1725: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1726: my $output;
1.135 bisitz 1727: if ($img eq 'login') {
1728: # suppress image for Log-in header
1729: } elsif (!$is_custom) {
1.70 raeburn 1730: if ($img ne 'domlogo') {
1.41 raeburn 1731: $output .= &mt('Default image:').'<br />';
1732: } else {
1733: $output .= &mt('Default in use:').'<br />';
1734: }
1735: }
1.135 bisitz 1736: if ($img eq 'login') { # suppress image for Log-in header
1737: $output .= '<td>'.$logincolors;
1.41 raeburn 1738: } else {
1.135 bisitz 1739: if ($img_import) {
1740: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1741: }
1742: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1743: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1744: if ($is_custom) {
1745: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1746: '<input type="checkbox" name="'.
1747: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1748: '</label> '.&mt('Replace:').'</span><br />';
1749: } else {
1.160.6.22 raeburn 1750: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1751: }
1.41 raeburn 1752: }
1753: return $output;
1754: }
1755:
1.3 raeburn 1756: sub print_quotas {
1.86 raeburn 1757: my ($dom,$settings,$rowtotal,$action) = @_;
1758: my $context;
1759: if ($action eq 'quotas') {
1760: $context = 'tools';
1761: } else {
1762: $context = $action;
1763: }
1.160.6.20 raeburn 1764: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1765: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1766: my $typecount = 0;
1.101 raeburn 1767: my ($css_class,%titles);
1.86 raeburn 1768: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1769: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1770: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1771: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1772: %titles = &courserequest_titles();
1.160.6.5 raeburn 1773: } elsif ($context eq 'requestauthor') {
1774: @usertools = ('author');
1775: @options = ('norequest','approval','automatic');
1776: %titles = &authorrequest_titles();
1.86 raeburn 1777: } else {
1.160.6.4 raeburn 1778: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1779: %titles = &tool_titles();
1.86 raeburn 1780: }
1.26 raeburn 1781: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1782: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1783: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1784: unless (($context eq 'requestcourses') ||
1785: ($context eq 'requestauthor')) {
1.86 raeburn 1786: if (ref($settings) eq 'HASH') {
1787: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1788: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1789: } else {
1790: $currdefquota = $settings->{$type};
1791: }
1.160.6.20 raeburn 1792: if (ref($settings->{authorquota}) eq 'HASH') {
1793: $currauthorquota = $settings->{authorquota}->{$type};
1794: }
1.78 raeburn 1795: }
1.72 raeburn 1796: }
1.3 raeburn 1797: if (defined($usertypes->{$type})) {
1798: $typecount ++;
1799: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1800: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1801: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1802: '<td class="LC_left_item">';
1.101 raeburn 1803: if ($context eq 'requestcourses') {
1804: $datatable .= '<table><tr>';
1805: }
1806: my %cell;
1.72 raeburn 1807: foreach my $item (@usertools) {
1.101 raeburn 1808: if ($context eq 'requestcourses') {
1809: my ($curroption,$currlimit);
1810: if (ref($settings) eq 'HASH') {
1811: if (ref($settings->{$item}) eq 'HASH') {
1812: $curroption = $settings->{$item}->{$type};
1813: if ($curroption =~ /^autolimit=(\d*)$/) {
1814: $currlimit = $1;
1815: }
1816: }
1817: }
1818: if (!$curroption) {
1819: $curroption = 'norequest';
1820: }
1821: $datatable .= '<th>'.$titles{$item}.'</th>';
1822: foreach my $option (@options) {
1823: my $val = $option;
1824: if ($option eq 'norequest') {
1825: $val = 0;
1826: }
1827: if ($option eq 'validate') {
1828: my $canvalidate = 0;
1829: if (ref($validations{$item}) eq 'HASH') {
1830: if ($validations{$item}{$type}) {
1831: $canvalidate = 1;
1832: }
1833: }
1834: next if (!$canvalidate);
1835: }
1836: my $checked = '';
1837: if ($option eq $curroption) {
1838: $checked = ' checked="checked"';
1839: } elsif ($option eq 'autolimit') {
1840: if ($curroption =~ /^autolimit/) {
1841: $checked = ' checked="checked"';
1842: }
1843: }
1844: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1845: '<input type="radio" name="crsreq_'.$item.
1846: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1847: $titles{$option}.'</label>';
1.101 raeburn 1848: if ($option eq 'autolimit') {
1.127 raeburn 1849: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1850: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1851: 'value="'.$currlimit.'" />';
1.101 raeburn 1852: }
1.127 raeburn 1853: $cell{$item} .= '</span> ';
1.103 raeburn 1854: if ($option eq 'autolimit') {
1.127 raeburn 1855: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1856: }
1.101 raeburn 1857: }
1.160.6.5 raeburn 1858: } elsif ($context eq 'requestauthor') {
1859: my $curroption;
1860: if (ref($settings) eq 'HASH') {
1861: $curroption = $settings->{$type};
1862: }
1863: if (!$curroption) {
1864: $curroption = 'norequest';
1865: }
1866: foreach my $option (@options) {
1867: my $val = $option;
1868: if ($option eq 'norequest') {
1869: $val = 0;
1870: }
1871: my $checked = '';
1872: if ($option eq $curroption) {
1873: $checked = ' checked="checked"';
1874: }
1875: $datatable .= '<span class="LC_nobreak"><label>'.
1876: '<input type="radio" name="authorreq_'.$type.
1877: '" value="'.$val.'"'.$checked.' />'.
1878: $titles{$option}.'</label></span> ';
1879: }
1.101 raeburn 1880: } else {
1881: my $checked = 'checked="checked" ';
1882: if (ref($settings) eq 'HASH') {
1883: if (ref($settings->{$item}) eq 'HASH') {
1884: if ($settings->{$item}->{$type} == 0) {
1885: $checked = '';
1886: } elsif ($settings->{$item}->{$type} == 1) {
1887: $checked = 'checked="checked" ';
1888: }
1.78 raeburn 1889: }
1.72 raeburn 1890: }
1.101 raeburn 1891: $datatable .= '<span class="LC_nobreak"><label>'.
1892: '<input type="checkbox" name="'.$context.'_'.$item.
1893: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1894: '</label></span> ';
1.72 raeburn 1895: }
1.101 raeburn 1896: }
1897: if ($context eq 'requestcourses') {
1898: $datatable .= '</tr><tr>';
1899: foreach my $item (@usertools) {
1.106 raeburn 1900: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1901: }
1902: $datatable .= '</tr></table>';
1.72 raeburn 1903: }
1.86 raeburn 1904: $datatable .= '</td>';
1.160.6.5 raeburn 1905: unless (($context eq 'requestcourses') ||
1906: ($context eq 'requestauthor')) {
1.86 raeburn 1907: $datatable .=
1.160.6.20 raeburn 1908: '<td class="LC_right_item">'.
1909: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1910: '<input type="text" name="quota_'.$type.
1.72 raeburn 1911: '" value="'.$currdefquota.
1.160.6.20 raeburn 1912: '" size="5" /></span>'.(' ' x 2).
1913: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1914: '<input type="text" name="authorquota_'.$type.
1915: '" value="'.$currauthorquota.
1916: '" size="5" /></span></td>';
1.86 raeburn 1917: }
1918: $datatable .= '</tr>';
1.3 raeburn 1919: }
1920: }
1921: }
1.160.6.5 raeburn 1922: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1923: $defaultquota = '20';
1.160.6.20 raeburn 1924: $authorquota = '500';
1.86 raeburn 1925: if (ref($settings) eq 'HASH') {
1926: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1927: $defaultquota = $settings->{'defaultquota'}->{'default'};
1928: } elsif (defined($settings->{'default'})) {
1929: $defaultquota = $settings->{'default'};
1930: }
1.160.6.20 raeburn 1931: if (ref($settings->{'authorquota'}) eq 'HASH') {
1932: $authorquota = $settings->{'authorquota'}->{'default'};
1933: }
1.3 raeburn 1934: }
1935: }
1936: $typecount ++;
1937: $css_class = $typecount%2?' class="LC_odd_row"':'';
1938: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1939: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1940: '<td class="LC_left_item">';
1.101 raeburn 1941: if ($context eq 'requestcourses') {
1942: $datatable .= '<table><tr>';
1943: }
1944: my %defcell;
1.72 raeburn 1945: foreach my $item (@usertools) {
1.101 raeburn 1946: if ($context eq 'requestcourses') {
1947: my ($curroption,$currlimit);
1948: if (ref($settings) eq 'HASH') {
1949: if (ref($settings->{$item}) eq 'HASH') {
1950: $curroption = $settings->{$item}->{'default'};
1951: if ($curroption =~ /^autolimit=(\d*)$/) {
1952: $currlimit = $1;
1953: }
1954: }
1955: }
1956: if (!$curroption) {
1957: $curroption = 'norequest';
1958: }
1959: $datatable .= '<th>'.$titles{$item}.'</th>';
1960: foreach my $option (@options) {
1961: my $val = $option;
1962: if ($option eq 'norequest') {
1963: $val = 0;
1964: }
1965: if ($option eq 'validate') {
1966: my $canvalidate = 0;
1967: if (ref($validations{$item}) eq 'HASH') {
1968: if ($validations{$item}{'default'}) {
1969: $canvalidate = 1;
1970: }
1971: }
1972: next if (!$canvalidate);
1973: }
1974: my $checked = '';
1975: if ($option eq $curroption) {
1976: $checked = ' checked="checked"';
1977: } elsif ($option eq 'autolimit') {
1978: if ($curroption =~ /^autolimit/) {
1979: $checked = ' checked="checked"';
1980: }
1981: }
1982: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1983: '<input type="radio" name="crsreq_'.$item.
1984: '_default" value="'.$val.'"'.$checked.' />'.
1985: $titles{$option}.'</label>';
1986: if ($option eq 'autolimit') {
1.127 raeburn 1987: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1988: $item.'_limit_default" size="1" '.
1989: 'value="'.$currlimit.'" />';
1990: }
1.127 raeburn 1991: $defcell{$item} .= '</span> ';
1.104 raeburn 1992: if ($option eq 'autolimit') {
1.127 raeburn 1993: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1994: }
1.101 raeburn 1995: }
1.160.6.5 raeburn 1996: } elsif ($context eq 'requestauthor') {
1997: my $curroption;
1998: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1999: $curroption = $settings->{'default'};
1.160.6.5 raeburn 2000: }
2001: if (!$curroption) {
2002: $curroption = 'norequest';
2003: }
2004: foreach my $option (@options) {
2005: my $val = $option;
2006: if ($option eq 'norequest') {
2007: $val = 0;
2008: }
2009: my $checked = '';
2010: if ($option eq $curroption) {
2011: $checked = ' checked="checked"';
2012: }
2013: $datatable .= '<span class="LC_nobreak"><label>'.
2014: '<input type="radio" name="authorreq_default"'.
2015: ' value="'.$val.'"'.$checked.' />'.
2016: $titles{$option}.'</label></span> ';
2017: }
1.101 raeburn 2018: } else {
2019: my $checked = 'checked="checked" ';
2020: if (ref($settings) eq 'HASH') {
2021: if (ref($settings->{$item}) eq 'HASH') {
2022: if ($settings->{$item}->{'default'} == 0) {
2023: $checked = '';
2024: } elsif ($settings->{$item}->{'default'} == 1) {
2025: $checked = 'checked="checked" ';
2026: }
1.78 raeburn 2027: }
1.72 raeburn 2028: }
1.101 raeburn 2029: $datatable .= '<span class="LC_nobreak"><label>'.
2030: '<input type="checkbox" name="'.$context.'_'.$item.
2031: '" value="default" '.$checked.'/>'.$titles{$item}.
2032: '</label></span> ';
2033: }
2034: }
2035: if ($context eq 'requestcourses') {
2036: $datatable .= '</tr><tr>';
2037: foreach my $item (@usertools) {
1.106 raeburn 2038: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2039: }
1.101 raeburn 2040: $datatable .= '</tr></table>';
1.72 raeburn 2041: }
1.86 raeburn 2042: $datatable .= '</td>';
1.160.6.5 raeburn 2043: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2044: $datatable .= '<td class="LC_right_item">'.
2045: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2046: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2047: $defaultquota.'" size="5" /></span>'.(' ' x2).
2048: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2049: '<input type="text" name="authorquota" value="'.
2050: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2051: }
2052: $datatable .= '</tr>';
1.72 raeburn 2053: $typecount ++;
2054: $css_class = $typecount%2?' class="LC_odd_row"':'';
2055: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2056: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2057: if ($context eq 'requestcourses') {
1.109 raeburn 2058: $datatable .= &mt('(overrides affiliation, if set)').
2059: '</td>'.
2060: '<td class="LC_left_item">'.
2061: '<table><tr>';
1.101 raeburn 2062: } else {
1.109 raeburn 2063: $datatable .= &mt('(overrides affiliation, if checked)').
2064: '</td>'.
2065: '<td class="LC_left_item" colspan="2">'.
2066: '<br />';
1.101 raeburn 2067: }
2068: my %advcell;
1.72 raeburn 2069: foreach my $item (@usertools) {
1.101 raeburn 2070: if ($context eq 'requestcourses') {
2071: my ($curroption,$currlimit);
2072: if (ref($settings) eq 'HASH') {
2073: if (ref($settings->{$item}) eq 'HASH') {
2074: $curroption = $settings->{$item}->{'_LC_adv'};
2075: if ($curroption =~ /^autolimit=(\d*)$/) {
2076: $currlimit = $1;
2077: }
2078: }
2079: }
2080: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2081: my $checked = '';
2082: if ($curroption eq '') {
2083: $checked = ' checked="checked"';
2084: }
2085: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2086: '<input type="radio" name="crsreq_'.$item.
2087: '__LC_adv" value=""'.$checked.' />'.
2088: &mt('No override set').'</label></span> ';
1.101 raeburn 2089: foreach my $option (@options) {
2090: my $val = $option;
2091: if ($option eq 'norequest') {
2092: $val = 0;
2093: }
2094: if ($option eq 'validate') {
2095: my $canvalidate = 0;
2096: if (ref($validations{$item}) eq 'HASH') {
2097: if ($validations{$item}{'_LC_adv'}) {
2098: $canvalidate = 1;
2099: }
2100: }
2101: next if (!$canvalidate);
2102: }
2103: my $checked = '';
1.104 raeburn 2104: if ($val eq $curroption) {
1.101 raeburn 2105: $checked = ' checked="checked"';
2106: } elsif ($option eq 'autolimit') {
2107: if ($curroption =~ /^autolimit/) {
2108: $checked = ' checked="checked"';
2109: }
2110: }
2111: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2112: '<input type="radio" name="crsreq_'.$item.
2113: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2114: $titles{$option}.'</label>';
2115: if ($option eq 'autolimit') {
1.127 raeburn 2116: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2117: $item.'_limit__LC_adv" size="1" '.
2118: 'value="'.$currlimit.'" />';
2119: }
1.127 raeburn 2120: $advcell{$item} .= '</span> ';
1.104 raeburn 2121: if ($option eq 'autolimit') {
1.127 raeburn 2122: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2123: }
1.101 raeburn 2124: }
1.160.6.5 raeburn 2125: } elsif ($context eq 'requestauthor') {
2126: my $curroption;
2127: if (ref($settings) eq 'HASH') {
2128: $curroption = $settings->{'_LC_adv'};
2129: }
2130: my $checked = '';
2131: if ($curroption eq '') {
2132: $checked = ' checked="checked"';
2133: }
2134: $datatable .= '<span class="LC_nobreak"><label>'.
2135: '<input type="radio" name="authorreq__LC_adv"'.
2136: ' value=""'.$checked.' />'.
2137: &mt('No override set').'</label></span> ';
2138: foreach my $option (@options) {
2139: my $val = $option;
2140: if ($option eq 'norequest') {
2141: $val = 0;
2142: }
2143: my $checked = '';
2144: if ($val eq $curroption) {
2145: $checked = ' checked="checked"';
2146: }
2147: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2148: '<input type="radio" name="authorreq__LC_adv"'.
2149: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2150: $titles{$option}.'</label></span> ';
2151: }
1.101 raeburn 2152: } else {
2153: my $checked = 'checked="checked" ';
2154: if (ref($settings) eq 'HASH') {
2155: if (ref($settings->{$item}) eq 'HASH') {
2156: if ($settings->{$item}->{'_LC_adv'} == 0) {
2157: $checked = '';
2158: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2159: $checked = 'checked="checked" ';
2160: }
1.79 raeburn 2161: }
1.72 raeburn 2162: }
1.101 raeburn 2163: $datatable .= '<span class="LC_nobreak"><label>'.
2164: '<input type="checkbox" name="'.$context.'_'.$item.
2165: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2166: '</label></span> ';
2167: }
2168: }
2169: if ($context eq 'requestcourses') {
2170: $datatable .= '</tr><tr>';
2171: foreach my $item (@usertools) {
1.106 raeburn 2172: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2173: }
1.101 raeburn 2174: $datatable .= '</tr></table>';
1.72 raeburn 2175: }
1.98 raeburn 2176: $datatable .= '</td></tr>';
1.30 raeburn 2177: $$rowtotal += $typecount;
1.3 raeburn 2178: return $datatable;
2179: }
2180:
1.160.6.5 raeburn 2181: sub print_requestmail {
2182: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2183: my ($now,$datatable,%currapp);
1.102 raeburn 2184: $now = time;
2185: if (ref($settings) eq 'HASH') {
2186: if (ref($settings->{'notify'}) eq 'HASH') {
2187: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2188: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2189: }
2190: }
2191: }
1.160.6.16 raeburn 2192: my $numinrow = 2;
1.160.6.34 raeburn 2193: my $css_class;
2194: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2195: my $text;
2196: if ($action eq 'requestcourses') {
2197: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2198: } elsif ($action eq 'requestauthor') {
2199: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2200: } else {
1.160.6.34 raeburn 2201: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2202: }
1.160.6.34 raeburn 2203: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2204: ' <td>'.$text.'</td>'.
1.102 raeburn 2205: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2206: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2207: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2208: if ($numdc > 0) {
2209: $datatable .= $table;
1.102 raeburn 2210: } else {
2211: $datatable .= &mt('There are no active Domain Coordinators');
2212: }
2213: $datatable .='</td></tr>';
2214: return $datatable;
2215: }
2216:
1.160.6.30 raeburn 2217: sub print_studentcode {
2218: my ($settings,$rowtotal) = @_;
2219: my $rownum = 0;
2220: my ($output,%current);
2221: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2222: if (ref($settings) eq 'HASH') {
2223: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2224: foreach my $type (@crstypes) {
2225: $current{$type} = $settings->{'uniquecode'}{$type};
2226: }
1.160.6.30 raeburn 2227: }
2228: }
2229: $output .= '<tr>'.
2230: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2231: '<td class="LC_left_item">';
2232: foreach my $type (@crstypes) {
2233: my $check = ' ';
2234: if ($current{$type}) {
2235: $check = ' checked="checked" ';
2236: }
2237: $output .= '<span class="LC_nobreak"><label>'.
2238: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2239: &mt($type).'</label></span>'.(' 'x2).' ';
2240: }
2241: $output .= '</td></tr>';
2242: $$rowtotal ++;
2243: return $output;
2244: }
2245:
2246: sub print_textbookcourses {
1.160.6.46 raeburn 2247: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2248: my $rownum = 0;
2249: my $css_class;
2250: my $itemcount = 1;
2251: my $maxnum = 0;
2252: my $bookshash;
2253: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2254: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2255: }
2256: my %ordered;
2257: if (ref($bookshash) eq 'HASH') {
2258: foreach my $item (keys(%{$bookshash})) {
2259: if (ref($bookshash->{$item}) eq 'HASH') {
2260: my $num = $bookshash->{$item}{'order'};
2261: $ordered{$num} = $item;
2262: }
2263: }
2264: }
2265: my $confname = $dom.'-domainconfig';
2266: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2267: my $maxnum = scalar(keys(%ordered));
2268: my $datatable;
1.160.6.30 raeburn 2269: if (keys(%ordered)) {
2270: my @items = sort { $a <=> $b } keys(%ordered);
2271: for (my $i=0; $i<@items; $i++) {
2272: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2273: my $key = $ordered{$items[$i]};
2274: my %coursehash=&Apache::lonnet::coursedescription($key);
2275: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2276: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2277: if (ref($bookshash->{$key}) eq 'HASH') {
2278: $subject = $bookshash->{$key}->{'subject'};
2279: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2280: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2281: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2282: $author = $bookshash->{$key}->{'author'};
2283: $image = $bookshash->{$key}->{'image'};
2284: if ($image ne '') {
2285: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2286: my $imagethumb = "$path/tn-".$imagefile;
2287: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2288: }
1.160.6.30 raeburn 2289: }
2290: }
1.160.6.46 raeburn 2291: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2292: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2293: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2294: for (my $k=0; $k<=$maxnum; $k++) {
2295: my $vpos = $k+1;
2296: my $selstr;
2297: if ($k == $i) {
2298: $selstr = ' selected="selected" ';
2299: }
2300: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2301: }
2302: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2303: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2304: &mt('Delete?').'</label></span></td>'.
2305: '<td colspan="2">'.
1.160.6.46 raeburn 2306: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2307: (' 'x2).
1.160.6.46 raeburn 2308: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2309: if ($type eq 'textbooks') {
2310: $datatable .= (' 'x2).
1.160.6.47 raeburn 2311: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2312: (' 'x2).
1.160.6.46 raeburn 2313: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2314: (' 'x2).
2315: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2316: if ($image) {
2317: $datatable .= '<span class="LC_nobreak">'.
2318: $imgsrc.
2319: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2320: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2321: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2322: }
2323: if ($switchserver) {
2324: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2325: } else {
2326: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2327: }
1.160.6.30 raeburn 2328: }
1.160.6.46 raeburn 2329: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2330: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2331: $coursetitle.'</span></td></tr>'."\n";
2332: $itemcount ++;
2333: }
2334: }
2335: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2336: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2337: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2338: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2339: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2340: for (my $k=0; $k<$maxnum+1; $k++) {
2341: my $vpos = $k+1;
2342: my $selstr;
2343: if ($k == $maxnum) {
2344: $selstr = ' selected="selected" ';
2345: }
2346: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2347: }
2348: $datatable .= '</select> '."\n".
1.160.6.46 raeburn 2349: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.160.6.30 raeburn 2350: '<td colspan="2">'.
1.160.6.46 raeburn 2351: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2352: (' 'x2).
1.160.6.46 raeburn 2353: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2354: (' 'x2);
2355: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2356: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2357: (' 'x2).
2358: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2359: (' 'x2).
2360: '<span class="LC_nobreak">'.&mt('Image:').' ';
2361: if ($switchserver) {
2362: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2363: } else {
2364: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2365: }
1.160.6.30 raeburn 2366: }
2367: $datatable .= '</span>'."\n".
2368: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2369: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2370: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2371: &Apache::loncommon::selectcourse_link
1.160.6.46 raeburn 2372: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.160.6.30 raeburn 2373: '</span></td>'."\n".
2374: '</tr>'."\n";
2375: $itemcount ++;
2376: return $datatable;
2377: }
2378:
2379: sub textbookcourses_javascript {
1.160.6.46 raeburn 2380: my ($settings) = @_;
2381: return unless(ref($settings) eq 'HASH');
2382: my (%ordered,%total,%jstext);
2383: foreach my $type ('textbooks','templates') {
2384: $total{$type} = 0;
2385: if (ref($settings->{$type}) eq 'HASH') {
2386: foreach my $item (keys(%{$settings->{$type}})) {
2387: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2388: my $num = $settings->{$type}->{$item}{'order'};
2389: $ordered{$type}{$num} = $item;
2390: }
2391: }
2392: $total{$type} = scalar(keys(%{$settings->{$type}}));
2393: }
2394: my @jsarray = ();
2395: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2396: push(@jsarray,$ordered{$type}{$item});
2397: }
2398: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2399: }
2400: return <<"ENDSCRIPT";
2401: <script type="text/javascript">
2402: // <![CDATA[
1.160.6.46 raeburn 2403: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2404: var changedVal;
1.160.6.46 raeburn 2405: $jstext{'textbooks'};
2406: $jstext{'templates'};
2407: var newpos;
2408: var maxh;
2409: if (caller == 'textbooks') {
2410: newpos = 'textbooks_addbook_pos';
2411: maxh = 1 + $total{'textbooks'};
2412: } else {
2413: newpos = 'templates_addbook_pos';
2414: maxh = 1 + $total{'templates'};
2415: }
1.160.6.30 raeburn 2416: var current = new Array;
2417: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2418: if (item == newpos) {
2419: changedVal = newitemVal;
2420: } else {
2421: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2422: current[newitemVal] = newpos;
2423: }
1.160.6.46 raeburn 2424: if (caller == 'textbooks') {
2425: for (var i=0; i<textbooks.length; i++) {
2426: var elementName = 'textbooks_'+textbooks[i];
2427: if (elementName != item) {
2428: if (form.elements[elementName]) {
2429: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2430: current[currVal] = elementName;
2431: }
2432: }
2433: }
2434: }
2435: if (caller == 'templates') {
2436: for (var i=0; i<templates.length; i++) {
2437: var elementName = 'templates_'+templates[i];
2438: if (elementName != item) {
2439: if (form.elements[elementName]) {
2440: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2441: current[currVal] = elementName;
2442: }
1.160.6.30 raeburn 2443: }
2444: }
2445: }
2446: var oldVal;
2447: for (var j=0; j<maxh; j++) {
2448: if (current[j] == undefined) {
2449: oldVal = j;
2450: }
2451: }
2452: if (oldVal < changedVal) {
2453: for (var k=oldVal+1; k<=changedVal ; k++) {
2454: var elementName = current[k];
2455: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2456: }
2457: } else {
2458: for (var k=changedVal; k<oldVal; k++) {
2459: var elementName = current[k];
2460: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2461: }
2462: }
2463: return;
2464: }
2465:
2466: // ]]>
2467: </script>
2468:
2469: ENDSCRIPT
2470: }
2471:
1.160.6.84.2. (raeburn 2472:): sub ltitools_javascript {
2473:): my ($settings) = @_;
2474:): return unless(ref($settings) eq 'HASH');
2475:): my (%ordered,$total,%jstext);
2476:): $total = 0;
2477:): foreach my $item (keys(%{$settings})) {
2478:): if (ref($settings->{$item}) eq 'HASH') {
2479:): my $num = $settings->{$item}{'order'};
2480:): $ordered{$num} = $item;
2481:): }
2482:): }
2483:): $total = scalar(keys(%{$settings}));
2484:): my @jsarray = ();
2485:): foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2486:): push(@jsarray,$ordered{$item});
2487:): }
2488:): my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2489:): return <<"ENDSCRIPT";
2490:): <script type="text/javascript">
2491:): // <![CDATA[
2492:): function reorderLTI(form,item) {
2493:): var changedVal;
2494:): $jstext
2495:): var newpos = 'ltitools_add_pos';
2496:): var maxh = 1 + $total;
2497:): var current = new Array;
2498:): var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2499:): if (item == newpos) {
2500:): changedVal = newitemVal;
2501:): } else {
2502:): changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2503:): current[newitemVal] = newpos;
2504:): }
2505:): for (var i=0; i<ltitools.length; i++) {
2506:): var elementName = 'ltitools_'+ltitools[i];
2507:): if (elementName != item) {
2508:): if (form.elements[elementName]) {
2509:): var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2510:): current[currVal] = elementName;
2511:): }
2512:): }
2513:): }
2514:): var oldVal;
2515:): for (var j=0; j<maxh; j++) {
2516:): if (current[j] == undefined) {
2517:): oldVal = j;
2518:): }
2519:): }
2520:): if (oldVal < changedVal) {
2521:): for (var k=oldVal+1; k<=changedVal ; k++) {
2522:): var elementName = current[k];
2523:): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2524:): }
2525:): } else {
2526:): for (var k=changedVal; k<oldVal; k++) {
2527:): var elementName = current[k];
2528:): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2529:): }
2530:): }
2531:): return;
2532:): }
2533:):
2534:): // ]]>
2535:): </script>
2536:):
2537:): ENDSCRIPT
2538:): }
2539:):
1.3 raeburn 2540: sub print_autoenroll {
1.30 raeburn 2541: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2542: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 2543: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2544: if (ref($settings) eq 'HASH') {
2545: if (exists($settings->{'run'})) {
2546: if ($settings->{'run'} eq '0') {
2547: $runoff = ' checked="checked" ';
2548: $runon = ' ';
2549: } else {
2550: $runon = ' checked="checked" ';
2551: $runoff = ' ';
2552: }
2553: } else {
2554: if ($autorun) {
2555: $runon = ' checked="checked" ';
2556: $runoff = ' ';
2557: } else {
2558: $runoff = ' checked="checked" ';
2559: $runon = ' ';
2560: }
2561: }
1.129 raeburn 2562: if (exists($settings->{'co-owners'})) {
2563: if ($settings->{'co-owners'} eq '0') {
2564: $coownersoff = ' checked="checked" ';
2565: $coownerson = ' ';
2566: } else {
2567: $coownerson = ' checked="checked" ';
2568: $coownersoff = ' ';
2569: }
2570: } else {
2571: $coownersoff = ' checked="checked" ';
2572: $coownerson = ' ';
2573: }
1.3 raeburn 2574: if (exists($settings->{'sender_domain'})) {
2575: $defdom = $settings->{'sender_domain'};
2576: }
1.160.6.68 raeburn 2577: if (exists($settings->{'autofailsafe'})) {
2578: $failsafe = $settings->{'autofailsafe'};
2579: }
1.14 raeburn 2580: } else {
2581: if ($autorun) {
2582: $runon = ' checked="checked" ';
2583: $runoff = ' ';
2584: } else {
2585: $runoff = ' checked="checked" ';
2586: $runon = ' ';
2587: }
1.3 raeburn 2588: }
2589: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2590: my $notif_sender;
2591: if (ref($settings) eq 'HASH') {
2592: $notif_sender = $settings->{'sender_uname'};
2593: }
1.3 raeburn 2594: my $datatable='<tr class="LC_odd_row">'.
2595: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2596: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2597: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2598: $runon.' value="1" />'.&mt('Yes').'</label> '.
2599: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2600: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2601: '</tr><tr>'.
2602: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2603: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2604: &mt('username').': '.
2605: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2606: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2607: ': '.$domform.'</span></td></tr>'.
2608: '<tr class="LC_odd_row">'.
2609: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2610: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2611: '<input type="radio" name="autoassign_coowners"'.
2612: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2613: '<label><input type="radio" name="autoassign_coowners"'.
2614: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 2615: '</tr><tr>'.
2616: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2617: '<td class="LC_right_item"><span class="LC_nobreak">'.
2618: '<input type="text" name="autoenroll_failsafe"'.
2619: ' value="'.$failsafe.'" size="4" /></td></tr>';
2620: $$rowtotal += 4;
1.3 raeburn 2621: return $datatable;
2622: }
2623:
2624: sub print_autoupdate {
1.30 raeburn 2625: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2626: my $datatable;
2627: if ($position eq 'top') {
2628: my $updateon = ' ';
2629: my $updateoff = ' checked="checked" ';
2630: my $classlistson = ' ';
2631: my $classlistsoff = ' checked="checked" ';
2632: if (ref($settings) eq 'HASH') {
2633: if ($settings->{'run'} eq '1') {
2634: $updateon = $updateoff;
2635: $updateoff = ' ';
2636: }
2637: if ($settings->{'classlists'} eq '1') {
2638: $classlistson = $classlistsoff;
2639: $classlistsoff = ' ';
2640: }
2641: }
2642: my %title = (
2643: run => 'Auto-update active?',
2644: classlists => 'Update information in classlists?',
2645: );
2646: $datatable = '<tr class="LC_odd_row">'.
2647: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2648: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2649: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2650: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2651: '<label><input type="radio" name="autoupdate_run"'.
2652: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2653: '</tr><tr>'.
2654: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2655: '<td class="LC_right_item"><span class="LC_nobreak">'.
2656: '<label><input type="radio" name="classlists"'.
2657: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2658: '<label><input type="radio" name="classlists"'.
2659: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2660: '</tr>';
1.30 raeburn 2661: $$rowtotal += 2;
1.131 raeburn 2662: } elsif ($position eq 'middle') {
2663: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2664: my $numinrow = 3;
2665: my $locknamesettings;
2666: $datatable .= &insttypes_row($settings,$types,$usertypes,
2667: $dom,$numinrow,$othertitle,
1.160.6.84.2. (raeburn 2668:): 'lockablenames',$rowtotal);
1.131 raeburn 2669: $$rowtotal ++;
1.3 raeburn 2670: } else {
1.44 raeburn 2671: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2672: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2673: 'permanentemail','id');
1.33 raeburn 2674: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2675: my $numrows = 0;
1.26 raeburn 2676: if (ref($types) eq 'ARRAY') {
2677: if (@{$types} > 0) {
2678: $datatable =
2679: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2680: \@fields,$types,\$numrows);
1.30 raeburn 2681: $$rowtotal += @{$types};
1.26 raeburn 2682: }
1.3 raeburn 2683: }
2684: $datatable .=
2685: &usertype_update_row($settings,{'default' => $othertitle},
2686: \%fieldtitles,\@fields,['default'],
2687: \$numrows);
1.30 raeburn 2688: $$rowtotal ++;
1.3 raeburn 2689: }
2690: return $datatable;
2691: }
2692:
1.125 raeburn 2693: sub print_autocreate {
2694: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2695: my (%createon,%createoff,%currhash);
1.125 raeburn 2696: my @types = ('xml','req');
2697: if (ref($settings) eq 'HASH') {
2698: foreach my $item (@types) {
2699: $createoff{$item} = ' checked="checked" ';
2700: $createon{$item} = ' ';
2701: if (exists($settings->{$item})) {
2702: if ($settings->{$item}) {
2703: $createon{$item} = ' checked="checked" ';
2704: $createoff{$item} = ' ';
2705: }
2706: }
2707: }
1.160.6.16 raeburn 2708: if ($settings->{'xmldc'} ne '') {
2709: $currhash{$settings->{'xmldc'}} = 1;
2710: }
1.125 raeburn 2711: } else {
2712: foreach my $item (@types) {
2713: $createoff{$item} = ' checked="checked" ';
2714: $createon{$item} = ' ';
2715: }
2716: }
2717: $$rowtotal += 2;
1.160.6.16 raeburn 2718: my $numinrow = 2;
1.125 raeburn 2719: my $datatable='<tr class="LC_odd_row">'.
2720: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2721: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2722: '<input type="radio" name="autocreate_xml"'.
2723: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2724: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2725: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2726: '</td></tr><tr>'.
2727: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2728: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2729: '<input type="radio" name="autocreate_req"'.
2730: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2731: '<label><input type="radio" name="autocreate_req"'.
2732: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2733: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2734: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2735: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2736: if ($numdc > 1) {
1.160.6.50 raeburn 2737: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2738: '</td><td class="LC_left_item">';
1.125 raeburn 2739: } else {
1.160.6.50 raeburn 2740: $datatable .= &mt('Course creation processed as:').
2741: '</td><td class="LC_right_item">';
1.125 raeburn 2742: }
1.160.6.50 raeburn 2743: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2744: $$rowtotal += $rows;
1.125 raeburn 2745: return $datatable;
2746: }
2747:
1.23 raeburn 2748: sub print_directorysrch {
1.160.6.72 raeburn 2749: my ($position,$dom,$settings,$rowtotal) = @_;
2750: my $datatable;
2751: if ($position eq 'top') {
2752: my $instsrchon = ' ';
2753: my $instsrchoff = ' checked="checked" ';
2754: my ($exacton,$containson,$beginson);
2755: my $instlocalon = ' ';
2756: my $instlocaloff = ' checked="checked" ';
2757: if (ref($settings) eq 'HASH') {
2758: if ($settings->{'available'} eq '1') {
2759: $instsrchon = $instsrchoff;
2760: $instsrchoff = ' ';
2761: }
2762: if ($settings->{'localonly'} eq '1') {
2763: $instlocalon = $instlocaloff;
2764: $instlocaloff = ' ';
2765: }
2766: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2767: foreach my $type (@{$settings->{'searchtypes'}}) {
2768: if ($type eq 'exact') {
2769: $exacton = ' checked="checked" ';
2770: } elsif ($type eq 'contains') {
2771: $containson = ' checked="checked" ';
2772: } elsif ($type eq 'begins') {
2773: $beginson = ' checked="checked" ';
2774: }
2775: }
2776: } else {
2777: if ($settings->{'searchtypes'} eq 'exact') {
2778: $exacton = ' checked="checked" ';
2779: } elsif ($settings->{'searchtypes'} eq 'contains') {
2780: $containson = ' checked="checked" ';
2781: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2782: $exacton = ' checked="checked" ';
2783: $containson = ' checked="checked" ';
2784: }
2785: }
1.23 raeburn 2786: }
1.160.6.72 raeburn 2787: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2788: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2789:
1.160.6.72 raeburn 2790: my $numinrow = 4;
2791: my $cansrchrow = 0;
2792: $datatable='<tr class="LC_odd_row">'.
2793: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2794: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2795: '<input type="radio" name="dirsrch_available"'.
2796: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2797: '<label><input type="radio" name="dirsrch_available"'.
2798: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2799: '</tr><tr>'.
2800: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2801: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2802: '<input type="radio" name="dirsrch_instlocalonly"'.
2803: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2804: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2805: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2806: '</tr>';
2807: $$rowtotal += 2;
2808: if (ref($usertypes) eq 'HASH') {
2809: if (keys(%{$usertypes}) > 0) {
2810: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.84.2. (raeburn 2811:): $numinrow,$othertitle,'cansearch',
2812:): $rowtotal);
1.160.6.72 raeburn 2813: $cansrchrow = 1;
2814: }
1.26 raeburn 2815: }
1.160.6.72 raeburn 2816: if ($cansrchrow) {
2817: $$rowtotal ++;
2818: $datatable .= '<tr>';
2819: } else {
2820: $datatable .= '<tr class="LC_odd_row">';
2821: }
2822: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2823: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2824: foreach my $title (@{$titleorder}) {
2825: if (defined($searchtitles->{$title})) {
2826: my $check = ' ';
2827: if (ref($settings) eq 'HASH') {
2828: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2829: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2830: $check = ' checked="checked" ';
2831: }
1.39 raeburn 2832: }
1.25 raeburn 2833: }
1.160.6.72 raeburn 2834: $datatable .= '<td class="LC_left_item">'.
2835: '<span class="LC_nobreak"><label>'.
2836: '<input type="checkbox" name="searchby" '.
2837: 'value="'.$title.'"'.$check.'/>'.
2838: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2839: }
2840: }
1.160.6.72 raeburn 2841: $datatable .= '</tr></table></td></tr>';
2842: $$rowtotal ++;
2843: if ($cansrchrow) {
2844: $datatable .= '<tr class="LC_odd_row">';
2845: } else {
2846: $datatable .= '<tr>';
2847: }
2848: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2849: '<td class="LC_left_item" colspan="2">'.
2850: '<span class="LC_nobreak"><label>'.
2851: '<input type="checkbox" name="searchtypes" '.
2852: $exacton.' value="exact" />'.&mt('Exact match').
2853: '</label> '.
2854: '<label><input type="checkbox" name="searchtypes" '.
2855: $beginson.' value="begins" />'.&mt('Begins with').
2856: '</label> '.
2857: '<label><input type="checkbox" name="searchtypes" '.
2858: $containson.' value="contains" />'.&mt('Contains').
2859: '</label></span></td></tr>';
2860: $$rowtotal ++;
1.26 raeburn 2861: } else {
1.160.6.72 raeburn 2862: my $domsrchon = ' checked="checked" ';
2863: my $domsrchoff = ' ';
2864: my $domlocalon = ' ';
2865: my $domlocaloff = ' checked="checked" ';
2866: if (ref($settings) eq 'HASH') {
2867: if ($settings->{'lclocalonly'} eq '1') {
2868: $domlocalon = $domlocaloff;
2869: $domlocaloff = ' ';
2870: }
2871: if ($settings->{'lcavailable'} eq '0') {
2872: $domsrchoff = $domsrchon;
2873: $domsrchon = ' ';
2874: }
2875: }
2876: $datatable='<tr class="LC_odd_row">'.
2877: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2878: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2879: '<input type="radio" name="dirsrch_domavailable"'.
2880: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2881: '<label><input type="radio" name="dirsrch_domavailable"'.
2882: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2883: '</tr><tr>'.
2884: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2885: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2886: '<input type="radio" name="dirsrch_domlocalonly"'.
2887: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2888: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2889: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2890: '</tr>';
2891: $$rowtotal += 2;
1.26 raeburn 2892: }
1.25 raeburn 2893: return $datatable;
2894: }
2895:
1.28 raeburn 2896: sub print_contacts {
1.160.6.78 raeburn 2897: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 2898: my $datatable;
2899: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 2900: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
2901: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
2902: if ($position eq 'top') {
2903: if (ref($settings) eq 'HASH') {
2904: foreach my $item (@contacts) {
2905: if (exists($settings->{$item})) {
2906: $to{$item} = $settings->{$item};
2907: }
1.28 raeburn 2908: }
2909: }
1.160.6.78 raeburn 2910: } elsif ($position eq 'middle') {
2911: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
2912: 'updatesmail','idconflictsmail');
1.28 raeburn 2913: foreach my $type (@mailings) {
1.160.6.78 raeburn 2914: $otheremails{$type} = '';
2915: }
2916: } else {
2917: @mailings = ('helpdeskmail','otherdomsmail');
2918: foreach my $type (@mailings) {
2919: $otheremails{$type} = '';
2920: }
2921: $bccemails{'helpdeskmail'} = '';
2922: $bccemails{'otherdomsmail'} = '';
2923: $includestr{'helpdeskmail'} = '';
2924: $includestr{'otherdomsmail'} = '';
2925: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
2926: }
2927: if (ref($settings) eq 'HASH') {
2928: unless ($position eq 'top') {
2929: foreach my $type (@mailings) {
2930: if (exists($settings->{$type})) {
2931: if (ref($settings->{$type}) eq 'HASH') {
2932: foreach my $item (@contacts) {
2933: if ($settings->{$type}{$item}) {
2934: $checked{$type}{$item} = ' checked="checked" ';
2935: }
1.28 raeburn 2936: }
1.160.6.78 raeburn 2937: $otheremails{$type} = $settings->{$type}{'others'};
2938: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2939: $bccemails{$type} = $settings->{$type}{'bcc'};
2940: if ($settings->{$type}{'include'} ne '') {
2941: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2942: $includestr{$type} = &unescape($includestr{$type});
2943: }
2944: }
2945: }
2946: } elsif ($type eq 'lonstatusmail') {
2947: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2948: }
2949: }
2950: }
2951: if ($position eq 'bottom') {
2952: foreach my $type (@mailings) {
2953: $bccemails{$type} = $settings->{$type}{'bcc'};
2954: if ($settings->{$type}{'include'} ne '') {
2955: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2956: $includestr{$type} = &unescape($includestr{$type});
2957: }
2958: }
2959: if (ref($settings->{'helpform'}) eq 'HASH') {
2960: if (ref($fields) eq 'ARRAY') {
2961: foreach my $field (@{$fields}) {
2962: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 2963: }
1.160.6.78 raeburn 2964: }
2965: if (exists($settings->{'helpform'}{'maxsize'})) {
2966: $maxsize = $settings->{'helpform'}{'maxsize'};
2967: } else {
2968: $maxsize = '1.0';
2969: }
2970: } else {
2971: if (ref($fields) eq 'ARRAY') {
2972: foreach my $field (@{$fields}) {
2973: $currfield{$field} = 'yes';
1.134 raeburn 2974: }
1.28 raeburn 2975: }
1.160.6.78 raeburn 2976: $maxsize = '1.0';
1.28 raeburn 2977: }
2978: }
2979: } else {
1.160.6.78 raeburn 2980: if ($position eq 'top') {
2981: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2982: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2983: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2984: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
2985: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2986: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
2987: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2988: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
2989: } elsif ($position eq 'bottom') {
2990: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2991: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
2992: if (ref($fields) eq 'ARRAY') {
2993: foreach my $field (@{$fields}) {
2994: $currfield{$field} = 'yes';
2995: }
2996: }
2997: $maxsize = '1.0';
2998: }
1.28 raeburn 2999: }
3000: my ($titles,$short_titles) = &contact_titles();
3001: my $rownum = 0;
3002: my $css_class;
1.160.6.78 raeburn 3003: if ($position eq 'top') {
3004: foreach my $item (@contacts) {
3005: $css_class = $rownum%2?' class="LC_odd_row"':'';
3006: $datatable .= '<tr'.$css_class.'>'.
3007: '<td><span class="LC_nobreak">'.$titles->{$item}.
3008: '</span></td><td class="LC_right_item">'.
3009: '<input type="text" name="'.$item.'" value="'.
3010: $to{$item}.'" /></td></tr>';
3011: $rownum ++;
3012: }
1.160.6.84.2. (raeburn 3013:): } elsif ($position eq 'bottom') {
3014:): $css_class = $rownum%2?' class="LC_odd_row"':'';
3015:): $datatable .= '<tr'.$css_class.'>'.
3016:): '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3017:): &mt('(e-mail, subject, and description always shown)').
3018:): '</td><td class="LC_left_item">';
3019:): if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3020:): (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3021:): $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3022:): foreach my $field (@{$fields}) {
3023:): $datatable .= '<tr><td>'.$fieldtitles->{$field};
3024:): if (($field eq 'screenshot') || ($field eq 'cc')) {
3025:): $datatable .= ' '.&mt('(logged-in users)');
3026:): }
3027:): $datatable .='</td><td>';
3028:): my $clickaction;
3029:): if ($field eq 'screenshot') {
3030:): $clickaction = ' onclick="screenshotSize(this);"';
3031:): }
3032:): if (ref($possoptions->{$field}) eq 'ARRAY') {
3033:): foreach my $option (@{$possoptions->{$field}}) {
3034:): my $checked;
3035:): if ($currfield{$field} eq $option) {
3036:): $checked = ' checked="checked"';
3037:): }
3038:): $datatable .= '<span class="LC_nobreak"><label>'.
3039:): '<input type="radio" name="helpform_'.$field.'" '.
3040:): 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3041:): '</label></span>'.(' 'x2);
3042:): }
3043:): }
3044:): if ($field eq 'screenshot') {
3045:): my $display;
3046:): if ($currfield{$field} eq 'no') {
3047:): $display = ' style="display:none"';
3048:): }
3049:): $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
3050:): '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3051:): '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3052:): }
3053:): $datatable .= '</td></tr>';
3054:): }
3055:): $datatable .= '</table>';
3056:): }
3057:): $datatable .= '</td></tr>'."\n";
3058:): $rownum ++;
3059:): }
3060:): unless ($position eq 'top') {
1.160.6.78 raeburn 3061: foreach my $type (@mailings) {
3062: $css_class = $rownum%2?' class="LC_odd_row"':'';
3063: $datatable .= '<tr'.$css_class.'>'.
3064: '<td><span class="LC_nobreak">'.
3065: $titles->{$type}.': </span></td>'.
3066: '<td class="LC_left_item">';
3067: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3068: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3069: }
3070: $datatable .= '<span class="LC_nobreak">';
3071: foreach my $item (@contacts) {
3072: $datatable .= '<label>'.
3073: '<input type="checkbox" name="'.$type.'"'.
3074: $checked{$type}{$item}.
3075: ' value="'.$item.'" />'.$short_titles->{$item}.
3076: '</label> ';
3077: }
3078: $datatable .= '</span><br />'.&mt('Others').': '.
3079: '<input type="text" name="'.$type.'_others" '.
3080: 'value="'.$otheremails{$type}.'" />';
3081: my %locchecked;
3082: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3083: foreach my $loc ('s','b') {
3084: if ($includeloc{$type} eq $loc) {
3085: $locchecked{$loc} = ' checked="checked"';
3086: last;
3087: }
3088: }
3089: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3090: '<input type="text" name="'.$type.'_bcc" '.
3091: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3092: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3093: &mt('Text automatically added to e-mail:').' '.
3094: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
3095: '<span class="LC_nobreak">'.&mt('Location:').' '.
3096: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3097: (' 'x2).
3098: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3099: '</span></fieldset>';
3100: }
3101: $datatable .= '</td></tr>'."\n";
3102: $rownum ++;
3103: }
1.28 raeburn 3104: }
1.160.6.78 raeburn 3105: if ($position eq 'middle') {
3106: my %choices;
3107: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
3108: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3109: &mt('LON-CAPA core group - MSU'),600,500));
3110: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3111: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3112: &mt('LON-CAPA core group - MSU'),600,500));
3113: my @toggles = ('reporterrors','reportupdates');
3114: my %defaultchecked = ('reporterrors' => 'on',
3115: 'reportupdates' => 'on');
3116: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3117: \%choices,$rownum);
3118: $datatable .= $reports;
3119: } elsif ($position eq 'bottom') {
1.160.6.84.2. (raeburn 3120:): my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3121:): my (@posstypes,%usertypeshash);
3122:): if (ref($types) eq 'ARRAY') {
3123:): @posstypes = @{$types};
3124:): }
3125:): if (@posstypes) {
3126:): if (ref($usertypes) eq 'HASH') {
3127:): %usertypeshash = %{$usertypes};
3128:): }
3129:): my @overridden;
3130:): my $numinrow = 4;
3131:): if (ref($settings) eq 'HASH') {
3132:): if (ref($settings->{'overrides'}) eq 'HASH') {
3133:): foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3134:): if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3135:): push(@overridden,$key);
3136:): foreach my $item (@contacts) {
3137:): if ($settings->{'overrides'}{$key}{$item}) {
3138:): $checked{'override_'.$key}{$item} = ' checked="checked" ';
3139:): }
3140:): }
3141:): $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3142:): $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3143:): $includeloc{'override_'.$key} = '';
3144:): $includestr{'override_'.$key} = '';
3145:): if ($settings->{'overrides'}{$key}{'include'} ne '') {
3146:): ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3147:): split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3148:): $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3149:): }
1.160.6.78 raeburn 3150: }
3151: }
3152: }
1.160.6.84.2. (raeburn 3153:): }
3154:): my $customclass = 'LC_helpdesk_override';
3155:): my $optionsprefix = 'LC_options_helpdesk_';
3156:):
3157:): my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3158:):
3159:): $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3160:): $numinrow,$othertitle,'overrides',
3161:): \$rownum,$onclicktypes,$customclass);
3162:): $rownum ++;
3163:): $usertypeshash{'default'} = $othertitle;
3164:): foreach my $status (@posstypes) {
3165:): my $css_class;
3166:): if ($rownum%2) {
3167:): $css_class = 'LC_odd_row ';
3168:): }
3169:): $css_class .= $customclass;
3170:): my $rowid = $optionsprefix.$status;
3171:): my $hidden = 1;
3172:): my $currstyle = 'display:none';
3173:): if (grep(/^\Q$status\E$/,@overridden)) {
3174:): $currstyle = 'display:table-row';
3175:): $hidden = 0;
3176:): }
3177:): my $key = 'override_'.$status;
3178:): $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3179:): $includeloc{$key},$includestr{$key},$status,$rowid,
3180:): $usertypeshash{$status},$css_class,$currstyle,
3181:): \@contacts,$short_titles);
3182:): unless ($hidden) {
3183:): $rownum ++;
1.160.6.78 raeburn 3184: }
3185: }
1.134 raeburn 3186: }
1.28 raeburn 3187: }
1.30 raeburn 3188: $$rowtotal += $rownum;
1.28 raeburn 3189: return $datatable;
3190: }
3191:
1.160.6.84.2. (raeburn 3192:): sub overridden_helpdesk {
3193:): my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3194:): $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3195:): my $class = 'LC_left_item';
3196:): if ($css_class) {
3197:): $css_class = ' class="'.$css_class.'"';
3198:): }
3199:): if ($rowid) {
3200:): $rowid = ' id="'.$rowid.'"';
3201:): }
3202:): if ($rowstyle) {
3203:): $rowstyle = ' style="'.$rowstyle.'"';
3204:): }
3205:): my ($output,$description);
3206:): $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3207:): $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3208:): "<td>$description</td>\n".
3209:): '<td class="'.$class.'" colspan="2">'.
3210:): '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3211:): '<span class="LC_nobreak">';
3212:): if (ref($contacts) eq 'ARRAY') {
3213:): foreach my $item (@{$contacts}) {
3214:): my $check;
3215:): if (ref($checked) eq 'HASH') {
3216:): $check = $checked->{$item};
3217:): }
3218:): my $title;
3219:): if (ref($short_titles) eq 'HASH') {
3220:): $title = $short_titles->{$item};
3221:): }
3222:): $output .= '<label>'.
3223:): '<input type="checkbox" name="override_'.$type.'"'.$check.
3224:): ' value="'.$item.'" />'.$title.'</label> ';
3225:): }
3226:): }
3227:): $output .= '</span><br />'.&mt('Others').': '.
3228:): '<input type="text" name="override_'.$type.'_others" '.
3229:): 'value="'.$otheremails.'" />';
3230:): my %locchecked;
3231:): foreach my $loc ('s','b') {
3232:): if ($includeloc eq $loc) {
3233:): $locchecked{$loc} = ' checked="checked"';
3234:): last;
3235:): }
3236:): }
3237:): $output .= '<br />'.&mt('Bcc:').(' 'x6).
3238:): '<input type="text" name="override_'.$type.'_bcc" '.
3239:): 'value="'.$bccemails.'" /></fieldset>'.
3240:): '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3241:): &mt('Text automatically added to e-mail:').' '.
3242:): '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br >'.
3243:): '<span class="LC_nobreak">'.&mt('Location:').' '.
3244:): '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3245:): (' 'x2).
3246:): '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3247:): '</span></fieldset>'.
3248:): '</td></tr>'."\n";
3249:): return $output;
3250:): }
3251:):
1.160.6.78 raeburn 3252: sub contacts_javascript {
3253: return <<"ENDSCRIPT";
3254:
3255: <script type="text/javascript">
3256: // <![CDATA[
3257:
3258: function screenshotSize(field) {
3259: if (document.getElementById('help_screenshotsize')) {
3260: if (field.value == 'no') {
3261: document.getElementById('help_screenshotsize').style.display="none";
3262: } else {
3263: document.getElementById('help_screenshotsize').style.display="";
3264: }
3265: }
3266: return;
3267: }
3268:
1.160.6.84.2. (raeburn 3269:): function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3270:): if (form.elements[checkbox].length != undefined) {
3271:): var count = 0;
3272:): if (docount) {
3273:): for (var i=0; i<form.elements[checkbox].length; i++) {
3274:): if (form.elements[checkbox][i].checked) {
3275:): count ++;
3276:): }
3277:): }
3278:): }
3279:): for (var i=0; i<form.elements[checkbox].length; i++) {
3280:): var type = form.elements[checkbox][i].value;
3281:): if (document.getElementById(prefix+type)) {
3282:): if (form.elements[checkbox][i].checked) {
3283:): document.getElementById(prefix+type).style.display = 'table-row';
3284:): if (count % 2 == 1) {
3285:): document.getElementById(prefix+type).className = target+' LC_odd_row';
3286:): } else {
3287:): document.getElementById(prefix+type).className = target;
3288:): }
3289:): count ++;
3290:): } else {
3291:): document.getElementById(prefix+type).style.display = 'none';
3292:): }
3293:): }
3294:): }
3295:): }
3296:): return;
3297:): }
3298:):
3299:):
1.160.6.78 raeburn 3300: // ]]>
3301: </script>
3302:
3303: ENDSCRIPT
3304: }
3305:
1.118 jms 3306: sub print_helpsettings {
1.160.6.73 raeburn 3307: my ($position,$dom,$settings,$rowtotal) = @_;
3308: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 3309: my $formname = 'display';
1.160.6.5 raeburn 3310: my ($datatable,$itemcount);
1.160.6.73 raeburn 3311: if ($position eq 'top') {
3312: $itemcount = 1;
3313: my (%choices,%defaultchecked,@toggles);
3314: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3315: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3316: &mt('LON-CAPA bug tracker'),600,500));
3317: %defaultchecked = ('submitbugs' => 'on');
3318: @toggles = ('submitbugs');
3319: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3320: \%choices,$itemcount);
3321: $$rowtotal ++;
3322: } else {
3323: my $css_class;
3324: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 3325: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 3326: if (ref($settings) eq 'HASH') {
3327: if (ref($settings->{'adhoc'}) eq 'HASH') {
3328: %current = %{$settings->{'adhoc'}};
3329: }
1.160.6.77 raeburn 3330: }
3331: my $count = 0;
3332: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 3333: if ($key=~/^rolesdef\_(\w+)$/) {
3334: my $rolename = $1;
1.160.6.77 raeburn 3335: my (%privs,$order);
1.160.6.73 raeburn 3336: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3337: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 3338: if (ref($current{$rolename}) eq 'HASH') {
3339: $order = $current{$rolename}{'order'};
3340: }
3341: if ($order eq '') {
3342: $order = $count;
3343: }
3344: $ordered{$order} = $rolename;
3345: $count++;
1.160.6.73 raeburn 3346: }
3347: }
1.160.6.77 raeburn 3348: my $maxnum = scalar(keys(%ordered));
3349: my @roles_by_num = ();
3350: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3351: push(@roles_by_num,$item);
3352: }
3353: my $context = 'domprefs';
3354: my $crstype = 'Course';
3355: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 3356: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 3357: my ($numstatustypes,@jsarray);
3358: if (ref($types) eq 'ARRAY') {
3359: if (@{$types} > 0) {
3360: $numstatustypes = scalar(@{$types});
3361: push(@accesstypes,'status');
3362: @jsarray = ('bystatus');
3363: }
3364: }
1.160.6.84.2. (raeburn 3365:): my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 3366: if (keys(%domhelpdesk)) {
3367: push(@accesstypes,('inc','exc'));
3368: push(@jsarray,('notinc','notexc'));
3369: }
3370: my $hiddenstr = join("','",@jsarray);
3371: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 3372: my $context = 'domprefs';
3373: my $crstype = 'Course';
1.160.6.77 raeburn 3374: my $prefix = 'helproles_';
3375: my $add_class = 'LC_hidden';
3376: foreach my $num (@roles_by_num) {
3377: my $role = $ordered{$num};
3378: my ($desc,$access,@statuses);
3379: if (ref($current{$role}) eq 'HASH') {
3380: $desc = $current{$role}{'desc'};
3381: $access = $current{$role}{'access'};
3382: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3383: @statuses = @{$current{$role}{'insttypes'}};
3384: }
3385: }
3386: if ($desc eq '') {
3387: $desc = $role;
3388: }
3389: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 3390: my %full=();
3391: my %levels= (
3392: course => {},
3393: domain => {},
3394: system => {},
3395: );
3396: my %levelscurrent=(
3397: course => {},
3398: domain => {},
3399: system => {},
3400: );
3401: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3402: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3403: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 3404: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3405: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3406: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3407: for (my $k=0; $k<=$maxnum; $k++) {
3408: my $vpos = $k+1;
3409: my $selstr;
3410: if ($k == $num) {
3411: $selstr = ' selected="selected" ';
3412: }
3413: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3414: }
3415: $datatable .= '</select>'.(' 'x2).
3416: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3417: '</td>'.
3418: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3419: &mt('Name shown to users:').
3420: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3421: '</fieldset>'.
3422: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3423: $othertitle,$usertypes,$types,\%domhelpdesk).
3424: '<fieldset>'.
3425: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 3426: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 3427: \%levelscurrent,$identifier,
3428: 'LC_hidden',$prefix.$num.'_privs').
3429: '</fieldset></td>';
1.160.6.73 raeburn 3430: $itemcount ++;
3431: }
3432: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3433: my $newcust = 'custhelp'.$count;
3434: my (%privs,%levelscurrent);
3435: my %full=();
3436: my %levels= (
3437: course => {},
3438: domain => {},
3439: system => {},
3440: );
3441: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3442: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 3443: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3444: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3445: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3446: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3447: for (my $k=0; $k<$maxnum+1; $k++) {
3448: my $vpos = $k+1;
3449: my $selstr;
3450: if ($k == $maxnum) {
3451: $selstr = ' selected="selected" ';
3452: }
3453: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3454: }
3455: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 3456: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3457: '</label></span></td>'.
1.160.6.77 raeburn 3458: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3459: '<span class="LC_nobreak">'.
3460: &mt('Internal name:').
3461: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3462: '</span>'.(' 'x4).
3463: '<span class="LC_nobreak">'.
3464: &mt('Name shown to users:').
3465: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3466: '</span></fieldset>'.
3467: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3468: $usertypes,$types,\%domhelpdesk).
3469: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 3470: &Apache::lonuserutils::custom_role_header($context,$crstype,
3471: \@templateroles,$newcust).
3472: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3473: \%levelscurrent,$newcust).
1.160.6.77 raeburn 3474: '</fieldset></td></tr>';
1.160.6.73 raeburn 3475: $count ++;
3476: $$rowtotal += $count;
3477: }
1.160.6.5 raeburn 3478: return $datatable;
1.121 raeburn 3479: }
3480:
1.160.6.77 raeburn 3481: sub adhocbutton {
3482: my ($prefix,$num,$field,$visibility) = @_;
3483: my %lt = &Apache::lonlocal::texthash(
3484: show => 'Show details',
3485: hide => 'Hide details',
3486: );
3487: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3488: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3489: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3490: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3491: }
3492:
3493: sub helpsettings_javascript {
3494: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3495: return unless(ref($roles_by_num) eq 'ARRAY');
3496: my %html_js_lt = &Apache::lonlocal::texthash(
3497: show => 'Show details',
3498: hide => 'Hide details',
3499: );
3500: &html_escape(\%html_js_lt);
3501: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3502: return <<"ENDSCRIPT";
3503: <script type="text/javascript">
3504: // <![CDATA[
3505:
3506: function reorderHelpRoles(form,item) {
3507: var changedVal;
3508: $jstext
3509: var newpos = 'helproles_${total}_pos';
3510: var maxh = 1 + $total;
3511: var current = new Array();
3512: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3513: if (item == newpos) {
3514: changedVal = newitemVal;
3515: } else {
3516: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3517: current[newitemVal] = newpos;
3518: }
3519: for (var i=0; i<helproles.length; i++) {
3520: var elementName = 'helproles_'+helproles[i]+'_pos';
3521: if (elementName != item) {
3522: if (form.elements[elementName]) {
3523: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3524: current[currVal] = elementName;
3525: }
3526: }
3527: }
3528: var oldVal;
3529: for (var j=0; j<maxh; j++) {
3530: if (current[j] == undefined) {
3531: oldVal = j;
3532: }
3533: }
3534: if (oldVal < changedVal) {
3535: for (var k=oldVal+1; k<=changedVal ; k++) {
3536: var elementName = current[k];
3537: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3538: }
3539: } else {
3540: for (var k=changedVal; k<oldVal; k++) {
3541: var elementName = current[k];
3542: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3543: }
3544: }
3545: return;
3546: }
3547:
3548: function helpdeskAccess(num) {
3549: var curraccess = null;
3550: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3551: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3552: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3553: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3554: }
3555: }
3556: }
3557: var shown = Array();
3558: var hidden = Array();
3559: if (curraccess == 'none') {
3560: hidden = Array('$hiddenstr');
3561: } else {
3562: if (curraccess == 'status') {
3563: shown = Array('bystatus');
3564: hidden = Array('notinc','notexc');
3565: } else {
3566: if (curraccess == 'exc') {
3567: shown = Array('notexc');
3568: hidden = Array('notinc','bystatus');
3569: }
3570: if (curraccess == 'inc') {
3571: shown = Array('notinc');
3572: hidden = Array('notexc','bystatus');
3573: }
1.160.6.79 raeburn 3574: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 3575: hidden = Array('notinc','notexc','bystatus');
3576: }
3577: }
3578: }
3579: if (hidden.length > 0) {
3580: for (var i=0; i<hidden.length; i++) {
3581: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3582: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3583: }
3584: }
3585: }
3586: if (shown.length > 0) {
3587: for (var i=0; i<shown.length; i++) {
3588: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3589: if (shown[i] == 'privs') {
3590: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3591: } else {
3592: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3593: }
3594: }
3595: }
3596: }
3597: return;
3598: }
3599:
3600: function toggleHelpdeskItem(num,field) {
3601: if (document.getElementById('helproles_'+num+'_'+field)) {
3602: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3603: document.getElementById('helproles_'+num+'_'+field).className =
3604: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3605: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3606: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3607: }
3608: } else {
3609: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3610: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3611: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3612: }
3613: }
3614: }
3615: return;
3616: }
3617:
3618: // ]]>
3619: </script>
3620:
3621: ENDSCRIPT
3622: }
3623:
3624: sub helpdeskroles_access {
3625: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3626: $usertypes,$types,$domhelpdesk) = @_;
3627: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3628: my %lt = &Apache::lonlocal::texthash(
3629: 'rou' => 'Role usage',
3630: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 3631: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3632: 'dh' => 'All with domain helpdesk role',
3633: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 3634: 'none' => 'None',
3635: 'status' => 'Determined based on institutional status',
3636: 'inc' => 'Include all, but exclude specific personnel',
3637: 'exc' => 'Exclude all, but include specific personnel',
3638: );
3639: my %usecheck = (
3640: all => ' checked="checked"',
3641: );
3642: my %displaydiv = (
3643: status => 'none',
3644: inc => 'none',
3645: exc => 'none',
3646: priv => 'block',
3647: );
3648: my $output;
3649: if (ref($current) eq 'HASH') {
3650: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3651: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3652: $usecheck{$current->{access}} = $usecheck{'all'};
3653: delete($usecheck{'all'});
3654: if ($current->{access} =~ /^(status|inc|exc)$/) {
3655: my $access = $1;
3656: $displaydiv{$access} = 'inline';
3657: } elsif ($current->{access} eq 'none') {
3658: $displaydiv{'priv'} = 'none';
3659: }
3660: }
3661: }
3662: }
3663: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3664: '<p>'.$lt{'whi'}.'</p>';
3665: foreach my $access (@{$accesstypes}) {
3666: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3667: ' onclick="helpdeskAccess('."'$num'".');" />'.
3668: $lt{$access}.'</label>';
3669: if ($access eq 'status') {
3670: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3671: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3672: $othertitle,$usertypes,$types).
3673: '</div>';
3674: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3675: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3676: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3677: '</div>';
3678: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3679: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3680: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3681: '</div>';
3682: }
3683: $output .= '</p>';
3684: }
3685: $output .= '</fieldset>';
3686: return $output;
3687: }
3688:
1.121 raeburn 3689: sub radiobutton_prefs {
1.160.6.16 raeburn 3690: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 3691: $additional,$align) = @_;
1.121 raeburn 3692: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3693: (ref($choices) eq 'HASH'));
3694:
3695: my (%checkedon,%checkedoff,$datatable,$css_class);
3696:
3697: foreach my $item (@{$toggles}) {
3698: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3699: $checkedon{$item} = ' checked="checked" ';
3700: $checkedoff{$item} = ' ';
1.121 raeburn 3701: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3702: $checkedoff{$item} = ' checked="checked" ';
3703: $checkedon{$item} = ' ';
3704: }
3705: }
3706: if (ref($settings) eq 'HASH') {
1.121 raeburn 3707: foreach my $item (@{$toggles}) {
1.118 jms 3708: if ($settings->{$item} eq '1') {
3709: $checkedon{$item} = ' checked="checked" ';
3710: $checkedoff{$item} = ' ';
3711: } elsif ($settings->{$item} eq '0') {
3712: $checkedoff{$item} = ' checked="checked" ';
3713: $checkedon{$item} = ' ';
3714: }
3715: }
1.121 raeburn 3716: }
1.160.6.16 raeburn 3717: if ($onclick) {
3718: $onclick = ' onclick="'.$onclick.'"';
3719: }
1.121 raeburn 3720: foreach my $item (@{$toggles}) {
1.118 jms 3721: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3722: $datatable .=
1.160.6.16 raeburn 3723: '<tr'.$css_class.'><td valign="top">'.
3724: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3725: '</span></td>';
3726: if ($align eq 'left') {
3727: $datatable .= '<td class="LC_left_item">';
3728: } else {
3729: $datatable .= '<td class="LC_right_item">';
3730: }
3731: $datatable .=
3732: '<span class="LC_nobreak">'.
1.118 jms 3733: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3734: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3735: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3736: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3737: '</span>'.$additional.
3738: '</td>'.
1.118 jms 3739: '</tr>';
3740: $itemcount ++;
1.121 raeburn 3741: }
3742: return ($datatable,$itemcount);
3743: }
3744:
1.160.6.84.2. (raeburn 3745:): sub print_ltitools {
3746:): my ($dom,$settings,$rowtotal) = @_;
3747:): my $rownum = 0;
3748:): my $css_class;
3749:): my $itemcount = 1;
3750:): my $maxnum = 0;
3751:): my %ordered;
3752:): if (ref($settings) eq 'HASH') {
3753:): foreach my $item (keys(%{$settings})) {
3754:): if (ref($settings->{$item}) eq 'HASH') {
3755:): my $num = $settings->{$item}{'order'};
3756:): $ordered{$num} = $item;
3757:): }
3758:): }
3759:): }
3760:): my $confname = $dom.'-domainconfig';
3761:): my $switchserver = &check_switchserver($dom,$confname);
3762:): my $maxnum = scalar(keys(%ordered));
3763:): my $datatable = <itools_javascript($settings);
3764:): my %lt = <itools_names();
3765:): my @courseroles = ('cc','in','ta','ep','st');
3766:): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3767:): my @fields = ('fullname','firstname','lastname','email','user','roles');
3768:): if (keys(%ordered)) {
3769:): my @items = sort { $a <=> $b } keys(%ordered);
3770:): for (my $i=0; $i<@items; $i++) {
3771:): $css_class = $itemcount%2?' class="LC_odd_row"':'';
3772:): my $item = $ordered{$items[$i]};
3773:): my ($title,$key,$secret,$url,$imgsrc,$version);
3774:): if (ref($settings->{$item}) eq 'HASH') {
3775:): $title = $settings->{$item}->{'title'};
3776:): $url = $settings->{$item}->{'url'};
3777:): $key = $settings->{$item}->{'key'};
3778:): $secret = $settings->{$item}->{'secret'};
3779:): my $image = $settings->{$item}->{'image'};
3780:): if ($image ne '') {
3781:): $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3782:): }
3783:): }
3784:): my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3785:): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3786:): .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3787:): for (my $k=0; $k<=$maxnum; $k++) {
3788:): my $vpos = $k+1;
3789:): my $selstr;
3790:): if ($k == $i) {
3791:): $selstr = ' selected="selected" ';
3792:): }
3793:): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3794:): }
3795:): $datatable .= '</select>'.(' 'x2).
3796:): '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3797:): &mt('Delete?').'</label></span></td>'.
3798:): '<td colspan="2">'.
3799:): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3800:): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3801:): (' 'x2).
3802:): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3803:): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3804:): (' 'x2).
3805:): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3806:): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3807:): '<br /><br />'.
3808:): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3809:): ' value="'.$url.'" /></span>'.
3810:): (' 'x2).
3811:): '<span class="LC_nobreak">'.$lt{'key'}.
3812:): '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3813:): (' 'x2).
3814:): '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3815:): '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3816:): '<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>'.
3817:): '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3818:): '</fieldset>'.
3819:): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3820:): '<span class="LC_nobreak">'.&mt('Display target:');
3821:): my %currdisp;
3822:): if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3823:): if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3824:): $currdisp{'window'} = ' checked="checked"';
3825:): } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
3826:): $currdisp{'tab'} = ' checked="checked"';
3827:): } else {
3828:): $currdisp{'iframe'} = ' checked="checked"';
3829:): }
3830:): if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3831:): $currdisp{'width'} = $1;
3832:): }
3833:): if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3834:): $currdisp{'height'} = $1;
3835:): }
3836:): $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
3837:): $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
3838:): } else {
3839:): $currdisp{'iframe'} = ' checked="checked"';
3840:): }
3841:): foreach my $disp ('iframe','tab','window') {
3842:): $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3843:): $lt{$disp}.'</label>'.(' 'x2);
3844:): }
3845:): $datatable .= (' 'x4);
3846:): foreach my $dimen ('width','height') {
3847:): $datatable .= '<label>'.$lt{$dimen}.' '.
3848:): '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3849:): (' 'x2);
3850:): }
3851:): $datatable .= '<br />'.
3852:): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
3853:): '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
3854:): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
3855:): '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
3856:): '</textarea></div><div style=""></div><br />';
3857:): $datatable .= '<br />';
3858:): foreach my $extra ('passback','roster') {
3859:): my $checkedon = '';
3860:): my $checkedoff = ' checked="checked"';
3861:): if ($settings->{$item}->{$extra}) {
3862:): $checkedon = $checkedoff;
3863:): $checkedoff = '';
3864:): }
3865:): $datatable .= $lt{$extra}.' '.
3866:): '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3867:): &mt('Yes').'</label>'.(' 'x2).
3868:): '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3869:): &mt('No').'</label>'.(' 'x4);
3870:): }
3871:): $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3872:): if ($imgsrc) {
3873:): $datatable .= $imgsrc.
3874:): '<label><input type="checkbox" name="ltitools_image_del"'.
3875:): ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3876:): '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3877:): } else {
3878:): $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3879:): }
3880:): if ($switchserver) {
3881:): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3882:): } else {
3883:): $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3884:): }
3885:): $datatable .= '</span></fieldset>';
3886:): my (%checkedfields,%rolemaps);
3887:): if (ref($settings->{$item}) eq 'HASH') {
3888:): if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3889:): %checkedfields = %{$settings->{$item}->{'fields'}};
3890:): }
3891:): if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3892:): %rolemaps = %{$settings->{$item}->{'roles'}};
3893:): $checkedfields{'roles'} = 1;
3894:): }
3895:): }
3896:): $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3897:): '<span class="LC_nobreak">';
3898:): foreach my $field (@fields) {
3899:): my $checked;
3900:): if ($checkedfields{$field}) {
3901:): $checked = ' checked="checked"';
3902:): }
3903:): $datatable .= '<label>'.
3904:): '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3905:): $lt{$field}.'</label>'.(' ' x2);
3906:): }
3907:): $datatable .= '</span></fieldset>'.
3908:): '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3909:): foreach my $role (@courseroles) {
3910:): my ($selected,$selectnone);
3911:): if (!$rolemaps{$role}) {
3912:): $selectnone = ' selected="selected"';
3913:): }
3914:): $datatable .= '<td align="center">'.
3915:): &Apache::lonnet::plaintext($role,'Course').'<br />'.
3916:): '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3917:): '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3918:): foreach my $ltirole (@ltiroles) {
3919:): unless ($selectnone) {
3920:): if ($rolemaps{$role} eq $ltirole) {
3921:): $selected = ' selected="selected"';
3922:): } else {
3923:): $selected = '';
3924:): }
3925:): }
3926:): $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3927:): }
3928:): $datatable .= '</select></td>';
3929:): }
3930:): $datatable .= '</tr></table></fieldset>';
3931:): my %courseconfig;
3932:): if (ref($settings->{$item}) eq 'HASH') {
3933:): if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3934:): %courseconfig = %{$settings->{$item}->{'crsconf'}};
3935:): }
3936:): }
3937:): $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3938:): foreach my $item ('label','title','target','linktext','explanation') {
3939:): my $checked;
3940:): if ($courseconfig{$item}) {
3941:): $checked = ' checked="checked"';
3942:): }
3943:): $datatable .= '<label>'.
3944:): '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3945:): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3946:): }
3947:): $datatable .= '</span></fieldset>'.
3948:): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3949:): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3950:): if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3951:): my %custom = %{$settings->{$item}->{'custom'}};
3952:): if (keys(%custom) > 0) {
3953:): foreach my $key (sort(keys(%custom))) {
3954:): $datatable .= '<tr><td><span class="LC_nobreak">'.
3955:): '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3956:): $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3957:): '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3958:): ' value="'.$custom{$key}.'" /></td></tr>';
3959:): }
3960:): }
3961:): }
3962:): $datatable .= '<tr><td><span class="LC_nobreak">'.
3963:): '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3964:): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3965:): '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3966:): $datatable .= '</table></fieldset></td></tr>'."\n";
3967:): $itemcount ++;
3968:): }
3969:): }
3970:): $css_class = $itemcount%2?' class="LC_odd_row"':'';
3971:): my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3972:): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3973:): '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3974:): '<select name="ltitools_add_pos"'.$chgstr.'>';
3975:): for (my $k=0; $k<$maxnum+1; $k++) {
3976:): my $vpos = $k+1;
3977:): my $selstr;
3978:): if ($k == $maxnum) {
3979:): $selstr = ' selected="selected" ';
3980:): }
3981:): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3982:): }
3983:): $datatable .= '</select> '."\n".
3984:): '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3985:): '<td colspan="2">'.
3986:): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3987:): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3988:): (' 'x2).
3989:): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3990:): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3991:): (' 'x2).
3992:): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3993:): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3994:): '<br />'.
3995:): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3996:): (' 'x2).
3997:): '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3998:): (' 'x2).
3999:): '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4000:): '<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".
4001:): '</fieldset>'.
4002:): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4003:): '<span class="LC_nobreak">'.&mt('Display target:');
4004:): my %defaultdisp;
4005:): $defaultdisp{'iframe'} = ' checked="checked"';
4006:): foreach my $disp ('iframe','tab','window') {
4007:): $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4008:): $lt{$disp}.'</label>'.(' 'x2);
4009:): }
4010:): $datatable .= (' 'x4);
4011:): foreach my $dimen ('width','height') {
4012:): $datatable .= '<label>'.$lt{$dimen}.' '.
4013:): '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4014:): (' 'x2);
4015:): }
4016:): $datatable .= '<br />'.
4017:): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4018:): '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
4019:): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4020:): '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
4021:): '</div><div style=""></div><br />';
4022:): foreach my $extra ('passback','roster') {
4023:): $datatable .= $lt{$extra}.' '.
4024:): '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
4025:): &mt('Yes').'</label>'.(' 'x2).
4026:): '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
4027:): &mt('No').'</label>'.(' 'x4);
4028:): }
4029:): $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
4030:): '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4031:): if ($switchserver) {
4032:): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4033:): } else {
4034:): $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4035:): }
4036:): $datatable .= '</span></fieldset>'.
4037:): '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4038:): '<span class="LC_nobreak">';
4039:): foreach my $field (@fields) {
4040:): $datatable .= '<label>'.
4041:): '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
4042:): $lt{$field}.'</label>'.(' ' x2);
4043:): }
4044:): $datatable .= '</span></fieldset>'.
4045:): '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4046:): foreach my $role (@courseroles) {
4047:): my ($checked,$checkednone);
4048:): $datatable .= '<td align="center">'.
4049:): &Apache::lonnet::plaintext($role,'Course').'<br />'.
4050:): '<select name="ltitools_add_roles_'.$role.'">'.
4051:): '<option value="" selected="selected">'.&mt('Select').'</option>';
4052:): foreach my $ltirole (@ltiroles) {
4053:): $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4054:): }
4055:): $datatable .= '</select></td>';
4056:): }
4057:): $datatable .= '</tr></table></fieldset>'.
4058:): '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
4059:): foreach my $item ('label','title','target','linktext','explanation') {
4060:): $datatable .= '<label>'.
4061:): '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4062:): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4063:): }
4064:): $datatable .= '</span></fieldset>'.
4065:): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4066:): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4067:): '<tr><td><span class="LC_nobreak">'.
4068:): '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4069:): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4070:): '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
4071:): '</table></fieldset></td></tr>'."\n".
4072:): '</td>'."\n".
4073:): '</tr>'."\n";
4074:): $itemcount ++;
4075:): return $datatable;
4076:): }
4077:):
4078:): sub ltitools_names {
4079:): my %lt = &Apache::lonlocal::texthash(
4080:): 'title' => 'Title',
4081:): 'version' => 'Version',
4082:): 'msgtype' => 'Message Type',
4083:): 'url' => 'URL',
4084:): 'key' => 'Key',
4085:): 'secret' => 'Secret',
4086:): 'icon' => 'Icon',
4087:): 'user' => 'Username:domain',
4088:): 'fullname' => 'Full Name',
4089:): 'firstname' => 'First Name',
4090:): 'lastname' => 'Last Name',
4091:): 'email' => 'E-mail',
4092:): 'roles' => 'Role',
4093:): 'window' => 'Window',
4094:): 'tab' => 'Tab',
4095:): 'iframe' => 'iFrame',
4096:): 'height' => 'Height',
4097:): 'width' => 'Width',
4098:): 'linktext' => 'Default Link Text',
4099:): 'explanation' => 'Default Explanation',
4100:): 'passback' => 'Tool can return grades:',
4101:): 'roster' => 'Tool can retrieve roster:',
4102:): 'crstarget' => 'Display target',
4103:): 'crslabel' => 'Course label',
4104:): 'crstitle' => 'Course title',
4105:): 'crslinktext' => 'Link Text',
4106:): 'crsexplanation' => 'Explanation',
4107:): );
4108:):
4109:): return %lt;
4110:): }
4111:):
1.121 raeburn 4112: sub print_coursedefaults {
1.139 raeburn 4113: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 4114: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4115: my $itemcount = 1;
1.160.6.16 raeburn 4116: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 4117: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 4118: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4119: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 4120: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4121: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
4122: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 4123: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 4124: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 4125: );
1.160.6.21 raeburn 4126: my %staticdefaults = (
4127: anonsurvey_threshold => 10,
4128: uploadquota => 500,
1.160.6.57 raeburn 4129: postsubmit => 60,
1.160.6.70 raeburn 4130: mysqltables => 172800,
1.160.6.21 raeburn 4131: );
1.139 raeburn 4132: if ($position eq 'top') {
1.160.6.57 raeburn 4133: %defaultchecked = (
4134: 'uselcmath' => 'on',
4135: 'usejsme' => 'on',
1.160.6.64 raeburn 4136: 'canclone' => 'none',
1.160.6.57 raeburn 4137: );
4138: @toggles = ('uselcmath','usejsme');
1.139 raeburn 4139: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4140: \%choices,$itemcount);
1.160.6.64 raeburn 4141: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4142: $datatable .=
4143: '<tr'.$css_class.'><td valign="top">'.
4144: '<span class="LC_nobreak">'.$choices{'canclone'}.
4145: '</span></td><td class="LC_left_item">';
4146: my $currcanclone = 'none';
4147: my $onclick;
4148: my @cloneoptions = ('none','domain');
4149: my %clonetitles = (
4150: none => 'No additional course requesters',
4151: domain => "Any course requester in course's domain",
4152: instcode => 'Course requests for official courses ...',
4153: );
4154: my (%codedefaults,@code_order,@posscodes);
4155: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4156: \@code_order) eq 'ok') {
4157: if (@code_order > 0) {
4158: push(@cloneoptions,'instcode');
4159: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4160: }
4161: }
4162: if (ref($settings) eq 'HASH') {
4163: if ($settings->{'canclone'}) {
4164: if (ref($settings->{'canclone'}) eq 'HASH') {
4165: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4166: if (@code_order > 0) {
4167: $currcanclone = 'instcode';
4168: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4169: }
4170: }
4171: } elsif ($settings->{'canclone'} eq 'domain') {
4172: $currcanclone = $settings->{'canclone'};
4173: }
4174: }
4175: }
4176: foreach my $option (@cloneoptions) {
4177: my ($checked,$additional);
4178: if ($currcanclone eq $option) {
4179: $checked = ' checked="checked"';
4180: }
4181: if ($option eq 'instcode') {
4182: if (@code_order) {
4183: my $show = 'none';
4184: if ($checked) {
4185: $show = 'block';
4186: }
4187: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4188: &mt('Institutional codes for new and cloned course have identical:').
4189: '<br />';
4190: foreach my $item (@code_order) {
4191: my $codechk;
4192: if ($checked) {
4193: if (grep(/^\Q$item\E$/,@posscodes)) {
4194: $codechk = ' checked="checked"';
4195: }
4196: }
4197: $additional .= '<label>'.
4198: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4199: $item.'</label>';
4200: }
4201: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4202: }
4203: }
4204: $datatable .=
4205: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4206: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4207: '</label> '.$additional.'</span><br />';
4208: }
4209: $datatable .= '</td>'.
4210: '</tr>';
4211: $itemcount ++;
1.139 raeburn 4212: } else {
4213: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 4214: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 4215: my $currusecredits = 0;
1.160.6.57 raeburn 4216: my $postsubmitclient = 1;
1.160.6.30 raeburn 4217: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 4218: if (ref($settings) eq 'HASH') {
4219: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 4220: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4221: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4222: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4223: }
4224: }
1.160.6.16 raeburn 4225: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 4226: foreach my $type (@types) {
4227: next if ($type eq 'community');
4228: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4229: if ($defcredits{$type} ne '') {
4230: $currusecredits = 1;
4231: }
4232: }
4233: }
4234: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4235: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4236: $postsubmitclient = 0;
4237: foreach my $type (@types) {
4238: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4239: }
4240: } else {
4241: foreach my $type (@types) {
4242: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4243: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
4244: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
4245: } else {
4246: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4247: }
4248: } else {
4249: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4250: }
4251: }
4252: }
4253: } else {
4254: foreach my $type (@types) {
4255: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 4256: }
4257: }
1.160.6.70 raeburn 4258: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4259: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4260: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4261: }
4262: } else {
4263: foreach my $type (@types) {
4264: $currmysql{$type} = $staticdefaults{'mysqltables'};
4265: }
4266: }
1.160.6.58 raeburn 4267: } else {
4268: foreach my $type (@types) {
4269: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4270: }
1.139 raeburn 4271: }
4272: if (!$currdefresponder) {
1.160.6.21 raeburn 4273: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4274: } elsif ($currdefresponder < 1) {
4275: $currdefresponder = 1;
4276: }
1.160.6.21 raeburn 4277: foreach my $type (@types) {
4278: if ($curruploadquota{$type} eq '') {
4279: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4280: }
4281: }
1.139 raeburn 4282: $datatable .=
1.160.6.16 raeburn 4283: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4284: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4285: '</span></td>'.
4286: '<td class="LC_right_item"><span class="LC_nobreak">'.
4287: '<input type="text" name="anonsurvey_threshold"'.
4288: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 4289: '</td></tr>'."\n";
4290: $itemcount ++;
4291: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4292: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4293: $choices{'uploadquota'}.
4294: '</span></td>'.
4295: '<td align="right" class="LC_right_item">'.
4296: '<table><tr>';
1.160.6.21 raeburn 4297: foreach my $type (@types) {
4298: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4299: '<input type="text" name="uploadquota_'.$type.'"'.
4300: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4301: }
4302: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 4303: $itemcount ++;
1.160.6.40 raeburn 4304: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 4305: my $display = 'none';
4306: if ($currusecredits) {
4307: $display = 'block';
4308: }
4309: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 4310: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4311: foreach my $type (@types) {
4312: next if ($type eq 'community');
4313: $additional .= '<td align="center">'.&mt($type).'<br />'.
4314: '<input type="text" name="'.$type.'_credits"'.
4315: ' value="'.$defcredits{$type}.'" size="3" /></td>';
4316: }
4317: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 4318: %defaultchecked = ('coursecredits' => 'off');
4319: @toggles = ('coursecredits');
4320: my $current = {
4321: 'coursecredits' => $currusecredits,
4322: };
4323: (my $table,$itemcount) =
4324: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4325: \%choices,$itemcount,$onclick,$additional,'left');
4326: $datatable .= $table;
4327: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4328: my $display = 'none';
4329: if ($postsubmitclient) {
4330: $display = 'block';
4331: }
4332: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 4333: &mt('Number of seconds submit is disabled').'<br />'.
4334: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4335: '<table><tr>';
1.160.6.57 raeburn 4336: foreach my $type (@types) {
4337: $additional .= '<td align="center">'.&mt($type).'<br />'.
4338: '<input type="text" name="'.$type.'_timeout" value="'.
4339: $deftimeout{$type}.'" size="5" /></td>';
4340: }
4341: $additional .= '</tr></table></div>'."\n";
4342: %defaultchecked = ('postsubmit' => 'on');
4343: @toggles = ('postsubmit');
1.160.6.70 raeburn 4344: $current = {
4345: 'postsubmit' => $postsubmitclient,
4346: };
1.160.6.57 raeburn 4347: ($table,$itemcount) =
4348: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4349: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 4350: $datatable .= $table;
1.160.6.70 raeburn 4351: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4352: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4353: $choices{'mysqltables'}.
4354: '</span></td>'.
4355: '<td align="right" class="LC_right_item">'.
4356: '<table><tr>';
4357: foreach my $type (@types) {
4358: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4359: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 4360: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 4361: }
4362: $datatable .= '</tr></table></td></tr>'."\n";
4363: $itemcount ++;
4364:
1.160.6.37 raeburn 4365: }
4366: $$rowtotal += $itemcount;
4367: return $datatable;
4368: }
4369:
4370: sub print_selfenrollment {
4371: my ($position,$dom,$settings,$rowtotal) = @_;
4372: my ($css_class,$datatable);
4373: my $itemcount = 1;
4374: my @types = ('official','unofficial','community','textbook');
4375: if (($position eq 'top') || ($position eq 'middle')) {
4376: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4377: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
4378: my @rows;
4379: my $key;
4380: if ($position eq 'top') {
4381: $key = 'admin';
4382: if (ref($rowsref) eq 'ARRAY') {
4383: @rows = @{$rowsref};
4384: }
4385: } elsif ($position eq 'middle') {
4386: $key = 'default';
4387: @rows = ('types','registered','approval','limit');
4388: }
4389: foreach my $row (@rows) {
4390: if (defined($titlesref->{$row})) {
4391: $itemcount ++;
4392: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4393: $datatable .= '<tr'.$css_class.'>'.
4394: '<td>'.$titlesref->{$row}.'</td>'.
4395: '<td class="LC_left_item">'.
4396: '<table><tr>';
4397: my (%current,%currentcap);
4398: if (ref($settings) eq 'HASH') {
4399: if (ref($settings->{$key}) eq 'HASH') {
4400: foreach my $type (@types) {
4401: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4402: $current{$type} = $settings->{$key}->{$type}->{$row};
4403: }
4404: if (($row eq 'limit') && ($key eq 'default')) {
4405: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4406: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4407: }
4408: }
4409: }
4410: }
4411: }
4412: my %roles = (
4413: '0' => &Apache::lonnet::plaintext('dc'),
4414: );
4415:
4416: foreach my $type (@types) {
4417: unless (($row eq 'registered') && ($key eq 'default')) {
4418: $datatable .= '<th>'.&mt($type).'</th>';
4419: }
4420: }
4421: unless (($row eq 'registered') && ($key eq 'default')) {
4422: $datatable .= '</tr><tr>';
4423: }
4424: foreach my $type (@types) {
4425: if ($type eq 'community') {
4426: $roles{'1'} = &mt('Community personnel');
4427: } else {
4428: $roles{'1'} = &mt('Course personnel');
4429: }
4430: $datatable .= '<td style="vertical-align: top">';
4431: if ($position eq 'top') {
4432: my %checked;
4433: if ($current{$type} eq '0') {
4434: $checked{'0'} = ' checked="checked"';
4435: } else {
4436: $checked{'1'} = ' checked="checked"';
4437: }
4438: foreach my $role ('1','0') {
4439: $datatable .= '<span class="LC_nobreak"><label>'.
4440: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4441: 'value="'.$role.'"'.$checked{$role}.' />'.
4442: $roles{$role}.'</label></span> ';
4443: }
4444: } else {
4445: if ($row eq 'types') {
4446: my %checked;
4447: if ($current{$type} =~ /^(all|dom)$/) {
4448: $checked{$1} = ' checked="checked"';
4449: } else {
4450: $checked{''} = ' checked="checked"';
4451: }
4452: foreach my $val ('','dom','all') {
4453: $datatable .= '<span class="LC_nobreak"><label>'.
4454: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4455: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4456: }
4457: } elsif ($row eq 'registered') {
4458: my %checked;
4459: if ($current{$type} eq '1') {
4460: $checked{'1'} = ' checked="checked"';
4461: } else {
4462: $checked{'0'} = ' checked="checked"';
4463: }
4464: foreach my $val ('0','1') {
4465: $datatable .= '<span class="LC_nobreak"><label>'.
4466: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4467: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4468: }
4469: } elsif ($row eq 'approval') {
4470: my %checked;
4471: if ($current{$type} =~ /^([12])$/) {
4472: $checked{$1} = ' checked="checked"';
4473: } else {
4474: $checked{'0'} = ' checked="checked"';
4475: }
4476: for my $val (0..2) {
4477: $datatable .= '<span class="LC_nobreak"><label>'.
4478: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4479: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4480: }
4481: } elsif ($row eq 'limit') {
4482: my %checked;
4483: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4484: $checked{$1} = ' checked="checked"';
4485: } else {
4486: $checked{'none'} = ' checked="checked"';
4487: }
4488: my $cap;
4489: if ($currentcap{$type} =~ /^\d+$/) {
4490: $cap = $currentcap{$type};
4491: }
4492: foreach my $val ('none','allstudents','selfenrolled') {
4493: $datatable .= '<span class="LC_nobreak"><label>'.
4494: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4495: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4496: }
4497: $datatable .= '<br />'.
4498: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4499: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4500: '</span>';
4501: }
4502: }
4503: $datatable .= '</td>';
4504: }
4505: $datatable .= '</tr>';
4506: }
4507: $datatable .= '</table></td></tr>';
4508: }
4509: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 4510: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4511: }
4512: $$rowtotal += $itemcount;
4513: return $datatable;
4514: }
4515:
4516: sub print_validation_rows {
4517: my ($caller,$dom,$settings,$rowtotal) = @_;
4518: my ($itemsref,$namesref,$fieldsref);
4519: if ($caller eq 'selfenroll') {
4520: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4521: } elsif ($caller eq 'requestcourses') {
4522: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4523: }
4524: my %currvalidation;
4525: if (ref($settings) eq 'HASH') {
4526: if (ref($settings->{'validation'}) eq 'HASH') {
4527: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 4528: }
1.160.6.39 raeburn 4529: }
4530: my $datatable;
4531: my $itemcount = 0;
4532: foreach my $item (@{$itemsref}) {
4533: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4534: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4535: $namesref->{$item}.
4536: '</span></td>'.
4537: '<td class="LC_left_item">';
4538: if (($item eq 'url') || ($item eq 'button')) {
4539: $datatable .= '<span class="LC_nobreak">'.
4540: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4541: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4542: } elsif ($item eq 'fields') {
4543: my @currfields;
4544: if (ref($currvalidation{$item}) eq 'ARRAY') {
4545: @currfields = @{$currvalidation{$item}};
4546: }
4547: foreach my $field (@{$fieldsref}) {
4548: my $check = '';
4549: if (grep(/^\Q$field\E$/,@currfields)) {
4550: $check = ' checked="checked"';
4551: }
4552: $datatable .= '<span class="LC_nobreak"><label>'.
4553: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4554: ' value="'.$field.'"'.$check.' />'.$field.
4555: '</label></span> ';
4556: }
4557: } elsif ($item eq 'markup') {
4558: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
4559: $currvalidation{$item}.
1.160.6.37 raeburn 4560: '</textarea>';
1.160.6.39 raeburn 4561: }
4562: $datatable .= '</td></tr>'."\n";
4563: if (ref($rowtotal)) {
1.160.6.37 raeburn 4564: $itemcount ++;
4565: }
1.139 raeburn 4566: }
1.160.6.39 raeburn 4567: if ($caller eq 'requestcourses') {
4568: my %currhash;
1.160.6.51 raeburn 4569: if (ref($settings) eq 'HASH') {
4570: if (ref($settings->{'validation'}) eq 'HASH') {
4571: if ($settings->{'validation'}{'dc'} ne '') {
4572: $currhash{$settings->{'validation'}{'dc'}} = 1;
4573: }
1.160.6.39 raeburn 4574: }
4575: }
4576: my $numinrow = 2;
4577: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4578: 'validationdc',%currhash);
1.160.6.50 raeburn 4579: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4580: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.160.6.39 raeburn 4581: if ($numdc > 1) {
1.160.6.50 raeburn 4582: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 4583: } else {
1.160.6.50 raeburn 4584: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 4585: }
1.160.6.50 raeburn 4586: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 4587: $itemcount ++;
4588: }
4589: if (ref($rowtotal)) {
4590: $$rowtotal += $itemcount;
4591: }
1.121 raeburn 4592: return $datatable;
1.118 jms 4593: }
4594:
1.137 raeburn 4595: sub print_usersessions {
4596: my ($position,$dom,$settings,$rowtotal) = @_;
4597: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 4598: my (%by_ip,%by_location,@intdoms);
4599: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 4600:
4601: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4602: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4603: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4604: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4605: my $itemcount = 1;
4606: if ($position eq 'top') {
1.152 raeburn 4607: if (keys(%serverhomes) > 1) {
1.145 raeburn 4608: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 4609: my $curroffloadnow;
4610: if (ref($settings) eq 'HASH') {
4611: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4612: $curroffloadnow = $settings->{'offloadnow'};
4613: }
4614: }
4615: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4616: } else {
1.140 raeburn 4617: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4618: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 4619: }
1.137 raeburn 4620: } else {
1.145 raeburn 4621: if (keys(%by_location) == 0) {
4622: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4623: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 4624: } else {
4625: my %lt = &usersession_titles();
4626: my $numinrow = 5;
4627: my $prefix;
4628: my @types;
4629: if ($position eq 'bottom') {
4630: $prefix = 'remote';
4631: @types = ('version','excludedomain','includedomain');
4632: } else {
4633: $prefix = 'hosted';
4634: @types = ('excludedomain','includedomain');
4635: }
4636: my (%current,%checkedon,%checkedoff);
4637: my @lcversions = &Apache::lonnet::all_loncaparevs();
4638: my @locations = sort(keys(%by_location));
4639: foreach my $type (@types) {
4640: $checkedon{$type} = '';
4641: $checkedoff{$type} = ' checked="checked"';
4642: }
4643: if (ref($settings) eq 'HASH') {
4644: if (ref($settings->{$prefix}) eq 'HASH') {
4645: foreach my $key (keys(%{$settings->{$prefix}})) {
4646: $current{$key} = $settings->{$prefix}{$key};
4647: if ($key eq 'version') {
4648: if ($current{$key} ne '') {
4649: $checkedon{$key} = ' checked="checked"';
4650: $checkedoff{$key} = '';
4651: }
4652: } elsif (ref($current{$key}) eq 'ARRAY') {
4653: $checkedon{$key} = ' checked="checked"';
4654: $checkedoff{$key} = '';
4655: }
1.137 raeburn 4656: }
4657: }
4658: }
1.145 raeburn 4659: foreach my $type (@types) {
4660: next if ($type ne 'version' && !@locations);
4661: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4662: $datatable .= '<tr'.$css_class.'>
4663: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
4664: <span class="LC_nobreak">
4665: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4666: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4667: if ($type eq 'version') {
4668: my $selector = '<select name="'.$prefix.'_version">';
4669: foreach my $version (@lcversions) {
4670: my $selected = '';
4671: if ($current{'version'} eq $version) {
4672: $selected = ' selected="selected"';
4673: }
4674: $selector .= ' <option value="'.$version.'"'.
4675: $selected.'>'.$version.'</option>';
4676: }
4677: $selector .= '</select> ';
4678: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4679: } else {
4680: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4681: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4682: ' />'.(' 'x2).
4683: '<input type="button" value="'.&mt('uncheck all').'" '.
4684: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4685: "\n".
4686: '</div><div><table>';
4687: my $rem;
4688: for (my $i=0; $i<@locations; $i++) {
4689: my ($showloc,$value,$checkedtype);
4690: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4691: my $ip = $by_location{$locations[$i]}->[0];
4692: if (ref($by_ip{$ip}) eq 'ARRAY') {
4693: $value = join(':',@{$by_ip{$ip}});
4694: $showloc = join(', ',@{$by_ip{$ip}});
4695: if (ref($current{$type}) eq 'ARRAY') {
4696: foreach my $loc (@{$by_ip{$ip}}) {
4697: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4698: $checkedtype = ' checked="checked"';
4699: last;
4700: }
4701: }
1.138 raeburn 4702: }
4703: }
4704: }
1.145 raeburn 4705: $rem = $i%($numinrow);
4706: if ($rem == 0) {
4707: if ($i > 0) {
4708: $datatable .= '</tr>';
4709: }
4710: $datatable .= '<tr>';
4711: }
4712: $datatable .= '<td class="LC_left_item">'.
4713: '<span class="LC_nobreak"><label>'.
4714: '<input type="checkbox" name="'.$prefix.'_'.$type.
4715: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4716: '</label></span></td>';
1.137 raeburn 4717: }
1.145 raeburn 4718: $rem = @locations%($numinrow);
4719: my $colsleft = $numinrow - $rem;
4720: if ($colsleft > 1 ) {
4721: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4722: ' </td>';
4723: } elsif ($colsleft == 1) {
4724: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4725: }
1.145 raeburn 4726: $datatable .= '</tr></table>';
1.137 raeburn 4727: }
1.145 raeburn 4728: $datatable .= '</td></tr>';
4729: $itemcount ++;
1.137 raeburn 4730: }
4731: }
4732: }
4733: $$rowtotal += $itemcount;
4734: return $datatable;
4735: }
4736:
1.138 raeburn 4737: sub build_location_hashes {
4738: my ($intdoms,$by_ip,$by_location) = @_;
4739: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
4740: (ref($by_location) eq 'HASH'));
4741: my %iphost = &Apache::lonnet::get_iphost();
4742: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4743: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4744: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4745: foreach my $id (@{$iphost{$primary_ip}}) {
4746: my $intdom = &Apache::lonnet::internet_dom($id);
4747: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4748: push(@{$intdoms},$intdom);
4749: }
4750: }
4751: }
4752: foreach my $ip (keys(%iphost)) {
4753: if (ref($iphost{$ip}) eq 'ARRAY') {
4754: foreach my $id (@{$iphost{$ip}}) {
4755: my $location = &Apache::lonnet::internet_dom($id);
4756: if ($location) {
4757: next if (grep(/^\Q$location\E$/,@{$intdoms}));
4758: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4759: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4760: push(@{$by_ip->{$ip}},$location);
4761: }
4762: } else {
4763: $by_ip->{$ip} = [$location];
4764: }
4765: }
4766: }
4767: }
4768: }
4769: foreach my $ip (sort(keys(%{$by_ip}))) {
4770: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4771: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4772: my $first = $by_ip->{$ip}->[0];
4773: if (ref($by_location->{$first}) eq 'ARRAY') {
4774: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4775: push(@{$by_location->{$first}},$ip);
4776: }
4777: } else {
4778: $by_location->{$first} = [$ip];
4779: }
4780: }
4781: }
4782: return;
4783: }
4784:
1.145 raeburn 4785: sub current_offloads_to {
4786: my ($dom,$settings,$servers) = @_;
4787: my (%spareid,%otherdomconfigs);
1.152 raeburn 4788: if (ref($servers) eq 'HASH') {
1.145 raeburn 4789: foreach my $lonhost (sort(keys(%{$servers}))) {
4790: my $gotspares;
1.152 raeburn 4791: if (ref($settings) eq 'HASH') {
4792: if (ref($settings->{'spares'}) eq 'HASH') {
4793: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4794: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4795: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4796: $gotspares = 1;
4797: }
1.145 raeburn 4798: }
4799: }
4800: unless ($gotspares) {
4801: my $gotspares;
4802: my $serverhomeID =
4803: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4804: my $serverhomedom =
4805: &Apache::lonnet::host_domain($serverhomeID);
4806: if ($serverhomedom ne $dom) {
4807: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4808: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4809: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4810: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4811: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4812: $gotspares = 1;
4813: }
4814: }
4815: } else {
4816: $otherdomconfigs{$serverhomedom} =
4817: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4818: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4819: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4820: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4821: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4822: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4823: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4824: $gotspares = 1;
4825: }
4826: }
4827: }
4828: }
4829: }
4830: }
4831: }
4832: unless ($gotspares) {
4833: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4834: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4835: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4836: } else {
4837: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4838: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4839: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4840: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4841: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4842: } else {
1.150 raeburn 4843: my %what = (
4844: spareid => 1,
4845: );
4846: my ($result,$returnhash) =
4847: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4848: if ($result eq 'ok') {
4849: if (ref($returnhash) eq 'HASH') {
4850: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4851: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4852: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4853: }
4854: }
1.145 raeburn 4855: }
4856: }
4857: }
4858: }
4859: }
4860: }
4861: return %spareid;
4862: }
4863:
4864: sub spares_row {
1.160.6.61 raeburn 4865: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4866: my $css_class;
4867: my $numinrow = 4;
4868: my $itemcount = 1;
4869: my $datatable;
1.152 raeburn 4870: my %typetitles = &sparestype_titles();
4871: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4872: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4873: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4874: my ($othercontrol,$serverdom);
4875: if ($serverhome ne $server) {
4876: $serverdom = &Apache::lonnet::host_domain($serverhome);
4877: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4878: } else {
4879: $serverdom = &Apache::lonnet::host_domain($server);
4880: if ($serverdom ne $dom) {
4881: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4882: }
4883: }
4884: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 4885: my $checkednow;
4886: if (ref($curroffloadnow) eq 'HASH') {
4887: if ($curroffloadnow->{$server}) {
4888: $checkednow = ' checked="checked"';
4889: }
4890: }
1.145 raeburn 4891: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4892: $datatable .= '<tr'.$css_class.'>
4893: <td rowspan="2">
1.160.6.13 raeburn 4894: <span class="LC_nobreak">'.
4895: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 4896: ,'<b>'.$server.'</b>').'</span><br />'.
4897: '<span class="LC_nobreak">'."\n".
4898: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4899: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 4900: "\n";
1.145 raeburn 4901: my (%current,%canselect);
1.152 raeburn 4902: my @choices =
4903: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4904: foreach my $type ('primary','default') {
4905: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4906: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4907: my @spares = @{$spareid->{$server}{$type}};
4908: if (@spares > 0) {
1.152 raeburn 4909: if ($othercontrol) {
4910: $current{$type} = join(', ',@spares);
4911: } else {
4912: $current{$type} .= '<table>';
4913: my $numspares = scalar(@spares);
4914: for (my $i=0; $i<@spares; $i++) {
4915: my $rem = $i%($numinrow);
4916: if ($rem == 0) {
4917: if ($i > 0) {
4918: $current{$type} .= '</tr>';
4919: }
4920: $current{$type} .= '<tr>';
1.145 raeburn 4921: }
1.152 raeburn 4922: $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'".');" /> '.
4923: $spareid->{$server}{$type}[$i].
4924: '</label></td>'."\n";
4925: }
4926: my $rem = @spares%($numinrow);
4927: my $colsleft = $numinrow - $rem;
4928: if ($colsleft > 1 ) {
4929: $current{$type} .= '<td colspan="'.$colsleft.
4930: '" class="LC_left_item">'.
4931: ' </td>';
4932: } elsif ($colsleft == 1) {
4933: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4934: }
1.152 raeburn 4935: $current{$type} .= '</tr></table>';
1.150 raeburn 4936: }
1.145 raeburn 4937: }
4938: }
4939: if ($current{$type} eq '') {
4940: $current{$type} = &mt('None specified');
4941: }
1.152 raeburn 4942: if ($othercontrol) {
4943: if ($type eq 'primary') {
4944: $canselect{$type} = $othercontrol;
4945: }
4946: } else {
4947: $canselect{$type} =
4948: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4949: '<select name="newspare_'.$type.'_'.$server.'" '.
4950: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4951: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4952: if (@choices > 0) {
4953: foreach my $lonhost (@choices) {
4954: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4955: }
4956: }
4957: $canselect{$type} .= '</select>'."\n";
4958: }
4959: } else {
4960: $current{$type} = &mt('Could not be determined');
4961: if ($type eq 'primary') {
4962: $canselect{$type} = $othercontrol;
4963: }
1.145 raeburn 4964: }
1.152 raeburn 4965: if ($type eq 'default') {
4966: $datatable .= '<tr'.$css_class.'>';
4967: }
4968: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4969: '<td>'.$current{$type}.'</td>'."\n".
4970: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4971: }
4972: $itemcount ++;
4973: }
4974: }
4975: $$rowtotal += $itemcount;
4976: return $datatable;
4977: }
4978:
1.152 raeburn 4979: sub possible_newspares {
4980: my ($server,$currspares,$serverhomes,$altids) = @_;
4981: my $serverhostname = &Apache::lonnet::hostname($server);
4982: my %excluded;
4983: if ($serverhostname ne '') {
4984: %excluded = (
4985: $serverhostname => 1,
4986: );
4987: }
4988: if (ref($currspares) eq 'HASH') {
4989: foreach my $type (keys(%{$currspares})) {
4990: if (ref($currspares->{$type}) eq 'ARRAY') {
4991: if (@{$currspares->{$type}} > 0) {
4992: foreach my $curr (@{$currspares->{$type}}) {
4993: my $hostname = &Apache::lonnet::hostname($curr);
4994: $excluded{$hostname} = 1;
4995: }
4996: }
4997: }
4998: }
4999: }
5000: my @choices;
5001: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5002: if (keys(%{$serverhomes}) > 1) {
5003: foreach my $name (sort(keys(%{$serverhomes}))) {
5004: unless ($excluded{$name}) {
5005: if (exists($altids->{$serverhomes->{$name}})) {
5006: push(@choices,$altids->{$serverhomes->{$name}});
5007: } else {
5008: push(@choices,$serverhomes->{$name});
1.145 raeburn 5009: }
5010: }
5011: }
5012: }
5013: }
1.152 raeburn 5014: return sort(@choices);
1.145 raeburn 5015: }
5016:
1.150 raeburn 5017: sub print_loadbalancing {
5018: my ($dom,$settings,$rowtotal) = @_;
5019: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5020: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5021: my $numinrow = 1;
5022: my $datatable;
5023: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 5024: my (%currbalancer,%currtargets,%currrules,%existing);
5025: if (ref($settings) eq 'HASH') {
5026: %existing = %{$settings};
5027: }
5028: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5029: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
5030: \%currtargets,\%currrules);
1.150 raeburn 5031: } else {
5032: return;
5033: }
5034: my ($othertitle,$usertypes,$types) =
5035: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 5036: my $rownum = 8;
1.150 raeburn 5037: if (ref($types) eq 'ARRAY') {
5038: $rownum += scalar(@{$types});
5039: }
1.160.6.7 raeburn 5040: my @css_class = ('LC_odd_row','LC_even_row');
5041: my $balnum = 0;
5042: my $islast;
5043: my (@toshow,$disabledtext);
5044: if (keys(%currbalancer) > 0) {
5045: @toshow = sort(keys(%currbalancer));
5046: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5047: push(@toshow,'');
5048: }
5049: } else {
5050: @toshow = ('');
5051: $disabledtext = &mt('No existing load balancer');
5052: }
5053: foreach my $lonhost (@toshow) {
5054: if ($balnum == scalar(@toshow)-1) {
5055: $islast = 1;
5056: } else {
5057: $islast = 0;
5058: }
5059: my $cssidx = $balnum%2;
5060: my $targets_div_style = 'display: none';
5061: my $disabled_div_style = 'display: block';
5062: my $homedom_div_style = 'display: none';
5063: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
5064: '<td rowspan="'.$rownum.'" valign="top">'.
5065: '<p>';
5066: if ($lonhost eq '') {
5067: $datatable .= '<span class="LC_nobreak">';
5068: if (keys(%currbalancer) > 0) {
5069: $datatable .= &mt('Add balancer:');
5070: } else {
5071: $datatable .= &mt('Enable balancer:');
5072: }
5073: $datatable .= ' '.
5074: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5075: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5076: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5077: '<option value="" selected="selected">'.&mt('None').
5078: '</option>'."\n";
5079: foreach my $server (sort(keys(%servers))) {
5080: next if ($currbalancer{$server});
5081: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5082: }
5083: $datatable .=
5084: '</select>'."\n".
5085: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5086: } else {
5087: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5088: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5089: &mt('Stop balancing').'</label>'.
5090: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5091: $targets_div_style = 'display: block';
5092: $disabled_div_style = 'display: none';
5093: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5094: $homedom_div_style = 'display: block';
5095: }
5096: }
5097: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
5098: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5099: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5100: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5101: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5102: my @sparestypes = ('primary','default');
5103: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 5104: my %hostherechecked = (
5105: no => ' checked="checked"',
5106: );
1.160.6.7 raeburn 5107: foreach my $sparetype (@sparestypes) {
5108: my $targettable;
5109: for (my $i=0; $i<$numspares; $i++) {
5110: my $checked;
5111: if (ref($currtargets{$lonhost}) eq 'HASH') {
5112: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5113: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5114: $checked = ' checked="checked"';
5115: }
5116: }
5117: }
5118: my ($chkboxval,$disabled);
5119: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5120: $chkboxval = $spares[$i];
5121: }
5122: if (exists($currbalancer{$spares[$i]})) {
5123: $disabled = ' disabled="disabled"';
5124: }
5125: $targettable .=
1.160.6.55 raeburn 5126: '<td><span class="LC_nobreak"><label>'.
5127: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 5128: $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 5129: '</span></label></span></td>';
1.160.6.7 raeburn 5130: my $rem = $i%($numinrow);
5131: if ($rem == 0) {
5132: if (($i > 0) && ($i < $numspares-1)) {
5133: $targettable .= '</tr>';
5134: }
5135: if ($i < $numspares-1) {
5136: $targettable .= '<tr>';
1.150 raeburn 5137: }
5138: }
5139: }
1.160.6.7 raeburn 5140: if ($targettable ne '') {
5141: my $rem = $numspares%($numinrow);
5142: my $colsleft = $numinrow - $rem;
5143: if ($colsleft > 1 ) {
5144: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5145: ' </td>';
5146: } elsif ($colsleft == 1) {
5147: $targettable .= '<td class="LC_left_item"> </td>';
5148: }
5149: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5150: '<table><tr>'.$targettable.'</tr></table><br />';
5151: }
1.160.6.76 raeburn 5152: $hostherechecked{$sparetype} = '';
5153: if (ref($currtargets{$lonhost}) eq 'HASH') {
5154: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5155: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5156: $hostherechecked{$sparetype} = ' checked="checked"';
5157: $hostherechecked{'no'} = '';
5158: }
5159: }
5160: }
5161: }
5162: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5163: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5164: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5165: foreach my $sparetype (@sparestypes) {
5166: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5167: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5168: '</i></label><br />';
1.160.6.7 raeburn 5169: }
5170: $datatable .= '</div></td></tr>'.
5171: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5172: $othertitle,$usertypes,$types,\%servers,
5173: \%currbalancer,$lonhost,
5174: $targets_div_style,$homedom_div_style,
5175: $css_class[$cssidx],$balnum,$islast);
5176: $$rowtotal += $rownum;
5177: $balnum ++;
5178: }
5179: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5180: return $datatable;
5181: }
5182:
5183: sub get_loadbalancers_config {
5184: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
5185: return unless ((ref($servers) eq 'HASH') &&
5186: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
5187: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
5188: if (keys(%{$existing}) > 0) {
5189: my $oldlonhost;
5190: foreach my $key (sort(keys(%{$existing}))) {
5191: if ($key eq 'lonhost') {
5192: $oldlonhost = $existing->{'lonhost'};
5193: $currbalancer->{$oldlonhost} = 1;
5194: } elsif ($key eq 'targets') {
5195: if ($oldlonhost) {
5196: $currtargets->{$oldlonhost} = $existing->{'targets'};
5197: }
5198: } elsif ($key eq 'rules') {
5199: if ($oldlonhost) {
5200: $currrules->{$oldlonhost} = $existing->{'rules'};
5201: }
5202: } elsif (ref($existing->{$key}) eq 'HASH') {
5203: $currbalancer->{$key} = 1;
5204: $currtargets->{$key} = $existing->{$key}{'targets'};
5205: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 5206: }
5207: }
1.160.6.7 raeburn 5208: } else {
5209: my ($balancerref,$targetsref) =
5210: &Apache::lonnet::get_lonbalancer_config($servers);
5211: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5212: foreach my $server (sort(keys(%{$balancerref}))) {
5213: $currbalancer->{$server} = 1;
5214: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5215: }
5216: }
5217: }
1.160.6.7 raeburn 5218: return;
1.150 raeburn 5219: }
5220:
5221: sub loadbalancing_rules {
5222: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 5223: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5224: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5225: my $output;
1.160.6.7 raeburn 5226: my $num = 0;
5227: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5228: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5229: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5230: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 5231: $num ++;
1.150 raeburn 5232: my $current;
5233: if (ref($currrules) eq 'HASH') {
5234: $current = $currrules->{$type};
5235: }
1.160.6.55 raeburn 5236: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 5237: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5238: $current = '';
5239: }
5240: }
5241: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 5242: $servers,$currbalancer,$lonhost,$dom,
5243: $targets_div_style,$homedom_div_style,
5244: $css_class,$balnum,$num,$islast);
1.150 raeburn 5245: }
5246: }
5247: return $output;
5248: }
5249:
5250: sub loadbalancing_titles {
5251: my ($dom,$intdom,$usertypes,$types) = @_;
5252: my %othertypes = (
5253: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5254: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5255: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5256: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 5257: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5258: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5259: );
1.160.6.26 raeburn 5260: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.84.2. (raeburn 5261:): my @available;
1.150 raeburn 5262: if (ref($types) eq 'ARRAY') {
1.160.6.84.2. (raeburn 5263:): @available = @{$types};
1.150 raeburn 5264: }
1.160.6.84.2. (raeburn 5265:): unless (grep(/^default$/,@available)) {
5266:): push(@available,'default');
5267:): }
5268:): unshift(@alltypes,@available);
1.150 raeburn 5269: my %titles;
5270: foreach my $type (@alltypes) {
5271: if ($type =~ /^_LC_/) {
5272: $titles{$type} = $othertypes{$type};
5273: } elsif ($type eq 'default') {
5274: $titles{$type} = &mt('All users from [_1]',$dom);
5275: if (ref($types) eq 'ARRAY') {
5276: if (@{$types} > 0) {
5277: $titles{$type} = &mt('Other users from [_1]',$dom);
5278: }
5279: }
5280: } elsif (ref($usertypes) eq 'HASH') {
5281: $titles{$type} = $usertypes->{$type};
5282: }
5283: }
5284: return (\@alltypes,\%othertypes,\%titles);
5285: }
5286:
5287: sub loadbalance_rule_row {
1.160.6.7 raeburn 5288: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5289: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 5290: my @rulenames;
1.150 raeburn 5291: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 5292: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 5293: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 5294: } else {
1.160.6.26 raeburn 5295: @rulenames = ('default','homeserver');
5296: if ($type eq '_LC_external') {
5297: push(@rulenames,'externalbalancer');
5298: } else {
5299: push(@rulenames,'specific');
5300: }
5301: push(@rulenames,'none');
1.150 raeburn 5302: }
5303: my $style = $targets_div_style;
1.160.6.55 raeburn 5304: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 5305: $style = $homedom_div_style;
5306: }
1.160.6.7 raeburn 5307: my $space;
5308: if ($islast && $num == 1) {
5309: $space = '<div display="inline-block"> </div>';
5310: }
5311: my $output =
5312: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
5313: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5314: '<td valaign="top">'.$space.
5315: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 5316: for (my $i=0; $i<@rulenames; $i++) {
5317: my $rule = $rulenames[$i];
5318: my ($checked,$extra);
5319: if ($rulenames[$i] eq 'default') {
5320: $rule = '';
5321: }
5322: if ($rulenames[$i] eq 'specific') {
5323: if (ref($servers) eq 'HASH') {
5324: my $default;
5325: if (($current ne '') && (exists($servers->{$current}))) {
5326: $checked = ' checked="checked"';
5327: }
5328: unless ($checked) {
5329: $default = ' selected="selected"';
5330: }
1.160.6.7 raeburn 5331: $extra =
5332: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5333: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5334: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5335: '<option value=""'.$default.'></option>'."\n";
5336: foreach my $server (sort(keys(%{$servers}))) {
5337: if (ref($currbalancer) eq 'HASH') {
5338: next if (exists($currbalancer->{$server}));
5339: }
1.150 raeburn 5340: my $selected;
1.160.6.7 raeburn 5341: if ($server eq $current) {
1.150 raeburn 5342: $selected = ' selected="selected"';
5343: }
1.160.6.7 raeburn 5344: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 5345: }
5346: $extra .= '</select>';
5347: }
5348: } elsif ($rule eq $current) {
5349: $checked = ' checked="checked"';
5350: }
5351: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 5352: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5353: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5354: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 5355: ')"'.$checked.' /> ';
1.160.6.56 raeburn 5356: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 5357: $output .= $ruletitles{'particular'};
5358: } else {
5359: $output .= $ruletitles{$rulenames[$i]};
5360: }
5361: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 5362: }
5363: $output .= '</div></td></tr>'."\n";
5364: return $output;
5365: }
5366:
5367: sub offloadtype_text {
5368: my %ruletitles = &Apache::lonlocal::texthash (
5369: 'default' => 'Offloads to default destinations',
5370: 'homeserver' => "Offloads to user's home server",
5371: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5372: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 5373: 'none' => 'No offload',
1.160.6.26 raeburn 5374: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5375: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 5376: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 5377: );
5378: return %ruletitles;
5379: }
5380:
5381: sub sparestype_titles {
5382: my %typestitles = &Apache::lonlocal::texthash (
5383: 'primary' => 'primary',
5384: 'default' => 'default',
5385: );
5386: return %typestitles;
5387: }
5388:
1.28 raeburn 5389: sub contact_titles {
5390: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 5391: 'supportemail' => 'Support E-mail address',
5392: 'adminemail' => 'Default Server Admin E-mail address',
5393: 'errormail' => 'Error reports to be e-mailed to',
5394: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.84.2. (raeburn 5395:): 'helpdeskmail' => "Helpdesk requests from all users in this domain",
5396:): 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 5397: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5398: 'requestsmail' => 'E-mail from course requests requiring approval',
5399: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 5400: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 5401: );
5402: my %short_titles = &Apache::lonlocal::texthash (
5403: adminemail => 'Admin E-mail address',
5404: supportemail => 'Support E-mail',
5405: );
5406: return (\%titles,\%short_titles);
5407: }
5408:
1.160.6.78 raeburn 5409: sub helpform_fields {
5410: my %titles = &Apache::lonlocal::texthash (
5411: 'username' => 'Name',
5412: 'user' => 'Username/domain',
5413: 'phone' => 'Phone',
5414: 'cc' => 'Cc e-mail',
5415: 'course' => 'Course Details',
5416: 'section' => 'Sections',
5417: 'screenshot' => 'File upload',
5418: );
5419: my @fields = ('username','phone','user','course','section','cc','screenshot');
5420: my %possoptions = (
5421: username => ['yes','no','req'],
5422: phone => ['yes','no','req'],
5423: user => ['yes','no'],
5424: cc => ['yes','no'],
5425: course => ['yes','no'],
5426: section => ['yes','no'],
5427: screenshot => ['yes','no'],
5428: );
5429: my %fieldoptions = &Apache::lonlocal::texthash (
5430: 'yes' => 'Optional',
5431: 'req' => 'Required',
5432: 'no' => "Not shown",
5433: );
5434: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5435: }
5436:
1.72 raeburn 5437: sub tool_titles {
5438: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 5439: aboutme => 'Personal web page',
1.86 raeburn 5440: blog => 'Blog',
1.160.6.4 raeburn 5441: webdav => 'WebDAV',
1.86 raeburn 5442: portfolio => 'Portfolio',
1.88 bisitz 5443: official => 'Official courses (with institutional codes)',
5444: unofficial => 'Unofficial courses',
1.98 raeburn 5445: community => 'Communities',
1.160.6.30 raeburn 5446: textbook => 'Textbook courses',
1.86 raeburn 5447: );
1.72 raeburn 5448: return %titles;
5449: }
5450:
1.101 raeburn 5451: sub courserequest_titles {
5452: my %titles = &Apache::lonlocal::texthash (
5453: official => 'Official',
5454: unofficial => 'Unofficial',
5455: community => 'Communities',
1.160.6.30 raeburn 5456: textbook => 'Textbook',
1.101 raeburn 5457: norequest => 'Not allowed',
1.104 raeburn 5458: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5459: validate => 'With validation',
5460: autolimit => 'Numerical limit',
1.103 raeburn 5461: unlimited => '(blank for unlimited)',
1.101 raeburn 5462: );
5463: return %titles;
5464: }
5465:
1.160.6.5 raeburn 5466: sub authorrequest_titles {
5467: my %titles = &Apache::lonlocal::texthash (
5468: norequest => 'Not allowed',
5469: approval => 'Approval by Dom. Coord.',
5470: automatic => 'Automatic approval',
5471: );
5472: return %titles;
5473: }
5474:
1.101 raeburn 5475: sub courserequest_conditions {
5476: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5477: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 5478: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 5479: );
5480: return %conditions;
5481: }
5482:
5483:
1.27 raeburn 5484: sub print_usercreation {
1.30 raeburn 5485: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 5486: my $numinrow = 4;
1.28 raeburn 5487: my $datatable;
5488: if ($position eq 'top') {
1.30 raeburn 5489: $$rowtotal ++;
1.34 raeburn 5490: my $rowcount = 0;
1.32 raeburn 5491: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 5492: if (ref($rules) eq 'HASH') {
5493: if (keys(%{$rules}) > 0) {
1.32 raeburn 5494: $datatable .= &user_formats_row('username',$settings,$rules,
5495: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 5496: $$rowtotal ++;
1.32 raeburn 5497: $rowcount ++;
5498: }
5499: }
5500: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5501: if (ref($idrules) eq 'HASH') {
5502: if (keys(%{$idrules}) > 0) {
5503: $datatable .= &user_formats_row('id',$settings,$idrules,
5504: $idruleorder,$numinrow,$rowcount);
5505: $$rowtotal ++;
5506: $rowcount ++;
1.28 raeburn 5507: }
5508: }
1.39 raeburn 5509: if ($rowcount == 0) {
5510: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5511: $$rowtotal ++;
5512: $rowcount ++;
5513: }
1.34 raeburn 5514: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 5515: my @creators = ('author','course','requestcrs');
1.37 raeburn 5516: my ($rules,$ruleorder) =
5517: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 5518: my %lt = &usercreation_types();
5519: my %checked;
5520: if (ref($settings) eq 'HASH') {
5521: if (ref($settings->{'cancreate'}) eq 'HASH') {
5522: foreach my $item (@creators) {
5523: $checked{$item} = $settings->{'cancreate'}{$item};
5524: }
5525: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5526: foreach my $item (@creators) {
5527: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5528: $checked{$item} = 'none';
5529: }
5530: }
5531: }
5532: }
5533: my $rownum = 0;
5534: foreach my $item (@creators) {
5535: $rownum ++;
1.160.6.34 raeburn 5536: if ($checked{$item} eq '') {
5537: $checked{$item} = 'any';
1.34 raeburn 5538: }
5539: my $css_class;
5540: if ($rownum%2) {
5541: $css_class = '';
5542: } else {
5543: $css_class = ' class="LC_odd_row" ';
5544: }
5545: $datatable .= '<tr'.$css_class.'>'.
5546: '<td><span class="LC_nobreak">'.$lt{$item}.
5547: '</span></td><td align="right">';
1.160.6.34 raeburn 5548: my @options = ('any');
5549: if (ref($rules) eq 'HASH') {
5550: if (keys(%{$rules}) > 0) {
5551: push(@options,('official','unofficial'));
1.37 raeburn 5552: }
5553: }
1.160.6.34 raeburn 5554: push(@options,'none');
1.37 raeburn 5555: foreach my $option (@options) {
1.50 raeburn 5556: my $type = 'radio';
1.34 raeburn 5557: my $check = ' ';
1.160.6.34 raeburn 5558: if ($checked{$item} eq $option) {
5559: $check = ' checked="checked" ';
1.34 raeburn 5560: }
5561: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5562: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5563: $item.'" value="'.$option.'"'.$check.'/> '.
5564: $lt{$option}.'</label> </span>';
5565: }
5566: $datatable .= '</td></tr>';
5567: }
1.28 raeburn 5568: } else {
5569: my @contexts = ('author','course','domain');
5570: my @authtypes = ('int','krb4','krb5','loc');
5571: my %checked;
5572: if (ref($settings) eq 'HASH') {
5573: if (ref($settings->{'authtypes'}) eq 'HASH') {
5574: foreach my $item (@contexts) {
5575: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5576: foreach my $auth (@authtypes) {
5577: if ($settings->{'authtypes'}{$item}{$auth}) {
5578: $checked{$item}{$auth} = ' checked="checked" ';
5579: }
5580: }
5581: }
5582: }
1.27 raeburn 5583: }
1.35 raeburn 5584: } else {
5585: foreach my $item (@contexts) {
1.36 raeburn 5586: foreach my $auth (@authtypes) {
1.35 raeburn 5587: $checked{$item}{$auth} = ' checked="checked" ';
5588: }
5589: }
1.27 raeburn 5590: }
1.28 raeburn 5591: my %title = &context_names();
5592: my %authname = &authtype_names();
5593: my $rownum = 0;
5594: my $css_class;
5595: foreach my $item (@contexts) {
5596: if ($rownum%2) {
5597: $css_class = '';
5598: } else {
5599: $css_class = ' class="LC_odd_row" ';
5600: }
1.30 raeburn 5601: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5602: '<td>'.$title{$item}.
5603: '</td><td class="LC_left_item">'.
5604: '<span class="LC_nobreak">';
5605: foreach my $auth (@authtypes) {
5606: $datatable .= '<label>'.
5607: '<input type="checkbox" name="'.$item.'_auth" '.
5608: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5609: $authname{$auth}.'</label> ';
5610: }
5611: $datatable .= '</span></td></tr>';
5612: $rownum ++;
1.27 raeburn 5613: }
1.30 raeburn 5614: $$rowtotal += $rownum;
1.27 raeburn 5615: }
5616: return $datatable;
5617: }
5618:
1.160.6.34 raeburn 5619: sub print_selfcreation {
5620: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 5621: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 5622: if (ref($settings) eq 'HASH') {
5623: if (ref($settings->{'cancreate'}) eq 'HASH') {
5624: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 5625: if (ref($createsettings) eq 'HASH') {
5626: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5627: @selfcreate = @{$createsettings->{'selfcreate'}};
5628: } elsif ($createsettings->{'selfcreate'} ne '') {
5629: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5630: @selfcreate = ('email','login','sso');
5631: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5632: @selfcreate = ($createsettings->{'selfcreate'});
5633: }
5634: }
5635: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5636: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 5637: }
5638: }
5639: }
5640: }
5641: my %radiohash;
5642: my $numinrow = 4;
5643: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.84.2. (raeburn 5644:): my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 5645: if ($position eq 'top') {
5646: my %choices = &Apache::lonlocal::texthash (
5647: cancreate_login => 'Institutional Login',
5648: cancreate_sso => 'Institutional Single Sign On',
5649: );
5650: my @toggles = sort(keys(%choices));
5651: my %defaultchecked = (
5652: 'cancreate_login' => 'off',
5653: 'cancreate_sso' => 'off',
5654: );
1.160.6.35 raeburn 5655: my ($onclick,$itemcount);
1.160.6.34 raeburn 5656: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5657: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 5658: $$rowtotal += $itemcount;
1.160.6.39 raeburn 5659:
1.160.6.34 raeburn 5660: if (ref($usertypes) eq 'HASH') {
5661: if (keys(%{$usertypes}) > 0) {
5662: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5663: $dom,$numinrow,$othertitle,
1.160.6.84.2. (raeburn 5664:): 'statustocreate',$rowtotal);
1.160.6.34 raeburn 5665: $$rowtotal ++;
5666: }
5667: }
1.160.6.44 raeburn 5668: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5669: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5670: $fieldtitles{'inststatus'} = &mt('Institutional status');
5671: my $rem;
5672: my $numperrow = 2;
5673: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5674: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 5675: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 5676: '<td class="LC_left_item">'."\n".
5677: '<table><tr><td>'."\n";
5678: for (my $i=0; $i<@fields; $i++) {
5679: $rem = $i%($numperrow);
5680: if ($rem == 0) {
5681: if ($i > 0) {
5682: $datatable .= '</tr>';
5683: }
5684: $datatable .= '<tr>';
5685: }
5686: my $currval;
1.160.6.51 raeburn 5687: if (ref($createsettings) eq 'HASH') {
5688: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5689: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5690: }
1.160.6.44 raeburn 5691: }
5692: $datatable .= '<td class="LC_left_item">'.
5693: '<span class="LC_nobreak">'.
5694: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5695: 'value="'.$currval.'" size="10" /> '.
5696: $fieldtitles{$fields[$i]}.'</span></td>';
5697: }
5698: my $colsleft = $numperrow - $rem;
5699: if ($colsleft > 1 ) {
5700: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5701: ' </td>';
5702: } elsif ($colsleft == 1) {
5703: $datatable .= '<td class="LC_left_item"> </td>';
5704: }
5705: $datatable .= '</tr></table></td></tr>';
5706: $$rowtotal ++;
1.160.6.34 raeburn 5707: } elsif ($position eq 'middle') {
5708: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.84.2. (raeburn 5709:): my @posstypes;
1.160.6.34 raeburn 5710: if (ref($types) eq 'ARRAY') {
1.160.6.84.2. (raeburn 5711:): @posstypes = @{$types};
5712:): }
5713:): unless (grep(/^default$/,@posstypes)) {
5714:): push(@posstypes,'default');
5715:): }
5716:): my %usertypeshash;
5717:): if (ref($usertypes) eq 'HASH') {
5718:): %usertypeshash = %{$usertypes};
5719:): }
5720:): $usertypeshash{'default'} = $othertitle;
5721:): foreach my $status (@posstypes) {
5722:): $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
5723:): $numinrow,$$rowtotal,\%usertypeshash);
5724:): $$rowtotal ++;
1.160.6.34 raeburn 5725: }
5726: } else {
1.160.6.40 raeburn 5727: my %choices = &Apache::lonlocal::texthash (
5728: cancreate_email => 'E-mail address as username',
5729: );
5730: my @toggles = sort(keys(%choices));
5731: my %defaultchecked = (
5732: 'cancreate_email' => 'off',
5733: );
5734: my $itemcount = 0;
5735: my $display = 'none';
5736: if (grep(/^\Qemail\E$/,@selfcreate)) {
5737: $display = 'block';
5738: }
5739: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5740: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5741: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.84.2. (raeburn 5742:): my (@ordered,%usertypeshash);
5743:): if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
5744:): @ordered = @{$domdefaults{'inststatusguest'}};
5745:): }
5746:): if (@ordered) {
5747:): unless (grep(/^default$/,@ordered)) {
5748:): push(@ordered,'default');
5749:): }
5750:): if (ref($usertypes) eq 'HASH') {
5751:): %usertypeshash = %{$usertypes};
5752:): }
5753:): $usertypeshash{'default'} = $othertitle;
5754:): $additional .= '<table><tr>';
5755:): foreach my $status (@ordered) {
5756:): $additional .= '<th>'.$usertypeshash{$status}.'</th>';
5757:): }
5758:): $additional .= '</tr><tr>';
5759:): foreach my $status (@ordered) {
5760:): $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 5761: }
1.160.6.84.2. (raeburn 5762:): $additional .= '</tr></table>';
5763:): } else {
5764:): $usertypeshash{'default'} = $othertitle;
5765:): $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 5766: }
1.160.6.40 raeburn 5767: $additional .= '</div>'."\n";
5768:
5769: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 5770: \%choices,$$rowtotal,$onclick,$additional);
5771: $$rowtotal ++;
1.160.6.40 raeburn 5772: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 5773: $$rowtotal ++;
1.160.6.35 raeburn 5774: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5775: $numinrow = 1;
1.160.6.84.2. (raeburn 5776:): foreach my $status (@ordered) {
5777:): $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5778:): $numinrow,$$rowtotal,\%usertypeshash,$infofields,$infotitles);
5779:): $$rowtotal ++;
1.160.6.35 raeburn 5780: }
1.160.6.34 raeburn 5781: my ($emailrules,$emailruleorder) =
5782: &Apache::lonnet::inst_userrules($dom,'email');
5783: if (ref($emailrules) eq 'HASH') {
5784: if (keys(%{$emailrules}) > 0) {
5785: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 5786: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 5787: $$rowtotal ++;
5788: }
5789: }
1.160.6.35 raeburn 5790: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 5791: }
5792: return $datatable;
5793: }
5794:
1.160.6.40 raeburn 5795: sub email_as_username {
5796: my ($rowtotal,$processing,$type) = @_;
5797: my %choices =
5798: &Apache::lonlocal::texthash (
5799: automatic => 'Automatic approval',
5800: approval => 'Queued for approval',
5801: );
5802: my $output;
5803: foreach my $option ('automatic','approval') {
5804: my $checked;
5805: if (ref($processing) eq 'HASH') {
5806: if ($type eq '') {
5807: if (!exists($processing->{'default'})) {
5808: if ($option eq 'automatic') {
5809: $checked = ' checked="checked"';
5810: }
5811: } else {
5812: if ($processing->{'default'} eq $option) {
5813: $checked = ' checked="checked"';
5814: }
5815: }
5816: } else {
5817: if (!exists($processing->{$type})) {
5818: if ($option eq 'automatic') {
5819: $checked = ' checked="checked"';
5820: }
5821: } else {
5822: if ($processing->{$type} eq $option) {
5823: $checked = ' checked="checked"';
5824: }
5825: }
5826: }
5827: } elsif ($option eq 'automatic') {
5828: $checked = ' checked="checked"';
5829: }
5830: my $name = 'cancreate_emailprocess';
5831: if (($type ne '') && ($type ne 'default')) {
5832: $name .= '_'.$type;
5833: }
5834: $output .= '<span class="LC_nobreak"><label>'.
5835: '<input type="radio" name="'.$name.'"'.
5836: $checked.' value="'.$option.'" />'.
5837: $choices{$option}.'</label></span>';
5838: if ($type eq '') {
5839: $output .= ' ';
5840: } else {
5841: $output .= '<br />';
5842: }
5843: }
5844: $$rowtotal ++;
5845: return $output;
5846: }
5847:
1.160.6.5 raeburn 5848: sub captcha_choice {
5849: my ($context,$settings,$itemcount) = @_;
1.160.6.69 raeburn 5850: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5851: $vertext,$currver);
1.160.6.5 raeburn 5852: my %lt = &captcha_phrases();
5853: $keyentry = 'hidden';
5854: if ($context eq 'cancreate') {
1.160.6.34 raeburn 5855: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 5856: } elsif ($context eq 'login') {
5857: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
5858: }
5859: if (ref($settings) eq 'HASH') {
5860: if ($settings->{'captcha'}) {
5861: $checked{$settings->{'captcha'}} = ' checked="checked"';
5862: } else {
5863: $checked{'original'} = ' checked="checked"';
5864: }
5865: if ($settings->{'captcha'} eq 'recaptcha') {
5866: $pubtext = $lt{'pub'};
5867: $privtext = $lt{'priv'};
5868: $keyentry = 'text';
1.160.6.69 raeburn 5869: $vertext = $lt{'ver'};
5870: $currver = $settings->{'recaptchaversion'};
5871: if ($currver ne '2') {
5872: $currver = 1;
5873: }
1.160.6.5 raeburn 5874: }
5875: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5876: $currpub = $settings->{'recaptchakeys'}{'public'};
5877: $currpriv = $settings->{'recaptchakeys'}{'private'};
5878: }
5879: } else {
5880: $checked{'original'} = ' checked="checked"';
5881: }
5882: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5883: my $output = '<tr'.$css_class.'>'.
5884: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
5885: '<table><tr><td>'."\n";
5886: foreach my $option ('original','recaptcha','notused') {
5887: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5888: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5889: $lt{$option}.'</label></span>';
5890: unless ($option eq 'notused') {
5891: $output .= (' 'x2)."\n";
5892: }
5893: }
5894: #
5895: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5896: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
5897: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
5898: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
5899: #
5900: $output .= '</td></tr>'."\n".
5901: '<tr><td>'."\n".
5902: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5903: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5904: $currpub.'" size="40" /></span><br />'."\n".
5905: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5906: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 5907: $currpriv.'" size="40" /></span><br />'.
5908: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5909: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5910: $currver.'" size="3" /></span><br />'.
5911: '</td></tr></table>'."\n".
1.160.6.5 raeburn 5912: '</td></tr>';
5913: return $output;
5914: }
5915:
1.32 raeburn 5916: sub user_formats_row {
5917: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5918: my $output;
5919: my %text = (
5920: 'username' => 'new usernames',
5921: 'id' => 'IDs',
1.45 raeburn 5922: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5923: );
5924: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5925: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5926: '<td><span class="LC_nobreak">';
5927: if ($type eq 'email') {
5928: $output .= &mt("Formats disallowed for $text{$type}: ");
5929: } else {
5930: $output .= &mt("Format rules to check for $text{$type}: ");
5931: }
5932: $output .= '</span></td>'.
5933: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5934: my $rem;
5935: if (ref($ruleorder) eq 'ARRAY') {
5936: for (my $i=0; $i<@{$ruleorder}; $i++) {
5937: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5938: my $rem = $i%($numinrow);
5939: if ($rem == 0) {
5940: if ($i > 0) {
5941: $output .= '</tr>';
5942: }
5943: $output .= '<tr>';
5944: }
5945: my $check = ' ';
1.39 raeburn 5946: if (ref($settings) eq 'HASH') {
5947: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5948: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5949: $check = ' checked="checked" ';
5950: }
1.27 raeburn 5951: }
5952: }
5953: $output .= '<td class="LC_left_item">'.
5954: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5955: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5956: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5957: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5958: }
5959: }
5960: $rem = @{$ruleorder}%($numinrow);
5961: }
5962: my $colsleft = $numinrow - $rem;
5963: if ($colsleft > 1 ) {
5964: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5965: ' </td>';
5966: } elsif ($colsleft == 1) {
5967: $output .= '<td class="LC_left_item"> </td>';
5968: }
5969: $output .= '</tr></table></td></tr>';
5970: return $output;
5971: }
5972:
1.34 raeburn 5973: sub usercreation_types {
5974: my %lt = &Apache::lonlocal::texthash (
5975: author => 'When adding a co-author',
5976: course => 'When adding a user to a course',
1.100 raeburn 5977: requestcrs => 'When requesting a course',
1.34 raeburn 5978: any => 'Any',
5979: official => 'Institutional only ',
5980: unofficial => 'Non-institutional only',
5981: none => 'None',
5982: );
5983: return %lt;
1.48 raeburn 5984: }
1.34 raeburn 5985:
1.160.6.34 raeburn 5986: sub selfcreation_types {
5987: my %lt = &Apache::lonlocal::texthash (
5988: selfcreate => 'User creates own account',
5989: any => 'Any',
5990: official => 'Institutional only ',
5991: unofficial => 'Non-institutional only',
5992: email => 'E-mail address',
5993: login => 'Institutional Login',
5994: sso => 'SSO',
5995: );
5996: }
5997:
1.28 raeburn 5998: sub authtype_names {
5999: my %lt = &Apache::lonlocal::texthash(
6000: int => 'Internal',
6001: krb4 => 'Kerberos 4',
6002: krb5 => 'Kerberos 5',
6003: loc => 'Local',
6004: );
6005: return %lt;
6006: }
6007:
6008: sub context_names {
6009: my %context_title = &Apache::lonlocal::texthash(
6010: author => 'Creating users when an Author',
6011: course => 'Creating users when in a course',
6012: domain => 'Creating users when a Domain Coordinator',
6013: );
6014: return %context_title;
6015: }
6016:
1.33 raeburn 6017: sub print_usermodification {
6018: my ($position,$dom,$settings,$rowtotal) = @_;
6019: my $numinrow = 4;
6020: my ($context,$datatable,$rowcount);
6021: if ($position eq 'top') {
6022: $rowcount = 0;
6023: $context = 'author';
6024: foreach my $role ('ca','aa') {
6025: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6026: $numinrow,$rowcount);
6027: $$rowtotal ++;
6028: $rowcount ++;
6029: }
1.160.6.37 raeburn 6030: } elsif ($position eq 'bottom') {
1.33 raeburn 6031: $context = 'course';
6032: $rowcount = 0;
6033: foreach my $role ('st','ep','ta','in','cr') {
6034: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6035: $numinrow,$rowcount);
6036: $$rowtotal ++;
6037: $rowcount ++;
6038: }
6039: }
6040: return $datatable;
6041: }
6042:
1.43 raeburn 6043: sub print_defaults {
1.160.6.40 raeburn 6044: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 6045: my $rownum = 0;
1.160.6.80 raeburn 6046: my ($datatable,$css_class,$titles);
6047: unless ($position eq 'bottom') {
6048: $titles = &defaults_titles($dom);
6049: }
1.160.6.40 raeburn 6050: if ($position eq 'top') {
6051: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6052: 'datelocale_def','portal_def');
6053: my %defaults;
6054: if (ref($settings) eq 'HASH') {
6055: %defaults = %{$settings};
1.43 raeburn 6056: } else {
1.160.6.40 raeburn 6057: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6058: foreach my $item (@items) {
6059: $defaults{$item} = $domdefaults{$item};
6060: }
1.43 raeburn 6061: }
1.160.6.40 raeburn 6062: foreach my $item (@items) {
6063: if ($rownum%2) {
6064: $css_class = '';
6065: } else {
6066: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 6067: }
1.160.6.40 raeburn 6068: $datatable .= '<tr'.$css_class.'>'.
6069: '<td><span class="LC_nobreak">'.$titles->{$item}.
6070: '</span></td><td class="LC_right_item" colspan="3">';
6071: if ($item eq 'auth_def') {
6072: my @authtypes = ('internal','krb4','krb5','localauth');
6073: my %shortauth = (
6074: internal => 'int',
6075: krb4 => 'krb4',
6076: krb5 => 'krb5',
6077: localauth => 'loc'
6078: );
6079: my %authnames = &authtype_names();
6080: foreach my $auth (@authtypes) {
6081: my $checked = ' ';
6082: if ($defaults{$item} eq $auth) {
6083: $checked = ' checked="checked" ';
6084: }
6085: $datatable .= '<label><input type="radio" name="'.$item.
6086: '" value="'.$auth.'"'.$checked.'/>'.
6087: $authnames{$shortauth{$auth}}.'</label> ';
6088: }
6089: } elsif ($item eq 'timezone_def') {
6090: my $includeempty = 1;
6091: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6092: } elsif ($item eq 'datelocale_def') {
6093: my $includeempty = 1;
6094: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
6095: } elsif ($item eq 'lang_def') {
1.160.6.63 raeburn 6096: my $includeempty = 1;
6097: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40 raeburn 6098: } else {
6099: my $size;
6100: if ($item eq 'portal_def') {
6101: $size = ' size="25"';
6102: }
6103: $datatable .= '<input type="text" name="'.$item.'" value="'.
6104: $defaults{$item}.'"'.$size.' />';
6105: }
6106: $datatable .= '</td></tr>';
6107: $rownum ++;
6108: }
1.160.6.80 raeburn 6109: } elsif ($position eq 'middle') {
6110: my @items = ('intauth_cost','intauth_check','intauth_switch');
6111: my %defaults;
6112: if (ref($settings) eq 'HASH') {
6113: %defaults = %{$settings};
6114: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6115: $defaults{'intauth_cost'} = 10;
6116: }
6117: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6118: $defaults{'intauth_check'} = 0;
6119: }
6120: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6121: $defaults{'intauth_switch'} = 0;
6122: }
6123: } else {
6124: %defaults = (
6125: 'intauth_cost' => 10,
6126: 'intauth_check' => 0,
6127: 'intauth_switch' => 0,
6128: );
6129: }
6130: foreach my $item (@items) {
6131: if ($rownum%2) {
6132: $css_class = '';
6133: } else {
6134: $css_class = ' class="LC_odd_row" ';
6135: }
6136: $datatable .= '<tr'.$css_class.'>'.
6137: '<td><span class="LC_nobreak">'.$titles->{$item}.
6138: '</span></td><td class="LC_left_item" colspan="3">';
6139: if ($item eq 'intauth_switch') {
6140: my @options = (0,1,2);
6141: my %optiondesc = &Apache::lonlocal::texthash (
6142: 0 => 'No',
6143: 1 => 'Yes',
6144: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6145: );
6146: $datatable .= '<table width="100%">';
6147: foreach my $option (@options) {
6148: my $checked = ' ';
6149: if ($defaults{$item} eq $option) {
6150: $checked = ' checked="checked"';
6151: }
6152: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6153: '<label><input type="radio" name="'.$item.
6154: '" value="'.$option.'"'.$checked.' />'.
6155: $optiondesc{$option}.'</label></span></td></tr>';
6156: }
6157: $datatable .= '</table>';
6158: } elsif ($item eq 'intauth_check') {
6159: my @options = (0,1,2);
6160: my %optiondesc = &Apache::lonlocal::texthash (
6161: 0 => 'No',
6162: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6163: 2 => 'Yes, disallow login if stored cost is less than domain default',
6164: );
6165: $datatable .= '<table wisth="100%">';
6166: foreach my $option (@options) {
6167: my $checked = ' ';
6168: my $onclick;
6169: if ($defaults{$item} eq $option) {
6170: $checked = ' checked="checked"';
6171: }
6172: if ($option == 2) {
6173: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6174: }
6175: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6176: '<label><input type="radio" name="'.$item.
6177: '" value="'.$option.'"'.$checked.$onclick.' />'.
6178: $optiondesc{$option}.'</label></span></td></tr>';
6179: }
6180: $datatable .= '</table>';
6181: } else {
6182: $datatable .= '<input type="text" name="'.$item.'" value="'.
6183: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6184: }
6185: $datatable .= '</td></tr>';
6186: $rownum ++;
6187: }
1.160.6.40 raeburn 6188: } else {
1.160.6.80 raeburn 6189: my %defaults;
1.160.6.40 raeburn 6190: if (ref($settings) eq 'HASH') {
6191: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
6192: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
6193: my $maxnum = @{$settings->{'inststatusorder'}};
6194: for (my $i=0; $i<$maxnum; $i++) {
6195: $css_class = $rownum%2?' class="LC_odd_row"':'';
6196: my $item = $settings->{'inststatusorder'}->[$i];
6197: my $title = $settings->{'inststatustypes'}->{$item};
6198: my $guestok;
6199: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
6200: $guestok = 1;
6201: }
6202: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6203: $datatable .= '<tr'.$css_class.'>'.
6204: '<td><span class="LC_nobreak">'.
6205: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6206: for (my $k=0; $k<=$maxnum; $k++) {
6207: my $vpos = $k+1;
6208: my $selstr;
6209: if ($k == $i) {
6210: $selstr = ' selected="selected" ';
6211: }
6212: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6213: }
6214: my ($checkedon,$checkedoff);
6215: $checkedoff = ' checked="checked"';
6216: if ($guestok) {
6217: $checkedon = $checkedoff;
6218: $checkedoff = '';
6219: }
6220: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6221: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6222: &mt('delete').'</span></td>'.
6223: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
6224: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
6225: '</span></td>'.
6226: '<td class="LC_right_item"><span class="LC_nobreak">'.
6227: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
6228: &mt('Yes').'</label>'.(' 'x2).
6229: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
6230: &mt('No').'</label></span></td></tr>';
6231: }
6232: $css_class = $rownum%2?' class="LC_odd_row"':'';
6233: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6234: $datatable .= '<tr '.$css_class.'>'.
6235: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6236: for (my $k=0; $k<=$maxnum; $k++) {
6237: my $vpos = $k+1;
6238: my $selstr;
6239: if ($k == $maxnum) {
6240: $selstr = ' selected="selected" ';
6241: }
6242: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6243: }
6244: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 6245: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 6246: ' '.&mt('(new)').
6247: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
6248: &mt('Name displayed:').
6249: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6250: '<td class="LC_right_item"><span class="LC_nobreak">'.
6251: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
6252: &mt('Yes').'</label>'.(' 'x2).
6253: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
6254: &mt('No').'</label></span></td></tr>';
6255: '</tr>'."\n";
6256: $rownum ++;
1.141 raeburn 6257: }
1.43 raeburn 6258: }
6259: }
6260: $$rowtotal += $rownum;
6261: return $datatable;
6262: }
6263:
1.160.6.5 raeburn 6264: sub get_languages_hash {
6265: my %langchoices;
6266: foreach my $id (&Apache::loncommon::languageids()) {
6267: my $code = &Apache::loncommon::supportedlanguagecode($id);
6268: if ($code ne '') {
6269: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6270: }
6271: }
6272: return %langchoices;
6273: }
6274:
1.43 raeburn 6275: sub defaults_titles {
1.141 raeburn 6276: my ($dom) = @_;
1.43 raeburn 6277: my %titles = &Apache::lonlocal::texthash (
6278: 'auth_def' => 'Default authentication type',
6279: 'auth_arg_def' => 'Default authentication argument',
6280: 'lang_def' => 'Default language',
1.54 raeburn 6281: 'timezone_def' => 'Default timezone',
1.68 raeburn 6282: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6283: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 6284: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
6285: 'intauth_check' => 'Check bcrypt cost if authenticated',
6286: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 6287: );
1.141 raeburn 6288: if ($dom) {
6289: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6290: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6291: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6292: $protocol = 'http' if ($protocol ne 'https');
6293: if ($uint_dom) {
6294: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6295: $uint_dom);
6296: }
6297: }
1.43 raeburn 6298: return (\%titles);
6299: }
6300:
1.160.6.84.2. 0(raebur 6301:9): sub print_scantron {
6302:9): my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
6303:9): if ($position eq 'top') {
6304:9): return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
6305:9): } else {
6306:9): return &print_scantronconfig($dom,$settings,\$rowtotal);
6307:9): }
6308:9): }
6309:9):
6310:9): sub scantron_javascript {
6311:9): return <<"ENDSCRIPT";
6312:9):
6313:9): <script type="text/javascript">
6314:9): // <![CDATA[
6315:9):
6316:9): function toggleScantron(form) {
6317:9): var csvfieldset = new Array();
6318:9): if (document.getElementById('scantroncsv_cols')) {
6319:9): csvfieldset.push(document.getElementById('scantroncsv_cols'));
6320:9): }
6321:9): if (document.getElementById('scantroncsv_options')) {
6322:9): csvfieldset.push(document.getElementById('scantroncsv_options'));
6323:9): }
6324:9): if (csvfieldset.length) {
6325:9): if (document.getElementById('scantronconfcsv')) {
6326:9): var scantroncsv = document.getElementById('scantronconfcsv');
6327:9): if (scantroncsv.checked) {
6328:9): for (var i=0; i<csvfieldset.length; i++) {
6329:9): csvfieldset[i].style.display = 'block';
6330:9): }
6331:9): } else {
6332:9): for (var i=0; i<csvfieldset.length; i++) {
6333:9): csvfieldset[i].style.display = 'none';
6334:9): }
6335:9): var csvselects = document.getElementsByClassName('scantronconfig_csv');
6336:9): if (csvselects.length) {
6337:9): for (var j=0; j<csvselects.length; j++) {
6338:9): csvselects[j].selectedIndex = 0;
6339:9): }
6340:9): }
6341:9): }
6342:9): }
6343:9): }
6344:9): return;
6345:9): }
6346:9): // ]]>
6347:9): </script>
6348:9):
6349:9): ENDSCRIPT
6350:9):
6351:9): }
6352:9):
1.46 raeburn 6353: sub print_scantronformat {
6354: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6355: my $itemcount = 1;
1.60 raeburn 6356: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6357: %confhash);
1.46 raeburn 6358: my $switchserver = &check_switchserver($dom,$confname);
6359: my %lt = &Apache::lonlocal::texthash (
1.95 www 6360: default => 'Default bubblesheet format file error',
6361: custom => 'Custom bubblesheet format file error',
1.46 raeburn 6362: );
6363: my %scantronfiles = (
6364: default => 'default.tab',
6365: custom => 'custom.tab',
6366: );
6367: foreach my $key (keys(%scantronfiles)) {
6368: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6369: .$scantronfiles{$key};
6370: }
6371: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6372: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6373: if (!$switchserver) {
6374: my $servadm = $r->dir_config('lonAdmEMail');
6375: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6376: if ($configuserok eq 'ok') {
6377: if ($author_ok eq 'ok') {
6378: my %legacyfile = (
1.160.6.84.2. 0(raebur 6379:9): default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6380:9): custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 6381: );
6382: my %md5chk;
6383: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6384: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6385: chomp($md5chk{$type});
1.46 raeburn 6386: }
6387: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6388: foreach my $type (keys(%legacyfile)) {
1.160.6.84.2. 0(raebur 6389:9): ($scantronurls{$type},my $error) =
1.46 raeburn 6390: &legacy_scantronformat($r,$dom,$confname,
6391: $type,$legacyfile{$type},
6392: $scantronurls{$type},
6393: $scantronfiles{$type});
1.60 raeburn 6394: if ($error ne '') {
6395: $error{$type} = $error;
6396: }
6397: }
6398: if (keys(%error) == 0) {
6399: $is_custom = 1;
1.160.6.84.2. 0(raebur 6400:9): $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 6401: $scantronurls{'custom'};
1.160.6.84.2. 0(raebur 6402:9): my $putresult =
1.60 raeburn 6403: &Apache::lonnet::put_dom('configuration',
6404: \%confhash,$dom);
6405: if ($putresult ne 'ok') {
1.160.6.84.2. 0(raebur 6406:9): $error{'custom'} =
1.60 raeburn 6407: '<span class="LC_error">'.
6408: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6409: }
1.46 raeburn 6410: }
6411: } else {
1.60 raeburn 6412: ($scantronurls{'default'},my $error) =
1.46 raeburn 6413: &legacy_scantronformat($r,$dom,$confname,
6414: 'default',$legacyfile{'default'},
6415: $scantronurls{'default'},
6416: $scantronfiles{'default'});
1.60 raeburn 6417: if ($error eq '') {
6418: $confhash{'scantron'}{'scantronformat'} = '';
6419: my $putresult =
6420: &Apache::lonnet::put_dom('configuration',
6421: \%confhash,$dom);
6422: if ($putresult ne 'ok') {
6423: $error{'default'} =
6424: '<span class="LC_error">'.
6425: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6426: }
6427: } else {
6428: $error{'default'} = $error;
6429: }
1.46 raeburn 6430: }
6431: }
6432: }
6433: } else {
1.95 www 6434: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 6435: }
6436: }
6437: if (ref($settings) eq 'HASH') {
6438: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6439: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
1.160.6.84.2. (raeburn 6440:): if ((!@info) || ($info[0] eq 'no_such_dir')) {
1.46 raeburn 6441: $scantronurl = '';
6442: } else {
6443: $scantronurl = $settings->{'scantronformat'};
6444: }
6445: $is_custom = 1;
6446: } else {
6447: $scantronurl = $scantronurls{'default'};
6448: }
6449: } else {
1.60 raeburn 6450: if ($is_custom) {
6451: $scantronurl = $scantronurls{'custom'};
6452: } else {
6453: $scantronurl = $scantronurls{'default'};
6454: }
1.46 raeburn 6455: }
6456: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6457: $datatable .= '<tr'.$css_class.'>';
6458: if (!$is_custom) {
1.65 raeburn 6459: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6460: '<span class="LC_nobreak">';
1.46 raeburn 6461: if ($scantronurl) {
1.160.6.21 raeburn 6462: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6463: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 6464: } else {
6465: $datatable = &mt('File unavailable for display');
6466: }
1.65 raeburn 6467: $datatable .= '</span></td>';
1.60 raeburn 6468: if (keys(%error) == 0) {
6469: $datatable .= '<td valign="bottom">';
6470: if (!$switchserver) {
6471: $datatable .= &mt('Upload:').'<br />';
6472: }
6473: } else {
6474: my $errorstr;
6475: foreach my $key (sort(keys(%error))) {
6476: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6477: }
6478: $datatable .= '<td>'.$errorstr;
6479: }
1.46 raeburn 6480: } else {
6481: if (keys(%error) > 0) {
6482: my $errorstr;
6483: foreach my $key (sort(keys(%error))) {
6484: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6485: }
1.60 raeburn 6486: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 6487: } elsif ($scantronurl) {
1.160.6.26 raeburn 6488: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 6489: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 6490: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 6491: $link.
6492: '<label><input type="checkbox" name="scantronformat_del"'.
6493: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 6494: '<td><span class="LC_nobreak"> '.
6495: &mt('Replace:').'</span><br />';
1.46 raeburn 6496: }
6497: }
6498: if (keys(%error) == 0) {
6499: if ($switchserver) {
6500: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6501: } else {
1.65 raeburn 6502: $datatable .='<span class="LC_nobreak"> '.
6503: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 6504: }
6505: }
6506: $datatable .= '</td></tr>';
6507: $$rowtotal ++;
6508: return $datatable;
6509: }
6510:
6511: sub legacy_scantronformat {
6512: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6513: my ($url,$error);
6514: my @statinfo = &Apache::lonnet::stat_file($newurl);
6515: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6516: (my $result,$url) =
6517: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6518: '','',$newfile);
6519: if ($result ne 'ok') {
1.130 raeburn 6520: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 6521: }
6522: }
6523: return ($url,$error);
6524: }
1.43 raeburn 6525:
1.160.6.84.2. 0(raebur 6526:9): sub print_scantronconfig {
6527:9): my ($dom,$settings,$rowtotal) = @_;
6528:9): my $itemcount = 2;
6529:9): my $is_checked = ' checked="checked"';
6530:9): my %optionson = (
6531:9): hdr => ' checked="checked"',
6532:9): pad => ' checked="checked"',
6533:9): rem => ' checked="checked"',
6534:9): );
6535:9): my %optionsoff = (
6536:9): hdr => '',
6537:9): pad => '',
6538:9): rem => '',
6539:9): );
6540:9): my $currcsvsty = 'none';
6541:9): my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
6542:9): my @fields = &scantroncsv_fields();
6543:9): my %titles = &scantronconfig_titles();
6544:9): if (ref($settings) eq 'HASH') {
6545:9): if (ref($settings->{config}) eq 'HASH') {
6546:9): if ($settings->{config}->{dat}) {
6547:9): $checked{'dat'} = $is_checked;
6548:9): }
6549:9): if (ref($settings->{config}->{csv}) eq 'HASH') {
6550:9): if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
6551:9): %csvfields = %{$settings->{config}->{csv}->{fields}};
6552:9): if (keys(%csvfields) > 0) {
6553:9): $checked{'csv'} = $is_checked;
6554:9): $currcsvsty = 'block';
6555:9): }
6556:9): }
6557:9): if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
6558:9): %csvoptions = %{$settings->{config}->{csv}->{options}};
6559:9): foreach my $option (keys(%optionson)) {
6560:9): unless ($csvoptions{$option}) {
6561:9): $optionsoff{$option} = $optionson{$option};
6562:9): $optionson{$option} = '';
6563:9): }
6564:9): }
6565:9): }
6566:9): }
6567:9): } else {
6568:9): $checked{'dat'} = $is_checked;
6569:9): }
6570:9): } else {
6571:9): $checked{'dat'} = $is_checked;
6572:9): }
6573:9): $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
6574:9): my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6575:9): $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
6576:9): '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
6577:9): foreach my $item ('dat','csv') {
6578:9): my $id;
6579:9): if ($item eq 'csv') {
6580:9): $id = 'id="scantronconfcsv" ';
6581:9): }
6582:9): $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
6583:9): $titles{$item}.'</label>'.(' 'x3);
6584:9): if ($item eq 'csv') {
6585:9): $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
6586:9): '<legend>'.&mt('CSV Column Mapping').'</legend>'.
6587:9): '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
6588:9): foreach my $col (@fields) {
6589:9): my $selnone;
6590:9): if ($csvfields{$col} eq '') {
6591:9): $selnone = ' selected="selected"';
6592:9): }
6593:9): $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
6594:9): '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
6595:9): '<option value=""'.$selnone.'></option>';
6596:9): for (my $i=0; $i<20; $i++) {
6597:9): my $shown = $i+1;
6598:9): my $sel;
6599:9): unless ($selnone) {
6600:9): if (exists($csvfields{$col})) {
6601:9): if ($csvfields{$col} == $i) {
6602:9): $sel = ' selected="selected"';
6603:9): }
6604:9): }
6605:9): }
6606:9): $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
6607:9): }
6608:9): $datatable .= '</select></td></tr>';
6609:9): }
6610:9): $datatable .= '</table></fieldset>'.
6611:9): '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
6612:9): '<legend>'.&mt('CSV Options').'</legend>';
6613:9): foreach my $option ('hdr','pad','rem') {
6614:9): $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
6615:9): '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
6616:9): &mt('Yes').'</label>'.(' 'x2)."\n".
6617:9): '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
6618:9): }
6619:9): $datatable .= '</fieldset>';
6620:9): $itemcount ++;
6621:9): }
6622:9): }
6623:9): $datatable .= '</td></tr>';
6624:9): $$rowtotal ++;
6625:9): return $datatable;
6626:9): }
6627:9):
6628:9): sub scantronconfig_titles {
6629:9): return &Apache::lonlocal::texthash(
6630:9): dat => 'Standard format (.dat)',
6631:9): csv => 'Comma separated values (.csv)',
6632:9): hdr => 'Remove first line in file (contains column titles)',
6633:9): pad => 'Prepend 0s to PaperID',
6634:9): rem => 'Remove leading spaces (except Question Response columns)',
6635:9): CODE => 'CODE',
6636:9): ID => 'Student ID',
6637:9): PaperID => 'Paper ID',
6638:9): FirstName => 'First Name',
6639:9): LastName => 'Last Name',
6640:9): FirstQuestion => 'First Question Response',
6641:9): Section => 'Section',
6642:9): );
6643:9): }
6644:9):
6645:9): sub scantroncsv_fields {
6646:9): return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
6647:9): }
6648:9):
1.49 raeburn 6649: sub print_coursecategories {
1.57 raeburn 6650: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6651: my $datatable;
6652: if ($position eq 'top') {
1.160.6.42 raeburn 6653: my (%checked);
6654: my @catitems = ('unauth','auth');
6655: my @cattypes = ('std','domonly','codesrch','none');
6656: $checked{'unauth'} = 'std';
6657: $checked{'auth'} = 'std';
6658: if (ref($settings) eq 'HASH') {
6659: foreach my $type (@cattypes) {
6660: if ($type eq $settings->{'unauth'}) {
6661: $checked{'unauth'} = $type;
6662: }
6663: if ($type eq $settings->{'auth'}) {
6664: $checked{'auth'} = $type;
6665: }
6666: }
6667: }
6668: my %lt = &Apache::lonlocal::texthash (
6669: unauth => 'Catalog type for unauthenticated users',
6670: auth => 'Catalog type for authenticated users',
6671: none => 'No catalog',
6672: std => 'Standard catalog',
6673: domonly => 'Domain-only catalog',
6674: codesrch => "Code search form",
6675: );
6676: my $itemcount = 0;
6677: foreach my $item (@catitems) {
6678: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6679: $datatable .= '<tr '.$css_class.'>'.
6680: '<td>'.$lt{$item}.'</td>'.
6681: '<td class="LC_right_item"><span class="LC_nobreak">';
6682: foreach my $type (@cattypes) {
6683: my $ischecked;
6684: if ($checked{$item} eq $type) {
6685: $ischecked=' checked="checked"';
6686: }
6687: $datatable .= '<label>'.
6688: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6689: ' />'.$lt{$type}.'</label> ';
6690: }
6691: $datatable .= '</td></tr>';
6692: $itemcount ++;
6693: }
6694: $$rowtotal += $itemcount;
6695: } elsif ($position eq 'middle') {
1.57 raeburn 6696: my $toggle_cats_crs = ' ';
6697: my $toggle_cats_dom = ' checked="checked" ';
6698: my $can_cat_crs = ' ';
6699: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 6700: my $toggle_catscomm_comm = ' ';
6701: my $toggle_catscomm_dom = ' checked="checked" ';
6702: my $can_catcomm_comm = ' ';
6703: my $can_catcomm_dom = ' checked="checked" ';
6704:
1.57 raeburn 6705: if (ref($settings) eq 'HASH') {
6706: if ($settings->{'togglecats'} eq 'crs') {
6707: $toggle_cats_crs = $toggle_cats_dom;
6708: $toggle_cats_dom = ' ';
6709: }
6710: if ($settings->{'categorize'} eq 'crs') {
6711: $can_cat_crs = $can_cat_dom;
6712: $can_cat_dom = ' ';
6713: }
1.120 raeburn 6714: if ($settings->{'togglecatscomm'} eq 'comm') {
6715: $toggle_catscomm_comm = $toggle_catscomm_dom;
6716: $toggle_catscomm_dom = ' ';
6717: }
6718: if ($settings->{'categorizecomm'} eq 'comm') {
6719: $can_catcomm_comm = $can_catcomm_dom;
6720: $can_catcomm_dom = ' ';
6721: }
1.57 raeburn 6722: }
6723: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 6724: togglecats => 'Show/Hide a course in catalog',
6725: togglecatscomm => 'Show/Hide a community in catalog',
6726: categorize => 'Assign a category to a course',
6727: categorizecomm => 'Assign a category to a community',
1.57 raeburn 6728: );
6729: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 6730: dom => 'Set in Domain',
6731: crs => 'Set in Course',
6732: comm => 'Set in Community',
1.57 raeburn 6733: );
6734: $datatable = '<tr class="LC_odd_row">'.
6735: '<td>'.$title{'togglecats'}.'</td>'.
6736: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6737: '<input type="radio" name="togglecats"'.
6738: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6739: '<label><input type="radio" name="togglecats"'.
6740: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
6741: '</tr><tr>'.
6742: '<td>'.$title{'categorize'}.'</td>'.
6743: '<td class="LC_right_item"><span class="LC_nobreak">'.
6744: '<label><input type="radio" name="categorize"'.
6745: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6746: '<label><input type="radio" name="categorize"'.
6747: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 6748: '</tr><tr class="LC_odd_row">'.
6749: '<td>'.$title{'togglecatscomm'}.'</td>'.
6750: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6751: '<input type="radio" name="togglecatscomm"'.
6752: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6753: '<label><input type="radio" name="togglecatscomm"'.
6754: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
6755: '</tr><tr>'.
6756: '<td>'.$title{'categorizecomm'}.'</td>'.
6757: '<td class="LC_right_item"><span class="LC_nobreak">'.
6758: '<label><input type="radio" name="categorizecomm"'.
6759: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6760: '<label><input type="radio" name="categorizecomm"'.
6761: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 6762: '</tr>';
1.120 raeburn 6763: $$rowtotal += 4;
1.57 raeburn 6764: } else {
6765: my $css_class;
6766: my $itemcount = 1;
6767: my $cathash;
6768: if (ref($settings) eq 'HASH') {
6769: $cathash = $settings->{'cats'};
6770: }
6771: if (ref($cathash) eq 'HASH') {
6772: my (@cats,@trails,%allitems,%idx,@jsarray);
6773: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
6774: \%allitems,\%idx,\@jsarray);
6775: my $maxdepth = scalar(@cats);
6776: my $colattrib = '';
6777: if ($maxdepth > 2) {
6778: $colattrib = ' colspan="2" ';
6779: }
6780: my @path;
6781: if (@cats > 0) {
6782: if (ref($cats[0]) eq 'ARRAY') {
6783: my $numtop = @{$cats[0]};
6784: my $maxnum = $numtop;
1.120 raeburn 6785: my %default_names = (
6786: instcode => &mt('Official courses'),
6787: communities => &mt('Communities'),
6788: );
6789:
6790: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6791: ($cathash->{'instcode::0'} eq '') ||
6792: (!grep(/^communities$/,@{$cats[0]})) ||
6793: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 6794: $maxnum ++;
6795: }
6796: my $lastidx;
6797: for (my $i=0; $i<$numtop; $i++) {
6798: my $parent = $cats[0][$i];
6799: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6800: my $item = &escape($parent).'::0';
6801: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6802: $lastidx = $idx{$item};
6803: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6804: .'<select name="'.$item.'"'.$chgstr.'>';
6805: for (my $k=0; $k<=$maxnum; $k++) {
6806: my $vpos = $k+1;
6807: my $selstr;
6808: if ($k == $i) {
6809: $selstr = ' selected="selected" ';
6810: }
6811: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6812: }
1.160.6.29 raeburn 6813: $datatable .= '</select></span></td><td>';
1.120 raeburn 6814: if ($parent eq 'instcode' || $parent eq 'communities') {
6815: $datatable .= '<span class="LC_nobreak">'
6816: .$default_names{$parent}.'</span>';
6817: if ($parent eq 'instcode') {
6818: $datatable .= '<br /><span class="LC_nobreak">('
6819: .&mt('with institutional codes')
6820: .')</span></td><td'.$colattrib.'>';
6821: } else {
6822: $datatable .= '<table><tr><td>';
6823: }
6824: $datatable .= '<span class="LC_nobreak">'
6825: .'<label><input type="radio" name="'
6826: .$parent.'" value="1" checked="checked" />'
6827: .&mt('Display').'</label>';
6828: if ($parent eq 'instcode') {
6829: $datatable .= ' ';
6830: } else {
6831: $datatable .= '</span></td></tr><tr><td>'
6832: .'<span class="LC_nobreak">';
6833: }
6834: $datatable .= '<label><input type="radio" name="'
6835: .$parent.'" value="0" />'
6836: .&mt('Do not display').'</label></span>';
6837: if ($parent eq 'communities') {
6838: $datatable .= '</td></tr></table>';
6839: }
6840: $datatable .= '</td>';
1.57 raeburn 6841: } else {
6842: $datatable .= $parent
1.160.6.29 raeburn 6843: .' <span class="LC_nobreak"><label>'
6844: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6845: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6846: }
6847: my $depth = 1;
6848: push(@path,$parent);
6849: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6850: pop(@path);
6851: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6852: $itemcount ++;
6853: }
1.48 raeburn 6854: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6855: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6856: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6857: for (my $k=0; $k<=$maxnum; $k++) {
6858: my $vpos = $k+1;
6859: my $selstr;
1.57 raeburn 6860: if ($k == $numtop) {
1.48 raeburn 6861: $selstr = ' selected="selected" ';
6862: }
6863: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6864: }
1.59 bisitz 6865: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6866: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6867: .'</tr>'."\n";
1.48 raeburn 6868: $itemcount ++;
1.120 raeburn 6869: foreach my $default ('instcode','communities') {
6870: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6871: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6872: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6873: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6874: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6875: for (my $k=0; $k<=$maxnum; $k++) {
6876: my $vpos = $k+1;
6877: my $selstr;
6878: if ($k == $maxnum) {
6879: $selstr = ' selected="selected" ';
6880: }
6881: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6882: }
1.120 raeburn 6883: $datatable .= '</select></span></td>'.
6884: '<td><span class="LC_nobreak">'.
6885: $default_names{$default}.'</span>';
6886: if ($default eq 'instcode') {
6887: $datatable .= '<br /><span class="LC_nobreak">('
6888: .&mt('with institutional codes').')</span>';
6889: }
6890: $datatable .= '</td>'
6891: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6892: .&mt('Display').'</label> '
6893: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6894: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6895: }
6896: }
6897: }
1.57 raeburn 6898: } else {
6899: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6900: }
6901: } else {
1.160.6.42 raeburn 6902: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6903: .&initialize_categories($itemcount);
1.48 raeburn 6904: }
1.57 raeburn 6905: $$rowtotal += $itemcount;
1.48 raeburn 6906: }
6907: return $datatable;
6908: }
6909:
1.69 raeburn 6910: sub print_serverstatuses {
6911: my ($dom,$settings,$rowtotal) = @_;
6912: my $datatable;
6913: my @pages = &serverstatus_pages();
6914: my (%namedaccess,%machineaccess);
6915: foreach my $type (@pages) {
6916: $namedaccess{$type} = '';
6917: $machineaccess{$type}= '';
6918: }
6919: if (ref($settings) eq 'HASH') {
6920: foreach my $type (@pages) {
6921: if (exists($settings->{$type})) {
6922: if (ref($settings->{$type}) eq 'HASH') {
6923: foreach my $key (keys(%{$settings->{$type}})) {
6924: if ($key eq 'namedusers') {
6925: $namedaccess{$type} = $settings->{$type}->{$key};
6926: } elsif ($key eq 'machines') {
6927: $machineaccess{$type} = $settings->{$type}->{$key};
6928: }
6929: }
6930: }
6931: }
6932: }
6933: }
1.81 raeburn 6934: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6935: my $rownum = 0;
6936: my $css_class;
6937: foreach my $type (@pages) {
6938: $rownum ++;
6939: $css_class = $rownum%2?' class="LC_odd_row"':'';
6940: $datatable .= '<tr'.$css_class.'>'.
6941: '<td><span class="LC_nobreak">'.
6942: $titles->{$type}.'</span></td>'.
6943: '<td class="LC_left_item">'.
6944: '<input type="text" name="'.$type.'_namedusers" '.
6945: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6946: '<td class="LC_right_item">'.
6947: '<span class="LC_nobreak">'.
6948: '<input type="text" name="'.$type.'_machines" '.
6949: 'value="'.$machineaccess{$type}.'" size="10" />'.
6950: '</td></tr>'."\n";
6951: }
6952: $$rowtotal += $rownum;
6953: return $datatable;
6954: }
6955:
6956: sub serverstatus_pages {
6957: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 6958: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 6959: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 6960: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6961: }
6962:
1.160.6.40 raeburn 6963: sub defaults_javascript {
6964: my ($settings) = @_;
1.160.6.80 raeburn 6965: 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.');
6966: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
6967: &js_escape(\$intauthcheck);
6968: &js_escape(\$intauthcost);
6969: my $intauthjs = <<"ENDSCRIPT";
6970:
6971: function warnIntAuth(field) {
6972: if (field.name == 'intauth_check') {
6973: if (field.value == '2') {
6974: alert('$intauthcheck');
6975: }
6976: }
6977: if (field.name == 'intauth_cost') {
6978: field.value.replace(/\s/g,'');
6979: if (field.value != '') {
6980: var regexdigit=/^\\d+\$/;
6981: if (!regexdigit.test(field.value)) {
6982: alert('$intauthcost');
6983: }
6984: }
6985: }
6986: return;
6987: }
6988:
6989: ENDSCRIPT
6990:
6991: if (ref($settings) ne 'HASH') {
6992: return &Apache::lonhtmlcommon::scripttag($intauthjs);
6993: }
1.160.6.40 raeburn 6994: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6995: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6996: if ($maxnum eq '') {
6997: $maxnum = 0;
6998: }
6999: $maxnum ++;
1.160.6.51 raeburn 7000: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 7001: return <<"ENDSCRIPT";
7002: <script type="text/javascript">
7003: // <![CDATA[
7004: function reorderTypes(form,caller) {
7005: var changedVal;
7006: $jstext
7007: var newpos = 'addinststatus_pos';
7008: var current = new Array;
7009: var maxh = $maxnum;
7010: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7011: var oldVal;
7012: if (caller == newpos) {
7013: changedVal = newitemVal;
7014: } else {
7015: var curritem = 'inststatus_pos_'+caller;
7016: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
7017: current[newitemVal] = newpos;
7018: }
7019: for (var i=0; i<inststatuses.length; i++) {
7020: if (inststatuses[i] != caller) {
7021: var elementName = 'inststatus_pos_'+inststatuses[i];
7022: if (form.elements[elementName]) {
7023: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7024: current[currVal] = elementName;
7025: }
7026: }
7027: }
7028: for (var j=0; j<maxh; j++) {
7029: if (current[j] == undefined) {
7030: oldVal = j;
7031: }
7032: }
7033: if (oldVal < changedVal) {
7034: for (var k=oldVal+1; k<=changedVal ; k++) {
7035: var elementName = current[k];
7036: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7037: }
7038: } else {
7039: for (var k=changedVal; k<oldVal; k++) {
7040: var elementName = current[k];
7041: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7042: }
7043: }
7044: return;
7045: }
7046:
1.160.6.80 raeburn 7047: $intauthjs
7048:
1.160.6.40 raeburn 7049: // ]]>
7050: </script>
7051:
7052: ENDSCRIPT
1.160.6.80 raeburn 7053: } else {
7054: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.160.6.40 raeburn 7055: }
7056: }
7057:
1.49 raeburn 7058: sub coursecategories_javascript {
7059: my ($settings) = @_;
1.57 raeburn 7060: my ($output,$jstext,$cathash);
1.49 raeburn 7061: if (ref($settings) eq 'HASH') {
1.57 raeburn 7062: $cathash = $settings->{'cats'};
7063: }
7064: if (ref($cathash) eq 'HASH') {
1.49 raeburn 7065: my (@cats,@jsarray,%idx);
1.57 raeburn 7066: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 7067: if (@jsarray > 0) {
7068: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
7069: for (my $i=0; $i<@jsarray; $i++) {
7070: if (ref($jsarray[$i]) eq 'ARRAY') {
7071: my $catstr = join('","',@{$jsarray[$i]});
7072: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
7073: }
7074: }
7075: }
7076: } else {
7077: $jstext = ' var categories = Array(1);'."\n".
7078: ' categories[0] = Array("instcode_pos");'."\n";
7079: }
1.160.6.42 raeburn 7080: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
7081: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 7082: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
7083: &js_escape(\$instcode_reserved);
7084: &js_escape(\$communities_reserved);
7085: &js_escape(\$choose_again);
1.49 raeburn 7086: $output = <<"ENDSCRIPT";
7087: <script type="text/javascript">
1.109 raeburn 7088: // <![CDATA[
1.49 raeburn 7089: function reorderCats(form,parent,item,idx) {
7090: var changedVal;
7091: $jstext
7092: var newpos = 'addcategory_pos';
7093: if (parent == '') {
7094: var has_instcode = 0;
7095: var maxtop = categories[idx].length;
7096: for (var j=0; j<maxtop; j++) {
7097: if (categories[idx][j] == 'instcode::0') {
7098: has_instcode == 1;
7099: }
7100: }
7101: if (has_instcode == 0) {
7102: categories[idx][maxtop] = 'instcode_pos';
7103: }
7104: } else {
7105: newpos += '_'+parent;
7106: }
7107: var maxh = 1 + categories[idx].length;
7108: var current = new Array;
7109: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7110: if (item == newpos) {
7111: changedVal = newitemVal;
7112: } else {
7113: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
7114: current[newitemVal] = newpos;
7115: }
7116: for (var i=0; i<categories[idx].length; i++) {
7117: var elementName = categories[idx][i];
7118: if (elementName != item) {
7119: if (form.elements[elementName]) {
7120: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7121: current[currVal] = elementName;
7122: }
7123: }
7124: }
7125: var oldVal;
7126: for (var j=0; j<maxh; j++) {
7127: if (current[j] == undefined) {
7128: oldVal = j;
7129: }
7130: }
7131: if (oldVal < changedVal) {
7132: for (var k=oldVal+1; k<=changedVal ; k++) {
7133: var elementName = current[k];
7134: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7135: }
7136: } else {
7137: for (var k=changedVal; k<oldVal; k++) {
7138: var elementName = current[k];
7139: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7140: }
7141: }
7142: return;
7143: }
1.120 raeburn 7144:
7145: function categoryCheck(form) {
7146: if (form.elements['addcategory_name'].value == 'instcode') {
7147: alert('$instcode_reserved\\n$choose_again');
7148: return false;
7149: }
7150: if (form.elements['addcategory_name'].value == 'communities') {
7151: alert('$communities_reserved\\n$choose_again');
7152: return false;
7153: }
7154: return true;
7155: }
7156:
1.109 raeburn 7157: // ]]>
1.49 raeburn 7158: </script>
7159:
7160: ENDSCRIPT
7161: return $output;
7162: }
7163:
1.48 raeburn 7164: sub initialize_categories {
7165: my ($itemcount) = @_;
1.120 raeburn 7166: my ($datatable,$css_class,$chgstr);
7167: my %default_names = (
7168: instcode => 'Official courses (with institutional codes)',
7169: communities => 'Communities',
7170: );
7171: my $select0 = ' selected="selected"';
7172: my $select1 = '';
7173: foreach my $default ('instcode','communities') {
7174: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7175: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
7176: if ($default eq 'communities') {
7177: $select1 = $select0;
7178: $select0 = '';
7179: }
7180: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7181: .'<select name="'.$default.'_pos">'
7182: .'<option value="0"'.$select0.'>1</option>'
7183: .'<option value="1"'.$select1.'>2</option>'
7184: .'<option value="2">3</option></select> '
7185: .$default_names{$default}
7186: .'</span></td><td><span class="LC_nobreak">'
7187: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
7188: .&mt('Display').'</label> <label>'
7189: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 7190: .'</label></span></td></tr>';
1.120 raeburn 7191: $itemcount ++;
7192: }
1.48 raeburn 7193: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 7194: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 7195: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 7196: .'<select name="addcategory_pos"'.$chgstr.'>'
7197: .'<option value="0">1</option>'
7198: .'<option value="1">2</option>'
7199: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 7200: .&mt('Add category').'</td><td>'.&mt('Name:')
7201: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
7202: return $datatable;
7203: }
7204:
7205: sub build_category_rows {
1.49 raeburn 7206: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
7207: my ($text,$name,$item,$chgstr);
1.48 raeburn 7208: if (ref($cats) eq 'ARRAY') {
7209: my $maxdepth = scalar(@{$cats});
7210: if (ref($cats->[$depth]) eq 'HASH') {
7211: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
7212: my $numchildren = @{$cats->[$depth]{$parent}};
7213: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 7214: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 7215: my ($idxnum,$parent_name,$parent_item);
7216: my $higher = $depth - 1;
7217: if ($higher == 0) {
7218: $parent_name = &escape($parent).'::'.$higher;
7219: } else {
7220: if (ref($path) eq 'ARRAY') {
7221: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7222: }
7223: }
7224: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 7225: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 7226: if ($j < $numchildren) {
1.48 raeburn 7227: $name = $cats->[$depth]{$parent}[$j];
7228: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 7229: $idxnum = $idx->{$item};
7230: } else {
7231: $name = $parent_name;
7232: $item = $parent_item;
1.48 raeburn 7233: }
1.49 raeburn 7234: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
7235: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 7236: for (my $i=0; $i<=$numchildren; $i++) {
7237: my $vpos = $i+1;
7238: my $selstr;
7239: if ($j == $i) {
7240: $selstr = ' selected="selected" ';
7241: }
7242: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
7243: }
7244: $text .= '</select> ';
7245: if ($j < $numchildren) {
7246: my $deeper = $depth+1;
7247: $text .= $name.' '
7248: .'<label><input type="checkbox" name="deletecategory" value="'
7249: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
7250: if(ref($path) eq 'ARRAY') {
7251: push(@{$path},$name);
1.49 raeburn 7252: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 7253: pop(@{$path});
7254: }
7255: } else {
1.59 bisitz 7256: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 7257: if ($j == $numchildren) {
7258: $text .= $name;
7259: } else {
7260: $text .= $item;
7261: }
7262: $text .= '" value="" />';
7263: }
7264: $text .= '</td></tr>';
7265: }
7266: $text .= '</table></td>';
7267: } else {
7268: my $higher = $depth-1;
7269: if ($higher == 0) {
7270: $name = &escape($parent).'::'.$higher;
7271: } else {
7272: if (ref($path) eq 'ARRAY') {
7273: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7274: }
7275: }
7276: my $colspan;
7277: if ($parent ne 'instcode') {
7278: $colspan = $maxdepth - $depth - 1;
7279: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
7280: }
7281: }
7282: }
7283: }
7284: return $text;
7285: }
7286:
1.33 raeburn 7287: sub modifiable_userdata_row {
1.160.6.35 raeburn 7288: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
7289: my ($role,$rolename,$statustype);
7290: $role = $item;
1.160.6.34 raeburn 7291: if ($context eq 'cancreate') {
1.160.6.35 raeburn 7292: if ($item =~ /^emailusername_(.+)$/) {
7293: $statustype = $1;
7294: $role = 'emailusername';
7295: if (ref($usertypes) eq 'HASH') {
7296: if ($usertypes->{$statustype}) {
7297: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7298: } else {
7299: $rolename = &mt('Data provided by user');
7300: }
7301: }
1.160.6.34 raeburn 7302: }
7303: } elsif ($context eq 'selfcreate') {
1.63 raeburn 7304: if (ref($usertypes) eq 'HASH') {
7305: $rolename = $usertypes->{$role};
7306: } else {
7307: $rolename = $role;
7308: }
1.33 raeburn 7309: } else {
1.63 raeburn 7310: if ($role eq 'cr') {
7311: $rolename = &mt('Custom role');
7312: } else {
7313: $rolename = &Apache::lonnet::plaintext($role);
7314: }
1.33 raeburn 7315: }
1.160.6.34 raeburn 7316: my (@fields,%fieldtitles);
7317: if (ref($fieldsref) eq 'ARRAY') {
7318: @fields = @{$fieldsref};
7319: } else {
7320: @fields = ('lastname','firstname','middlename','generation',
7321: 'permanentemail','id');
7322: }
7323: if ((ref($titlesref) eq 'HASH')) {
7324: %fieldtitles = %{$titlesref};
7325: } else {
7326: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7327: }
1.33 raeburn 7328: my $output;
7329: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7330: $output = '<tr '.$css_class.'>'.
7331: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7332: '<td class="LC_left_item" colspan="2"><table>';
7333: my $rem;
7334: my %checks;
7335: if (ref($settings) eq 'HASH') {
7336: if (ref($settings->{$context}) eq 'HASH') {
7337: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 7338: my $hashref = $settings->{$context}->{$role};
7339: if ($role eq 'emailusername') {
7340: if ($statustype) {
7341: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7342: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 7343: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 7344: foreach my $field (@fields) {
7345: if ($hashref->{$field}) {
7346: $checks{$field} = $hashref->{$field};
7347: }
7348: }
7349: }
7350: }
7351: }
7352: } else {
7353: if (ref($hashref) eq 'HASH') {
7354: foreach my $field (@fields) {
7355: if ($hashref->{$field}) {
7356: $checks{$field} = ' checked="checked" ';
7357: }
7358: }
1.33 raeburn 7359: }
7360: }
7361: }
7362: }
7363: }
1.160.6.39 raeburn 7364:
1.33 raeburn 7365: for (my $i=0; $i<@fields; $i++) {
7366: my $rem = $i%($numinrow);
7367: if ($rem == 0) {
7368: if ($i > 0) {
7369: $output .= '</tr>';
7370: }
7371: $output .= '<tr>';
7372: }
7373: my $check = ' ';
1.160.6.35 raeburn 7374: unless ($role eq 'emailusername') {
7375: if (exists($checks{$fields[$i]})) {
7376: $check = $checks{$fields[$i]}
7377: } else {
7378: if ($role eq 'st') {
7379: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 7380: $check = ' checked="checked" ';
1.160.6.35 raeburn 7381: }
1.33 raeburn 7382: }
7383: }
7384: }
7385: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 7386: '<span class="LC_nobreak">';
7387: if ($role eq 'emailusername') {
7388: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7389: $checks{$fields[$i]} = 'omit';
7390: }
7391: foreach my $option ('required','optional','omit') {
7392: my $checked='';
7393: if ($checks{$fields[$i]} eq $option) {
7394: $checked='checked="checked" ';
7395: }
7396: $output .= '<label>'.
7397: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7398: &mt($option).'</label>'.(' ' x2);
7399: }
7400: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7401: } else {
7402: $output .= '<label>'.
7403: '<input type="checkbox" name="canmodify_'.$role.'" '.
7404: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7405: '</label>';
7406: }
7407: $output .= '</span></td>';
1.33 raeburn 7408: $rem = @fields%($numinrow);
7409: }
7410: my $colsleft = $numinrow - $rem;
7411: if ($colsleft > 1 ) {
7412: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7413: ' </td>';
7414: } elsif ($colsleft == 1) {
7415: $output .= '<td class="LC_left_item"> </td>';
7416: }
7417: $output .= '</tr></table></td></tr>';
7418: return $output;
7419: }
1.28 raeburn 7420:
1.93 raeburn 7421: sub insttypes_row {
1.160.6.84.2. (raeburn 7422:): my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
7423:): $customcss,$rowstyle) = @_;
1.93 raeburn 7424: my %lt = &Apache::lonlocal::texthash (
7425: cansearch => 'Users allowed to search',
7426: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 7427: lockablenames => 'User preference to lock name',
1.160.6.84.2. (raeburn 7428:): overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 7429: );
7430: my $showdom;
7431: if ($context eq 'cansearch') {
7432: $showdom = ' ('.$dom.')';
7433: }
1.160.6.5 raeburn 7434: my $class = 'LC_left_item';
7435: if ($context eq 'statustocreate') {
7436: $class = 'LC_right_item';
7437: }
1.160.6.84.2. (raeburn 7438:): my $css_class;
7439:): if ($$rowtotal%2) {
7440:): $css_class = 'LC_odd_row';
7441:): }
7442:): if ($customcss) {
7443:): $css_class .= ' '.$customcss;
7444:): }
7445:): $css_class =~ s/^\s+//;
7446:): if ($css_class) {
7447:): $css_class = ' class="'.$css_class.'"';
7448:): }
7449:): if ($rowstyle) {
7450:): $css_class .= ' style="'.$rowstyle.'"';
7451:): }
7452:): if ($onclick) {
7453:): $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 7454: }
7455: my $output = '<tr'.$css_class.'>'.
7456: '<td>'.$lt{$context}.$showdom.
7457: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7458: my $rem;
7459: if (ref($types) eq 'ARRAY') {
7460: for (my $i=0; $i<@{$types}; $i++) {
7461: if (defined($usertypes->{$types->[$i]})) {
7462: my $rem = $i%($numinrow);
7463: if ($rem == 0) {
7464: if ($i > 0) {
7465: $output .= '</tr>';
7466: }
7467: $output .= '<tr>';
1.23 raeburn 7468: }
1.26 raeburn 7469: my $check = ' ';
1.99 raeburn 7470: if (ref($settings) eq 'HASH') {
7471: if (ref($settings->{$context}) eq 'ARRAY') {
7472: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7473: $check = ' checked="checked" ';
7474: }
1.160.6.84.2. (raeburn 7475:): } elsif (ref($settings->{$context}) eq 'HASH') {
7476:): if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
7477:): $check = ' checked="checked" ';
7478:): }
1.99 raeburn 7479: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7480: $check = ' checked="checked" ';
7481: }
1.23 raeburn 7482: }
1.26 raeburn 7483: $output .= '<td class="LC_left_item">'.
7484: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7485: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 7486: 'value="'.$types->[$i].'"'.$check.'/>'.
7487: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7488: }
7489: }
1.26 raeburn 7490: $rem = @{$types}%($numinrow);
1.23 raeburn 7491: }
7492: my $colsleft = $numinrow - $rem;
1.160.6.84.2. (raeburn 7493:): if ($context eq 'overrides') {
7494:): if ($colsleft > 1) {
7495:): $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
7496:): } else {
7497:): $output .= '<td class="LC_left_item">';
7498:): }
7499:): $output .= ' ';
1.23 raeburn 7500: } else {
1.160.6.84.2. (raeburn 7501:): if (($rem == 0) && (@{$types} > 0)) {
7502:): $output .= '<tr>';
7503:): }
7504:): if ($colsleft > 1) {
7505:): $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
7506:): } else {
7507:): $output .= '<td class="LC_left_item">';
7508:): }
7509:): my $defcheck = ' ';
7510:): if (ref($settings) eq 'HASH') {
7511:): if (ref($settings->{$context}) eq 'ARRAY') {
7512:): if (grep(/^default$/,@{$settings->{$context}})) {
7513:): $defcheck = ' checked="checked" ';
7514:): }
7515:): } elsif ($context eq 'statustocreate') {
1.99 raeburn 7516: $defcheck = ' checked="checked" ';
7517: }
1.26 raeburn 7518: }
1.160.6.84.2. (raeburn 7519:): $output .= '<span class="LC_nobreak"><label>'.
7520:): '<input type="checkbox" name="'.$context.'" '.
7521:): 'value="default"'.$defcheck.'/>'.
7522:): $othertitle.'</label></span>';
1.23 raeburn 7523: }
1.160.6.84.2. (raeburn 7524:): $output .= '</td></tr></table></td></tr>';
1.25 raeburn 7525: return $output;
1.23 raeburn 7526: }
7527:
7528: sub sorted_searchtitles {
7529: my %searchtitles = &Apache::lonlocal::texthash(
7530: 'uname' => 'username',
7531: 'lastname' => 'last name',
7532: 'lastfirst' => 'last name, first name',
7533: );
7534: my @titleorder = ('uname','lastname','lastfirst');
7535: return (\%searchtitles,\@titleorder);
7536: }
7537:
1.25 raeburn 7538: sub sorted_searchtypes {
7539: my %srchtypes_desc = (
7540: exact => 'is exact match',
7541: contains => 'contains ..',
7542: begins => 'begins with ..',
7543: );
7544: my @srchtypeorder = ('exact','begins','contains');
7545: return (\%srchtypes_desc,\@srchtypeorder);
7546: }
7547:
1.3 raeburn 7548: sub usertype_update_row {
7549: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7550: my $datatable;
7551: my $numinrow = 4;
7552: foreach my $type (@{$types}) {
7553: if (defined($usertypes->{$type})) {
7554: $$rownums ++;
7555: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7556: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7557: '</td><td class="LC_left_item"><table>';
7558: for (my $i=0; $i<@{$fields}; $i++) {
7559: my $rem = $i%($numinrow);
7560: if ($rem == 0) {
7561: if ($i > 0) {
7562: $datatable .= '</tr>';
7563: }
7564: $datatable .= '<tr>';
7565: }
7566: my $check = ' ';
1.39 raeburn 7567: if (ref($settings) eq 'HASH') {
7568: if (ref($settings->{'fields'}) eq 'HASH') {
7569: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7570: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7571: $check = ' checked="checked" ';
7572: }
1.3 raeburn 7573: }
7574: }
7575: }
7576:
7577: if ($i == @{$fields}-1) {
7578: my $colsleft = $numinrow - $rem;
7579: if ($colsleft > 1) {
7580: $datatable .= '<td colspan="'.$colsleft.'">';
7581: } else {
7582: $datatable .= '<td>';
7583: }
7584: } else {
7585: $datatable .= '<td>';
7586: }
1.8 raeburn 7587: $datatable .= '<span class="LC_nobreak"><label>'.
7588: '<input type="checkbox" name="updateable_'.$type.
7589: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7590: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 7591: }
7592: $datatable .= '</tr></table></td></tr>';
7593: }
7594: }
7595: return $datatable;
1.1 raeburn 7596: }
7597:
7598: sub modify_login {
1.160.6.24 raeburn 7599: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 7600: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7601: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7602: %title = ( coursecatalog => 'Display course catalog',
7603: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 7604: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 7605: newuser => 'Link for visitors to create a user account',
7606: loginheader => 'Log-in box header');
7607: @offon = ('off','on');
1.112 raeburn 7608: if (ref($domconfig{login}) eq 'HASH') {
7609: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7610: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7611: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7612: }
7613: }
7614: }
1.9 raeburn 7615: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7616: \%domconfig,\%loginhash);
1.160.6.14 raeburn 7617: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7618: foreach my $item (@toggles) {
7619: $loginhash{login}{$item} = $env{'form.'.$item};
7620: }
1.41 raeburn 7621: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 7622: if (ref($colchanges{'login'}) eq 'HASH') {
7623: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7624: \%loginhash);
7625: }
1.110 raeburn 7626:
1.149 raeburn 7627: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 7628: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 7629: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 7630: if (keys(%servers) > 1) {
7631: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 7632: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7633: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7634: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7635: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7636: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7637: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7638: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7639: $changes{'loginvia'}{$lonhost} = 1;
7640: } else {
7641: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7642: $changes{'loginvia'}{$lonhost} = 1;
7643: }
7644: } else {
7645: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7646: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7647: $changes{'loginvia'}{$lonhost} = 1;
7648: }
7649: }
7650: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7651: foreach my $item (@loginvia_attribs) {
7652: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7653: }
7654: } else {
7655: foreach my $item (@loginvia_attribs) {
7656: my $new = $env{'form.'.$lonhost.'_'.$item};
7657: if (($item eq 'serverpath') && ($new eq 'custom')) {
7658: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7659: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7660: $new = '/';
7661: }
7662: }
7663: if (($item eq 'custompath') &&
7664: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7665: $new = '';
7666: }
7667: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7668: $changes{'loginvia'}{$lonhost} = 1;
7669: }
7670: if ($item eq 'exempt') {
1.160.6.56 raeburn 7671: $new = &check_exempt_addresses($new);
1.128 raeburn 7672: }
7673: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7674: }
7675: }
1.112 raeburn 7676: } else {
1.128 raeburn 7677: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7678: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 7679: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 7680: foreach my $item (@loginvia_attribs) {
7681: my $new = $env{'form.'.$lonhost.'_'.$item};
7682: if (($item eq 'serverpath') && ($new eq 'custom')) {
7683: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7684: $new = '/';
7685: }
7686: }
7687: if (($item eq 'custompath') &&
7688: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7689: $new = '';
7690: }
7691: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7692: }
1.110 raeburn 7693: }
7694: }
7695: }
7696: }
1.119 raeburn 7697:
1.160.6.5 raeburn 7698: my $servadm = $r->dir_config('lonAdmEMail');
7699: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
7700: if (ref($domconfig{'login'}) eq 'HASH') {
7701: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
7702: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
7703: if ($lang eq 'nolang') {
7704: push(@currlangs,$lang);
7705: } elsif (defined($langchoices{$lang})) {
7706: push(@currlangs,$lang);
7707: } else {
7708: next;
7709: }
7710: }
7711: }
7712: }
7713: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
7714: if (@currlangs > 0) {
7715: foreach my $lang (@currlangs) {
7716: if (grep(/^\Q$lang\E$/,@delurls)) {
7717: $changes{'helpurl'}{$lang} = 1;
7718: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
7719: $changes{'helpurl'}{$lang} = 1;
7720: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
7721: push(@newlangs,$lang);
7722: } else {
7723: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7724: }
7725: }
7726: }
7727: unless (grep(/^nolang$/,@currlangs)) {
7728: if ($env{'form.loginhelpurl_nolang.filename'}) {
7729: $changes{'helpurl'}{'nolang'} = 1;
7730: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
7731: push(@newlangs,'nolang');
7732: }
7733: }
7734: if ($env{'form.loginhelpurl_add_lang'}) {
7735: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
7736: ($env{'form.loginhelpurl_add_file.filename'})) {
7737: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
7738: $addedfile = $env{'form.loginhelpurl_add_lang'};
7739: }
7740: }
7741: if ((@newlangs > 0) || ($addedfile)) {
7742: my $error;
7743: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7744: if ($configuserok eq 'ok') {
7745: if ($switchserver) {
7746: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7747: } elsif ($author_ok eq 'ok') {
7748: my @allnew = @newlangs;
7749: if ($addedfile ne '') {
7750: push(@allnew,$addedfile);
7751: }
7752: foreach my $lang (@allnew) {
7753: my $formelem = 'loginhelpurl_'.$lang;
7754: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
7755: $formelem = 'loginhelpurl_add_file';
7756: }
7757: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7758: "help/$lang",'','',$newfile{$lang});
7759: if ($result eq 'ok') {
7760: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
7761: $changes{'helpurl'}{$lang} = 1;
7762: } else {
7763: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
7764: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7765: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
7766: (!grep(/^\Q$lang\E$/,@delurls))) {
7767: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7768: }
7769: }
7770: }
7771: } else {
7772: $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);
7773: }
7774: } else {
7775: $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);
7776: }
7777: if ($error) {
7778: &Apache::lonnet::logthis($error);
7779: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7780: }
7781: }
1.160.6.56 raeburn 7782:
7783: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
7784: if (ref($domconfig{'login'}) eq 'HASH') {
7785: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
7786: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
7787: if ($domservers{$lonhost}) {
7788: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7789: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 7790: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 7791: }
7792: }
7793: }
7794: }
7795: }
7796: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
7797: foreach my $lonhost (sort(keys(%domservers))) {
7798: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7799: $changes{'headtag'}{$lonhost} = 1;
7800: } else {
7801: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
7802: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
7803: }
7804: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
7805: push(@newhosts,$lonhost);
7806: } elsif ($currheadtagurls{$lonhost}) {
7807: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
7808: if ($currexempt{$lonhost}) {
7809: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
7810: $changes{'headtag'}{$lonhost} = 1;
7811: }
7812: } elsif ($possexempt{$lonhost}) {
7813: $changes{'headtag'}{$lonhost} = 1;
7814: }
7815: if ($possexempt{$lonhost}) {
7816: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7817: }
7818: }
7819: }
7820: }
7821: if (@newhosts) {
7822: my $error;
7823: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7824: if ($configuserok eq 'ok') {
7825: if ($switchserver) {
7826: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
7827: } elsif ($author_ok eq 'ok') {
7828: foreach my $lonhost (@newhosts) {
7829: my $formelem = 'loginheadtag_'.$lonhost;
7830: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7831: "login/headtag/$lonhost",'','',
7832: $env{'form.loginheadtag_'.$lonhost.'.filename'});
7833: if ($result eq 'ok') {
7834: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
7835: $changes{'headtag'}{$lonhost} = 1;
7836: if ($possexempt{$lonhost}) {
7837: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7838: }
7839: } else {
7840: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7841: $newheadtagurls{$lonhost},$result);
7842: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7843: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7844: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7845: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7846: }
7847: }
7848: }
7849: } else {
7850: $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);
7851: }
7852: } else {
7853: $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);
7854: }
7855: if ($error) {
7856: &Apache::lonnet::logthis($error);
7857: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7858: }
7859: }
1.160.6.5 raeburn 7860: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
7861:
7862: my $defaulthelpfile = '/adm/loginproblems.html';
7863: my $defaulttext = &mt('Default in use');
7864:
1.1 raeburn 7865: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7866: $dom);
7867: if ($putresult eq 'ok') {
1.160.6.14 raeburn 7868: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7869: my %defaultchecked = (
7870: 'coursecatalog' => 'on',
1.160.6.14 raeburn 7871: 'helpdesk' => 'on',
1.42 raeburn 7872: 'adminmail' => 'off',
1.43 raeburn 7873: 'newuser' => 'off',
1.42 raeburn 7874: );
1.55 raeburn 7875: if (ref($domconfig{'login'}) eq 'HASH') {
7876: foreach my $item (@toggles) {
7877: if ($defaultchecked{$item} eq 'on') {
7878: if (($domconfig{'login'}{$item} eq '0') &&
7879: ($env{'form.'.$item} eq '1')) {
7880: $changes{$item} = 1;
7881: } elsif (($domconfig{'login'}{$item} eq '' ||
7882: $domconfig{'login'}{$item} eq '1') &&
7883: ($env{'form.'.$item} eq '0')) {
7884: $changes{$item} = 1;
7885: }
7886: } elsif ($defaultchecked{$item} eq 'off') {
7887: if (($domconfig{'login'}{$item} eq '1') &&
7888: ($env{'form.'.$item} eq '0')) {
7889: $changes{$item} = 1;
7890: } elsif (($domconfig{'login'}{$item} eq '' ||
7891: $domconfig{'login'}{$item} eq '0') &&
7892: ($env{'form.'.$item} eq '1')) {
7893: $changes{$item} = 1;
7894: }
1.42 raeburn 7895: }
7896: }
1.41 raeburn 7897: }
1.6 raeburn 7898: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7899: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7900: if (ref($lastactref) eq 'HASH') {
7901: $lastactref->{'domainconfig'} = 1;
7902: }
1.1 raeburn 7903: $resulttext = &mt('Changes made:').'<ul>';
7904: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7905: if ($item eq 'loginvia') {
1.112 raeburn 7906: if (ref($changes{$item}) eq 'HASH') {
7907: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7908: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7909: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7910: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7911: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7912: $protocol = 'http' if ($protocol ne 'https');
7913: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7914:
7915: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7916: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7917: } else {
7918: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7919: }
7920: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7921: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7922: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7923: }
7924: $resulttext .= '</li>';
7925: } else {
7926: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7927: }
1.112 raeburn 7928: } else {
1.128 raeburn 7929: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7930: }
7931: }
1.128 raeburn 7932: $resulttext .= '</ul></li>';
1.112 raeburn 7933: }
1.160.6.5 raeburn 7934: } elsif ($item eq 'helpurl') {
7935: if (ref($changes{$item}) eq 'HASH') {
7936: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7937: if (grep(/^\Q$lang\E$/,@delurls)) {
7938: my ($chg,$link);
7939: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7940: if ($lang eq 'nolang') {
7941: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7942: } else {
7943: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7944: }
7945: $resulttext .= '<li>'.$chg.'</li>';
7946: } else {
7947: my $chg;
7948: if ($lang eq 'nolang') {
7949: $chg = &mt('custom log-in help file for no preferred language');
7950: } else {
7951: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7952: }
7953: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7954: $loginhash{'login'}{'helpurl'}{$lang}.
7955: '?inhibitmenu=yes',$chg,600,500).
7956: '</li>';
7957: }
7958: }
7959: }
1.160.6.56 raeburn 7960: } elsif ($item eq 'headtag') {
7961: if (ref($changes{$item}) eq 'HASH') {
7962: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7963: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7964: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7965: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7966: $resulttext .= '<li><a href="'.
7967: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7968: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7969: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7970: if ($possexempt{$lonhost}) {
7971: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7972: } else {
7973: $resulttext .= &mt('included for any client IP');
7974: }
7975: $resulttext .= '</li>';
7976: }
7977: }
7978: }
1.160.6.5 raeburn 7979: } elsif ($item eq 'captcha') {
7980: if (ref($loginhash{'login'}) eq 'HASH') {
7981: my $chgtxt;
7982: if ($loginhash{'login'}{$item} eq 'notused') {
7983: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7984: } else {
7985: my %captchas = &captcha_phrases();
7986: if ($captchas{$loginhash{'login'}{$item}}) {
7987: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7988: } else {
7989: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7990: }
7991: }
7992: $resulttext .= '<li>'.$chgtxt.'</li>';
7993: }
7994: } elsif ($item eq 'recaptchakeys') {
7995: if (ref($loginhash{'login'}) eq 'HASH') {
7996: my ($privkey,$pubkey);
7997: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7998: $pubkey = $loginhash{'login'}{$item}{'public'};
7999: $privkey = $loginhash{'login'}{$item}{'private'};
8000: }
8001: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
8002: if (!$pubkey) {
8003: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
8004: } else {
8005: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8006: }
8007: if (!$privkey) {
8008: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
8009: } else {
1.160.6.53 raeburn 8010: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 8011: }
8012: $chgtxt .= '</ul>';
8013: $resulttext .= '<li>'.$chgtxt.'</li>';
8014: }
1.160.6.69 raeburn 8015: } elsif ($item eq 'recaptchaversion') {
8016: if (ref($loginhash{'login'}) eq 'HASH') {
8017: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
8018: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
8019: '</li>';
8020: }
8021: }
1.41 raeburn 8022: } else {
8023: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
8024: }
1.1 raeburn 8025: }
1.6 raeburn 8026: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 8027: } else {
8028: $resulttext = &mt('No changes made to log-in page settings');
8029: }
8030: } else {
1.11 albertel 8031: $resulttext = '<span class="LC_error">'.
8032: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8033: }
1.6 raeburn 8034: if ($errors) {
1.9 raeburn 8035: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 8036: $errors.'</ul>';
8037: }
8038: return $resulttext;
8039: }
8040:
1.160.6.56 raeburn 8041: sub check_exempt_addresses {
8042: my ($iplist) = @_;
8043: $iplist =~ s/^\s+//;
8044: $iplist =~ s/\s+$//;
8045: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
8046: my (@okips,$new);
8047: foreach my $ip (@poss_ips) {
8048: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
8049: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
8050: push(@okips,$ip);
8051: }
8052: }
8053: }
8054: if (@okips > 0) {
8055: $new = join(',',@okips);
8056: } else {
8057: $new = '';
8058: }
8059: return $new;
8060: }
8061:
1.6 raeburn 8062: sub color_font_choices {
8063: my %choices =
8064: &Apache::lonlocal::texthash (
8065: img => "Header",
8066: bgs => "Background colors",
8067: links => "Link colors",
1.55 raeburn 8068: images => "Images",
1.6 raeburn 8069: font => "Font color",
1.160.6.22 raeburn 8070: fontmenu => "Font menu",
1.76 raeburn 8071: pgbg => "Page",
1.6 raeburn 8072: tabbg => "Header",
8073: sidebg => "Border",
8074: link => "Link",
8075: alink => "Active link",
8076: vlink => "Visited link",
8077: );
8078: return %choices;
8079: }
8080:
8081: sub modify_rolecolors {
1.160.6.24 raeburn 8082: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 8083: my ($resulttext,%rolehash);
8084: $rolehash{'rolecolors'} = {};
1.55 raeburn 8085: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
8086: if ($domconfig{'rolecolors'} eq '') {
8087: $domconfig{'rolecolors'} = {};
8088: }
8089: }
1.9 raeburn 8090: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 8091: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
8092: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
8093: $dom);
8094: if ($putresult eq 'ok') {
8095: if (keys(%changes) > 0) {
1.41 raeburn 8096: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8097: if (ref($lastactref) eq 'HASH') {
8098: $lastactref->{'domainconfig'} = 1;
8099: }
1.6 raeburn 8100: $resulttext = &display_colorchgs($dom,\%changes,$roles,
8101: $rolehash{'rolecolors'});
8102: } else {
8103: $resulttext = &mt('No changes made to default color schemes');
8104: }
8105: } else {
1.11 albertel 8106: $resulttext = '<span class="LC_error">'.
8107: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 8108: }
8109: if ($errors) {
8110: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8111: $errors.'</ul>';
8112: }
8113: return $resulttext;
8114: }
8115:
8116: sub modify_colors {
1.9 raeburn 8117: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 8118: my (%changes,%choices);
1.51 raeburn 8119: my @bgs;
1.6 raeburn 8120: my @links = ('link','alink','vlink');
1.41 raeburn 8121: my @logintext;
1.6 raeburn 8122: my @images;
8123: my $servadm = $r->dir_config('lonAdmEMail');
8124: my $errors;
1.160.6.22 raeburn 8125: my %defaults;
1.6 raeburn 8126: foreach my $role (@{$roles}) {
8127: if ($role eq 'login') {
1.12 raeburn 8128: %choices = &login_choices();
1.41 raeburn 8129: @logintext = ('textcol','bgcol');
1.12 raeburn 8130: } else {
8131: %choices = &color_font_choices();
8132: }
8133: if ($role eq 'login') {
1.41 raeburn 8134: @images = ('img','logo','domlogo','login');
1.51 raeburn 8135: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 8136: } else {
8137: @images = ('img');
1.160.6.22 raeburn 8138: @bgs = ('pgbg','tabbg','sidebg');
8139: }
8140: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
8141: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
8142: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
8143: }
8144: if ($role eq 'login') {
8145: foreach my $item (@logintext) {
1.160.6.39 raeburn 8146: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8147: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8148: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8149: }
8150: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 8151: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8152: }
8153: }
8154: } else {
1.160.6.39 raeburn 8155: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
8156: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
8157: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
8158: }
8159: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 8160: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
8161: }
1.6 raeburn 8162: }
1.160.6.22 raeburn 8163: foreach my $item (@bgs) {
1.160.6.39 raeburn 8164: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8165: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8166: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8167: }
8168: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 8169: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8170: }
8171: }
8172: foreach my $item (@links) {
1.160.6.39 raeburn 8173: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8174: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8175: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8176: }
8177: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 8178: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8179: }
1.6 raeburn 8180: }
1.46 raeburn 8181: my ($configuserok,$author_ok,$switchserver) =
8182: &config_check($dom,$confname,$servadm);
1.9 raeburn 8183: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 8184: if (ref($domconfig->{$role}) ne 'HASH') {
8185: $domconfig->{$role} = {};
8186: }
1.8 raeburn 8187: foreach my $img (@images) {
1.70 raeburn 8188: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
8189: if (defined($env{'form.login_showlogo_'.$img})) {
8190: $confhash->{$role}{'showlogo'}{$img} = 1;
8191: } else {
8192: $confhash->{$role}{'showlogo'}{$img} = 0;
8193: }
8194: }
1.18 albertel 8195: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
8196: && !defined($domconfig->{$role}{$img})
8197: && !$env{'form.'.$role.'_del_'.$img}
8198: && $env{'form.'.$role.'_import_'.$img}) {
8199: # import the old configured image from the .tab setting
8200: # if they haven't provided a new one
8201: $domconfig->{$role}{$img} =
8202: $env{'form.'.$role.'_import_'.$img};
8203: }
1.6 raeburn 8204: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 8205: my $error;
1.6 raeburn 8206: if ($configuserok eq 'ok') {
1.9 raeburn 8207: if ($switchserver) {
1.12 raeburn 8208: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 8209: } else {
8210: if ($author_ok eq 'ok') {
8211: my ($result,$logourl) =
8212: &publishlogo($r,'upload',$role.'_'.$img,
8213: $dom,$confname,$img,$width,$height);
8214: if ($result eq 'ok') {
8215: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 8216: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8217: } else {
1.12 raeburn 8218: $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 8219: }
8220: } else {
1.46 raeburn 8221: $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 8222: }
8223: }
8224: } else {
1.46 raeburn 8225: $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 8226: }
8227: if ($error) {
1.8 raeburn 8228: &Apache::lonnet::logthis($error);
1.11 albertel 8229: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 8230: }
8231: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 8232: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
8233: my $error;
8234: if ($configuserok eq 'ok') {
8235: # is confname an author?
8236: if ($switchserver eq '') {
8237: if ($author_ok eq 'ok') {
8238: my ($result,$logourl) =
8239: &publishlogo($r,'copy',$domconfig->{$role}{$img},
8240: $dom,$confname,$img,$width,$height);
8241: if ($result eq 'ok') {
8242: $confhash->{$role}{$img} = $logourl;
1.18 albertel 8243: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8244: }
8245: }
8246: }
8247: }
1.6 raeburn 8248: }
8249: }
8250: }
8251: if (ref($domconfig) eq 'HASH') {
8252: if (ref($domconfig->{$role}) eq 'HASH') {
8253: foreach my $img (@images) {
8254: if ($domconfig->{$role}{$img} ne '') {
8255: if ($env{'form.'.$role.'_del_'.$img}) {
8256: $confhash->{$role}{$img} = '';
1.12 raeburn 8257: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8258: } else {
1.9 raeburn 8259: if ($confhash->{$role}{$img} eq '') {
8260: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8261: }
1.6 raeburn 8262: }
8263: } else {
8264: if ($env{'form.'.$role.'_del_'.$img}) {
8265: $confhash->{$role}{$img} = '';
1.12 raeburn 8266: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8267: }
8268: }
1.70 raeburn 8269: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8270: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8271: if ($confhash->{$role}{'showlogo'}{$img} ne
8272: $domconfig->{$role}{'showlogo'}{$img}) {
8273: $changes{$role}{'showlogo'}{$img} = 1;
8274: }
8275: } else {
8276: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8277: $changes{$role}{'showlogo'}{$img} = 1;
8278: }
8279: }
8280: }
8281: }
1.6 raeburn 8282: if ($domconfig->{$role}{'font'} ne '') {
8283: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8284: $changes{$role}{'font'} = 1;
8285: }
8286: } else {
8287: if ($confhash->{$role}{'font'}) {
8288: $changes{$role}{'font'} = 1;
8289: }
8290: }
1.107 raeburn 8291: if ($role ne 'login') {
8292: if ($domconfig->{$role}{'fontmenu'} ne '') {
8293: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8294: $changes{$role}{'fontmenu'} = 1;
8295: }
8296: } else {
8297: if ($confhash->{$role}{'fontmenu'}) {
8298: $changes{$role}{'fontmenu'} = 1;
8299: }
1.97 tempelho 8300: }
8301: }
1.6 raeburn 8302: foreach my $item (@bgs) {
8303: if ($domconfig->{$role}{$item} ne '') {
8304: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8305: $changes{$role}{'bgs'}{$item} = 1;
8306: }
8307: } else {
8308: if ($confhash->{$role}{$item}) {
8309: $changes{$role}{'bgs'}{$item} = 1;
8310: }
8311: }
8312: }
8313: foreach my $item (@links) {
8314: if ($domconfig->{$role}{$item} ne '') {
8315: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8316: $changes{$role}{'links'}{$item} = 1;
8317: }
8318: } else {
8319: if ($confhash->{$role}{$item}) {
8320: $changes{$role}{'links'}{$item} = 1;
8321: }
8322: }
8323: }
1.41 raeburn 8324: foreach my $item (@logintext) {
8325: if ($domconfig->{$role}{$item} ne '') {
8326: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8327: $changes{$role}{'logintext'}{$item} = 1;
8328: }
8329: } else {
8330: if ($confhash->{$role}{$item}) {
8331: $changes{$role}{'logintext'}{$item} = 1;
8332: }
8333: }
8334: }
1.6 raeburn 8335: } else {
8336: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8337: \@logintext,$confhash,\%changes);
1.6 raeburn 8338: }
8339: } else {
8340: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8341: \@logintext,$confhash,\%changes);
1.6 raeburn 8342: }
8343: }
8344: return ($errors,%changes);
8345: }
8346:
1.46 raeburn 8347: sub config_check {
8348: my ($dom,$confname,$servadm) = @_;
8349: my ($configuserok,$author_ok,$switchserver,%currroles);
8350: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8351: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8352: $confname,$servadm);
8353: if ($configuserok eq 'ok') {
8354: $switchserver = &check_switchserver($dom,$confname);
8355: if ($switchserver eq '') {
8356: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8357: }
8358: }
8359: return ($configuserok,$author_ok,$switchserver);
8360: }
8361:
1.6 raeburn 8362: sub default_change_checker {
1.41 raeburn 8363: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8364: foreach my $item (@{$links}) {
8365: if ($confhash->{$role}{$item}) {
8366: $changes->{$role}{'links'}{$item} = 1;
8367: }
8368: }
8369: foreach my $item (@{$bgs}) {
8370: if ($confhash->{$role}{$item}) {
8371: $changes->{$role}{'bgs'}{$item} = 1;
8372: }
8373: }
1.41 raeburn 8374: foreach my $item (@{$logintext}) {
8375: if ($confhash->{$role}{$item}) {
8376: $changes->{$role}{'logintext'}{$item} = 1;
8377: }
8378: }
1.6 raeburn 8379: foreach my $img (@{$images}) {
8380: if ($env{'form.'.$role.'_del_'.$img}) {
8381: $confhash->{$role}{$img} = '';
1.12 raeburn 8382: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8383: }
1.70 raeburn 8384: if ($role eq 'login') {
8385: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8386: $changes->{$role}{'showlogo'}{$img} = 1;
8387: }
8388: }
1.6 raeburn 8389: }
8390: if ($confhash->{$role}{'font'}) {
8391: $changes->{$role}{'font'} = 1;
8392: }
1.48 raeburn 8393: }
1.6 raeburn 8394:
8395: sub display_colorchgs {
8396: my ($dom,$changes,$roles,$confhash) = @_;
8397: my (%choices,$resulttext);
8398: if (!grep(/^login$/,@{$roles})) {
8399: $resulttext = &mt('Changes made:').'<br />';
8400: }
8401: foreach my $role (@{$roles}) {
8402: if ($role eq 'login') {
8403: %choices = &login_choices();
8404: } else {
8405: %choices = &color_font_choices();
8406: }
8407: if (ref($changes->{$role}) eq 'HASH') {
8408: if ($role ne 'login') {
8409: $resulttext .= '<h4>'.&mt($role).'</h4>';
8410: }
8411: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8412: if ($role ne 'login') {
8413: $resulttext .= '<ul>';
8414: }
8415: if (ref($changes->{$role}{$key}) eq 'HASH') {
8416: if ($role ne 'login') {
8417: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8418: }
8419: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8420: if (($role eq 'login') && ($key eq 'showlogo')) {
8421: if ($confhash->{$role}{$key}{$item}) {
8422: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8423: } else {
8424: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8425: }
8426: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8427: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8428: } else {
1.12 raeburn 8429: my $newitem = $confhash->{$role}{$item};
8430: if ($key eq 'images') {
8431: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
8432: }
8433: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8434: }
8435: }
8436: if ($role ne 'login') {
8437: $resulttext .= '</ul></li>';
8438: }
8439: } else {
8440: if ($confhash->{$role}{$key} eq '') {
8441: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8442: } else {
8443: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8444: }
8445: }
8446: if ($role ne 'login') {
8447: $resulttext .= '</ul>';
8448: }
8449: }
8450: }
8451: }
1.3 raeburn 8452: return $resulttext;
1.1 raeburn 8453: }
8454:
1.9 raeburn 8455: sub thumb_dimensions {
8456: return ('200','50');
8457: }
8458:
1.16 raeburn 8459: sub check_dimensions {
8460: my ($inputfile) = @_;
8461: my ($fullwidth,$fullheight);
8462: if ($inputfile =~ m|^[/\w.\-]+$|) {
8463: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8464: my $imageinfo = <PIPE>;
8465: if (!close(PIPE)) {
8466: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8467: }
8468: chomp($imageinfo);
8469: my ($fullsize) =
1.21 raeburn 8470: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8471: if ($fullsize) {
8472: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8473: }
8474: }
8475: }
8476: return ($fullwidth,$fullheight);
8477: }
8478:
1.9 raeburn 8479: sub check_configuser {
8480: my ($uhome,$dom,$confname,$servadm) = @_;
8481: my ($configuserok,%currroles);
8482: if ($uhome eq 'no_host') {
8483: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
8484: my $configpass = &LONCAPA::Enrollment::create_password();
8485: $configuserok =
8486: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8487: $configpass,'','','','','',undef,$servadm);
8488: } else {
8489: $configuserok = 'ok';
8490: %currroles =
8491: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8492: }
8493: return ($configuserok,%currroles);
8494: }
8495:
8496: sub check_authorstatus {
8497: my ($dom,$confname,%currroles) = @_;
8498: my $author_ok;
1.40 raeburn 8499: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8500: my $start = time;
8501: my $end = 0;
8502: $author_ok =
8503: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8504: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8505: } else {
8506: $author_ok = 'ok';
8507: }
8508: return $author_ok;
8509: }
8510:
8511: sub publishlogo {
1.46 raeburn 8512: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 8513: my ($output,$fname,$logourl);
8514: if ($action eq 'upload') {
8515: $fname=$env{'form.'.$formname.'.filename'};
8516: chop($env{'form.'.$formname});
8517: } else {
8518: ($fname) = ($formname =~ /([^\/]+)$/);
8519: }
1.46 raeburn 8520: if ($savefileas ne '') {
8521: $fname = $savefileas;
8522: }
1.9 raeburn 8523: $fname=&Apache::lonnet::clean_filename($fname);
8524: # See if there is anything left
8525: unless ($fname) { return ('error: no uploaded file'); }
8526: $fname="$subdir/$fname";
1.160.6.5 raeburn 8527: my $docroot=$r->dir_config('lonDocRoot');
8528: my $filepath="$docroot/priv";
8529: my $relpath = "$dom/$confname";
1.9 raeburn 8530: my ($fnamepath,$file,$fetchthumb);
8531: $file=$fname;
8532: if ($fname=~m|/|) {
8533: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8534: }
1.160.6.26 raeburn 8535: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8536: my $count;
1.160.6.5 raeburn 8537: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8538: $filepath.="/$parts[$count]";
8539: if ((-e $filepath)!=1) {
8540: mkdir($filepath,02770);
8541: }
8542: }
8543: # Check for bad extension and disallow upload
8544: if ($file=~/\.(\w+)$/ &&
8545: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8546: $output =
1.160.6.25 raeburn 8547: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8548: } elsif ($file=~/\.(\w+)$/ &&
8549: !defined(&Apache::loncommon::fileembstyle($1))) {
8550: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8551: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 8552: $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 8553: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 8554: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8555: } else {
8556: my $source = $filepath.'/'.$file;
8557: my $logfile;
1.160.6.84.2. (raeburn 8558:): if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 8559: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8560: }
8561: print $logfile
8562: "\n================= Publish ".localtime()." ================\n".
8563: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8564: # Save the file
1.160.6.84.2. (raeburn 8565:): if (!open(FH,">",$source)) {
1.9 raeburn 8566: &Apache::lonnet::logthis('Failed to create '.$source);
8567: return (&mt('Failed to create file'));
8568: }
8569: if ($action eq 'upload') {
8570: if (!print FH ($env{'form.'.$formname})) {
8571: &Apache::lonnet::logthis('Failed to write to '.$source);
8572: return (&mt('Failed to write file'));
8573: }
8574: } else {
8575: my $original = &Apache::lonnet::filelocation('',$formname);
8576: if(!copy($original,$source)) {
8577: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8578: return (&mt('Failed to write file'));
8579: }
8580: }
8581: close(FH);
8582: chmod(0660, $source); # Permissions to rw-rw---.
8583:
8584: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8585: my $copyfile=$targetdir.'/'.$file;
8586:
8587: my @parts=split(/\//,$targetdir);
8588: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8589: for (my $count=5;$count<=$#parts;$count++) {
8590: $path.="/$parts[$count]";
8591: if (!-e $path) {
8592: print $logfile "\nCreating directory ".$path;
8593: mkdir($path,02770);
8594: }
8595: }
8596: my $versionresult;
8597: if (-e $copyfile) {
8598: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8599: } else {
8600: $versionresult = 'ok';
8601: }
8602: if ($versionresult eq 'ok') {
8603: if (copy($source,$copyfile)) {
8604: print $logfile "\nCopied original source to ".$copyfile."\n";
8605: $output = 'ok';
8606: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8607: push(@{$modified_urls},[$copyfile,$source]);
8608: my $metaoutput =
8609: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8610: unless ($registered_cleanup) {
8611: my $handlers = $r->get_handlers('PerlCleanupHandler');
8612: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8613: $registered_cleanup=1;
8614: }
1.9 raeburn 8615: } else {
8616: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8617: $output = &mt('Failed to copy file to RES space').", $!";
8618: }
8619: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8620: my $inputfile = $filepath.'/'.$file;
8621: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8622: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8623: if ($fullwidth ne '' && $fullheight ne '') {
8624: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8625: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.84.2. (raeburn 8626:): my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
8627:): system({$args[0]} @args);
1.16 raeburn 8628: chmod(0660, $filepath.'/tn-'.$file);
8629: if (-e $outfile) {
8630: my $copyfile=$targetdir.'/tn-'.$file;
8631: if (copy($outfile,$copyfile)) {
8632: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8633: my $thumb_metaoutput =
8634: &write_metadata($dom,$confname,$formname,
8635: $targetdir,'tn-'.$file,$logfile);
8636: push(@{$modified_urls},[$copyfile,$outfile]);
8637: unless ($registered_cleanup) {
8638: my $handlers = $r->get_handlers('PerlCleanupHandler');
8639: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8640: $registered_cleanup=1;
8641: }
1.16 raeburn 8642: } else {
8643: print $logfile "\nUnable to write ".$copyfile.
8644: ':'.$!."\n";
8645: }
8646: }
1.9 raeburn 8647: }
8648: }
8649: }
8650: } else {
8651: $output = $versionresult;
8652: }
8653: }
8654: return ($output,$logourl);
8655: }
8656:
8657: sub logo_versioning {
8658: my ($targetdir,$file,$logfile) = @_;
8659: my $target = $targetdir.'/'.$file;
8660: my ($maxversion,$fn,$extn,$output);
8661: $maxversion = 0;
8662: if ($file =~ /^(.+)\.(\w+)$/) {
8663: $fn=$1;
8664: $extn=$2;
8665: }
8666: opendir(DIR,$targetdir);
8667: while (my $filename=readdir(DIR)) {
8668: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8669: $maxversion=($1>$maxversion)?$1:$maxversion;
8670: }
8671: }
8672: $maxversion++;
8673: print $logfile "\nCreating old version ".$maxversion."\n";
8674: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8675: if (copy($target,$copyfile)) {
8676: print $logfile "Copied old target to ".$copyfile."\n";
8677: $copyfile=$copyfile.'.meta';
8678: if (copy($target.'.meta',$copyfile)) {
8679: print $logfile "Copied old target metadata to ".$copyfile."\n";
8680: $output = 'ok';
8681: } else {
8682: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8683: $output = &mt('Failed to copy old meta').", $!, ";
8684: }
8685: } else {
8686: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8687: $output = &mt('Failed to copy old target').", $!, ";
8688: }
8689: return $output;
8690: }
8691:
8692: sub write_metadata {
8693: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
8694: my (%metadatafields,%metadatakeys,$output);
8695: $metadatafields{'title'}=$formname;
8696: $metadatafields{'creationdate'}=time;
8697: $metadatafields{'lastrevisiondate'}=time;
8698: $metadatafields{'copyright'}='public';
8699: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
8700: $env{'user.domain'};
8701: $metadatafields{'authorspace'}=$confname.':'.$dom;
8702: $metadatafields{'domain'}=$dom;
8703: {
8704: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
8705: my $mfh;
1.160.6.84.2. (raeburn 8706:): if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 8707: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 8708: unless ($_=~/\./) {
8709: my $unikey=$_;
8710: $unikey=~/^([A-Za-z]+)/;
8711: my $tag=$1;
8712: $tag=~tr/A-Z/a-z/;
8713: print $mfh "\n\<$tag";
8714: foreach (split(/\,/,$metadatakeys{$unikey})) {
8715: my $value=$metadatafields{$unikey.'.'.$_};
8716: $value=~s/\"/\'\'/g;
8717: print $mfh ' '.$_.'="'.$value.'"';
8718: }
8719: print $mfh '>'.
8720: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
8721: .'</'.$tag.'>';
8722: }
8723: }
8724: $output = 'ok';
8725: print $logfile "\nWrote metadata";
8726: close($mfh);
8727: } else {
8728: print $logfile "\nFailed to open metadata file";
1.9 raeburn 8729: $output = &mt('Could not write metadata');
8730: }
8731: }
1.155 raeburn 8732: return $output;
8733: }
8734:
8735: sub notifysubscribed {
8736: foreach my $targetsource (@{$modified_urls}){
8737: next unless (ref($targetsource) eq 'ARRAY');
8738: my ($target,$source)=@{$targetsource};
8739: if ($source ne '') {
1.160.6.84.2. (raeburn 8740:): if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 8741: print $logfh "\nCleanup phase: Notifications\n";
8742: my @subscribed=&subscribed_hosts($target);
8743: foreach my $subhost (@subscribed) {
8744: print $logfh "\nNotifying host ".$subhost.':';
8745: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
8746: print $logfh $reply;
8747: }
8748: my @subscribedmeta=&subscribed_hosts("$target.meta");
8749: foreach my $subhost (@subscribedmeta) {
8750: print $logfh "\nNotifying host for metadata only ".$subhost.':';
8751: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
8752: $subhost);
8753: print $logfh $reply;
8754: }
8755: print $logfh "\n============ Done ============\n";
1.160 raeburn 8756: close($logfh);
1.155 raeburn 8757: }
8758: }
8759: }
8760: return OK;
8761: }
8762:
8763: sub subscribed_hosts {
8764: my ($target) = @_;
8765: my @subscribed;
1.160.6.84.2. (raeburn 8766:): if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 8767: while (my $subline=<$fh>) {
8768: if ($subline =~ /^($match_lonid):/) {
8769: my $host = $1;
8770: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
8771: unless (grep(/^\Q$host\E$/,@subscribed)) {
8772: push(@subscribed,$host);
8773: }
8774: }
8775: }
8776: }
8777: }
8778: return @subscribed;
1.9 raeburn 8779: }
8780:
8781: sub check_switchserver {
8782: my ($dom,$confname) = @_;
8783: my ($allowed,$switchserver);
8784: my $home = &Apache::lonnet::homeserver($confname,$dom);
8785: if ($home eq 'no_host') {
8786: $home = &Apache::lonnet::domain($dom,'primary');
8787: }
8788: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 8789: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
8790: if (!$allowed) {
1.160.6.11 raeburn 8791: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 8792: }
8793: return $switchserver;
8794: }
8795:
1.1 raeburn 8796: sub modify_quotas {
1.160.6.30 raeburn 8797: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 8798: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 8799: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 8800: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8801: $validationfieldsref);
1.86 raeburn 8802: if ($action eq 'quotas') {
8803: $context = 'tools';
1.160.6.26 raeburn 8804: } else {
1.86 raeburn 8805: $context = $action;
8806: }
8807: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 8808: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 8809: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 8810: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8811: %titles = &courserequest_titles();
8812: $toolregexp = join('|',@usertools);
8813: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 8814: $confname = $dom.'-domainconfig';
8815: my $servadm = $r->dir_config('lonAdmEMail');
8816: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 8817: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8818: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 8819: } elsif ($context eq 'requestauthor') {
8820: @usertools = ('author');
8821: %titles = &authorrequest_titles();
1.86 raeburn 8822: } else {
1.160.6.4 raeburn 8823: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 8824: %titles = &tool_titles();
1.86 raeburn 8825: }
1.160.6.27 raeburn 8826: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 8827: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8828: foreach my $key (keys(%env)) {
1.101 raeburn 8829: if ($context eq 'requestcourses') {
8830: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8831: my $item = $1;
8832: my $type = $2;
8833: if ($type =~ /^limit_(.+)/) {
8834: $limithash{$item}{$1} = $env{$key};
8835: } else {
8836: $confhash{$item}{$type} = $env{$key};
8837: }
8838: }
1.160.6.5 raeburn 8839: } elsif ($context eq 'requestauthor') {
8840: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8841: $confhash{$1} = $env{$key};
8842: }
1.101 raeburn 8843: } else {
1.86 raeburn 8844: if ($key =~ /^form\.quota_(.+)$/) {
8845: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 8846: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8847: $confhash{'authorquota'}{$1} = $env{$key};
8848: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8849: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8850: }
1.72 raeburn 8851: }
8852: }
1.160.6.5 raeburn 8853: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 8854: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8855: @approvalnotify = sort(@approvalnotify);
8856: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 8857: my @crstypes = ('official','unofficial','community','textbook');
8858: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8859: foreach my $type (@hasuniquecode) {
8860: if (grep(/^\Q$type\E$/,@crstypes)) {
8861: $confhash{'uniquecode'}{$type} = 1;
8862: }
8863: }
1.160.6.46 raeburn 8864: my (%newbook,%allpos);
1.160.6.30 raeburn 8865: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8866: foreach my $type ('textbooks','templates') {
8867: @{$allpos{$type}} = ();
8868: my $invalid;
8869: if ($type eq 'textbooks') {
8870: $invalid = &mt('Invalid LON-CAPA course for textbook');
8871: } else {
8872: $invalid = &mt('Invalid LON-CAPA course for template');
8873: }
8874: if ($env{'form.'.$type.'_addbook'}) {
8875: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8876: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8877: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8878: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8879: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8880: } else {
8881: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8882: my $position = $env{'form.'.$type.'_addbook_pos'};
8883: $position =~ s/\D+//g;
8884: if ($position ne '') {
8885: $allpos{$type}[$position] = $newbook{$type};
8886: }
1.160.6.30 raeburn 8887: }
1.160.6.46 raeburn 8888: } else {
8889: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 8890: }
8891: }
1.160.6.46 raeburn 8892: }
1.160.6.30 raeburn 8893: }
1.102 raeburn 8894: if (ref($domconfig{$action}) eq 'HASH') {
8895: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8896: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8897: $changes{'notify'}{'approval'} = 1;
8898: }
8899: } else {
1.144 raeburn 8900: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8901: $changes{'notify'}{'approval'} = 1;
8902: }
8903: }
1.160.6.30 raeburn 8904: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8905: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8906: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8907: unless ($confhash{'uniquecode'}{$crstype}) {
8908: $changes{'uniquecode'} = 1;
8909: }
8910: }
8911: unless ($changes{'uniquecode'}) {
8912: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8913: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8914: $changes{'uniquecode'} = 1;
8915: }
8916: }
8917: }
8918: } else {
8919: $changes{'uniquecode'} = 1;
8920: }
8921: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8922: $changes{'uniquecode'} = 1;
8923: }
8924: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8925: foreach my $type ('textbooks','templates') {
8926: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8927: my %deletions;
8928: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8929: if (@todelete) {
8930: map { $deletions{$_} = 1; } @todelete;
8931: }
8932: my %imgdeletions;
8933: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8934: if (@todeleteimages) {
8935: map { $imgdeletions{$_} = 1; } @todeleteimages;
8936: }
8937: my $maxnum = $env{'form.'.$type.'_maxnum'};
8938: for (my $i=0; $i<=$maxnum; $i++) {
8939: my $itemid = $env{'form.'.$type.'_id_'.$i};
8940: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8941: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8942: if ($deletions{$key}) {
8943: if ($domconfig{$action}{$type}{$key}{'image'}) {
8944: #FIXME need to obsolete item in RES space
8945: }
8946: next;
8947: } else {
8948: my $newpos = $env{'form.'.$itemid};
8949: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 8950: foreach my $item ('subject','title','publisher','author') {
8951: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8952: ($type eq 'templates'));
1.160.6.46 raeburn 8953: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8954: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8955: $changes{$type}{$key} = 1;
8956: }
8957: }
8958: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 8959: }
1.160.6.46 raeburn 8960: if ($imgdeletions{$key}) {
8961: $changes{$type}{$key} = 1;
8962: #FIXME need to obsolete item in RES space
8963: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8964: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.84.2. (raeburn 8965:): if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
8966:): $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
8967:): } else {
8968:): my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8969:): $cdom,$cnum,$type,$configuserok,
8970:): $switchserver,$author_ok);
8971:): if ($imgurl) {
8972:): $confhash{$type}{$key}{'image'} = $imgurl;
8973:): $changes{$type}{$key} = 1;
8974:): }
8975:): if ($error) {
8976:): &Apache::lonnet::logthis($error);
8977:): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8978:): }
1.160.6.46 raeburn 8979: }
8980: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8981: $confhash{$type}{$key}{'image'} =
8982: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 8983: }
8984: }
8985: }
8986: }
8987: }
8988: }
1.102 raeburn 8989: } else {
1.144 raeburn 8990: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8991: $changes{'notify'}{'approval'} = 1;
8992: }
1.160.6.30 raeburn 8993: if (ref($confhash{'uniquecode'} eq 'HASH')) {
8994: $changes{'uniquecode'} = 1;
8995: }
8996: }
8997: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8998: foreach my $type ('textbooks','templates') {
8999: if ($newbook{$type}) {
9000: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 9001: foreach my $item ('subject','title','publisher','author') {
9002: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9003: ($type eq 'template'));
1.160.6.46 raeburn 9004: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
9005: if ($env{'form.'.$type.'_addbook_'.$item}) {
9006: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
9007: }
9008: }
9009: if ($type eq 'textbooks') {
9010: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
9011: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.84.2. 0(raebur 9012:9): if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
9013:9): my ($imageurl,$error) =
9014:9): &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
9015:9): $configuserok,$switchserver,$author_ok);
9016:9): if ($imageurl) {
9017:9): $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
9018:9): }
9019:9): if ($error) {
9020:9): &Apache::lonnet::logthis($error);
9021:9): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9022:9): }
1.160.6.46 raeburn 9023: }
9024: }
1.160.6.30 raeburn 9025: }
9026: }
1.160.6.46 raeburn 9027: if (@{$allpos{$type}} > 0) {
9028: my $idx = 0;
9029: foreach my $item (@{$allpos{$type}}) {
9030: if ($item ne '') {
9031: $confhash{$type}{$item}{'order'} = $idx;
9032: if (ref($domconfig{$action}) eq 'HASH') {
9033: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9034: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
9035: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
9036: $changes{$type}{$item} = 1;
9037: }
1.160.6.30 raeburn 9038: }
9039: }
9040: }
1.160.6.46 raeburn 9041: $idx ++;
1.160.6.30 raeburn 9042: }
9043: }
9044: }
9045: }
1.160.6.39 raeburn 9046: if (ref($validationitemsref) eq 'ARRAY') {
9047: foreach my $item (@{$validationitemsref}) {
9048: if ($item eq 'fields') {
9049: my @changed;
9050: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
9051: if (@{$confhash{'validation'}{$item}} > 0) {
9052: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
9053: }
1.160.6.65 raeburn 9054: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9055: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9056: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
9057: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
9058: $domconfig{'requestcourses'}{'validation'}{$item});
9059: } else {
9060: @changed = @{$confhash{'validation'}{$item}};
9061: }
1.160.6.39 raeburn 9062: } else {
9063: @changed = @{$confhash{'validation'}{$item}};
9064: }
9065: } else {
9066: @changed = @{$confhash{'validation'}{$item}};
9067: }
9068: if (@changed) {
9069: if ($confhash{'validation'}{$item}) {
9070: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
9071: } else {
9072: $changes{'validation'}{$item} = &mt('None');
9073: }
9074: }
9075: } else {
9076: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
9077: if ($item eq 'markup') {
9078: if ($env{'form.requestcourses_validation_'.$item}) {
9079: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
9080: }
9081: }
1.160.6.65 raeburn 9082: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9083: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9084: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
9085: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9086: }
9087: } else {
9088: if ($confhash{'validation'}{$item} ne '') {
9089: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9090: }
1.160.6.39 raeburn 9091: }
9092: } else {
9093: if ($confhash{'validation'}{$item} ne '') {
9094: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9095: }
9096: }
9097: }
9098: }
9099: }
9100: if ($env{'form.validationdc'}) {
9101: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 9102: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 9103: if (exists($domcoords{$newval})) {
9104: $confhash{'validation'}{'dc'} = $newval;
9105: }
9106: }
9107: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 9108: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9109: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9110: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9111: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
9112: if ($confhash{'validation'}{'dc'} eq '') {
9113: $changes{'validation'}{'dc'} = &mt('None');
9114: } else {
9115: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9116: }
1.160.6.39 raeburn 9117: }
1.160.6.65 raeburn 9118: } elsif ($confhash{'validation'}{'dc'} ne '') {
9119: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 9120: }
9121: } elsif ($confhash{'validation'}{'dc'} ne '') {
9122: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9123: }
9124: } elsif ($confhash{'validation'}{'dc'} ne '') {
9125: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9126: }
1.160.6.65 raeburn 9127: } else {
9128: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9129: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9130: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9131: $changes{'validation'}{'dc'} = &mt('None');
9132: }
9133: }
1.160.6.39 raeburn 9134: }
9135: }
1.102 raeburn 9136: }
9137: } else {
1.86 raeburn 9138: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 9139: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 9140: }
1.72 raeburn 9141: foreach my $item (@usertools) {
9142: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 9143: my $unset;
1.101 raeburn 9144: if ($context eq 'requestcourses') {
1.104 raeburn 9145: $unset = '0';
9146: if ($type eq '_LC_adv') {
9147: $unset = '';
9148: }
1.101 raeburn 9149: if ($confhash{$item}{$type} eq 'autolimit') {
9150: $confhash{$item}{$type} .= '=';
9151: unless ($limithash{$item}{$type} =~ /\D/) {
9152: $confhash{$item}{$type} .= $limithash{$item}{$type};
9153: }
9154: }
1.160.6.5 raeburn 9155: } elsif ($context eq 'requestauthor') {
9156: $unset = '0';
9157: if ($type eq '_LC_adv') {
9158: $unset = '';
9159: }
1.72 raeburn 9160: } else {
1.101 raeburn 9161: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
9162: $confhash{$item}{$type} = 1;
9163: } else {
9164: $confhash{$item}{$type} = 0;
9165: }
1.72 raeburn 9166: }
1.86 raeburn 9167: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 9168: if ($action eq 'requestauthor') {
9169: if ($domconfig{$action}{$type} ne $confhash{$type}) {
9170: $changes{$type} = 1;
9171: }
9172: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 9173: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
9174: $changes{$item}{$type} = 1;
9175: }
9176: } else {
9177: if ($context eq 'requestcourses') {
1.104 raeburn 9178: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 9179: $changes{$item}{$type} = 1;
9180: }
9181: } else {
9182: if (!$confhash{$item}{$type}) {
9183: $changes{$item}{$type} = 1;
9184: }
9185: }
9186: }
9187: } else {
9188: if ($context eq 'requestcourses') {
1.104 raeburn 9189: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 9190: $changes{$item}{$type} = 1;
9191: }
1.160.6.5 raeburn 9192: } elsif ($context eq 'requestauthor') {
9193: if ($confhash{$type} ne $unset) {
9194: $changes{$type} = 1;
9195: }
1.72 raeburn 9196: } else {
9197: if (!$confhash{$item}{$type}) {
9198: $changes{$item}{$type} = 1;
9199: }
9200: }
9201: }
1.1 raeburn 9202: }
9203: }
1.160.6.5 raeburn 9204: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 9205: if (ref($domconfig{'quotas'}) eq 'HASH') {
9206: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9207: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
9208: if (exists($confhash{'defaultquota'}{$key})) {
9209: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
9210: $changes{'defaultquota'}{$key} = 1;
9211: }
9212: } else {
9213: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 9214: }
9215: }
1.86 raeburn 9216: } else {
9217: foreach my $key (keys(%{$domconfig{'quotas'}})) {
9218: if (exists($confhash{'defaultquota'}{$key})) {
9219: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
9220: $changes{'defaultquota'}{$key} = 1;
9221: }
9222: } else {
9223: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 9224: }
1.1 raeburn 9225: }
9226: }
1.160.6.20 raeburn 9227: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9228: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
9229: if (exists($confhash{'authorquota'}{$key})) {
9230: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
9231: $changes{'authorquota'}{$key} = 1;
9232: }
9233: } else {
9234: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
9235: }
9236: }
9237: }
1.1 raeburn 9238: }
1.86 raeburn 9239: if (ref($confhash{'defaultquota'}) eq 'HASH') {
9240: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
9241: if (ref($domconfig{'quotas'}) eq 'HASH') {
9242: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9243: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
9244: $changes{'defaultquota'}{$key} = 1;
9245: }
9246: } else {
9247: if (!exists($domconfig{'quotas'}{$key})) {
9248: $changes{'defaultquota'}{$key} = 1;
9249: }
1.72 raeburn 9250: }
9251: } else {
1.86 raeburn 9252: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 9253: }
1.1 raeburn 9254: }
9255: }
1.160.6.20 raeburn 9256: if (ref($confhash{'authorquota'}) eq 'HASH') {
9257: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9258: if (ref($domconfig{'quotas'}) eq 'HASH') {
9259: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9260: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9261: $changes{'authorquota'}{$key} = 1;
9262: }
9263: } else {
9264: $changes{'authorquota'}{$key} = 1;
9265: }
9266: } else {
9267: $changes{'authorquota'}{$key} = 1;
9268: }
9269: }
9270: }
1.1 raeburn 9271: }
1.72 raeburn 9272:
1.160.6.5 raeburn 9273: if ($context eq 'requestauthor') {
9274: $domdefaults{'requestauthor'} = \%confhash;
9275: } else {
9276: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 9277: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 9278: $domdefaults{$key} = $confhash{$key};
9279: }
1.160.6.5 raeburn 9280: }
1.72 raeburn 9281: }
1.160.6.5 raeburn 9282:
1.1 raeburn 9283: my %quotahash = (
1.86 raeburn 9284: $action => { %confhash }
1.1 raeburn 9285: );
9286: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9287: $dom);
9288: if ($putresult eq 'ok') {
9289: if (keys(%changes) > 0) {
1.72 raeburn 9290: my $cachetime = 24*60*60;
9291: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9292: if (ref($lastactref) eq 'HASH') {
9293: $lastactref->{'domdefaults'} = 1;
9294: }
1.1 raeburn 9295: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 9296: unless (($context eq 'requestcourses') ||
9297: ($context eq 'requestauthor')) {
1.86 raeburn 9298: if (ref($changes{'defaultquota'}) eq 'HASH') {
9299: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9300: foreach my $type (@{$types},'default') {
9301: if (defined($changes{'defaultquota'}{$type})) {
9302: my $typetitle = $usertypes->{$type};
9303: if ($type eq 'default') {
9304: $typetitle = $othertitle;
9305: }
1.160.6.28 raeburn 9306: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9307: }
9308: }
1.86 raeburn 9309: $resulttext .= '</ul></li>';
1.72 raeburn 9310: }
1.160.6.20 raeburn 9311: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 9312: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 9313: foreach my $type (@{$types},'default') {
9314: if (defined($changes{'authorquota'}{$type})) {
9315: my $typetitle = $usertypes->{$type};
9316: if ($type eq 'default') {
9317: $typetitle = $othertitle;
9318: }
1.160.6.28 raeburn 9319: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 9320: }
9321: }
9322: $resulttext .= '</ul></li>';
9323: }
1.72 raeburn 9324: }
1.80 raeburn 9325: my %newenv;
1.72 raeburn 9326: foreach my $item (@usertools) {
1.160.6.5 raeburn 9327: my (%haschgs,%inconf);
9328: if ($context eq 'requestauthor') {
9329: %haschgs = %changes;
9330: %inconf = %confhash;
9331: } else {
9332: if (ref($changes{$item}) eq 'HASH') {
9333: %haschgs = %{$changes{$item}};
9334: }
9335: if (ref($confhash{$item}) eq 'HASH') {
9336: %inconf = %{$confhash{$item}};
9337: }
9338: }
9339: if (keys(%haschgs) > 0) {
1.80 raeburn 9340: my $newacc =
9341: &Apache::lonnet::usertools_access($env{'user.name'},
9342: $env{'user.domain'},
1.86 raeburn 9343: $item,'reload',$context);
1.160.6.5 raeburn 9344: if (($context eq 'requestcourses') ||
9345: ($context eq 'requestauthor')) {
1.108 raeburn 9346: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9347: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9348: }
9349: } else {
9350: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9351: $newenv{'environment.availabletools.'.$item} = $newacc;
9352: }
1.80 raeburn 9353: }
1.160.6.5 raeburn 9354: unless ($context eq 'requestauthor') {
9355: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9356: }
1.72 raeburn 9357: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 9358: if ($haschgs{$type}) {
1.72 raeburn 9359: my $typetitle = $usertypes->{$type};
9360: if ($type eq 'default') {
9361: $typetitle = $othertitle;
9362: } elsif ($type eq '_LC_adv') {
9363: $typetitle = 'LON-CAPA Advanced Users';
9364: }
1.160.6.5 raeburn 9365: if ($inconf{$type}) {
1.101 raeburn 9366: if ($context eq 'requestcourses') {
9367: my $cond;
1.160.6.5 raeburn 9368: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9369: if ($1 eq '') {
9370: $cond = &mt('(Automatic processing of any request).');
9371: } else {
9372: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9373: }
9374: } else {
1.160.6.5 raeburn 9375: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9376: }
9377: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 9378: } elsif ($context eq 'requestauthor') {
9379: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9380: $titles{$inconf{$type}},$typetitle);
9381:
1.101 raeburn 9382: } else {
9383: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9384: }
1.72 raeburn 9385: } else {
1.104 raeburn 9386: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 9387: if ($inconf{$type} eq '0') {
1.104 raeburn 9388: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9389: } else {
9390: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9391: }
9392: } else {
9393: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9394: }
1.72 raeburn 9395: }
9396: }
1.26 raeburn 9397: }
1.160.6.5 raeburn 9398: unless ($context eq 'requestauthor') {
9399: $resulttext .= '</ul></li>';
9400: }
1.26 raeburn 9401: }
1.1 raeburn 9402: }
1.160.6.5 raeburn 9403: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9404: if (ref($changes{'notify'}) eq 'HASH') {
9405: if ($changes{'notify'}{'approval'}) {
9406: if (ref($confhash{'notify'}) eq 'HASH') {
9407: if ($confhash{'notify'}{'approval'}) {
9408: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9409: } else {
1.160.6.5 raeburn 9410: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9411: }
9412: }
9413: }
9414: }
9415: }
1.160.6.30 raeburn 9416: if ($action eq 'requestcourses') {
9417: my @offon = ('off','on');
9418: if ($changes{'uniquecode'}) {
9419: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9420: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9421: $resulttext .= '<li>'.
9422: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9423: '</li>';
9424: } else {
9425: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9426: '</li>';
9427: }
9428: }
1.160.6.46 raeburn 9429: foreach my $type ('textbooks','templates') {
9430: if (ref($changes{$type}) eq 'HASH') {
9431: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9432: foreach my $key (sort(keys(%{$changes{$type}}))) {
9433: my %coursehash = &Apache::lonnet::coursedescription($key);
9434: my $coursetitle = $coursehash{'description'};
9435: my $position = $confhash{$type}{$key}{'order'} + 1;
9436: $resulttext .= '<li>';
1.160.6.47 raeburn 9437: foreach my $item ('subject','title','publisher','author') {
9438: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9439: ($type eq 'templates'));
1.160.6.46 raeburn 9440: my $name = $item.':';
9441: $name =~ s/^(\w)/\U$1/;
9442: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9443: }
9444: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9445: if ($type eq 'textbooks') {
9446: if ($confhash{$type}{$key}{'image'}) {
9447: $resulttext .= ' '.&mt('Image: [_1]',
9448: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9449: ' alt="Textbook cover" />').'<br />';
9450: }
9451: }
9452: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 9453: }
1.160.6.46 raeburn 9454: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 9455: }
9456: }
1.160.6.39 raeburn 9457: if (ref($changes{'validation'}) eq 'HASH') {
9458: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9459: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9460: foreach my $item (@{$validationitemsref}) {
9461: if (exists($changes{'validation'}{$item})) {
9462: if ($item eq 'markup') {
9463: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9464: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9465: } else {
9466: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9467: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9468: }
9469: }
9470: }
9471: if (exists($changes{'validation'}{'dc'})) {
9472: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9473: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9474: }
9475: }
9476: }
1.160.6.30 raeburn 9477: }
1.1 raeburn 9478: $resulttext .= '</ul>';
1.80 raeburn 9479: if (keys(%newenv)) {
9480: &Apache::lonnet::appenv(\%newenv);
9481: }
1.1 raeburn 9482: } else {
1.86 raeburn 9483: if ($context eq 'requestcourses') {
9484: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 9485: } elsif ($context eq 'requestauthor') {
9486: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9487: } else {
1.90 weissno 9488: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9489: }
1.1 raeburn 9490: }
9491: } else {
1.11 albertel 9492: $resulttext = '<span class="LC_error">'.
9493: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9494: }
1.160.6.30 raeburn 9495: if ($errors) {
9496: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9497: '<ul>'.$errors.'</ul></p>';
9498: }
1.3 raeburn 9499: return $resulttext;
1.1 raeburn 9500: }
9501:
1.160.6.30 raeburn 9502: sub process_textbook_image {
1.160.6.46 raeburn 9503: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 9504: my $filename = $env{'form.'.$caller.'.filename'};
9505: my ($error,$url);
9506: my ($width,$height) = (50,50);
9507: if ($configuserok eq 'ok') {
9508: if ($switchserver) {
9509: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9510: $switchserver);
9511: } elsif ($author_ok eq 'ok') {
9512: my ($result,$imageurl) =
9513: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.84.2. (raeburn 9514:): "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 9515: if ($result eq 'ok') {
9516: $url = $imageurl;
9517: } else {
9518: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9519: }
9520: } else {
9521: $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);
9522: }
9523: } else {
9524: $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);
9525: }
9526: return ($url,$error);
9527: }
9528:
1.160.6.84.2. (raeburn 9529:): sub modify_ltitools {
9530:): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
9531:): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9532:): my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
9533:): my $confname = $dom.'-domainconfig';
9534:): my $servadm = $r->dir_config('lonAdmEMail');
9535:): my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9536:): my (%posslti,%possfield);
9537:): my @courseroles = ('cc','in','ta','ep','st');
9538:): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
9539:): map { $posslti{$_} = 1; } @ltiroles;
9540:): my @allfields = ('fullname','firstname','lastname','email','user','roles');
9541:): map { $possfield{$_} = 1; } @allfields;
9542:): my %lt = <itools_names();
9543:): if ($env{'form.ltitools_add'}) {
9544:): my $title = $env{'form.ltitools_add_title'};
9545:): $title =~ s/(`)/'/g;
9546:): ($newid,my $error) = &get_ltitools_id($dom,$title);
9547:): if ($newid) {
9548:): my $position = $env{'form.ltitools_add_pos'};
9549:): $position =~ s/\D+//g;
9550:): if ($position ne '') {
9551:): $allpos[$position] = $newid;
9552:): }
9553:): $changes{$newid} = 1;
9554:): foreach my $item ('title','url','key','secret') {
9555:): $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
9556:): if ($env{'form.ltitools_add_'.$item}) {
9557:): if (($item eq 'key') || ($item eq 'secret')) {
9558:): $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9559:): } else {
9560:): $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9561:): }
9562:): }
9563:): }
9564:): if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
9565:): $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
9566:): }
9567:): if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
9568:): $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
9569:): }
9570:): foreach my $item ('width','height','linktext','explanation') {
9571:): $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
9572:): $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
9573:): if (($item eq 'width') || ($item eq 'height')) {
9574:): if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
9575:): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9576:): }
9577:): } else {
9578:): if ($env{'form.ltitools_add_'.$item} ne '') {
9579:): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9580:): }
9581:): }
9582:): }
9583:): if ($env{'form.ltitools_add_target'} eq 'window') {
9584:): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
9585:): } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
9586:): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
9587:): } else {
9588:): $confhash{$newid}{'display'}{'target'} = 'iframe';
9589:): }
9590:): foreach my $item ('passback','roster') {
9591:): if ($env{'form.ltitools_add_'.$item}) {
9592:): $confhash{$newid}{$item} = 1;
9593:): }
9594:): }
9595:): if ($env{'form.ltitools_add_image.filename'} ne '') {
9596:): my ($imageurl,$error) =
9597:): &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
9598:): $configuserok,$switchserver,$author_ok);
9599:): if ($imageurl) {
9600:): $confhash{$newid}{'image'} = $imageurl;
9601:): }
9602:): if ($error) {
9603:): &Apache::lonnet::logthis($error);
9604:): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9605:): }
9606:): }
9607:): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
9608:): foreach my $field (@fields) {
9609:): if ($possfield{$field}) {
9610:): if ($field eq 'roles') {
9611:): foreach my $role (@courseroles) {
9612:): my $choice = $env{'form.ltitools_add_roles_'.$role};
9613:): if (($choice ne '') && ($posslti{$choice})) {
9614:): $confhash{$newid}{'roles'}{$role} = $choice;
9615:): if ($role eq 'cc') {
9616:): $confhash{$newid}{'roles'}{'co'} = $choice;
9617:): }
9618:): }
9619:): }
9620:): } else {
9621:): $confhash{$newid}{'fields'}{$field} = 1;
9622:): }
9623:): }
9624:): }
9625:): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
9626:): foreach my $item (@courseconfig) {
9627:): $confhash{$newid}{'crsconf'}{$item} = 1;
9628:): }
9629:): if ($env{'form.ltitools_add_custom'}) {
9630:): my $name = $env{'form.ltitools_add_custom_name'};
9631:): my $value = $env{'form.ltitools_add_custom_value'};
9632:): $value =~ s/(`)/'/g;
9633:): $name =~ s/(`)/'/g;
9634:): $confhash{$newid}{'custom'}{$name} = $value;
9635:): }
9636:): } else {
9637:): my $error = &mt('Failed to acquire unique ID for new external tool');
9638:): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9639:): }
9640:): }
9641:): if (ref($domconfig{$action}) eq 'HASH') {
9642:): my %deletions;
9643:): my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
9644:): if (@todelete) {
9645:): map { $deletions{$_} = 1; } @todelete;
9646:): }
9647:): my %customadds;
9648:): my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
9649:): if (@newcustom) {
9650:): map { $customadds{$_} = 1; } @newcustom;
9651:): }
9652:): my %imgdeletions;
9653:): my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
9654:): if (@todeleteimages) {
9655:): map { $imgdeletions{$_} = 1; } @todeleteimages;
9656:): }
9657:): my $maxnum = $env{'form.ltitools_maxnum'};
9658:): for (my $i=0; $i<=$maxnum; $i++) {
9659:): my $itemid = $env{'form.ltitools_id_'.$i};
9660:): $itemid =~ s/\D+//g;
9661:): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9662:): if ($deletions{$itemid}) {
9663:): if ($domconfig{$action}{$itemid}{'image'}) {
9664:): #FIXME need to obsolete item in RES space
9665:): }
9666:): $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
9667:): next;
9668:): } else {
9669:): my $newpos = $env{'form.ltitools_'.$itemid};
9670:): $newpos =~ s/\D+//g;
9671:): foreach my $item ('title','url') {
9672:): $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9673:): if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
9674:): $changes{$itemid} = 1;
9675:): }
9676:): }
9677:): foreach my $item ('key','secret') {
9678:): $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9679:): if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
9680:): $changes{$itemid} = 1;
9681:): }
9682:): }
9683:): if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
9684:): $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
9685:): }
9686:): if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
9687:): $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
9688:): }
9689:): foreach my $size ('width','height') {
9690:): $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
9691:): $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
9692:): if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
9693:): $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
9694:): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9695:): if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
9696:): $changes{$itemid} = 1;
9697:): }
9698:): } else {
9699:): $changes{$itemid} = 1;
9700:): }
9701:): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9702:): if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
9703:): $changes{$itemid} = 1;
9704:): }
9705:): }
9706:): }
9707:): foreach my $item ('linktext','explanation') {
9708:): $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
9709:): $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
9710:): if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
9711:): $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9712:): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9713:): if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
9714:): $changes{$itemid} = 1;
9715:): }
9716:): } else {
9717:): $changes{$itemid} = 1;
9718:): }
9719:): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9720:): if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
9721:): $changes{$itemid} = 1;
9722:): }
9723:): }
9724:): }
9725:): if ($env{'form.ltitools_target_'.$i} eq 'window') {
9726:): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
9727:): } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
9728:): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
9729:): } else {
9730:): $confhash{$itemid}{'display'}{'target'} = 'iframe';
9731:): }
9732:): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9733:): if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
9734:): $changes{$itemid} = 1;
9735:): }
9736:): } else {
9737:): $changes{$itemid} = 1;
9738:): }
9739:): foreach my $extra ('passback','roster') {
9740:): if ($env{'form.ltitools_'.$extra.'_'.$i}) {
9741:): $confhash{$itemid}{$extra} = 1;
9742:): }
9743:): if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
9744:): $changes{$itemid} = 1;
9745:): }
9746:): }
9747:): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
9748:): foreach my $item ('label','title','target','linktext','explanation') {
9749:): if (grep(/^\Q$item\E$/,@courseconfig)) {
9750:): $confhash{$itemid}{'crsconf'}{$item} = 1;
9751:): if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
9752:): if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
9753:): $changes{$itemid} = 1;
9754:): }
9755:): } else {
9756:): $changes{$itemid} = 1;
9757:): }
9758:): }
9759:): }
9760:): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
9761:): foreach my $field (@fields) {
9762:): if ($possfield{$field}) {
9763:): if ($field eq 'roles') {
9764:): foreach my $role (@courseroles) {
9765:): my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
9766:): if (($choice ne '') && ($posslti{$choice})) {
9767:): $confhash{$itemid}{'roles'}{$role} = $choice;
9768:): if ($role eq 'cc') {
9769:): $confhash{$itemid}{'roles'}{'co'} = $choice;
9770:): }
9771:): }
9772:): if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
9773:): if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
9774:): $changes{$itemid} = 1;
9775:): }
9776:): } elsif ($confhash{$itemid}{'roles'}{$role}) {
9777:): $changes{$itemid} = 1;
9778:): }
9779:): }
9780:): } else {
9781:): $confhash{$itemid}{'fields'}{$field} = 1;
9782:): if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
9783:): if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
9784:): $changes{$itemid} = 1;
9785:): }
9786:): } else {
9787:): $changes{$itemid} = 1;
9788:): }
9789:): }
9790:): }
9791:): }
9792:): $allpos[$newpos] = $itemid;
9793:): }
9794:): if ($imgdeletions{$itemid}) {
9795:): $changes{$itemid} = 1;
9796:): #FIXME need to obsolete item in RES space
9797:): } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
9798:): my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
9799:): $itemid,$configuserok,$switchserver,
9800:): $author_ok);
9801:): if ($imgurl) {
9802:): $confhash{$itemid}{'image'} = $imgurl;
9803:): $changes{$itemid} = 1;
9804:): }
9805:): if ($error) {
9806:): &Apache::lonnet::logthis($error);
9807:): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9808:): }
9809:): } elsif ($domconfig{$action}{$itemid}{'image'}) {
9810:): $confhash{$itemid}{'image'} =
9811:): $domconfig{$action}{$itemid}{'image'};
9812:): }
9813:): if ($customadds{$i}) {
9814:): my $name = $env{'form.ltitools_custom_name_'.$i};
9815:): $name =~ s/(`)/'/g;
9816:): $name =~ s/^\s+//;
9817:): $name =~ s/\s+$//;
9818:): my $value = $env{'form.ltitools_custom_value_'.$i};
9819:): $value =~ s/(`)/'/g;
9820:): $value =~ s/^\s+//;
9821:): $value =~ s/\s+$//;
9822:): if ($name ne '') {
9823:): $confhash{$itemid}{'custom'}{$name} = $value;
9824:): $changes{$itemid} = 1;
9825:): }
9826:): }
9827:): my %customdels;
9828:): my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
9829:): if (@customdeletions) {
9830:): $changes{$itemid} = 1;
9831:): }
9832:): map { $customdels{$_} = 1; } @customdeletions;
9833:): if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
9834:): foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
9835:): unless ($customdels{$key}) {
9836:): if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
9837:): $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
9838:): }
9839:): if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
9840:): $changes{$itemid} = 1;
9841:): }
9842:): }
9843:): }
9844:): }
9845:): unless ($changes{$itemid}) {
9846:): foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
9847:): if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
9848:): if (ref($confhash{$itemid}{$key}) eq 'HASH') {
9849:): foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
9850:): unless (exists($confhash{$itemid}{$key}{$innerkey})) {
9851:): $changes{$itemid} = 1;
9852:): last;
9853:): }
9854:): }
9855:): } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
9856:): $changes{$itemid} = 1;
9857:): }
9858:): }
9859:): last if ($changes{$itemid});
9860:): }
9861:): }
9862:): }
9863:): }
9864:): }
9865:): if (@allpos > 0) {
9866:): my $idx = 0;
9867:): foreach my $itemid (@allpos) {
9868:): if ($itemid ne '') {
9869:): $confhash{$itemid}{'order'} = $idx;
9870:): if (ref($domconfig{$action}) eq 'HASH') {
9871:): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9872:): if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
9873:): $changes{$itemid} = 1;
9874:): }
9875:): }
9876:): }
9877:): $idx ++;
9878:): }
9879:): }
9880:): }
9881:): my %ltitoolshash = (
9882:): $action => { %confhash }
9883:): );
9884:): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
9885:): $dom);
9886:): if ($putresult eq 'ok') {
9887:): my %ltienchash = (
9888:): $action => { %encconfig }
9889:): );
9890:): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
9891:): if (keys(%changes) > 0) {
9892:): my $cachetime = 24*60*60;
9893:): my %ltiall = %confhash;
9894:): foreach my $id (keys(%ltiall)) {
9895:): if (ref($encconfig{$id}) eq 'HASH') {
9896:): foreach my $item ('key','secret') {
9897:): $ltiall{$id}{$item} = $encconfig{$id}{$item};
9898:): }
9899:): }
9900:): }
9901:): &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
9902:): if (ref($lastactref) eq 'HASH') {
9903:): $lastactref->{'ltitools'} = 1;
9904:): }
9905:): $resulttext = &mt('Changes made:').'<ul>';
9906:): my %bynum;
9907:): foreach my $itemid (sort(keys(%changes))) {
9908:): my $position = $confhash{$itemid}{'order'};
9909:): $bynum{$position} = $itemid;
9910:): }
9911:): foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9912:): my $itemid = $bynum{$pos};
9913:): if (ref($confhash{$itemid}) ne 'HASH') {
9914:): $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9915:): } else {
9916:): $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
9917:): if ($confhash{$itemid}{'image'}) {
9918:): $resulttext .= ' '.
9919:): '<img src="'.$confhash{$itemid}{'image'}.'"'.
9920:): ' alt="'.&mt('Tool Provider icon').'" />';
9921:): }
9922:): $resulttext .= '</li><ul>';
9923:): my $position = $pos + 1;
9924:): $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
9925:): foreach my $item ('version','msgtype','url') {
9926:): if ($confhash{$itemid}{$item} ne '') {
9927:): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
9928:): }
9929:): }
9930:): if ($encconfig{$itemid}{'key'} ne '') {
9931:): $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
9932:): }
9933:): if ($encconfig{$itemid}{'secret'} ne '') {
9934:): $resulttext .= '<li>'.$lt{'secret'}.': ';
9935:): my $num = length($encconfig{$itemid}{'secret'});
9936:): $resulttext .= ('*'x$num).'</li>';
9937:): }
9938:): $resulttext .= '<li>'.&mt('Configurable in course:');
9939:): my @possconfig = ('label','title','target','linktext','explanation');
9940:): my $numconfig = 0;
9941:): if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
9942:): foreach my $item (@possconfig) {
9943:): if ($confhash{$itemid}{'crsconf'}{$item}) {
9944:): $numconfig ++;
9945:): $resulttext .= ' "'.$lt{'crs'.$item}.'"';
9946:): }
9947:): }
9948:): }
9949:): if (!$numconfig) {
9950:): $resulttext .= &mt('None');
9951:): }
9952:): $resulttext .= '</li>';
9953:): foreach my $item ('passback','roster') {
9954:): $resulttext .= '<li>'.$lt{$item}.' ';
9955:): if ($confhash{$itemid}{$item}) {
9956:): $resulttext .= &mt('Yes');
9957:): } else {
9958:): $resulttext .= &mt('No');
9959:): }
9960:): $resulttext .= '</li>';
9961:): }
9962:): if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
9963:): my $displaylist;
9964:): if ($confhash{$itemid}{'display'}{'target'}) {
9965:): $displaylist = &mt('Display target').': '.
9966:): $confhash{$itemid}{'display'}{'target'}.',';
9967:): }
9968:): foreach my $size ('width','height') {
9969:): if ($confhash{$itemid}{'display'}{$size}) {
9970:): $displaylist .= (' 'x2).$lt{$size}.': '.
9971:): $confhash{$itemid}{'display'}{$size}.',';
9972:): }
9973:): }
9974:): if ($displaylist) {
9975:): $displaylist =~ s/,$//;
9976:): $resulttext .= '<li>'.$displaylist.'</li>';
9977:): }
9978:): foreach my $item ('linktext','explanation') {
9979:): if ($confhash{$itemid}{'display'}{$item}) {
9980:): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
9981:): }
9982:): }
9983:): }
9984:): if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
9985:): my $fieldlist;
9986:): foreach my $field (@allfields) {
9987:): if ($confhash{$itemid}{'fields'}{$field}) {
9988:): $fieldlist .= (' 'x2).$lt{$field}.',';
9989:): }
9990:): }
9991:): if ($fieldlist) {
9992:): $fieldlist =~ s/,$//;
9993:): $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
9994:): }
9995:): }
9996:): if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
9997:): my $rolemaps;
9998:): foreach my $role (@courseroles) {
9999:): if ($confhash{$itemid}{'roles'}{$role}) {
10000:): $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
10001:): $confhash{$itemid}{'roles'}{$role}.',';
10002:): }
10003:): }
10004:): if ($rolemaps) {
10005:): $rolemaps =~ s/,$//;
10006:): $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
10007:): }
10008:): }
10009:): if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
10010:): my $customlist;
10011:): if (keys(%{$confhash{$itemid}{'custom'}})) {
10012:): foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
10013:): $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
10014:): }
10015:): }
10016:): if ($customlist) {
10017:): $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
10018:): }
10019:): }
10020:): $resulttext .= '</ul></li>';
10021:): }
10022:): }
10023:): $resulttext .= '</ul>';
10024:): } else {
10025:): $resulttext = &mt('No changes made.');
10026:): }
10027:): } else {
10028:): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
10029:): }
10030:): if ($errors) {
10031:): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10032:): $errors.'</ul>';
10033:): }
10034:): return $resulttext;
10035:): }
10036:):
10037:): sub process_ltitools_image {
10038:): my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
10039:): my $filename = $env{'form.'.$caller.'.filename'};
10040:): my ($error,$url);
10041:): my ($width,$height) = (21,21);
10042:): if ($configuserok eq 'ok') {
10043:): if ($switchserver) {
10044:): $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
10045:): $switchserver);
10046:): } elsif ($author_ok eq 'ok') {
10047:): my ($result,$imageurl,$madethumb) =
10048:): &publishlogo($r,'upload',$caller,$dom,$confname,
10049:): "ltitools/$itemid/icon",$width,$height);
10050:): if ($result eq 'ok') {
10051:): if ($madethumb) {
10052:): my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
10053:): my $imagethumb = "$path/tn-".$imagefile;
10054:): $url = $imagethumb;
10055:): } else {
10056:): $url = $imageurl;
10057:): }
10058:): } else {
10059:): $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10060:): }
10061:): } else {
10062:): $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);
10063:): }
10064:): } else {
10065:): $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);
10066:): }
10067:): return ($url,$error);
10068:): }
10069:):
10070:): sub get_ltitools_id {
10071:): my ($cdom,$title) = @_;
10072:): # get lock on ltitools db
10073:): my $lockhash = {
10074:): lock => $env{'user.name'}.
10075:): ':'.$env{'user.domain'},
10076:): };
10077:): my $tries = 0;
10078:): my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10079:): my ($id,$error);
10080:):
10081:): while (($gotlock ne 'ok') && ($tries<10)) {
10082:): $tries ++;
10083:): sleep (0.1);
10084:): $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10085:): }
10086:): if ($gotlock eq 'ok') {
10087:): my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
10088:): if ($currids{'lock'}) {
10089:): delete($currids{'lock'});
10090:): if (keys(%currids)) {
10091:): my @curr = sort { $a <=> $b } keys(%currids);
10092:): if ($curr[-1] =~ /^\d+$/) {
10093:): $id = 1 + $curr[-1];
10094:): }
10095:): } else {
10096:): $id = 1;
10097:): }
10098:): if ($id) {
10099:): unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
10100:): $error = 'nostore';
10101:): }
10102:): } else {
10103:): $error = 'nonumber';
10104:): }
10105:): }
10106:): my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
10107:): } else {
10108:): $error = 'nolock';
10109:): }
10110:): return ($id,$error);
10111:): }
10112:):
1.3 raeburn 10113: sub modify_autoenroll {
1.160.6.24 raeburn 10114: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 10115: my ($resulttext,%changes);
10116: my %currautoenroll;
10117: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
10118: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
10119: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
10120: }
10121: }
10122: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
10123: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 10124: sender => 'Sender for notification messages',
1.160.6.68 raeburn 10125: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
10126: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 10127: my @offon = ('off','on');
1.17 raeburn 10128: my $sender_uname = $env{'form.sender_uname'};
10129: my $sender_domain = $env{'form.sender_domain'};
10130: if ($sender_domain eq '') {
10131: $sender_uname = '';
10132: } elsif ($sender_uname eq '') {
10133: $sender_domain = '';
10134: }
1.129 raeburn 10135: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 10136: my $failsafe = $env{'form.autoenroll_failsafe'};
10137: $failsafe =~ s{^\s+|\s+$}{}g;
10138: if ($failsafe =~ /\D/) {
10139: undef($failsafe);
10140: }
1.1 raeburn 10141: my %autoenrollhash = (
1.129 raeburn 10142: autoenroll => { 'run' => $env{'form.autoenroll_run'},
10143: 'sender_uname' => $sender_uname,
10144: 'sender_domain' => $sender_domain,
10145: 'co-owners' => $coowners,
1.160.6.68 raeburn 10146: 'autofailsafe' => $failsafe,
1.1 raeburn 10147: }
10148: );
1.4 raeburn 10149: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
10150: $dom);
1.1 raeburn 10151: if ($putresult eq 'ok') {
10152: if (exists($currautoenroll{'run'})) {
10153: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
10154: $changes{'run'} = 1;
10155: }
10156: } elsif ($autorun) {
10157: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 10158: $changes{'run'} = 1;
1.1 raeburn 10159: }
10160: }
1.17 raeburn 10161: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 10162: $changes{'sender'} = 1;
10163: }
1.17 raeburn 10164: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 10165: $changes{'sender'} = 1;
10166: }
1.129 raeburn 10167: if ($currautoenroll{'co-owners'} ne '') {
10168: if ($currautoenroll{'co-owners'} ne $coowners) {
10169: $changes{'coowners'} = 1;
10170: }
10171: } elsif ($coowners) {
10172: $changes{'coowners'} = 1;
1.160.6.68 raeburn 10173: }
10174: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
10175: $changes{'autofailsafe'} = 1;
10176: }
1.1 raeburn 10177: if (keys(%changes) > 0) {
10178: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 10179: if ($changes{'run'}) {
1.1 raeburn 10180: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
10181: }
10182: if ($changes{'sender'}) {
1.17 raeburn 10183: if ($sender_uname eq '' || $sender_domain eq '') {
10184: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
10185: } else {
10186: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
10187: }
1.1 raeburn 10188: }
1.129 raeburn 10189: if ($changes{'coowners'}) {
10190: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
10191: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10192: if (ref($lastactref) eq 'HASH') {
10193: $lastactref->{'domainconfig'} = 1;
10194: }
1.129 raeburn 10195: }
1.160.6.68 raeburn 10196: if ($changes{'autofailsafe'}) {
10197: if ($failsafe ne '') {
1.160.6.82 raeburn 10198: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 10199: } else {
1.160.6.82 raeburn 10200: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 10201: }
10202: &Apache::lonnet::get_domain_defaults($dom,1);
10203: if (ref($lastactref) eq 'HASH') {
10204: $lastactref->{'domdefaults'} = 1;
10205: }
10206: }
1.1 raeburn 10207: $resulttext .= '</ul>';
10208: } else {
10209: $resulttext = &mt('No changes made to auto-enrollment settings');
10210: }
10211: } else {
1.11 albertel 10212: $resulttext = '<span class="LC_error">'.
10213: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10214: }
1.3 raeburn 10215: return $resulttext;
1.1 raeburn 10216: }
10217:
10218: sub modify_autoupdate {
1.3 raeburn 10219: my ($dom,%domconfig) = @_;
1.1 raeburn 10220: my ($resulttext,%currautoupdate,%fields,%changes);
10221: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
10222: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
10223: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
10224: }
10225: }
10226: my @offon = ('off','on');
10227: my %title = &Apache::lonlocal::texthash (
10228: run => 'Auto-update:',
10229: classlists => 'Updates to user information in classlists?'
10230: );
1.44 raeburn 10231: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10232: my %fieldtitles = &Apache::lonlocal::texthash (
10233: id => 'Student/Employee ID',
1.20 raeburn 10234: permanentemail => 'E-mail address',
1.1 raeburn 10235: lastname => 'Last Name',
10236: firstname => 'First Name',
10237: middlename => 'Middle Name',
1.132 raeburn 10238: generation => 'Generation',
1.1 raeburn 10239: );
1.142 raeburn 10240: $othertitle = &mt('All users');
1.1 raeburn 10241: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 10242: $othertitle = &mt('Other users');
1.1 raeburn 10243: }
10244: foreach my $key (keys(%env)) {
10245: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 10246: my ($usertype,$item) = ($1,$2);
10247: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
10248: if ($usertype eq 'default') {
10249: push(@{$fields{$1}},$2);
10250: } elsif (ref($types) eq 'ARRAY') {
10251: if (grep(/^\Q$usertype\E$/,@{$types})) {
10252: push(@{$fields{$1}},$2);
10253: }
10254: }
10255: }
1.1 raeburn 10256: }
10257: }
1.131 raeburn 10258: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
10259: @lockablenames = sort(@lockablenames);
10260: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
10261: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10262: if (@changed) {
10263: $changes{'lockablenames'} = 1;
10264: }
10265: } else {
10266: if (@lockablenames) {
10267: $changes{'lockablenames'} = 1;
10268: }
10269: }
1.1 raeburn 10270: my %updatehash = (
10271: autoupdate => { run => $env{'form.autoupdate_run'},
10272: classlists => $env{'form.classlists'},
10273: fields => {%fields},
1.131 raeburn 10274: lockablenames => \@lockablenames,
1.1 raeburn 10275: }
10276: );
10277: foreach my $key (keys(%currautoupdate)) {
10278: if (($key eq 'run') || ($key eq 'classlists')) {
10279: if (exists($updatehash{autoupdate}{$key})) {
10280: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
10281: $changes{$key} = 1;
10282: }
10283: }
10284: } elsif ($key eq 'fields') {
10285: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 10286: foreach my $item (@{$types},'default') {
1.1 raeburn 10287: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
10288: my $change = 0;
10289: foreach my $type (@{$currautoupdate{$key}{$item}}) {
10290: if (!exists($fields{$item})) {
10291: $change = 1;
1.132 raeburn 10292: last;
1.1 raeburn 10293: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 10294: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 10295: $change = 1;
1.132 raeburn 10296: last;
1.1 raeburn 10297: }
10298: }
10299: }
10300: if ($change) {
10301: push(@{$changes{$key}},$item);
10302: }
1.26 raeburn 10303: }
1.1 raeburn 10304: }
10305: }
1.131 raeburn 10306: } elsif ($key eq 'lockablenames') {
10307: if (ref($currautoupdate{$key}) eq 'ARRAY') {
10308: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10309: if (@changed) {
10310: $changes{'lockablenames'} = 1;
10311: }
10312: } else {
10313: if (@lockablenames) {
10314: $changes{'lockablenames'} = 1;
10315: }
10316: }
10317: }
10318: }
10319: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10320: if (@lockablenames) {
10321: $changes{'lockablenames'} = 1;
1.1 raeburn 10322: }
10323: }
1.26 raeburn 10324: foreach my $item (@{$types},'default') {
10325: if (defined($fields{$item})) {
10326: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 10327: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10328: my $change = 0;
10329: if (ref($fields{$item}) eq 'ARRAY') {
10330: foreach my $type (@{$fields{$item}}) {
10331: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10332: $change = 1;
10333: last;
10334: }
10335: }
10336: }
10337: if ($change) {
10338: push(@{$changes{'fields'}},$item);
10339: }
10340: } else {
1.26 raeburn 10341: push(@{$changes{'fields'}},$item);
10342: }
10343: } else {
10344: push(@{$changes{'fields'}},$item);
1.1 raeburn 10345: }
10346: }
10347: }
10348: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10349: $dom);
10350: if ($putresult eq 'ok') {
10351: if (keys(%changes) > 0) {
10352: $resulttext = &mt('Changes made:').'<ul>';
10353: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 10354: if ($key eq 'lockablenames') {
10355: $resulttext .= '<li>';
10356: if (@lockablenames) {
10357: $usertypes->{'default'} = $othertitle;
10358: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10359: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10360: } else {
10361: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10362: }
10363: $resulttext .= '</li>';
10364: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 10365: foreach my $item (@{$changes{$key}}) {
10366: my @newvalues;
10367: foreach my $type (@{$fields{$item}}) {
10368: push(@newvalues,$fieldtitles{$type});
10369: }
1.3 raeburn 10370: my $newvaluestr;
10371: if (@newvalues > 0) {
10372: $newvaluestr = join(', ',@newvalues);
10373: } else {
10374: $newvaluestr = &mt('none');
1.6 raeburn 10375: }
1.1 raeburn 10376: if ($item eq 'default') {
1.26 raeburn 10377: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 10378: } else {
1.26 raeburn 10379: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 10380: }
10381: }
10382: } else {
10383: my $newvalue;
10384: if ($key eq 'run') {
10385: $newvalue = $offon[$env{'form.autoupdate_run'}];
10386: } else {
10387: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 10388: }
1.1 raeburn 10389: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
10390: }
10391: }
10392: $resulttext .= '</ul>';
10393: } else {
1.3 raeburn 10394: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 10395: }
10396: } else {
1.11 albertel 10397: $resulttext = '<span class="LC_error">'.
10398: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10399: }
1.3 raeburn 10400: return $resulttext;
1.1 raeburn 10401: }
10402:
1.125 raeburn 10403: sub modify_autocreate {
10404: my ($dom,%domconfig) = @_;
10405: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10406: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10407: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10408: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10409: }
10410: }
10411: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10412: req => 'Auto-creation of validated requests for official courses',
10413: xmldc => 'Identity of course creator of courses from XML files',
10414: );
10415: my @types = ('xml','req');
10416: foreach my $item (@types) {
10417: $newvals{$item} = $env{'form.autocreate_'.$item};
10418: $newvals{$item} =~ s/\D//g;
10419: $newvals{$item} = 0 if ($newvals{$item} eq '');
10420: }
10421: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 10422: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 10423: unless (exists($domcoords{$newvals{'xmldc'}})) {
10424: $newvals{'xmldc'} = '';
10425: }
10426: %autocreatehash = (
10427: autocreate => { xml => $newvals{'xml'},
10428: req => $newvals{'req'},
10429: }
10430: );
10431: if ($newvals{'xmldc'} ne '') {
10432: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10433: }
10434: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10435: $dom);
10436: if ($putresult eq 'ok') {
10437: my @items = @types;
10438: if ($newvals{'xml'}) {
10439: push(@items,'xmldc');
10440: }
10441: foreach my $item (@items) {
10442: if (exists($currautocreate{$item})) {
10443: if ($currautocreate{$item} ne $newvals{$item}) {
10444: $changes{$item} = 1;
10445: }
10446: } elsif ($newvals{$item}) {
10447: $changes{$item} = 1;
10448: }
10449: }
10450: if (keys(%changes) > 0) {
10451: my @offon = ('off','on');
10452: $resulttext = &mt('Changes made:').'<ul>';
10453: foreach my $item (@types) {
10454: if ($changes{$item}) {
10455: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 10456: $resulttext .= '<li>'.
10457: &mt("$title{$item} set to [_1]$newtxt [_2]",
10458: '<b>','</b>').
10459: '</li>';
1.125 raeburn 10460: }
10461: }
10462: if ($changes{'xmldc'}) {
10463: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10464: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 10465: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 10466: }
10467: $resulttext .= '</ul>';
10468: } else {
10469: $resulttext = &mt('No changes made to auto-creation settings');
10470: }
10471: } else {
10472: $resulttext = '<span class="LC_error">'.
10473: &mt('An error occurred: [_1]',$putresult).'</span>';
10474: }
10475: return $resulttext;
10476: }
10477:
1.23 raeburn 10478: sub modify_directorysrch {
1.160.6.81 raeburn 10479: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 10480: my ($resulttext,%changes);
10481: my %currdirsrch;
10482: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10483: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10484: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10485: }
10486: }
1.160.6.72 raeburn 10487: my %title = ( available => 'Institutional directory search available',
10488: localonly => 'Other domains can search institution',
10489: lcavailable => 'LON-CAPA directory search available',
10490: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 10491: searchby => 'Search types',
10492: searchtypes => 'Search latitude');
10493: my @offon = ('off','on');
1.24 raeburn 10494: my @otherdoms = ('Yes','No');
1.23 raeburn 10495:
1.25 raeburn 10496: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 10497: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10498: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10499:
1.44 raeburn 10500: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 10501: if (keys(%{$usertypes}) == 0) {
10502: @cansearch = ('default');
10503: } else {
10504: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10505: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10506: if (!grep(/^\Q$type\E$/,@cansearch)) {
10507: push(@{$changes{'cansearch'}},$type);
10508: }
1.23 raeburn 10509: }
1.26 raeburn 10510: foreach my $type (@cansearch) {
10511: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10512: push(@{$changes{'cansearch'}},$type);
10513: }
1.23 raeburn 10514: }
1.26 raeburn 10515: } else {
10516: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 10517: }
10518: }
10519:
10520: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10521: foreach my $by (@{$currdirsrch{'searchby'}}) {
10522: if (!grep(/^\Q$by\E$/,@searchby)) {
10523: push(@{$changes{'searchby'}},$by);
10524: }
10525: }
10526: foreach my $by (@searchby) {
10527: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10528: push(@{$changes{'searchby'}},$by);
10529: }
10530: }
10531: } else {
10532: push(@{$changes{'searchby'}},@searchby);
10533: }
1.25 raeburn 10534:
10535: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10536: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10537: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10538: push(@{$changes{'searchtypes'}},$type);
10539: }
10540: }
10541: foreach my $type (@searchtypes) {
10542: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10543: push(@{$changes{'searchtypes'}},$type);
10544: }
10545: }
10546: } else {
10547: if (exists($currdirsrch{'searchtypes'})) {
10548: foreach my $type (@searchtypes) {
10549: if ($type ne $currdirsrch{'searchtypes'}) {
10550: push(@{$changes{'searchtypes'}},$type);
10551: }
10552: }
10553: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10554: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10555: }
10556: } else {
10557: push(@{$changes{'searchtypes'}},@searchtypes);
10558: }
10559: }
10560:
1.23 raeburn 10561: my %dirsrch_hash = (
10562: directorysrch => { available => $env{'form.dirsrch_available'},
10563: cansearch => \@cansearch,
1.160.6.72 raeburn 10564: localonly => $env{'form.dirsrch_instlocalonly'},
10565: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10566: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 10567: searchby => \@searchby,
1.25 raeburn 10568: searchtypes => \@searchtypes,
1.23 raeburn 10569: }
10570: );
10571: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10572: $dom);
10573: if ($putresult eq 'ok') {
10574: if (exists($currdirsrch{'available'})) {
10575: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10576: $changes{'available'} = 1;
10577: }
10578: } else {
10579: if ($env{'form.dirsrch_available'} eq '1') {
10580: $changes{'available'} = 1;
10581: }
10582: }
1.160.6.72 raeburn 10583: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 10584: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
10585: $changes{'lcavailable'} = 1;
10586: }
1.24 raeburn 10587: } else {
1.160.6.72 raeburn 10588: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10589: $changes{'lcavailable'} = 1;
10590: }
10591: }
10592: if (exists($currdirsrch{'localonly'})) {
10593: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 10594: $changes{'localonly'} = 1;
10595: }
1.160.6.72 raeburn 10596: } else {
10597: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
10598: $changes{'localonly'} = 1;
10599: }
10600: }
10601: if (exists($currdirsrch{'lclocalonly'})) {
10602: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
10603: $changes{'lclocalonly'} = 1;
10604: }
10605: } else {
10606: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10607: $changes{'lclocalonly'} = 1;
10608: }
1.24 raeburn 10609: }
1.23 raeburn 10610: if (keys(%changes) > 0) {
10611: $resulttext = &mt('Changes made:').'<ul>';
10612: if ($changes{'available'}) {
10613: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10614: }
1.160.6.72 raeburn 10615: if ($changes{'lcavailable'}) {
10616: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10617: }
1.24 raeburn 10618: if ($changes{'localonly'}) {
1.160.6.72 raeburn 10619: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
10620: }
10621: if ($changes{'lclocalonly'}) {
10622: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 10623: }
1.23 raeburn 10624: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10625: my $chgtext;
1.26 raeburn 10626: if (ref($usertypes) eq 'HASH') {
10627: if (keys(%{$usertypes}) > 0) {
10628: foreach my $type (@{$types}) {
10629: if (grep(/^\Q$type\E$/,@cansearch)) {
10630: $chgtext .= $usertypes->{$type}.'; ';
10631: }
10632: }
10633: if (grep(/^default$/,@cansearch)) {
10634: $chgtext .= $othertitle;
10635: } else {
10636: $chgtext =~ s/\; $//;
10637: }
1.160.6.13 raeburn 10638: $resulttext .=
10639: '<li>'.
10640: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10641: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10642: '</li>';
1.23 raeburn 10643: }
10644: }
10645: }
10646: if (ref($changes{'searchby'}) eq 'ARRAY') {
10647: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10648: my $chgtext;
10649: foreach my $type (@{$titleorder}) {
10650: if (grep(/^\Q$type\E$/,@searchby)) {
10651: if (defined($searchtitles->{$type})) {
10652: $chgtext .= $searchtitles->{$type}.'; ';
10653: }
10654: }
10655: }
10656: $chgtext =~ s/\; $//;
10657: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10658: }
1.25 raeburn 10659: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10660: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10661: my $chgtext;
10662: foreach my $type (@{$srchtypeorder}) {
10663: if (grep(/^\Q$type\E$/,@searchtypes)) {
10664: if (defined($srchtypes_desc->{$type})) {
10665: $chgtext .= $srchtypes_desc->{$type}.'; ';
10666: }
10667: }
10668: }
10669: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 10670: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 10671: }
10672: $resulttext .= '</ul>';
1.160.6.81 raeburn 10673: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
10674: if (ref($lastactref) eq 'HASH') {
10675: $lastactref->{'directorysrch'} = 1;
10676: }
1.23 raeburn 10677: } else {
1.160.6.72 raeburn 10678: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 10679: }
10680: } else {
10681: $resulttext = '<span class="LC_error">'.
1.27 raeburn 10682: &mt('An error occurred: [_1]',$putresult).'</span>';
10683: }
10684: return $resulttext;
10685: }
10686:
1.28 raeburn 10687: sub modify_contacts {
1.160.6.24 raeburn 10688: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 10689: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10690: if (ref($domconfig{'contacts'}) eq 'HASH') {
10691: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10692: $currsetting{$key} = $domconfig{'contacts'}{$key};
10693: }
10694: }
1.160.6.78 raeburn 10695: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 10696: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 10697: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
10698: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.160.6.23 raeburn 10699: my @toggles = ('reporterrors','reportupdates');
1.160.6.78 raeburn 10700: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 10701: foreach my $type (@mailings) {
10702: @{$newsetting{$type}} =
10703: &Apache::loncommon::get_env_multiple('form.'.$type);
10704: foreach my $item (@contacts) {
10705: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
10706: $contacts_hash{contacts}{$type}{$item} = 1;
10707: } else {
10708: $contacts_hash{contacts}{$type}{$item} = 0;
10709: }
1.160.6.78 raeburn 10710: }
1.28 raeburn 10711: $others{$type} = $env{'form.'.$type.'_others'};
10712: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 10713: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10714: $bcc{$type} = $env{'form.'.$type.'_bcc'};
10715: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 10716: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
10717: $includestr{$type} = $env{'form.'.$type.'_includestr'};
10718: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
10719: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10720: }
1.134 raeburn 10721: }
1.28 raeburn 10722: }
10723: foreach my $item (@contacts) {
10724: $to{$item} = $env{'form.'.$item};
10725: $contacts_hash{'contacts'}{$item} = $to{$item};
10726: }
1.160.6.23 raeburn 10727: foreach my $item (@toggles) {
10728: if ($env{'form.'.$item} =~ /^(0|1)$/) {
10729: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
10730: }
10731: }
1.160.6.78 raeburn 10732: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
10733: foreach my $field (@{$fields}) {
10734: if (ref($possoptions->{$field}) eq 'ARRAY') {
10735: my $value = $env{'form.helpform_'.$field};
10736: $value =~ s/^\s+|\s+$//g;
10737: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.84.2. (raeburn 10738:): $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 10739: if ($field eq 'screenshot') {
10740: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
10741: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.84.2. (raeburn 10742:): $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 10743: }
10744: }
10745: }
10746: }
10747: }
10748: }
1.160.6.84.2. (raeburn 10749:): my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10750:): my (@statuses,%usertypeshash,@overrides);
10751:): if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
10752:): @statuses = @{$types};
10753:): if (ref($usertypes) eq 'HASH') {
10754:): %usertypeshash = %{$usertypes};
10755:): }
10756:): }
10757:): if (@statuses) {
10758:): my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
10759:): foreach my $type (@possoverrides) {
10760:): if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
10761:): push(@overrides,$type);
10762:): }
10763:): }
10764:): if (@overrides) {
10765:): foreach my $type (@overrides) {
10766:): my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
10767:): foreach my $item (@contacts) {
10768:): if (grep(/^\Q$item\E$/,@standard)) {
10769:): $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
10770:): $newsetting{'override_'.$type}{$item} = 1;
10771:): } else {
10772:): $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
10773:): $newsetting{'override_'.$type}{$item} = 0;
10774:): }
10775:): }
10776:): $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
10777:): $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
10778:): $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
10779:): $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
10780:): if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
10781:): $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
10782:): $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
10783:): $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10784:): $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
10785:): }
10786:): }
10787:): }
10788:): }
1.28 raeburn 10789: if (keys(%currsetting) > 0) {
10790: foreach my $item (@contacts) {
10791: if ($to{$item} ne $currsetting{$item}) {
10792: $changes{$item} = 1;
10793: }
10794: }
10795: foreach my $type (@mailings) {
10796: foreach my $item (@contacts) {
10797: if (ref($currsetting{$type}) eq 'HASH') {
10798: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
10799: push(@{$changes{$type}},$item);
10800: }
10801: } else {
10802: push(@{$changes{$type}},@{$newsetting{$type}});
10803: }
10804: }
10805: if ($others{$type} ne $currsetting{$type}{'others'}) {
10806: push(@{$changes{$type}},'others');
10807: }
1.160.6.78 raeburn 10808: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10809: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
10810: push(@{$changes{$type}},'bcc');
10811: }
1.160.6.78 raeburn 10812: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
10813: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
10814: push(@{$changes{$type}},'include');
10815: }
10816: }
10817: }
10818: if (ref($fields) eq 'ARRAY') {
10819: if (ref($currsetting{'helpform'}) eq 'HASH') {
10820: foreach my $field (@{$fields}) {
10821: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
10822: push(@{$changes{'helpform'}},$field);
10823: }
10824: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10825: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
10826: push(@{$changes{'helpform'}},'maxsize');
10827: }
10828: }
10829: }
10830: } else {
10831: foreach my $field (@{$fields}) {
10832: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10833: push(@{$changes{'helpform'}},$field);
10834: }
10835: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10836: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10837: push(@{$changes{'helpform'}},'maxsize');
10838: }
10839: }
10840: }
1.134 raeburn 10841: }
1.28 raeburn 10842: }
1.160.6.84.2. (raeburn 10843:): if (@statuses) {
10844:): if (ref($currsetting{'overrides'}) eq 'HASH') {
10845:): foreach my $key (keys(%{$currsetting{'overrides'}})) {
10846:): if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
10847:): if (ref($newsetting{'override_'.$key}) eq 'HASH') {
10848:): foreach my $item (@contacts,'bcc','others','include') {
10849:): if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
10850:): push(@{$changes{'overrides'}},$key);
10851:): last;
10852:): }
10853:): }
10854:): } else {
10855:): push(@{$changes{'overrides'}},$key);
10856:): }
10857:): }
10858:): }
10859:): foreach my $key (@overrides) {
10860:): unless (exists($currsetting{'overrides'}{$key})) {
10861:): push(@{$changes{'overrides'}},$key);
10862:): }
10863:): }
10864:): } else {
10865:): foreach my $key (@overrides) {
10866:): push(@{$changes{'overrides'}},$key);
10867:): }
10868:): }
10869:): }
1.28 raeburn 10870: } else {
10871: my %default;
10872: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
10873: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
10874: $default{'errormail'} = 'adminemail';
10875: $default{'packagesmail'} = 'adminemail';
10876: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 10877: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 10878: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 10879: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 10880: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 10881: foreach my $item (@contacts) {
10882: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 10883: $changes{$item} = 1;
1.160.6.23 raeburn 10884: }
1.28 raeburn 10885: }
10886: foreach my $type (@mailings) {
10887: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
10888: push(@{$changes{$type}},@{$newsetting{$type}});
10889: }
10890: if ($others{$type} ne '') {
10891: push(@{$changes{$type}},'others');
1.134 raeburn 10892: }
1.160.6.78 raeburn 10893: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10894: if ($bcc{$type} ne '') {
10895: push(@{$changes{$type}},'bcc');
10896: }
1.160.6.78 raeburn 10897: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
10898: push(@{$changes{$type}},'include');
10899: }
10900: }
10901: }
10902: if (ref($fields) eq 'ARRAY') {
10903: foreach my $field (@{$fields}) {
10904: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10905: push(@{$changes{'helpform'}},$field);
10906: }
10907: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10908: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10909: push(@{$changes{'helpform'}},'maxsize');
10910: }
10911: }
1.134 raeburn 10912: }
1.28 raeburn 10913: }
10914: }
1.160.6.23 raeburn 10915: foreach my $item (@toggles) {
10916: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
10917: $changes{$item} = 1;
10918: } elsif ((!$env{'form.'.$item}) &&
10919: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
10920: $changes{$item} = 1;
10921: }
10922: }
1.28 raeburn 10923: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
10924: $dom);
10925: if ($putresult eq 'ok') {
10926: if (keys(%changes) > 0) {
1.160.6.24 raeburn 10927: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10928: if (ref($lastactref) eq 'HASH') {
10929: $lastactref->{'domainconfig'} = 1;
10930: }
1.28 raeburn 10931: my ($titles,$short_titles) = &contact_titles();
10932: $resulttext = &mt('Changes made:').'<ul>';
10933: foreach my $item (@contacts) {
10934: if ($changes{$item}) {
10935: $resulttext .= '<li>'.$titles->{$item}.
10936: &mt(' set to: ').
10937: '<span class="LC_cusr_emph">'.
10938: $to{$item}.'</span></li>';
10939: }
10940: }
10941: foreach my $type (@mailings) {
10942: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 10943: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
10944: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
10945: } else {
10946: $resulttext .= '<li>'.$titles->{$type}.': ';
10947: }
1.28 raeburn 10948: my @text;
10949: foreach my $item (@{$newsetting{$type}}) {
10950: push(@text,$short_titles->{$item});
10951: }
10952: if ($others{$type} ne '') {
10953: push(@text,$others{$type});
10954: }
1.160.6.78 raeburn 10955: if (@text) {
10956: $resulttext .= '<span class="LC_cusr_emph">'.
10957: join(', ',@text).'</span>';
10958: }
10959: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10960: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 10961: my $bcctext;
10962: if (@text) {
10963: $bcctext = ' '.&mt('with Bcc to');
10964: } else {
10965: $bcctext = '(Bcc)';
10966: }
10967: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10968: } elsif (!@text) {
10969: $resulttext .= &mt('No one');
1.134 raeburn 10970: }
1.160.6.78 raeburn 10971: if ($includestr{$type} ne '') {
10972: if ($includeloc{$type} eq 'b') {
10973: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
10974: } elsif ($includeloc{$type} eq 's') {
10975: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
10976: }
10977: }
10978: } elsif (!@text) {
10979: $resulttext .= &mt('No recipients');
1.134 raeburn 10980: }
10981: $resulttext .= '</li>';
1.28 raeburn 10982: }
10983: }
1.160.6.84.2. (raeburn 10984:): if (ref($changes{'overrides'}) eq 'ARRAY') {
10985:): my @deletions;
10986:): foreach my $type (@{$changes{'overrides'}}) {
10987:): if ($usertypeshash{$type}) {
10988:): if (grep(/^\Q$type\E/,@overrides)) {
10989:): $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
10990:): $usertypeshash{$type}).'<ul><li>';
10991:): if (ref($newsetting{'override_'.$type}) eq 'HASH') {
10992:): my @text;
10993:): foreach my $item (@contacts) {
10994:): if ($newsetting{'override_'.$type}{$item}) {
10995:): push(@text,$short_titles->{$item});
10996:): }
10997:): }
10998:): if ($newsetting{'override_'.$type}{'others'} ne '') {
10999:): push(@text,$newsetting{'override_'.$type}{'others'});
11000:): }
11001:):
11002:): if (@text) {
11003:): $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
11004:): '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
11005:): }
11006:): if ($newsetting{'override_'.$type}{'bcc'} ne '') {
11007:): my $bcctext;
11008:): if (@text) {
11009:): $bcctext = ' '.&mt('with Bcc to');
11010:): } else {
11011:): $bcctext = '(Bcc)';
11012:): }
11013:): $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
11014:): } elsif (!@text) {
11015:): $resulttext .= &mt('Helpdesk e-mail sent to no one');
11016:): }
11017:): $resulttext .= '</li>';
11018:): if ($newsetting{'override_'.$type}{'include'} ne '') {
11019:): my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
11020:): if ($loc eq 'b') {
11021:): $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
11022:): } elsif ($loc eq 's') {
11023:): $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
11024:): }
11025:): }
11026:): }
11027:): $resulttext .= '</li></ul></li>';
11028:): } else {
11029:): push(@deletions,$usertypeshash{$type});
11030:): }
11031:): }
11032:): }
11033:): if (@deletions) {
11034:): $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
11035:): join(', ',@deletions)).'</li>';
11036:): }
11037:): }
1.160.6.23 raeburn 11038: my @offon = ('off','on');
11039: if ($changes{'reporterrors'}) {
11040: $resulttext .= '<li>'.
11041: &mt('E-mail error reports to [_1] set to "'.
11042: $offon[$env{'form.reporterrors'}].'".',
11043: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
11044: &mt('LON-CAPA core group - MSU'),600,500)).
11045: '</li>';
11046: }
11047: if ($changes{'reportupdates'}) {
11048: $resulttext .= '<li>'.
11049: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
11050: $offon[$env{'form.reportupdates'}].'".',
11051: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
11052: &mt('LON-CAPA core group - MSU'),600,500)).
11053: '</li>';
11054: }
1.160.6.78 raeburn 11055: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
11056: my (@optional,@required,@unused,$maxsizechg);
11057: foreach my $field (@{$changes{'helpform'}}) {
11058: if ($field eq 'maxsize') {
11059: $maxsizechg = 1;
11060: next;
11061: }
11062: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
11063: push(@optional,$field);
11064: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
11065: push(@unused,$field);
11066: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
11067: push(@required,$field);
11068: }
11069: }
11070: if (@optional) {
11071: $resulttext .= '<li>'.
11072: &mt('Help form fields changed to "Optional": [_1].',
11073: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
11074: '</li>';
11075: }
11076: if (@required) {
11077: $resulttext .= '<li>'.
11078: &mt('Help form fields changed to "Required": [_1].',
11079: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
11080: '</li>';
11081: }
11082: if (@unused) {
11083: $resulttext .= '<li>'.
11084: &mt('Help form fields changed to "Not shown": [_1].',
11085: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
11086: '</li>';
11087: }
11088: if ($maxsizechg) {
11089: $resulttext .= '<li>'.
11090: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
11091: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
11092: '</li>';
11093: }
11094: }
1.28 raeburn 11095: $resulttext .= '</ul>';
11096: } else {
1.160.6.78 raeburn 11097: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 11098: }
11099: } else {
11100: $resulttext = '<span class="LC_error">'.
11101: &mt('An error occurred: [_1].',$putresult).'</span>';
11102: }
11103: return $resulttext;
11104: }
11105:
11106: sub modify_usercreation {
1.27 raeburn 11107: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 11108: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 11109: my $warningmsg;
1.27 raeburn 11110: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11111: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 11112: if ($key eq 'cancreate') {
11113: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11114: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11115: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.69 raeburn 11116: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
11117: ($item eq 'recaptchaversion')) {
1.160.6.34 raeburn 11118: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11119: } else {
11120: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11121: }
1.50 raeburn 11122: }
1.43 raeburn 11123: }
1.160.6.34 raeburn 11124: } elsif ($key eq 'email_rule') {
11125: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11126: } else {
11127: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 11128: }
11129: }
1.34 raeburn 11130: }
1.160.6.34 raeburn 11131: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
11132: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
11133: my @contexts = ('author','course','requestcrs');
11134: foreach my $item(@contexts) {
11135: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 11136: }
1.34 raeburn 11137: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11138: foreach my $item (@contexts) {
1.160.6.34 raeburn 11139: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
11140: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 11141: }
1.27 raeburn 11142: }
1.34 raeburn 11143: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
11144: foreach my $item (@contexts) {
1.43 raeburn 11145: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 11146: if ($cancreate{$item} ne 'any') {
11147: push(@{$changes{'cancreate'}},$item);
11148: }
11149: } else {
11150: if ($cancreate{$item} ne 'none') {
11151: push(@{$changes{'cancreate'}},$item);
11152: }
1.27 raeburn 11153: }
11154: }
11155: } else {
1.43 raeburn 11156: foreach my $item (@contexts) {
1.34 raeburn 11157: push(@{$changes{'cancreate'}},$item);
11158: }
1.27 raeburn 11159: }
1.34 raeburn 11160:
1.27 raeburn 11161: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
11162: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
11163: if (!grep(/^\Q$type\E$/,@username_rule)) {
11164: push(@{$changes{'username_rule'}},$type);
11165: }
11166: }
11167: foreach my $type (@username_rule) {
11168: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
11169: push(@{$changes{'username_rule'}},$type);
11170: }
11171: }
11172: } else {
11173: push(@{$changes{'username_rule'}},@username_rule);
11174: }
11175:
1.32 raeburn 11176: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
11177: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
11178: if (!grep(/^\Q$type\E$/,@id_rule)) {
11179: push(@{$changes{'id_rule'}},$type);
11180: }
11181: }
11182: foreach my $type (@id_rule) {
11183: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
11184: push(@{$changes{'id_rule'}},$type);
11185: }
11186: }
11187: } else {
11188: push(@{$changes{'id_rule'}},@id_rule);
11189: }
11190:
1.43 raeburn 11191: my @authen_contexts = ('author','course','domain');
1.28 raeburn 11192: my @authtypes = ('int','krb4','krb5','loc');
11193: my %authhash;
1.43 raeburn 11194: foreach my $item (@authen_contexts) {
1.28 raeburn 11195: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
11196: foreach my $auth (@authtypes) {
11197: if (grep(/^\Q$auth\E$/,@authallowed)) {
11198: $authhash{$item}{$auth} = 1;
11199: } else {
11200: $authhash{$item}{$auth} = 0;
11201: }
11202: }
11203: }
11204: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 11205: foreach my $item (@authen_contexts) {
1.28 raeburn 11206: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
11207: foreach my $auth (@authtypes) {
11208: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
11209: push(@{$changes{'authtypes'}},$item);
11210: last;
11211: }
11212: }
11213: }
11214: }
11215: } else {
1.43 raeburn 11216: foreach my $item (@authen_contexts) {
1.28 raeburn 11217: push(@{$changes{'authtypes'}},$item);
11218: }
11219: }
11220:
1.160.6.34 raeburn 11221: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
11222: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
11223: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
11224: $save_usercreate{'id_rule'} = \@id_rule;
11225: $save_usercreate{'username_rule'} = \@username_rule,
11226: $save_usercreate{'authtypes'} = \%authhash;
11227:
1.27 raeburn 11228: my %usercreation_hash = (
1.160.6.34 raeburn 11229: usercreation => \%save_usercreate,
11230: );
1.27 raeburn 11231:
11232: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
11233: $dom);
1.50 raeburn 11234:
1.160.6.34 raeburn 11235: if ($putresult eq 'ok') {
11236: if (keys(%changes) > 0) {
11237: $resulttext = &mt('Changes made:').'<ul>';
11238: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11239: my %lt = &usercreation_types();
11240: foreach my $type (@{$changes{'cancreate'}}) {
11241: my $chgtext = $lt{$type}.', ';
11242: if ($cancreate{$type} eq 'none') {
11243: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
11244: } elsif ($cancreate{$type} eq 'any') {
11245: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
11246: } elsif ($cancreate{$type} eq 'official') {
11247: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
11248: } elsif ($cancreate{$type} eq 'unofficial') {
11249: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
11250: }
11251: $resulttext .= '<li>'.$chgtext.'</li>';
11252: }
11253: }
11254: if (ref($changes{'username_rule'}) eq 'ARRAY') {
11255: my ($rules,$ruleorder) =
11256: &Apache::lonnet::inst_userrules($dom,'username');
11257: my $chgtext = '<ul>';
11258: foreach my $type (@username_rule) {
11259: if (ref($rules->{$type}) eq 'HASH') {
11260: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
11261: }
11262: }
11263: $chgtext .= '</ul>';
11264: if (@username_rule > 0) {
11265: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11266: } else {
11267: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
11268: }
11269: }
11270: if (ref($changes{'id_rule'}) eq 'ARRAY') {
11271: my ($idrules,$idruleorder) =
11272: &Apache::lonnet::inst_userrules($dom,'id');
11273: my $chgtext = '<ul>';
11274: foreach my $type (@id_rule) {
11275: if (ref($idrules->{$type}) eq 'HASH') {
11276: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
11277: }
11278: }
11279: $chgtext .= '</ul>';
11280: if (@id_rule > 0) {
11281: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11282: } else {
11283: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
11284: }
11285: }
11286: my %authname = &authtype_names();
11287: my %context_title = &context_names();
11288: if (ref($changes{'authtypes'}) eq 'ARRAY') {
11289: my $chgtext = '<ul>';
11290: foreach my $type (@{$changes{'authtypes'}}) {
11291: my @allowed;
11292: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
11293: foreach my $auth (@authtypes) {
11294: if ($authhash{$type}{$auth}) {
11295: push(@allowed,$authname{$auth});
11296: }
11297: }
11298: if (@allowed > 0) {
11299: $chgtext .= join(', ',@allowed).'</li>';
11300: } else {
11301: $chgtext .= &mt('none').'</li>';
11302: }
11303: }
11304: $chgtext .= '</ul>';
11305: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
11306: $resulttext .= '</li>';
11307: }
11308: $resulttext .= '</ul>';
11309: } else {
11310: $resulttext = &mt('No changes made to user creation settings');
11311: }
11312: } else {
11313: $resulttext = '<span class="LC_error">'.
11314: &mt('An error occurred: [_1]',$putresult).'</span>';
11315: }
11316: if ($warningmsg ne '') {
11317: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11318: }
11319: return $resulttext;
11320: }
11321:
11322: sub modify_selfcreation {
11323: my ($dom,%domconfig) = @_;
11324: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
11325: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 11326: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11327: if (ref($types) eq 'ARRAY') {
11328: $usertypes->{'default'} = $othertitle;
11329: push(@{$types},'default');
11330: }
1.160.6.34 raeburn 11331: #
11332: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
11333: #
11334: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11335: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11336: if ($key eq 'cancreate') {
11337: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11338: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11339: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
11340: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.69 raeburn 11341: ($item eq 'recaptchaversion') ||
1.160.6.40 raeburn 11342: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 11343: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 11344: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11345: } else {
11346: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11347: }
11348: }
11349: }
11350: } elsif ($key eq 'email_rule') {
11351: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11352: } else {
11353: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11354: }
11355: }
11356: }
11357: #
11358: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
11359: #
11360: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11361: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11362: if ($key eq 'selfcreate') {
11363: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
11364: } else {
11365: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
11366: }
11367: }
11368: }
11369:
11370: my @contexts = ('selfcreate');
11371: @{$cancreate{'selfcreate'}} = ();
11372: %{$cancreate{'emailusername'}} = ();
11373: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 11374: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 11375: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 11376: my %selfcreatetypes = (
11377: sso => 'users authenticated by institutional single sign on',
11378: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 11379: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 11380: );
1.160.6.34 raeburn 11381: #
11382: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
11383: # is permitted.
11384: #
1.160.6.40 raeburn 11385:
11386: my @statuses;
11387: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11388: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
11389: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
11390: }
11391: }
11392: push(@statuses,'default');
11393:
1.160.6.35 raeburn 11394: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 11395: if ($item eq 'email') {
1.160.6.40 raeburn 11396: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 11397: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 11398: push(@contexts,'selfcreateprocessing');
11399: foreach my $type (@statuses) {
11400: if ($type eq 'default') {
11401: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
11402: } else {
11403: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
11404: }
11405: }
1.160.6.34 raeburn 11406: }
11407: } else {
11408: if ($env{'form.cancreate_'.$item}) {
11409: push(@{$cancreate{'selfcreate'}},$item);
11410: }
11411: }
11412: }
11413: my (@email_rule,%userinfo,%savecaptcha);
11414: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
11415: #
1.160.6.35 raeburn 11416: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
11417: # 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 11418: #
1.160.6.40 raeburn 11419:
1.160.6.48 raeburn 11420: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 11421: push(@contexts,'emailusername');
1.160.6.35 raeburn 11422: if (ref($types) eq 'ARRAY') {
11423: foreach my $type (@{$types}) {
11424: if (ref($infofields) eq 'ARRAY') {
11425: foreach my $field (@{$infofields}) {
11426: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
11427: $cancreate{'emailusername'}{$type}{$field} = $1;
11428: }
11429: }
1.160.6.34 raeburn 11430: }
11431: }
11432: }
11433: #
11434: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
11435: # queued requests for self-creation of account using e-mail address as username
11436: #
11437:
11438: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
11439: @approvalnotify = sort(@approvalnotify);
11440: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
11441: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11442: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11443: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11444: push(@{$changes{'cancreate'}},'notify');
11445: }
11446: } else {
11447: if ($cancreate{'notify'}{'approval'}) {
11448: push(@{$changes{'cancreate'}},'notify');
11449: }
11450: }
11451: } elsif ($cancreate{'notify'}{'approval'}) {
11452: push(@{$changes{'cancreate'}},'notify');
11453: }
11454:
11455: #
11456: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
11457: #
11458: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
11459: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11460: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11461: if (@{$curr_usercreation{'email_rule'}} > 0) {
11462: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
11463: if (!grep(/^\Q$type\E$/,@email_rule)) {
11464: push(@{$changes{'email_rule'}},$type);
11465: }
11466: }
11467: }
11468: if (@email_rule > 0) {
11469: foreach my $type (@email_rule) {
11470: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
11471: push(@{$changes{'email_rule'}},$type);
11472: }
11473: }
11474: }
11475: } elsif (@email_rule > 0) {
11476: push(@{$changes{'email_rule'}},@email_rule);
11477: }
11478: }
11479: #
1.160.6.40 raeburn 11480: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 11481: # institutional log-in.
11482: #
11483: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11484: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11485: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11486: ($domdefaults{'auth_def'} eq 'localauth'))) {
11487: $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.').' '.
11488: &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.');
11489: }
11490: }
11491: my @fields = ('lastname','firstname','middlename','generation',
11492: 'permanentemail','id');
1.160.6.44 raeburn 11493: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 11494: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11495: #
11496: # Where usernames may created for institutional log-in and/or institutional single sign on:
11497: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11498: # may self-create accounts
11499: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11500: # which the user may supply, if institutional data is unavailable.
11501: #
11502: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
11503: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 11504: if (@{$types} > 1) {
1.160.6.34 raeburn 11505: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11506: push(@contexts,'statustocreate');
11507: } else {
11508: undef($cancreate{'statustocreate'});
11509: }
11510: foreach my $type (@{$types}) {
11511: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11512: foreach my $field (@fields) {
11513: if (grep(/^\Q$field\E$/,@modifiable)) {
11514: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11515: } else {
11516: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11517: }
11518: }
11519: }
11520: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
11521: foreach my $type (@{$types}) {
11522: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11523: foreach my $field (@fields) {
11524: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11525: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11526: push(@{$changes{'selfcreate'}},$type);
11527: last;
11528: }
11529: }
11530: }
11531: }
11532: } else {
11533: foreach my $type (@{$types}) {
11534: push(@{$changes{'selfcreate'}},$type);
11535: }
11536: }
11537: }
1.160.6.44 raeburn 11538: foreach my $field (@shibfields) {
11539: if ($env{'form.shibenv_'.$field} ne '') {
11540: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11541: }
11542: }
11543: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11544: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11545: foreach my $field (@shibfields) {
11546: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11547: push(@{$changes{'cancreate'}},'shibenv');
11548: }
11549: }
11550: } else {
11551: foreach my $field (@shibfields) {
11552: if ($env{'form.shibenv_'.$field}) {
11553: push(@{$changes{'cancreate'}},'shibenv');
11554: last;
11555: }
11556: }
11557: }
11558: }
1.160.6.34 raeburn 11559: }
11560: foreach my $item (@contexts) {
11561: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11562: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11563: if (ref($cancreate{$item}) eq 'ARRAY') {
11564: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11565: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11566: push(@{$changes{'cancreate'}},$item);
11567: }
11568: }
11569: }
11570: }
11571: if (ref($cancreate{$item}) eq 'ARRAY') {
11572: foreach my $type (@{$cancreate{$item}}) {
11573: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11574: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11575: push(@{$changes{'cancreate'}},$item);
11576: }
11577: }
11578: }
11579: }
11580: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11581: if (ref($cancreate{$item}) eq 'HASH') {
11582: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 11583: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
11584: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
11585: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
11586: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11587: push(@{$changes{'cancreate'}},$item);
11588: }
11589: }
11590: }
1.160.6.40 raeburn 11591: } elsif ($item eq 'selfcreateprocessing') {
11592: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
11593: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11594: push(@{$changes{'cancreate'}},$item);
11595: }
11596: }
1.160.6.35 raeburn 11597: } else {
11598: if (!$cancreate{$item}{$curr}) {
11599: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11600: push(@{$changes{'cancreate'}},$item);
11601: }
1.160.6.34 raeburn 11602: }
11603: }
11604: }
11605: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 11606: if (ref($cancreate{$item}{$field}) eq 'HASH') {
11607: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
11608: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
11609: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
11610: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11611: push(@{$changes{'cancreate'}},$item);
11612: }
11613: }
11614: } else {
11615: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11616: push(@{$changes{'cancreate'}},$item);
11617: }
11618: }
11619: }
1.160.6.40 raeburn 11620: } elsif ($item eq 'selfcreateprocessing') {
11621: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
11622: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11623: push(@{$changes{'cancreate'}},$item);
11624: }
11625: }
1.160.6.35 raeburn 11626: } else {
11627: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
11628: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11629: push(@{$changes{'cancreate'}},$item);
11630: }
1.160.6.34 raeburn 11631: }
11632: }
11633: }
11634: }
11635: } elsif ($curr_usercreation{'cancreate'}{$item}) {
11636: if (ref($cancreate{$item}) eq 'ARRAY') {
11637: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
11638: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11639: push(@{$changes{'cancreate'}},$item);
11640: }
11641: }
11642: } elsif (ref($cancreate{$item}) eq 'HASH') {
11643: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
11644: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11645: push(@{$changes{'cancreate'}},$item);
11646: }
11647: }
11648: }
11649: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 11650: if (ref($cancreate{$item}) eq 'HASH') {
11651: foreach my $type (keys(%{$cancreate{$item}})) {
11652: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11653: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11654: if ($cancreate{$item}{$type}{$field}) {
11655: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11656: push(@{$changes{'cancreate'}},$item);
11657: }
11658: last;
11659: }
11660: }
11661: }
11662: }
1.160.6.34 raeburn 11663: }
11664: }
11665: }
11666: #
11667: # Populate %save_usercreate hash with updates to self-creation configuration.
11668: #
11669: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
11670: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 11671: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 11672: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
11673: if (ref($cancreate{'notify'}) eq 'HASH') {
11674: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
11675: }
1.160.6.40 raeburn 11676: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
11677: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
11678: }
1.160.6.34 raeburn 11679: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11680: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
11681: }
1.160.6.44 raeburn 11682: if (ref($cancreate{'shibenv'}) eq 'HASH') {
11683: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
11684: }
1.160.6.34 raeburn 11685: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.84.2. (raeburn 11686:): $save_usercreate{'email_rule'} = \@email_rule;
1.160.6.34 raeburn 11687:
11688: my %userconfig_hash = (
11689: usercreation => \%save_usercreate,
11690: usermodification => \%save_usermodify,
11691: );
11692: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
11693: $dom);
11694: #
11695: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
11696: #
1.27 raeburn 11697: if ($putresult eq 'ok') {
11698: if (keys(%changes) > 0) {
11699: $resulttext = &mt('Changes made:').'<ul>';
11700: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 11701: my %lt = &selfcreation_types();
1.34 raeburn 11702: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 11703: my $chgtext;
1.45 raeburn 11704: if ($type eq 'selfcreate') {
1.50 raeburn 11705: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 11706: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 11707: } else {
1.160.6.34 raeburn 11708: $chgtext .= &mt('Self-creation of a new account is permitted for:').
11709: '<ul>';
1.50 raeburn 11710: foreach my $case (@{$cancreate{$type}}) {
11711: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
11712: }
11713: $chgtext .= '</ul>';
1.100 raeburn 11714: if (ref($cancreate{$type}) eq 'ARRAY') {
11715: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
11716: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11717: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 11718: $chgtext .= '<br />'.
11719: '<span class="LC_warning">'.
11720: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11721: '</span>';
1.100 raeburn 11722: }
11723: }
11724: }
11725: }
1.43 raeburn 11726: }
1.160.6.44 raeburn 11727: } elsif ($type eq 'shibenv') {
11728: if (keys(%{$cancreate{$type}}) == 0) {
11729: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
11730: } else {
11731: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
11732: '<ul>';
11733: foreach my $field (@shibfields) {
11734: next if ($cancreate{$type}{$field} eq '');
11735: if ($field eq 'inststatus') {
11736: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
11737: } else {
11738: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
11739: }
11740: }
11741: $chgtext .= '</ul>';
11742: }
1.93 raeburn 11743: } elsif ($type eq 'statustocreate') {
1.96 raeburn 11744: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
11745: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
11746: if (@{$cancreate{'selfcreate'}} > 0) {
11747: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 11748: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 11749: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 11750: $chgtext .= '<br />'.
11751: '<span class="LC_warning">'.
11752: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11753: '</span>';
11754: }
1.96 raeburn 11755: } elsif (ref($usertypes) eq 'HASH') {
11756: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 11757: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
11758: } else {
11759: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
11760: }
11761: $chgtext .= '<ul>';
11762: foreach my $case (@{$cancreate{$type}}) {
11763: if ($case eq 'default') {
11764: $chgtext .= '<li>'.$othertitle.'</li>';
11765: } else {
11766: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 11767: }
11768: }
1.100 raeburn 11769: $chgtext .= '</ul>';
11770: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 11771: $chgtext .= '<br /><span class="LC_warning">'.
11772: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
11773: '</span>';
1.100 raeburn 11774: }
11775: }
11776: } else {
11777: if (@{$cancreate{$type}} == 0) {
11778: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
11779: } else {
11780: $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 11781: }
11782: }
11783: }
1.160.6.40 raeburn 11784: } elsif ($type eq 'selfcreateprocessing') {
11785: my %choices = &Apache::lonlocal::texthash (
11786: automatic => 'Automatic approval',
11787: approval => 'Queued for approval',
11788: );
11789: if (@statuses > 1) {
11790: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
11791: '<ul>';
11792: foreach my $type (@statuses) {
11793: if ($type eq 'default') {
11794: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11795: } else {
11796: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11797: }
11798: }
11799: $chgtext .= '</ul>';
11800: } else {
11801: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
11802: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
11803: }
1.160.6.5 raeburn 11804: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 11805: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 11806: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
11807: } else {
11808: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 11809: if ($captchas{$savecaptcha{$type}}) {
11810: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 11811: } else {
11812: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
11813: }
11814: }
11815: } elsif ($type eq 'recaptchakeys') {
11816: my ($privkey,$pubkey);
1.160.6.34 raeburn 11817: if (ref($savecaptcha{$type}) eq 'HASH') {
11818: $pubkey = $savecaptcha{$type}{'public'};
11819: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 11820: }
11821: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
11822: if (!$pubkey) {
11823: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
11824: } else {
11825: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11826: }
11827: if (!$privkey) {
11828: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
11829: } else {
11830: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
11831: }
11832: $chgtext .= '</ul>';
1.160.6.69 raeburn 11833: } elsif ($type eq 'recaptchaversion') {
11834: if ($savecaptcha{'captcha'} eq 'recaptcha') {
11835: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
11836: }
1.160.6.34 raeburn 11837: } elsif ($type eq 'emailusername') {
11838: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 11839: if (ref($types) eq 'ARRAY') {
11840: foreach my $type (@{$types}) {
11841: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
11842: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50 raeburn 11843: $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 11844: '<ul>';
11845: foreach my $field (@{$infofields}) {
11846: if ($cancreate{'emailusername'}{$type}{$field}) {
11847: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
11848: }
11849: }
1.160.6.50 raeburn 11850: $chgtext .= '</ul>';
11851: } else {
11852: $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 11853: }
11854: } else {
1.160.6.50 raeburn 11855: $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 11856: }
11857: }
11858: }
11859: }
11860: } elsif ($type eq 'notify') {
11861: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
11862: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11863: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
11864: if ($cancreate{'notify'}{'approval'}) {
11865: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
11866: }
11867: }
1.43 raeburn 11868: }
1.34 raeburn 11869: }
1.160.6.34 raeburn 11870: if ($chgtext) {
11871: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 11872: }
11873: }
11874: }
1.43 raeburn 11875: if (ref($changes{'email_rule'}) eq 'ARRAY') {
11876: my ($emailrules,$emailruleorder) =
11877: &Apache::lonnet::inst_userrules($dom,'email');
11878: my $chgtext = '<ul>';
11879: foreach my $type (@email_rule) {
11880: if (ref($emailrules->{$type}) eq 'HASH') {
11881: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
11882: }
11883: }
11884: $chgtext .= '</ul>';
11885: if (@email_rule > 0) {
1.160.6.34 raeburn 11886: $resulttext .= '<li>'.
11887: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
11888: $chgtext.
11889: '</li>';
1.43 raeburn 11890: } else {
1.160.6.34 raeburn 11891: $resulttext .= '<li>'.
11892: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
11893: '</li>';
1.43 raeburn 11894: }
11895: }
1.160.6.34 raeburn 11896: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
11897: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
11898: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11899: foreach my $type (@{$changes{'selfcreate'}}) {
11900: my $typename = $type;
11901: if (ref($usertypes) eq 'HASH') {
11902: if ($usertypes->{$type} ne '') {
11903: $typename = $usertypes->{$type};
1.28 raeburn 11904: }
11905: }
1.160.6.34 raeburn 11906: my @modifiable;
11907: $resulttext .= '<li>'.
11908: &mt('Self-creation of account by users with status: [_1]',
11909: '<span class="LC_cusr_emph">'.$typename.'</span>').
11910: ' - '.&mt('modifiable fields (if institutional data blank): ');
11911: foreach my $field (@fields) {
11912: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
11913: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
11914: }
11915: }
11916: if (@modifiable > 0) {
11917: $resulttext .= join(', ',@modifiable);
1.43 raeburn 11918: } else {
1.160.6.34 raeburn 11919: $resulttext .= &mt('none');
1.43 raeburn 11920: }
1.160.6.34 raeburn 11921: $resulttext .= '</li>';
1.28 raeburn 11922: }
1.160.6.34 raeburn 11923: $resulttext .= '</ul></li>';
1.28 raeburn 11924: }
1.27 raeburn 11925: $resulttext .= '</ul>';
11926: } else {
1.160.6.34 raeburn 11927: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 11928: }
11929: } else {
11930: $resulttext = '<span class="LC_error">'.
1.23 raeburn 11931: &mt('An error occurred: [_1]',$putresult).'</span>';
11932: }
1.43 raeburn 11933: if ($warningmsg ne '') {
11934: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11935: }
1.23 raeburn 11936: return $resulttext;
11937: }
11938:
1.160.6.5 raeburn 11939: sub process_captcha {
11940: my ($container,$changes,$newsettings,$current) = @_;
11941: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
11942: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
11943: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
11944: $newsettings->{'captcha'} = 'original';
11945: }
11946: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
11947: if ($container eq 'cancreate') {
11948: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11949: push(@{$changes->{'cancreate'}},'captcha');
11950: } elsif (!defined($changes->{'cancreate'})) {
11951: $changes->{'cancreate'} = ['captcha'];
11952: }
11953: } else {
11954: $changes->{'captcha'} = 1;
11955: }
11956: }
1.160.6.69 raeburn 11957: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 11958: if ($newsettings->{'captcha'} eq 'recaptcha') {
11959: $newpub = $env{'form.'.$container.'_recaptchapub'};
11960: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 11961: $newpub =~ s/[^\w\-]//g;
11962: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 11963: $newsettings->{'recaptchakeys'} = {
11964: public => $newpub,
11965: private => $newpriv,
11966: };
1.160.6.69 raeburn 11967: $newversion = $env{'form.'.$container.'_recaptchaversion'};
11968: $newversion =~ s/\D//g;
11969: if ($newversion ne '2') {
11970: $newversion = 1;
11971: }
11972: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 11973: }
11974: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
11975: $currpub = $current->{'recaptchakeys'}{'public'};
11976: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 11977: unless ($newsettings->{'captcha'} eq 'recaptcha') {
11978: $newsettings->{'recaptchakeys'} = {
11979: public => '',
11980: private => '',
11981: }
11982: }
1.160.6.5 raeburn 11983: }
1.160.6.69 raeburn 11984: if ($current->{'captcha'} eq 'recaptcha') {
11985: $currversion = $current->{'recaptchaversion'};
11986: if ($currversion ne '2') {
11987: $currversion = 1;
11988: }
11989: }
11990: if ($currversion ne $newversion) {
11991: if ($container eq 'cancreate') {
11992: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11993: push(@{$changes->{'cancreate'}},'recaptchaversion');
11994: } elsif (!defined($changes->{'cancreate'})) {
11995: $changes->{'cancreate'} = ['recaptchaversion'];
11996: }
11997: } else {
11998: $changes->{'recaptchaversion'} = 1;
11999: }
12000: }
1.160.6.5 raeburn 12001: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
12002: if ($container eq 'cancreate') {
12003: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12004: push(@{$changes->{'cancreate'}},'recaptchakeys');
12005: } elsif (!defined($changes->{'cancreate'})) {
12006: $changes->{'cancreate'} = ['recaptchakeys'];
12007: }
12008: } else {
12009: $changes->{'recaptchakeys'} = 1;
12010: }
12011: }
12012: return;
12013: }
12014:
1.33 raeburn 12015: sub modify_usermodification {
12016: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 12017: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 12018: if (ref($domconfig{'usermodification'}) eq 'HASH') {
12019: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 12020: if ($key eq 'selfcreate') {
12021: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
12022: } else {
12023: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
12024: }
1.33 raeburn 12025: }
12026: }
1.160.6.34 raeburn 12027: my @contexts = ('author','course');
1.33 raeburn 12028: my %context_title = (
12029: author => 'In author context',
12030: course => 'In course context',
12031: );
12032: my @fields = ('lastname','firstname','middlename','generation',
12033: 'permanentemail','id');
12034: my %roles = (
12035: author => ['ca','aa'],
12036: course => ['st','ep','ta','in','cr'],
12037: );
12038: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12039: foreach my $context (@contexts) {
12040: foreach my $role (@{$roles{$context}}) {
12041: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
12042: foreach my $item (@fields) {
12043: if (grep(/^\Q$item\E$/,@modifiable)) {
12044: $modifyhash{$context}{$role}{$item} = 1;
12045: } else {
12046: $modifyhash{$context}{$role}{$item} = 0;
12047: }
12048: }
12049: }
12050: if (ref($curr_usermodification{$context}) eq 'HASH') {
12051: foreach my $role (@{$roles{$context}}) {
12052: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
12053: foreach my $field (@fields) {
12054: if ($modifyhash{$context}{$role}{$field} ne
12055: $curr_usermodification{$context}{$role}{$field}) {
12056: push(@{$changes{$context}},$role);
12057: last;
12058: }
12059: }
12060: }
12061: }
12062: } else {
12063: foreach my $context (@contexts) {
12064: foreach my $role (@{$roles{$context}}) {
12065: push(@{$changes{$context}},$role);
12066: }
12067: }
12068: }
12069: }
12070: my %usermodification_hash = (
12071: usermodification => \%modifyhash,
12072: );
12073: my $putresult = &Apache::lonnet::put_dom('configuration',
12074: \%usermodification_hash,$dom);
12075: if ($putresult eq 'ok') {
12076: if (keys(%changes) > 0) {
12077: $resulttext = &mt('Changes made: ').'<ul>';
12078: foreach my $context (@contexts) {
12079: if (ref($changes{$context}) eq 'ARRAY') {
12080: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
12081: if (ref($changes{$context}) eq 'ARRAY') {
12082: foreach my $role (@{$changes{$context}}) {
12083: my $rolename;
1.160.6.34 raeburn 12084: if ($role eq 'cr') {
12085: $rolename = &mt('Custom');
1.33 raeburn 12086: } else {
1.160.6.34 raeburn 12087: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 12088: }
12089: my @modifiable;
1.160.6.34 raeburn 12090: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 12091: foreach my $field (@fields) {
12092: if ($modifyhash{$context}{$role}{$field}) {
12093: push(@modifiable,$fieldtitles{$field});
12094: }
12095: }
12096: if (@modifiable > 0) {
12097: $resulttext .= join(', ',@modifiable);
12098: } else {
12099: $resulttext .= &mt('none');
12100: }
12101: $resulttext .= '</li>';
12102: }
12103: $resulttext .= '</ul></li>';
12104: }
12105: }
12106: }
12107: $resulttext .= '</ul>';
12108: } else {
12109: $resulttext = &mt('No changes made to user modification settings');
12110: }
12111: } else {
12112: $resulttext = '<span class="LC_error">'.
12113: &mt('An error occurred: [_1]',$putresult).'</span>';
12114: }
12115: return $resulttext;
12116: }
12117:
1.43 raeburn 12118: sub modify_defaults {
1.160.6.27 raeburn 12119: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 12120: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 12121: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 12122: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
12123: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 12124: my @authtypes = ('internal','krb4','krb5','localauth');
12125: foreach my $item (@items) {
12126: $newvalues{$item} = $env{'form.'.$item};
12127: if ($item eq 'auth_def') {
12128: if ($newvalues{$item} ne '') {
12129: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
12130: push(@errors,$item);
12131: }
12132: }
12133: } elsif ($item eq 'lang_def') {
12134: if ($newvalues{$item} ne '') {
12135: if ($newvalues{$item} =~ /^(\w+)/) {
12136: my $langcode = $1;
1.103 raeburn 12137: if ($langcode ne 'x_chef') {
12138: if (code2language($langcode) eq '') {
12139: push(@errors,$item);
12140: }
1.43 raeburn 12141: }
12142: } else {
12143: push(@errors,$item);
12144: }
12145: }
1.54 raeburn 12146: } elsif ($item eq 'timezone_def') {
12147: if ($newvalues{$item} ne '') {
1.62 raeburn 12148: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 12149: push(@errors,$item);
12150: }
12151: }
1.68 raeburn 12152: } elsif ($item eq 'datelocale_def') {
12153: if ($newvalues{$item} ne '') {
12154: my @datelocale_ids = DateTime::Locale->ids();
12155: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
12156: push(@errors,$item);
12157: }
12158: }
1.141 raeburn 12159: } elsif ($item eq 'portal_def') {
12160: if ($newvalues{$item} ne '') {
12161: 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])\/?$/) {
12162: push(@errors,$item);
12163: }
12164: }
1.160.6.80 raeburn 12165: } elsif ($item eq 'intauth_cost') {
12166: if ($newvalues{$item} ne '') {
12167: if ($newvalues{$item} =~ /\D/) {
12168: push(@errors,$item);
12169: }
12170: }
12171: } elsif ($item eq 'intauth_check') {
12172: if ($newvalues{$item} ne '') {
12173: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
12174: push(@errors,$item);
12175: }
12176: }
12177: } elsif ($item eq 'intauth_switch') {
12178: if ($newvalues{$item} ne '') {
12179: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
12180: push(@errors,$item);
12181: }
12182: }
1.43 raeburn 12183: }
12184: if (grep(/^\Q$item\E$/,@errors)) {
12185: $newvalues{$item} = $domdefaults{$item};
12186: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
12187: $changes{$item} = 1;
12188: }
1.72 raeburn 12189: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 12190: }
12191: my %defaults_hash = (
1.72 raeburn 12192: defaults => \%newvalues,
12193: );
1.43 raeburn 12194: my $title = &defaults_titles();
1.160.6.40 raeburn 12195:
12196: my $currinststatus;
12197: if (ref($domconfig{'inststatus'}) eq 'HASH') {
12198: $currinststatus = $domconfig{'inststatus'};
12199: } else {
12200: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12201: $currinststatus = {
12202: inststatustypes => $usertypes,
12203: inststatusorder => $types,
12204: inststatusguest => [],
12205: };
12206: }
12207: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
12208: my @allpos;
12209: my %guests;
12210: my %alltypes;
12211: my ($currtitles,$currguests,$currorder);
12212: if (ref($currinststatus) eq 'HASH') {
12213: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
12214: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
12215: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
12216: if ($currinststatus->{inststatustypes}->{$type} ne '') {
12217: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
12218: }
12219: }
12220: unless (grep(/^\Q$type\E$/,@todelete)) {
12221: my $position = $env{'form.inststatus_pos_'.$type};
12222: $position =~ s/\D+//g;
12223: $allpos[$position] = $type;
12224: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
12225: $alltypes{$type} =~ s/`//g;
12226: if ($env{'form.inststatus_guest_'.$type}) {
12227: $guests{$type} = 1;
12228: }
12229: }
12230: }
12231: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
12232: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
12233: }
12234: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
12235: $currtitles =~ s/,$//;
12236: }
12237: }
12238: if ($env{'form.addinststatus'}) {
12239: my $newtype = $env{'form.addinststatus'};
12240: $newtype =~ s/\W//g;
12241: unless (exists($alltypes{$newtype})) {
12242: if ($env{'form.addinststatus_guest'}) {
12243: $guests{$newtype} = 1;
12244: }
12245: $alltypes{$newtype} = $env{'form.addinststatus_title'};
12246: $alltypes{$newtype} =~ s/`//g;
12247: my $position = $env{'form.addinststatus_pos'};
12248: $position =~ s/\D+//g;
12249: if ($position ne '') {
12250: $allpos[$position] = $newtype;
12251: }
12252: }
12253: }
12254: my (@orderedstatus,@orderedguests);
12255: foreach my $type (@allpos) {
12256: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
12257: push(@orderedstatus,$type);
12258: if ($guests{$type}) {
12259: push(@orderedguests,$type);
12260: }
12261: }
12262: }
12263: foreach my $type (keys(%alltypes)) {
12264: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
12265: delete($alltypes{$type});
12266: }
12267: }
12268: $defaults_hash{'inststatus'} = {
12269: inststatustypes => \%alltypes,
12270: inststatusorder => \@orderedstatus,
12271: inststatusguest => \@orderedguests,
12272: };
12273: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
12274: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
12275: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
12276: }
12277: }
12278: if ($currorder ne join(',',@orderedstatus)) {
12279: $changes{'inststatus'}{'inststatusorder'} = 1;
12280: }
12281: if ($currguests ne join(',',@orderedguests)) {
12282: $changes{'inststatus'}{'inststatusguest'} = 1;
12283: }
12284: my $newtitles;
12285: foreach my $item (@orderedstatus) {
12286: $newtitles .= $alltypes{$item}.',';
12287: }
12288: $newtitles =~ s/,$//;
12289: if ($currtitles ne $newtitles) {
12290: $changes{'inststatus'}{'inststatustypes'} = 1;
12291: }
1.43 raeburn 12292: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
12293: $dom);
12294: if ($putresult eq 'ok') {
12295: if (keys(%changes) > 0) {
12296: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 12297: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 12298: 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";
12299: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 12300: if ($item eq 'inststatus') {
12301: if (ref($changes{'inststatus'}) eq 'HASH') {
12302: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
12303: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
12304: foreach my $type (@orderedstatus) {
12305: $resulttext .= $alltypes{$type}.', ';
12306: }
12307: $resulttext =~ s/, $//;
12308: $resulttext .= '</li>';
12309: }
12310: if ($changes{'inststatus'}{'inststatusguest'}) {
12311: $resulttext .= '<li>';
12312: if (@orderedguests) {
12313: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
12314: foreach my $type (@orderedguests) {
12315: $resulttext .= $alltypes{$type}.', ';
12316: }
12317: $resulttext =~ s/, $//;
12318: } else {
12319: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
12320: }
12321: $resulttext .= '</li>';
12322: }
12323: }
12324: } else {
12325: my $value = $env{'form.'.$item};
12326: if ($value eq '') {
12327: $value = &mt('none');
12328: } elsif ($item eq 'auth_def') {
12329: my %authnames = &authtype_names();
12330: my %shortauth = (
12331: internal => 'int',
12332: krb4 => 'krb4',
12333: krb5 => 'krb5',
12334: localauth => 'loc',
12335: );
12336: $value = $authnames{$shortauth{$value}};
1.160.6.80 raeburn 12337: } elsif ($item eq 'intauth_switch') {
12338: my %optiondesc = &Apache::lonlocal::texthash (
12339: 0 => 'No',
12340: 1 => 'Yes',
12341: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
12342: );
12343: if ($value =~ /^(0|1|2)$/) {
12344: $value = $optiondesc{$value};
12345: } else {
12346: $value = &mt('none -- defaults to No');
12347: }
12348: } elsif ($item eq 'intauth_check') {
12349: my %optiondesc = &Apache::lonlocal::texthash (
12350: 0 => 'No',
12351: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
12352: 2 => 'Yes, disallow login if stored cost is less than domain default',
12353: );
12354: if ($value =~ /^(0|1|2)$/) {
12355: $value = $optiondesc{$value};
12356: } else {
12357: $value = &mt('none -- defaults to No');
12358: }
1.160.6.40 raeburn 12359: }
12360: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
12361: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 12362: }
12363: }
12364: $resulttext .= '</ul>';
12365: $mailmsgtext .= "\n";
12366: my $cachetime = 24*60*60;
1.72 raeburn 12367: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 12368: if (ref($lastactref) eq 'HASH') {
12369: $lastactref->{'domdefaults'} = 1;
12370: }
1.68 raeburn 12371: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 12372: my $notify = 1;
12373: if (ref($domconfig{'contacts'}) eq 'HASH') {
12374: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
12375: $notify = 0;
12376: }
12377: }
12378: if ($notify) {
12379: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
12380: "LON-CAPA Domain Settings Change - $dom",
12381: $mailmsgtext);
12382: }
1.54 raeburn 12383: }
1.43 raeburn 12384: } else {
1.54 raeburn 12385: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 12386: }
12387: } else {
12388: $resulttext = '<span class="LC_error">'.
12389: &mt('An error occurred: [_1]',$putresult).'</span>';
12390: }
12391: if (@errors > 0) {
12392: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
12393: foreach my $item (@errors) {
12394: $resulttext .= ' "'.$title->{$item}.'",';
12395: }
12396: $resulttext =~ s/,$//;
12397: }
12398: return $resulttext;
12399: }
12400:
1.46 raeburn 12401: sub modify_scantron {
1.160.6.24 raeburn 12402: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 12403: my ($resulttext,%confhash,%changes,$errors);
12404: my $custom = 'custom.tab';
12405: my $default = 'default.tab';
12406: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.84.2. 0(raebur 12407:9): my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 12408: &config_check($dom,$confname,$servadm);
12409: if ($env{'form.scantronformat.filename'} ne '') {
12410: my $error;
12411: if ($configuserok eq 'ok') {
12412: if ($switchserver) {
1.130 raeburn 12413: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 12414: } else {
12415: if ($author_ok eq 'ok') {
12416: my ($result,$scantronurl) =
12417: &publishlogo($r,'upload','scantronformat',$dom,
12418: $confname,'scantron','','',$custom);
12419: if ($result eq 'ok') {
12420: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 12421: $changes{'scantronformat'} = 1;
1.46 raeburn 12422: } else {
12423: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
12424: }
12425: } else {
12426: $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);
12427: }
12428: }
12429: } else {
12430: $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);
12431: }
12432: if ($error) {
12433: &Apache::lonnet::logthis($error);
12434: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12435: }
12436: }
1.48 raeburn 12437: if (ref($domconfig{'scantron'}) eq 'HASH') {
12438: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
12439: if ($env{'form.scantronformat_del'}) {
12440: $confhash{'scantron'}{'scantronformat'} = '';
12441: $changes{'scantronformat'} = 1;
1.160.6.84.2. 0(raebur 12442:9): } else {
12443:9): $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
12444:9): }
12445:9): }
12446:9): }
12447:9): my @options = ('hdr','pad','rem');
12448:9): my @fields = &scantroncsv_fields();
12449:9): my %titles = &scantronconfig_titles();
12450:9): my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
12451:9): my ($newdat,$currdat,%newcol,%currcol);
12452:9): if (grep(/^dat$/,@formats)) {
12453:9): $confhash{'scantron'}{config}{dat} = 1;
12454:9): $newdat = 1;
12455:9): } else {
12456:9): $newdat = 0;
12457:9): }
12458:9): if (grep(/^csv$/,@formats)) {
12459:9): my %bynum;
12460:9): foreach my $field (@fields) {
12461:9): if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
12462:9): my $posscol = $1;
12463:9): if (($posscol < 20) && (!$bynum{$posscol})) {
12464:9): $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
12465:9): $bynum{$posscol} = $field;
12466:9): $newcol{$field} = $posscol;
12467:9): }
12468:9): }
12469:9): }
12470:9): if (keys(%newcol)) {
12471:9): foreach my $option (@options) {
12472:9): if ($env{'form.scantroncsv_'.$option}) {
12473:9): $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
12474:9): }
12475:9): }
12476:9): }
12477:9): }
12478:9): $currdat = 1;
12479:9): if (ref($domconfig{'scantron'}) eq 'HASH') {
12480:9): if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
12481:9): unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
12482:9): $currdat = 0;
12483:9): }
12484:9): if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
12485:9): if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
12486:9): %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
12487:9): }
12488:9): }
12489:9): }
12490:9): }
12491:9): if ($currdat != $newdat) {
12492:9): $changes{'config'} = 1;
12493:9): } else {
12494:9): foreach my $field (@fields) {
12495:9): if ($currcol{$field} ne '') {
12496:9): if ($currcol{$field} ne $newcol{$field}) {
12497:9): $changes{'config'} = 1;
12498:9): last;
12499:9): }
12500:9): } elsif ($newcol{$field} ne '') {
12501:9): $changes{'config'} = 1;
12502:9): last;
1.46 raeburn 12503: }
12504: }
12505: }
12506: if (keys(%confhash) > 0) {
12507: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
12508: $dom);
12509: if ($putresult eq 'ok') {
12510: if (keys(%changes) > 0) {
1.48 raeburn 12511: if (ref($confhash{'scantron'}) eq 'HASH') {
12512: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.84.2. 0(raebur 12513:9): if ($changes{'scantronformat'}) {
12514:9): if ($confhash{'scantron'}{'scantronformat'} eq '') {
12515:9): $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
12516:9): } else {
12517:9): $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
12518:9): }
12519:9): }
12520:9): if ($changes{'config'}) {
12521:9): if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
12522:9): if ($confhash{'scantron'}{'config'}{'dat'}) {
12523:9): $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
12524:9): }
12525:9): if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
12526:9): if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
12527:9): if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
12528:9): $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
12529:9): foreach my $field (@fields) {
12530:9): if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
12531:9): my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
12532:9): $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
12533:9): }
12534:9): }
12535:9): $resulttext .= '</ul></li>';
12536:9): if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
12537:9): if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
12538:9): $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
12539:9): foreach my $option (@options) {
12540:9): if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
12541:9): $resulttext .= '<li>'.$titles{$option}.'</li>';
12542:9): }
12543:9): }
12544:9): $resulttext .= '</ul></li>';
12545:9): }
12546:9): }
12547:9): }
12548:9): }
12549:9): }
12550:9): } else {
12551:9): $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
12552:9): }
1.46 raeburn 12553: }
1.48 raeburn 12554: $resulttext .= '</ul>';
12555: } else {
1.130 raeburn 12556: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 12557: }
12558: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 12559: if (ref($lastactref) eq 'HASH') {
12560: $lastactref->{'domainconfig'} = 1;
12561: }
1.46 raeburn 12562: } else {
1.160.6.84.2. 0(raebur 12563:9): $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 12564: }
12565: } else {
12566: $resulttext = '<span class="LC_error">'.
12567: &mt('An error occurred: [_1]',$putresult).'</span>';
12568: }
12569: } else {
1.160.6.84.2. 0(raebur 12570:9): $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 12571: }
12572: if ($errors) {
12573: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12574: $errors.'</ul>';
12575: }
12576: return $resulttext;
12577: }
12578:
1.48 raeburn 12579: sub modify_coursecategories {
1.160.6.43 raeburn 12580: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 12581: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
12582: $cathash);
1.48 raeburn 12583: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 12584: my @catitems = ('unauth','auth');
12585: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 12586: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 12587: $cathash = $domconfig{'coursecategories'}{'cats'};
12588: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
12589: $changes{'togglecats'} = 1;
12590: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
12591: }
12592: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
12593: $changes{'categorize'} = 1;
12594: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
12595: }
1.120 raeburn 12596: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
12597: $changes{'togglecatscomm'} = 1;
12598: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
12599: }
12600: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
12601: $changes{'categorizecomm'} = 1;
12602: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
12603: }
1.160.6.42 raeburn 12604: foreach my $item (@catitems) {
12605: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12606: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
12607: $changes{$item} = 1;
12608: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12609: }
12610: }
12611: }
1.57 raeburn 12612: } else {
12613: $changes{'togglecats'} = 1;
12614: $changes{'categorize'} = 1;
1.124 raeburn 12615: $changes{'togglecatscomm'} = 1;
12616: $changes{'categorizecomm'} = 1;
1.87 raeburn 12617: $domconfig{'coursecategories'} = {
12618: togglecats => $env{'form.togglecats'},
12619: categorize => $env{'form.categorize'},
1.124 raeburn 12620: togglecatscomm => $env{'form.togglecatscomm'},
12621: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 12622: };
1.160.6.42 raeburn 12623: foreach my $item (@catitems) {
12624: if ($env{'form.coursecat_'.$item} ne 'std') {
12625: $changes{$item} = 1;
12626: }
12627: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12628: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12629: }
12630: }
1.57 raeburn 12631: }
12632: if (ref($cathash) eq 'HASH') {
12633: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 12634: push (@deletecategory,'instcode::0');
12635: }
1.120 raeburn 12636: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
12637: push(@deletecategory,'communities::0');
12638: }
1.48 raeburn 12639: }
1.57 raeburn 12640: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
12641: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12642: if (@deletecategory > 0) {
12643: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 12644: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 12645: foreach my $item (@deletecategory) {
1.57 raeburn 12646: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
12647: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 12648: $deletions{$item} = 1;
1.57 raeburn 12649: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 12650: }
12651: }
12652: }
1.57 raeburn 12653: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 12654: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 12655: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 12656: $reorderings{$item} = 1;
1.57 raeburn 12657: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 12658: }
12659: if ($env{'form.addcategory_name_'.$item} ne '') {
12660: my $newcat = $env{'form.addcategory_name_'.$item};
12661: my $newdepth = $depth+1;
12662: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12663: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 12664: $adds{$newitem} = 1;
12665: }
12666: if ($env{'form.subcat_'.$item} ne '') {
12667: my $newcat = $env{'form.subcat_'.$item};
12668: my $newdepth = $depth+1;
12669: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12670: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 12671: $adds{$newitem} = 1;
12672: }
12673: }
12674: }
12675: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 12676: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12677: my $newitem = 'instcode::0';
1.57 raeburn 12678: if ($cathash->{$newitem} eq '') {
12679: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12680: $adds{$newitem} = 1;
12681: }
12682: } else {
12683: my $newitem = 'instcode::0';
1.57 raeburn 12684: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12685: $adds{$newitem} = 1;
12686: }
12687: }
1.120 raeburn 12688: if ($env{'form.communities'} eq '1') {
12689: if (ref($cathash) eq 'HASH') {
12690: my $newitem = 'communities::0';
12691: if ($cathash->{$newitem} eq '') {
12692: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12693: $adds{$newitem} = 1;
12694: }
12695: } else {
12696: my $newitem = 'communities::0';
12697: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12698: $adds{$newitem} = 1;
12699: }
12700: }
1.48 raeburn 12701: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 12702: if (($env{'form.addcategory_name'} ne 'instcode') &&
12703: ($env{'form.addcategory_name'} ne 'communities')) {
12704: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
12705: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
12706: $adds{$newitem} = 1;
12707: }
1.48 raeburn 12708: }
1.57 raeburn 12709: my $putresult;
1.48 raeburn 12710: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12711: if (keys(%deletions) > 0) {
12712: foreach my $key (keys(%deletions)) {
12713: if ($predelallitems{$key} ne '') {
12714: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
12715: }
12716: }
12717: }
12718: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 12719: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 12720: if (ref($chkcats[0]) eq 'ARRAY') {
12721: my $depth = 0;
12722: my $chg = 0;
12723: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
12724: my $name = $chkcats[0][$i];
12725: my $item;
12726: if ($name eq '') {
12727: $chg ++;
12728: } else {
12729: $item = &escape($name).'::0';
12730: if ($chg) {
1.57 raeburn 12731: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 12732: }
12733: $depth ++;
1.57 raeburn 12734: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 12735: $depth --;
12736: }
12737: }
12738: }
1.57 raeburn 12739: }
12740: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12741: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 12742: if ($putresult eq 'ok') {
1.57 raeburn 12743: my %title = (
1.120 raeburn 12744: togglecats => 'Show/Hide a course in catalog',
12745: categorize => 'Assign a category to a course',
12746: togglecatscomm => 'Show/Hide a community in catalog',
12747: categorizecomm => 'Assign a category to a community',
1.57 raeburn 12748: );
12749: my %level = (
1.120 raeburn 12750: dom => 'set in Domain ("Modify Course/Community")',
12751: crs => 'set in Course ("Course Configuration")',
12752: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 12753: none => 'No catalog',
12754: std => 'Standard catalog',
12755: domonly => 'Domain-only catalog',
12756: codesrch => 'Code search form',
1.57 raeburn 12757: );
1.48 raeburn 12758: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 12759: if ($changes{'togglecats'}) {
12760: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
12761: }
12762: if ($changes{'categorize'}) {
12763: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 12764: }
1.120 raeburn 12765: if ($changes{'togglecatscomm'}) {
12766: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
12767: }
12768: if ($changes{'categorizecomm'}) {
12769: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
12770: }
1.160.6.42 raeburn 12771: if ($changes{'unauth'}) {
12772: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
12773: }
12774: if ($changes{'auth'}) {
12775: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
12776: }
1.57 raeburn 12777: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12778: my $cathash;
12779: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
12780: $cathash = $domconfig{'coursecategories'}{'cats'};
12781: } else {
12782: $cathash = {};
12783: }
12784: my (@cats,@trails,%allitems);
12785: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
12786: if (keys(%deletions) > 0) {
12787: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
12788: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
12789: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
12790: }
12791: $resulttext .= '</ul></li>';
12792: }
12793: if (keys(%reorderings) > 0) {
12794: my %sort_by_trail;
12795: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
12796: foreach my $key (keys(%reorderings)) {
12797: if ($allitems{$key} ne '') {
12798: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12799: }
1.48 raeburn 12800: }
1.57 raeburn 12801: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12802: $resulttext .= '<li>'.$trails[$trail].'</li>';
12803: }
12804: $resulttext .= '</ul></li>';
1.48 raeburn 12805: }
1.57 raeburn 12806: if (keys(%adds) > 0) {
12807: my %sort_by_trail;
12808: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
12809: foreach my $key (keys(%adds)) {
12810: if ($allitems{$key} ne '') {
12811: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12812: }
12813: }
12814: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12815: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 12816: }
1.57 raeburn 12817: $resulttext .= '</ul></li>';
1.48 raeburn 12818: }
12819: }
12820: $resulttext .= '</ul>';
1.160.6.43 raeburn 12821: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 12822: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12823: if ($changes{'auth'}) {
12824: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
12825: }
12826: if ($changes{'unauth'}) {
12827: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
12828: }
12829: my $cachetime = 24*60*60;
12830: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 12831: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 12832: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 12833: }
12834: }
1.48 raeburn 12835: } else {
12836: $resulttext = '<span class="LC_error">'.
1.57 raeburn 12837: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 12838: }
12839: } else {
1.120 raeburn 12840: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 12841: }
12842: return $resulttext;
12843: }
12844:
1.69 raeburn 12845: sub modify_serverstatuses {
12846: my ($dom,%domconfig) = @_;
12847: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
12848: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
12849: %currserverstatus = %{$domconfig{'serverstatuses'}};
12850: }
12851: my @pages = &serverstatus_pages();
12852: foreach my $type (@pages) {
12853: $newserverstatus{$type}{'namedusers'} = '';
12854: $newserverstatus{$type}{'machines'} = '';
12855: if (defined($env{'form.'.$type.'_namedusers'})) {
12856: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
12857: my @okusers;
12858: foreach my $user (@users) {
12859: my ($uname,$udom) = split(/:/,$user);
12860: if (($udom =~ /^$match_domain$/) &&
12861: (&Apache::lonnet::domain($udom)) &&
12862: ($uname =~ /^$match_username$/)) {
12863: if (!grep(/^\Q$user\E/,@okusers)) {
12864: push(@okusers,$user);
12865: }
12866: }
12867: }
12868: if (@okusers > 0) {
12869: @okusers = sort(@okusers);
12870: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
12871: }
12872: }
12873: if (defined($env{'form.'.$type.'_machines'})) {
12874: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
12875: my @okmachines;
12876: foreach my $ip (@machines) {
12877: my @parts = split(/\./,$ip);
12878: next if (@parts < 4);
12879: my $badip = 0;
12880: for (my $i=0; $i<4; $i++) {
12881: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
12882: $badip = 1;
12883: last;
12884: }
12885: }
12886: if (!$badip) {
12887: push(@okmachines,$ip);
12888: }
12889: }
12890: @okmachines = sort(@okmachines);
12891: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
12892: }
12893: }
12894: my %serverstatushash = (
12895: serverstatuses => \%newserverstatus,
12896: );
12897: foreach my $type (@pages) {
1.83 raeburn 12898: foreach my $setting ('namedusers','machines') {
1.84 raeburn 12899: my (@current,@new);
1.83 raeburn 12900: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 12901: if ($currserverstatus{$type}{$setting} ne '') {
12902: @current = split(/,/,$currserverstatus{$type}{$setting});
12903: }
12904: }
12905: if ($newserverstatus{$type}{$setting} ne '') {
12906: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 12907: }
12908: if (@current > 0) {
12909: if (@new > 0) {
12910: foreach my $item (@current) {
12911: if (!grep(/^\Q$item\E$/,@new)) {
12912: $changes{$type}{$setting} = 1;
1.82 raeburn 12913: last;
12914: }
12915: }
1.84 raeburn 12916: foreach my $item (@new) {
12917: if (!grep(/^\Q$item\E$/,@current)) {
12918: $changes{$type}{$setting} = 1;
12919: last;
1.82 raeburn 12920: }
12921: }
12922: } else {
1.83 raeburn 12923: $changes{$type}{$setting} = 1;
1.69 raeburn 12924: }
1.83 raeburn 12925: } elsif (@new > 0) {
12926: $changes{$type}{$setting} = 1;
1.69 raeburn 12927: }
12928: }
12929: }
12930: if (keys(%changes) > 0) {
1.81 raeburn 12931: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 12932: my $putresult = &Apache::lonnet::put_dom('configuration',
12933: \%serverstatushash,$dom);
12934: if ($putresult eq 'ok') {
12935: $resulttext .= &mt('Changes made:').'<ul>';
12936: foreach my $type (@pages) {
1.84 raeburn 12937: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 12938: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 12939: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 12940: if ($newserverstatus{$type}{'namedusers'} eq '') {
12941: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
12942: } else {
12943: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
12944: }
1.84 raeburn 12945: }
12946: if ($changes{$type}{'machines'}) {
1.69 raeburn 12947: if ($newserverstatus{$type}{'machines'} eq '') {
12948: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
12949: } else {
12950: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
12951: }
12952:
12953: }
12954: $resulttext .= '</ul></li>';
12955: }
12956: }
12957: $resulttext .= '</ul>';
12958: } else {
12959: $resulttext = '<span class="LC_error">'.
12960: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
12961:
12962: }
12963: } else {
12964: $resulttext = &mt('No changes made to access to server status pages');
12965: }
12966: return $resulttext;
12967: }
12968:
1.118 jms 12969: sub modify_helpsettings {
1.160.6.77 raeburn 12970: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 12971: my ($resulttext,$errors,%changes,%helphash);
12972: my %defaultchecked = ('submitbugs' => 'on');
12973: my @offon = ('off','on');
1.118 jms 12974: my @toggles = ('submitbugs');
1.160.6.77 raeburn 12975: my %current = ('submitbugs' => '',
12976: 'adhoc' => {},
12977: );
1.118 jms 12978: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 12979: %current = %{$domconfig{'helpsettings'}};
12980: }
1.160.6.77 raeburn 12981: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 12982: foreach my $item (@toggles) {
12983: if ($defaultchecked{$item} eq 'on') {
12984: if ($current{$item} eq '') {
12985: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 12986: $changes{$item} = 1;
12987: }
1.160.6.73 raeburn 12988: } elsif ($current{$item} ne $env{'form.'.$item}) {
12989: $changes{$item} = 1;
12990: }
12991: } elsif ($defaultchecked{$item} eq 'off') {
12992: if ($current{$item} eq '') {
12993: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 12994: $changes{$item} = 1;
12995: }
1.160.6.73 raeburn 12996: } elsif ($current{$item} ne $env{'form.'.$item}) {
12997: $changes{$item} = 1;
12998: }
12999: }
13000: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
13001: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
13002: }
13003: }
1.160.6.77 raeburn 13004: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 13005: my $confname = $dom.'-domainconfig';
13006: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 13007: my (@allpos,%newsettings,%changedprivs,$newrole);
13008: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 13009: my @accesstypes = ('all','dh','da','none','status','inc','exc');
13010: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 13011: my %lt = &Apache::lonlocal::texthash(
13012: s => 'system',
13013: d => 'domain',
13014: order => 'Display order',
13015: access => 'Role usage',
1.160.6.79 raeburn 13016: all => 'All with domain helpdesk or helpdesk assistant role',
13017: dh => 'All with domain helpdesk role',
13018: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 13019: none => 'None',
13020: status => 'Determined based on institutional status',
13021: inc => 'Include all, but exclude specific personnel',
13022: exc => 'Exclude all, but include specific personnel',
13023: );
13024: for (my $num=0; $num<=$maxnum; $num++) {
13025: my ($prefix,$identifier,$rolename,%curr);
13026: if ($num == $maxnum) {
13027: next unless ($env{'form.newcusthelp'} == $maxnum);
13028: $identifier = 'custhelp'.$num;
13029: $prefix = 'helproles_'.$num;
13030: $rolename = $env{'form.custhelpname'.$num};
13031: $rolename=~s/[^A-Za-z0-9]//gs;
13032: next if ($rolename eq '');
13033: next if (exists($existing{'rolesdef_'.$rolename}));
13034: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13035: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13036: $newprivs{'c'},$confname,$dom);
13037: if ($result ne 'ok') {
13038: $errors .= '<li><span class="LC_error">'.
13039: &mt('An error occurred storing the new custom role: [_1]',
13040: $result).'</span></li>';
13041: next;
13042: } else {
13043: $changedprivs{$rolename} = \%newprivs;
13044: $newrole = $rolename;
13045: }
13046: } else {
13047: $prefix = 'helproles_'.$num;
13048: $rolename = $env{'form.'.$prefix};
13049: next if ($rolename eq '');
13050: next unless (exists($existing{'rolesdef_'.$rolename}));
13051: $identifier = 'custhelp'.$num;
13052: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13053: my %currprivs;
13054: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
13055: split(/\_/,$existing{'rolesdef_'.$rolename});
13056: foreach my $level ('c','d','s') {
13057: if ($newprivs{$level} ne $currprivs{$level}) {
13058: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13059: $newprivs{'c'},$confname,$dom);
13060: if ($result ne 'ok') {
13061: $errors .= '<li><span class="LC_error">'.
13062: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
13063: $rolename,$result).'</span></li>';
13064: } else {
13065: $changedprivs{$rolename} = \%newprivs;
13066: }
13067: last;
13068: }
13069: }
13070: if (ref($current{'adhoc'}) eq 'HASH') {
13071: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13072: %curr = %{$current{'adhoc'}{$rolename}};
13073: }
13074: }
13075: }
13076: my $newpos = $env{'form.'.$prefix.'_pos'};
13077: $newpos =~ s/\D+//g;
13078: $allpos[$newpos] = $rolename;
13079: my $newdesc = $env{'form.'.$prefix.'_desc'};
13080: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
13081: if ($curr{'desc'}) {
13082: if ($curr{'desc'} ne $newdesc) {
13083: $changes{'customrole'}{$rolename}{'desc'} = 1;
13084: $newsettings{$rolename}{'desc'} = $newdesc;
13085: }
13086: } elsif ($newdesc ne '') {
13087: $changes{'customrole'}{$rolename}{'desc'} = 1;
13088: $newsettings{$rolename}{'desc'} = $newdesc;
13089: }
13090: my $access = $env{'form.'.$prefix.'_access'};
13091: if (grep(/^\Q$access\E$/,@accesstypes)) {
13092: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
13093: if ($access eq 'status') {
13094: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
13095: if (scalar(@statuses) == 0) {
13096: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
13097: } else {
13098: my (@shownstatus,$numtypes);
13099: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13100: if (ref($types) eq 'ARRAY') {
13101: $numtypes = scalar(@{$types});
13102: foreach my $type (sort(@statuses)) {
13103: if ($type eq 'default') {
13104: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13105: } elsif (grep(/^\Q$type\E$/,@{$types})) {
13106: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13107: push(@shownstatus,$usertypes->{$type});
13108: }
1.160.6.73 raeburn 13109: }
13110: }
1.160.6.77 raeburn 13111: if (grep(/^default$/,@statuses)) {
13112: push(@shownstatus,$othertitle);
13113: }
13114: if (scalar(@shownstatus) == 1+$numtypes) {
13115: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
13116: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
13117: } else {
13118: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
13119: if (ref($curr{'status'}) eq 'ARRAY') {
13120: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13121: if (@diffs) {
13122: $changes{'customrole'}{$rolename}{$access} = 1;
13123: }
13124: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13125: $changes{'customrole'}{$rolename}{$access} = 1;
13126: }
13127: }
13128: }
13129: } elsif (($access eq 'inc') || ($access eq 'exc')) {
13130: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
13131: my @newspecstaff;
13132: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13133: foreach my $person (sort(@personnel)) {
13134: if ($domhelpdesk{$person}) {
13135: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
13136: }
13137: }
13138: if (ref($curr{$access}) eq 'ARRAY') {
13139: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13140: if (@diffs) {
13141: $changes{'customrole'}{$rolename}{$access} = 1;
13142: }
13143: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13144: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 13145: }
1.160.6.77 raeburn 13146: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13147: my ($uname,$udom) = split(/:/,$person);
13148: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
13149: }
13150: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 13151: }
1.160.6.77 raeburn 13152: } else {
13153: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
13154: }
13155: unless ($curr{'access'} eq $access) {
13156: $changes{'customrole'}{$rolename}{'access'} = 1;
13157: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 13158: }
13159: }
1.160.6.77 raeburn 13160: if (@allpos > 0) {
13161: my $idx = 0;
13162: foreach my $rolename (@allpos) {
13163: if ($rolename ne '') {
13164: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
13165: if (ref($current{'adhoc'}) eq 'HASH') {
13166: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13167: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
13168: $changes{'customrole'}{$rolename}{'order'} = 1;
13169: $newsettings{$rolename}{'order'} = $idx+1;
13170: }
13171: }
1.160.6.73 raeburn 13172: }
1.160.6.77 raeburn 13173: $idx ++;
1.122 jms 13174: }
13175: }
1.118 jms 13176: }
1.123 jms 13177: my $putresult;
13178: if (keys(%changes) > 0) {
1.160.6.5 raeburn 13179: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
13180: if ($putresult eq 'ok') {
1.160.6.77 raeburn 13181: if (ref($helphash{'helpsettings'}) eq 'HASH') {
13182: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
13183: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
13184: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
13185: }
13186: }
13187: my $cachetime = 24*60*60;
13188: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13189: if (ref($lastactref) eq 'HASH') {
13190: $lastactref->{'domdefaults'} = 1;
13191: }
13192: } else {
13193: $errors .= '<li><span class="LC_error">'.
13194: &mt('An error occurred storing the settings: [_1]',
13195: $putresult).'</span></li>';
13196: }
13197: }
13198: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
13199: $resulttext = &mt('Changes made:').'<ul>';
13200: my (%shownprivs,@levelorder);
13201: @levelorder = ('c','d','s');
13202: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 13203: foreach my $item (sort(keys(%changes))) {
13204: if ($item eq 'submitbugs') {
13205: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
13206: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
13207: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 13208: } elsif ($item eq 'customrole') {
13209: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 13210: my @keyorder = ('order','desc','access','status','exc','inc');
13211: my %keytext = &Apache::lonlocal::texthash(
13212: order => 'Order',
13213: desc => 'Role description',
13214: access => 'Role usage',
1.160.6.83 raeburn 13215: status => 'Allowed institutional types',
1.160.6.77 raeburn 13216: exc => 'Allowed personnel',
13217: inc => 'Disallowed personnel',
13218: );
1.160.6.73 raeburn 13219: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 13220: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
13221: if ($role eq $newrole) {
13222: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
13223: $role).'<ul>';
13224: } else {
13225: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13226: $role).'<ul>';
13227: }
13228: foreach my $key (@keyorder) {
13229: if ($changes{'customrole'}{$role}{$key}) {
13230: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
13231: $keytext{$key},$newsettings{$role}{$key}).
13232: '</li>';
13233: }
13234: }
13235: if (ref($changedprivs{$role}) eq 'HASH') {
13236: $shownprivs{$role} = 1;
13237: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
13238: foreach my $level (@levelorder) {
13239: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13240: next if ($item eq '');
13241: my ($priv) = split(/\&/,$item,2);
13242: if (&Apache::lonnet::plaintext($priv)) {
13243: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13244: unless ($level eq 'c') {
13245: $resulttext .= ' ('.$lt{$level}.')';
13246: }
13247: $resulttext .= '</li>';
13248: }
13249: }
13250: }
13251: $resulttext .= '</ul>';
13252: }
13253: $resulttext .= '</ul></li>';
13254: }
1.160.6.73 raeburn 13255: }
13256: }
1.160.6.5 raeburn 13257: }
13258: }
13259: }
1.160.6.77 raeburn 13260: if (keys(%changedprivs)) {
13261: foreach my $role (sort(keys(%changedprivs))) {
13262: unless ($shownprivs{$role}) {
13263: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13264: $role).'<ul>'.
13265: '<li>'.&mt('Privileges set to :').'<ul>';
13266: foreach my $level (@levelorder) {
13267: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13268: next if ($item eq '');
13269: my ($priv) = split(/\&/,$item,2);
13270: if (&Apache::lonnet::plaintext($priv)) {
13271: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13272: unless ($level eq 'c') {
13273: $resulttext .= ' ('.$lt{$level}.')';
13274: }
13275: $resulttext .= '</li>';
13276: }
13277: }
13278: }
13279: $resulttext .= '</ul></li></ul></li>';
13280: }
13281: }
13282: }
13283: $resulttext .= '</ul>';
13284: } else {
13285: $resulttext = &mt('No changes made to help settings');
1.118 jms 13286: }
13287: if ($errors) {
1.160.6.5 raeburn 13288: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 13289: $errors.'</ul>';
1.118 jms 13290: }
13291: return $resulttext;
13292: }
13293:
1.121 raeburn 13294: sub modify_coursedefaults {
1.160.6.27 raeburn 13295: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 13296: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 13297: my %defaultchecked = (
13298: 'uselcmath' => 'on',
13299: 'usejsme' => 'on'
13300: );
13301: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 13302: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 13303: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
13304: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 13305: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 13306: my %staticdefaults = (
13307: anonsurvey_threshold => 10,
13308: uploadquota => 500,
1.160.6.57 raeburn 13309: postsubmit => 60,
1.160.6.70 raeburn 13310: mysqltables => 172800,
1.160.6.21 raeburn 13311: );
1.121 raeburn 13312:
13313: $defaultshash{'coursedefaults'} = {};
13314:
13315: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
13316: if ($domconfig{'coursedefaults'} eq '') {
13317: $domconfig{'coursedefaults'} = {};
13318: }
13319: }
13320:
13321: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
13322: foreach my $item (@toggles) {
13323: if ($defaultchecked{$item} eq 'on') {
13324: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13325: ($env{'form.'.$item} eq '0')) {
13326: $changes{$item} = 1;
1.160.6.16 raeburn 13327: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 13328: $changes{$item} = 1;
13329: }
13330: } elsif ($defaultchecked{$item} eq 'off') {
13331: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13332: ($env{'form.'.$item} eq '1')) {
13333: $changes{$item} = 1;
13334: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
13335: $changes{$item} = 1;
13336: }
13337: }
13338: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
13339: }
1.160.6.21 raeburn 13340: foreach my $item (@numbers) {
13341: my ($currdef,$newdef);
1.160.6.26 raeburn 13342: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 13343: if ($item eq 'anonsurvey_threshold') {
13344: $currdef = $domconfig{'coursedefaults'}{$item};
13345: $newdef =~ s/\D//g;
13346: if ($newdef eq '' || $newdef < 1) {
13347: $newdef = 1;
13348: }
13349: $defaultshash{'coursedefaults'}{$item} = $newdef;
13350: } else {
1.160.6.70 raeburn 13351: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
13352: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
13353: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 13354: }
13355: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 13356: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 13357: }
13358: if ($currdef ne $newdef) {
13359: my $staticdef;
13360: if ($item eq 'anonsurvey_threshold') {
13361: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
13362: $changes{$item} = 1;
13363: }
1.160.6.70 raeburn 13364: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
13365: my $setting = $1;
13366: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
13367: $changes{$setting} = 1;
1.160.6.21 raeburn 13368: }
13369: }
1.139 raeburn 13370: }
13371: }
1.160.6.64 raeburn 13372: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
13373: my @currclonecode;
13374: if (ref($currclone) eq 'HASH') {
13375: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
13376: @currclonecode = @{$currclone->{'instcode'}};
13377: }
13378: }
13379: my $newclone;
13380: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
13381: $newclone = $env{'form.canclone'};
13382: }
13383: if ($newclone eq 'instcode') {
13384: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
13385: my (%codedefaults,@code_order,@clonecode);
13386: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
13387: \@code_order);
13388: foreach my $item (@code_order) {
13389: if (grep(/^\Q$item\E$/,@newcodes)) {
13390: push(@clonecode,$item);
13391: }
13392: }
13393: if (@clonecode) {
13394: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
13395: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
13396: if (@diffs) {
13397: $changes{'canclone'} = 1;
13398: }
13399: } else {
13400: $newclone eq '';
13401: }
13402: } elsif ($newclone ne '') {
13403: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
13404: }
13405: if ($newclone ne $currclone) {
13406: $changes{'canclone'} = 1;
13407: }
1.160.6.57 raeburn 13408: my %credits;
13409: foreach my $type (@types) {
13410: unless ($type eq 'community') {
13411: $credits{$type} = $env{'form.'.$type.'_credits'};
13412: $credits{$type} =~ s/[^\d.]+//g;
13413: }
13414: }
13415: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
13416: ($env{'form.coursecredits'} eq '1')) {
13417: $changes{'coursecredits'} = 1;
13418: foreach my $type (keys(%credits)) {
13419: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13420: }
13421: } else {
13422: if ($env{'form.coursecredits'} eq '1') {
13423: foreach my $type (@types) {
13424: unless ($type eq 'community') {
13425: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
13426: $changes{'coursecredits'} = 1;
13427: }
13428: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13429: }
13430: }
13431: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13432: foreach my $type (@types) {
13433: unless ($type eq 'community') {
13434: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
13435: $changes{'coursecredits'} = 1;
13436: last;
13437: }
13438: }
13439: }
13440: }
13441: }
13442: if ($env{'form.postsubmit'} eq '1') {
13443: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
13444: my %currtimeout;
13445: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13446: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
13447: $changes{'postsubmit'} = 1;
13448: }
13449: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13450: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
13451: }
13452: } else {
13453: $changes{'postsubmit'} = 1;
13454: }
13455: foreach my $type (@types) {
13456: my $timeout = $env{'form.'.$type.'_timeout'};
13457: $timeout =~ s/\D//g;
13458: if ($timeout == $staticdefaults{'postsubmit'}) {
13459: $timeout = '';
13460: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
13461: $timeout = '0';
13462: }
13463: unless ($timeout eq '') {
13464: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
13465: }
13466: if (exists($currtimeout{$type})) {
13467: if ($timeout ne $currtimeout{$type}) {
13468: $changes{'postsubmit'} = 1;
13469: }
13470: } elsif ($timeout ne '') {
13471: $changes{'postsubmit'} = 1;
13472: }
13473: }
13474: } else {
13475: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
13476: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13477: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
13478: $changes{'postsubmit'} = 1;
13479: }
13480: } else {
13481: $changes{'postsubmit'} = 1;
13482: }
1.160.6.16 raeburn 13483: }
1.121 raeburn 13484: }
13485: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13486: $dom);
13487: if ($putresult eq 'ok') {
13488: if (keys(%changes) > 0) {
1.160.6.27 raeburn 13489: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 13490: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 13491: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.70 raeburn 13492: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.160.6.57 raeburn 13493: foreach my $item ('uselcmath','usejsme') {
13494: if ($changes{$item}) {
13495: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
13496: }
1.160.6.16 raeburn 13497: }
13498: if ($changes{'coursecredits'}) {
13499: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 13500: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
13501: $domdefaults{$type.'credits'} =
13502: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
13503: }
13504: }
13505: }
13506: if ($changes{'postsubmit'}) {
13507: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13508: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
13509: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13510: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
13511: $domdefaults{$type.'postsubtimeout'} =
13512: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13513: }
13514: }
1.160.6.16 raeburn 13515: }
13516: }
1.160.6.21 raeburn 13517: if ($changes{'uploadquota'}) {
13518: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13519: foreach my $type (@types) {
13520: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
13521: }
13522: }
13523: }
1.160.6.64 raeburn 13524: if ($changes{'canclone'}) {
13525: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13526: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13527: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
13528: if (@clonecodes) {
13529: $domdefaults{'canclone'} = join('+',@clonecodes);
13530: }
13531: }
13532: } else {
13533: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
13534: }
13535: }
1.121 raeburn 13536: my $cachetime = 24*60*60;
13537: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 13538: if (ref($lastactref) eq 'HASH') {
13539: $lastactref->{'domdefaults'} = 1;
13540: }
1.121 raeburn 13541: }
13542: $resulttext = &mt('Changes made:').'<ul>';
13543: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 13544: if ($item eq 'uselcmath') {
1.121 raeburn 13545: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 13546: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 13547: } else {
1.160.6.57 raeburn 13548: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
13549: }
13550: } elsif ($item eq 'usejsme') {
13551: if ($env{'form.'.$item} eq '1') {
13552: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
13553: } else {
13554: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 13555: }
1.139 raeburn 13556: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 13557: $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 13558: } elsif ($item eq 'uploadquota') {
13559: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13560: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
13561: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
13562: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 13563: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
13564:
1.160.6.21 raeburn 13565: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
13566: '</ul>'.
13567: '</li>';
13568: } else {
13569: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
13570: }
1.160.6.70 raeburn 13571: } elsif ($item eq 'mysqltables') {
13572: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
13573: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
13574: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
13575: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
13576: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
13577: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
13578: '</ul>'.
13579: '</li>';
13580: } else {
13581: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
13582: }
1.160.6.57 raeburn 13583: } elsif ($item eq 'postsubmit') {
13584: if ($domdefaults{'postsubmit'} eq 'off') {
13585: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
13586: } else {
13587: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
13588: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13589: $resulttext .= &mt('durations:').'<ul>';
13590: foreach my $type (@types) {
13591: $resulttext .= '<li>';
13592: my $timeout;
13593: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13594: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13595: }
13596: my $display;
13597: if ($timeout eq '0') {
13598: $display = &mt('unlimited');
13599: } elsif ($timeout eq '') {
13600: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
13601: } else {
13602: $display = &mt('[quant,_1,second]',$timeout);
13603: }
13604: if ($type eq 'community') {
13605: $resulttext .= &mt('Communities');
13606: } elsif ($type eq 'official') {
13607: $resulttext .= &mt('Official courses');
13608: } elsif ($type eq 'unofficial') {
13609: $resulttext .= &mt('Unofficial courses');
13610: } elsif ($type eq 'textbook') {
13611: $resulttext .= &mt('Textbook courses');
13612: }
13613: $resulttext .= ' -- '.$display.'</li>';
13614: }
13615: $resulttext .= '</ul>';
13616: }
13617: $resulttext .= '</li>';
13618: }
1.160.6.16 raeburn 13619: } elsif ($item eq 'coursecredits') {
13620: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13621: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 13622: ($domdefaults{'unofficialcredits'} eq '') &&
13623: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 13624: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13625: } else {
13626: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
13627: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
13628: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 13629: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 13630: '</ul>'.
13631: '</li>';
13632: }
13633: } else {
13634: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13635: }
1.160.6.64 raeburn 13636: } elsif ($item eq 'canclone') {
13637: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13638: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13639: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
13640: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
13641: }
13642: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
13643: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
13644: } else {
13645: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
13646: }
1.140 raeburn 13647: }
1.121 raeburn 13648: }
13649: $resulttext .= '</ul>';
13650: } else {
13651: $resulttext = &mt('No changes made to course defaults');
13652: }
13653: } else {
13654: $resulttext = '<span class="LC_error">'.
13655: &mt('An error occurred: [_1]',$putresult).'</span>';
13656: }
13657: return $resulttext;
13658: }
13659:
1.160.6.37 raeburn 13660: sub modify_selfenrollment {
13661: my ($dom,$lastactref,%domconfig) = @_;
13662: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
13663: my @types = ('official','unofficial','community','textbook');
13664: my %titles = &tool_titles();
13665: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
13666: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
13667: $ordered{'default'} = ['types','registered','approval','limit'];
13668:
13669: my (%roles,%shown,%toplevel);
13670: $roles{'0'} = &Apache::lonnet::plaintext('dc');
13671:
13672: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
13673: if ($domconfig{'selfenrollment'} eq '') {
13674: $domconfig{'selfenrollment'} = {};
13675: }
13676: }
13677: %toplevel = (
13678: admin => 'Configuration Rights',
13679: default => 'Default settings',
13680: validation => 'Validation of self-enrollment requests',
13681: );
13682: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
13683:
13684: if (ref($ordered{'admin'}) eq 'ARRAY') {
13685: foreach my $item (@{$ordered{'admin'}}) {
13686: foreach my $type (@types) {
13687: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
13688: $selfenrollhash{'admin'}{$type}{$item} = 1;
13689: } else {
13690: $selfenrollhash{'admin'}{$type}{$item} = 0;
13691: }
13692: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
13693: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
13694: if ($selfenrollhash{'admin'}{$type}{$item} ne
13695: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
13696: push(@{$changes{'admin'}{$type}},$item);
13697: }
13698: } else {
13699: if (!$selfenrollhash{'admin'}{$type}{$item}) {
13700: push(@{$changes{'admin'}{$type}},$item);
13701: }
13702: }
13703: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
13704: push(@{$changes{'admin'}{$type}},$item);
13705: }
13706: }
13707: }
13708: }
13709:
13710: foreach my $item (@{$ordered{'default'}}) {
13711: foreach my $type (@types) {
13712: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
13713: if ($item eq 'types') {
13714: unless (($value eq 'all') || ($value eq 'dom')) {
13715: $value = '';
13716: }
13717: } elsif ($item eq 'registered') {
13718: unless ($value eq '1') {
13719: $value = 0;
13720: }
13721: } elsif ($item eq 'approval') {
13722: unless ($value =~ /^[012]$/) {
13723: $value = 0;
13724: }
13725: } else {
13726: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13727: $value = 'none';
13728: }
13729: }
13730: $selfenrollhash{'default'}{$type}{$item} = $value;
13731: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
13732: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13733: if ($selfenrollhash{'default'}{$type}{$item} ne
13734: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
13735: push(@{$changes{'default'}{$type}},$item);
13736: }
13737: } else {
13738: push(@{$changes{'default'}{$type}},$item);
13739: }
13740: } else {
13741: push(@{$changes{'default'}{$type}},$item);
13742: }
13743: if ($item eq 'limit') {
13744: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13745: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
13746: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
13747: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
13748: }
13749: } else {
13750: $selfenrollhash{'default'}{$type}{'cap'} = '';
13751: }
13752: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13753: if ($selfenrollhash{'default'}{$type}{'cap'} ne
13754: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
13755: push(@{$changes{'default'}{$type}},'cap');
13756: }
13757: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
13758: push(@{$changes{'default'}{$type}},'cap');
13759: }
13760: }
13761: }
13762: }
13763:
13764: foreach my $item (@{$itemsref}) {
13765: if ($item eq 'fields') {
13766: my @changed;
13767: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
13768: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
13769: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
13770: }
13771: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13772: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
13773: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
13774: $domconfig{'selfenrollment'}{'validation'}{$item});
13775: } else {
13776: @changed = @{$selfenrollhash{'validation'}{$item}};
13777: }
13778: } else {
13779: @changed = @{$selfenrollhash{'validation'}{$item}};
13780: }
13781: if (@changed) {
13782: if ($selfenrollhash{'validation'}{$item}) {
13783: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
13784: } else {
13785: $changes{'validation'}{$item} = &mt('None');
13786: }
13787: }
13788: } else {
13789: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
13790: if ($item eq 'markup') {
13791: if ($env{'form.selfenroll_validation_'.$item}) {
13792: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13793: }
13794: }
13795: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13796: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
13797: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
13798: }
13799: }
13800: }
13801: }
13802:
13803: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
13804: $dom);
13805: if ($putresult eq 'ok') {
13806: if (keys(%changes) > 0) {
13807: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13808: $resulttext = &mt('Changes made:').'<ul>';
13809: foreach my $key ('admin','default','validation') {
13810: if (ref($changes{$key}) eq 'HASH') {
13811: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
13812: if ($key eq 'validation') {
13813: foreach my $item (@{$itemsref}) {
13814: if (exists($changes{$key}{$item})) {
13815: if ($item eq 'markup') {
13816: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13817: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
13818: } else {
13819: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13820: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
13821: }
13822: }
13823: }
13824: } else {
13825: foreach my $type (@types) {
13826: if ($type eq 'community') {
13827: $roles{'1'} = &mt('Community personnel');
13828: } else {
13829: $roles{'1'} = &mt('Course personnel');
13830: }
13831: if (ref($changes{$key}{$type}) eq 'ARRAY') {
13832: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13833: if ($key eq 'admin') {
13834: my @mgrdc = ();
13835: if (ref($ordered{$key}) eq 'ARRAY') {
13836: foreach my $item (@{$ordered{'admin'}}) {
13837: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13838: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
13839: push(@mgrdc,$item);
13840: }
13841: }
13842: }
13843: if (@mgrdc) {
13844: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
13845: } else {
13846: delete($domdefaults{$type.'selfenrolladmdc'});
13847: }
13848: }
13849: } else {
13850: if (ref($ordered{$key}) eq 'ARRAY') {
13851: foreach my $item (@{$ordered{$key}}) {
13852: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13853: $domdefaults{$type.'selfenroll'.$item} =
13854: $selfenrollhash{$key}{$type}{$item};
13855: }
13856: }
13857: }
13858: }
13859: }
13860: $resulttext .= '<li>'.$titles{$type}.'<ul>';
13861: foreach my $item (@{$ordered{$key}}) {
13862: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13863: $resulttext .= '<li>';
13864: if ($key eq 'admin') {
13865: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
13866: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
13867: } else {
13868: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
13869: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
13870: }
13871: $resulttext .= '</li>';
13872: }
13873: }
13874: $resulttext .= '</ul></li>';
13875: }
13876: }
13877: $resulttext .= '</ul></li>';
13878: }
13879: }
13880: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
13881: my $cachetime = 24*60*60;
13882: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13883: if (ref($lastactref) eq 'HASH') {
13884: $lastactref->{'domdefaults'} = 1;
13885: }
13886: }
13887: }
13888: $resulttext .= '</ul>';
13889: } else {
13890: $resulttext = &mt('No changes made to self-enrollment settings');
13891: }
13892: } else {
13893: $resulttext = '<span class="LC_error">'.
13894: &mt('An error occurred: [_1]',$putresult).'</span>';
13895: }
13896: return $resulttext;
13897: }
13898:
1.137 raeburn 13899: sub modify_usersessions {
1.160.6.27 raeburn 13900: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 13901: my @hostingtypes = ('version','excludedomain','includedomain');
13902: my @offloadtypes = ('primary','default');
13903: my %types = (
13904: remote => \@hostingtypes,
13905: hosted => \@hostingtypes,
13906: spares => \@offloadtypes,
13907: );
13908: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 13909: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 13910: my (%by_ip,%by_location,@intdoms);
13911: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
13912: my @locations = sort(keys(%by_location));
1.137 raeburn 13913: my (%defaultshash,%changes);
13914: foreach my $prefix (@prefixes) {
13915: $defaultshash{'usersessions'}{$prefix} = {};
13916: }
1.160.6.27 raeburn 13917: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 13918: my $resulttext;
1.138 raeburn 13919: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 13920: foreach my $prefix (@prefixes) {
1.145 raeburn 13921: next if ($prefix eq 'spares');
13922: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 13923: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13924: if ($type eq 'version') {
13925: my $value = $env{'form.'.$prefix.'_'.$type};
13926: my $okvalue;
13927: if ($value ne '') {
13928: if (grep(/^\Q$value\E$/,@lcversions)) {
13929: $okvalue = $value;
13930: }
13931: }
13932: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13933: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13934: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
13935: if ($inuse == 0) {
13936: $changes{$prefix}{$type} = 1;
13937: } else {
13938: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
13939: $changes{$prefix}{$type} = 1;
13940: }
13941: if ($okvalue ne '') {
13942: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13943: }
13944: }
13945: } else {
13946: if (($inuse == 1) && ($okvalue ne '')) {
13947: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13948: $changes{$prefix}{$type} = 1;
13949: }
13950: }
13951: } else {
13952: if (($inuse == 1) && ($okvalue ne '')) {
13953: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13954: $changes{$prefix}{$type} = 1;
13955: }
13956: }
13957: } else {
13958: if (($inuse == 1) && ($okvalue ne '')) {
13959: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13960: $changes{$prefix}{$type} = 1;
13961: }
13962: }
13963: } else {
13964: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13965: my @okvals;
13966: foreach my $val (@vals) {
1.138 raeburn 13967: if ($val =~ /:/) {
13968: my @items = split(/:/,$val);
13969: foreach my $item (@items) {
13970: if (ref($by_location{$item}) eq 'ARRAY') {
13971: push(@okvals,$item);
13972: }
13973: }
13974: } else {
13975: if (ref($by_location{$val}) eq 'ARRAY') {
13976: push(@okvals,$val);
13977: }
1.137 raeburn 13978: }
13979: }
13980: @okvals = sort(@okvals);
13981: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13982: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13983: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13984: if ($inuse == 0) {
13985: $changes{$prefix}{$type} = 1;
13986: } else {
13987: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13988: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
13989: if (@changed > 0) {
13990: $changes{$prefix}{$type} = 1;
13991: }
13992: }
13993: } else {
13994: if ($inuse == 1) {
13995: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13996: $changes{$prefix}{$type} = 1;
13997: }
13998: }
13999: } else {
14000: if ($inuse == 1) {
14001: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14002: $changes{$prefix}{$type} = 1;
14003: }
14004: }
14005: } else {
14006: if ($inuse == 1) {
14007: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14008: $changes{$prefix}{$type} = 1;
14009: }
14010: }
14011: }
14012: }
14013: }
1.145 raeburn 14014:
14015: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 14016: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 14017: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
14018: my $savespares;
14019:
14020: foreach my $lonhost (sort(keys(%servers))) {
14021: my $serverhomeID =
14022: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 14023: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 14024: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
14025: my %spareschg;
14026: foreach my $type (@{$types{'spares'}}) {
14027: my @okspares;
14028: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
14029: foreach my $server (@checked) {
1.152 raeburn 14030: if (&Apache::lonnet::hostname($server) ne '') {
14031: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
14032: unless (grep(/^\Q$server\E$/,@okspares)) {
14033: push(@okspares,$server);
14034: }
1.145 raeburn 14035: }
14036: }
14037: }
14038: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
14039: my $newspare;
1.152 raeburn 14040: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
14041: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 14042: $newspare = $new;
14043: }
14044: }
1.152 raeburn 14045: my @spares;
14046: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
14047: @spares = sort(@okspares,$newspare);
14048: } else {
14049: @spares = sort(@okspares);
14050: }
14051: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 14052: if (ref($spareid{$lonhost}) eq 'HASH') {
14053: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 14054: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 14055: if (@diffs > 0) {
14056: $spareschg{$type} = 1;
14057: }
14058: }
14059: }
14060: }
14061: if (keys(%spareschg) > 0) {
14062: $changes{'spares'}{$lonhost} = \%spareschg;
14063: }
14064: }
1.160.6.61 raeburn 14065: $defaultshash{'usersessions'}{'offloadnow'} = {};
14066: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
14067: my @okoffload;
14068: if (@offloadnow) {
14069: foreach my $server (@offloadnow) {
14070: if (&Apache::lonnet::hostname($server) ne '') {
14071: unless (grep(/^\Q$server\E$/,@okoffload)) {
14072: push(@okoffload,$server);
14073: }
14074: }
14075: }
14076: if (@okoffload) {
14077: foreach my $lonhost (@okoffload) {
14078: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
14079: }
14080: }
14081: }
1.145 raeburn 14082: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14083: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
14084: if (ref($changes{'spares'}) eq 'HASH') {
14085: if (keys(%{$changes{'spares'}}) > 0) {
14086: $savespares = 1;
14087: }
14088: }
14089: } else {
14090: $savespares = 1;
14091: }
1.160.6.61 raeburn 14092: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
14093: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
14094: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
14095: $changes{'offloadnow'} = 1;
14096: last;
14097: }
14098: }
14099: unless ($changes{'offloadnow'}) {
14100: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
14101: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
14102: $changes{'offloadnow'} = 1;
14103: last;
14104: }
14105: }
14106: }
14107: } elsif (@okoffload) {
14108: $changes{'offloadnow'} = 1;
14109: }
14110: } elsif (@okoffload) {
14111: $changes{'offloadnow'} = 1;
1.145 raeburn 14112: }
1.147 raeburn 14113: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
14114: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 14115: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14116: $dom);
14117: if ($putresult eq 'ok') {
14118: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14119: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
14120: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
14121: }
14122: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
14123: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
14124: }
1.160.6.61 raeburn 14125: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
14126: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
14127: }
1.137 raeburn 14128: }
14129: my $cachetime = 24*60*60;
14130: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 14131: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 14132: if (ref($lastactref) eq 'HASH') {
14133: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 14134: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 14135: }
1.147 raeburn 14136: if (keys(%changes) > 0) {
14137: my %lt = &usersession_titles();
14138: $resulttext = &mt('Changes made:').'<ul>';
14139: foreach my $prefix (@prefixes) {
14140: if (ref($changes{$prefix}) eq 'HASH') {
14141: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14142: if ($prefix eq 'spares') {
14143: if (ref($changes{$prefix}) eq 'HASH') {
14144: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
14145: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 14146: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 14147: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
14148: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 14149: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
14150: foreach my $type (@{$types{$prefix}}) {
14151: if ($changes{$prefix}{$lonhost}{$type}) {
14152: my $offloadto = &mt('None');
14153: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
14154: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
14155: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
14156: }
1.145 raeburn 14157: }
1.147 raeburn 14158: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 14159: }
1.137 raeburn 14160: }
14161: }
1.147 raeburn 14162: $resulttext .= '</li>';
1.137 raeburn 14163: }
14164: }
1.147 raeburn 14165: } else {
14166: foreach my $type (@{$types{$prefix}}) {
14167: if (defined($changes{$prefix}{$type})) {
14168: my $newvalue;
14169: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14170: if (ref($defaultshash{'usersessions'}{$prefix})) {
14171: if ($type eq 'version') {
14172: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
14173: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14174: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
14175: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
14176: }
1.145 raeburn 14177: }
14178: }
14179: }
1.147 raeburn 14180: if ($newvalue eq '') {
14181: if ($type eq 'version') {
14182: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
14183: } else {
14184: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14185: }
1.145 raeburn 14186: } else {
1.147 raeburn 14187: if ($type eq 'version') {
14188: $newvalue .= ' '.&mt('(or later)');
14189: }
14190: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 14191: }
1.137 raeburn 14192: }
14193: }
14194: }
1.147 raeburn 14195: $resulttext .= '</ul>';
1.137 raeburn 14196: }
14197: }
1.160.6.61 raeburn 14198: if ($changes{'offloadnow'}) {
14199: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
14200: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
14201: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
14202: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
14203: $resulttext .= '<li>'.$lonhost.'</li>';
14204: }
14205: $resulttext .= '</ul>';
14206: } else {
14207: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
14208: }
14209: } else {
14210: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
14211: }
14212: }
1.147 raeburn 14213: $resulttext .= '</ul>';
14214: } else {
14215: $resulttext = $nochgmsg;
1.137 raeburn 14216: }
14217: } else {
14218: $resulttext = '<span class="LC_error">'.
14219: &mt('An error occurred: [_1]',$putresult).'</span>';
14220: }
14221: } else {
1.147 raeburn 14222: $resulttext = $nochgmsg;
1.137 raeburn 14223: }
14224: return $resulttext;
14225: }
14226:
1.150 raeburn 14227: sub modify_loadbalancing {
14228: my ($dom,%domconfig) = @_;
14229: my $primary_id = &Apache::lonnet::domain($dom,'primary');
14230: my $intdom = &Apache::lonnet::internet_dom($primary_id);
14231: my ($othertitle,$usertypes,$types) =
14232: &Apache::loncommon::sorted_inst_types($dom);
14233: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 14234: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 14235: my @sparestypes = ('primary','default');
14236: my %typetitles = &sparestype_titles();
14237: my $resulttext;
1.160.6.7 raeburn 14238: my (%currbalancer,%currtargets,%currrules,%existing);
14239: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14240: %existing = %{$domconfig{'loadbalancing'}};
14241: }
14242: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
14243: \%currtargets,\%currrules);
14244: my ($saveloadbalancing,%defaultshash,%changes);
14245: my ($alltypes,$othertypes,$titles) =
14246: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
14247: my %ruletitles = &offloadtype_text();
14248: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
14249: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
14250: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
14251: if ($balancer eq '') {
14252: next;
14253: }
14254: if (!exists($servers{$balancer})) {
14255: if (exists($currbalancer{$balancer})) {
14256: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 14257: }
1.160.6.7 raeburn 14258: next;
14259: }
14260: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
14261: push(@{$changes{'delete'}},$balancer);
14262: next;
14263: }
14264: if (!exists($currbalancer{$balancer})) {
14265: push(@{$changes{'add'}},$balancer);
14266: }
14267: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
14268: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
14269: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
14270: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14271: $saveloadbalancing = 1;
14272: }
14273: foreach my $sparetype (@sparestypes) {
14274: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
14275: my @offloadto;
14276: foreach my $target (@targets) {
14277: if (($servers{$target}) && ($target ne $balancer)) {
14278: if ($sparetype eq 'default') {
14279: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
14280: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 14281: }
14282: }
1.160.6.7 raeburn 14283: unless(grep(/^\Q$target\E$/,@offloadto)) {
14284: push(@offloadto,$target);
14285: }
1.150 raeburn 14286: }
14287: }
1.160.6.76 raeburn 14288: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
14289: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
14290: push(@offloadto,$balancer);
14291: }
14292: }
14293: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 14294: }
1.160.6.7 raeburn 14295: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 14296: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 14297: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
14298: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 14299: if (@targetdiffs > 0) {
1.160.6.7 raeburn 14300: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14301: }
1.160.6.7 raeburn 14302: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14303: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14304: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14305: }
14306: }
14307: }
14308: } else {
1.160.6.7 raeburn 14309: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
14310: foreach my $sparetype (@sparestypes) {
14311: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14312: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14313: $changes{'curr'}{$balancer}{'targets'} = 1;
14314: }
1.150 raeburn 14315: }
14316: }
1.160.6.7 raeburn 14317: }
1.150 raeburn 14318: }
14319: my $ishomedom;
1.160.6.7 raeburn 14320: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
14321: $ishomedom = 1;
1.150 raeburn 14322: }
14323: if (ref($alltypes) eq 'ARRAY') {
14324: foreach my $type (@{$alltypes}) {
14325: my $rule;
1.160.6.7 raeburn 14326: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 14327: (!$ishomedom)) {
1.160.6.7 raeburn 14328: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
14329: }
14330: if ($rule eq 'specific') {
1.160.6.55 raeburn 14331: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
14332: if (exists($servers{$specifiedhost})) {
14333: $rule = $specifiedhost;
14334: }
1.150 raeburn 14335: }
1.160.6.7 raeburn 14336: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
14337: if (ref($currrules{$balancer}) eq 'HASH') {
14338: if ($rule ne $currrules{$balancer}{$type}) {
14339: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14340: }
14341: } elsif ($rule ne '') {
1.160.6.7 raeburn 14342: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14343: }
14344: }
14345: }
1.160.6.7 raeburn 14346: }
14347: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
14348: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
14349: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
14350: $defaultshash{'loadbalancing'} = {};
14351: }
14352: my $putresult = &Apache::lonnet::put_dom('configuration',
14353: \%defaultshash,$dom);
14354: if ($putresult eq 'ok') {
14355: if (keys(%changes) > 0) {
1.160.6.54 raeburn 14356: my %toupdate;
1.160.6.7 raeburn 14357: if (ref($changes{'delete'}) eq 'ARRAY') {
14358: foreach my $balancer (sort(@{$changes{'delete'}})) {
14359: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 14360: $toupdate{$balancer} = 1;
1.150 raeburn 14361: }
1.160.6.7 raeburn 14362: }
14363: if (ref($changes{'add'}) eq 'ARRAY') {
14364: foreach my $balancer (sort(@{$changes{'add'}})) {
14365: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 14366: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 14367: }
14368: }
14369: if (ref($changes{'curr'}) eq 'HASH') {
14370: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 14371: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 14372: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
14373: if ($changes{'curr'}{$balancer}{'targets'}) {
14374: my %offloadstr;
14375: foreach my $sparetype (@sparestypes) {
14376: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14377: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14378: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14379: }
14380: }
1.150 raeburn 14381: }
1.160.6.7 raeburn 14382: if (keys(%offloadstr) == 0) {
14383: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 14384: } else {
1.160.6.7 raeburn 14385: my $showoffload;
14386: foreach my $sparetype (@sparestypes) {
14387: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
14388: if (defined($offloadstr{$sparetype})) {
14389: $showoffload .= $offloadstr{$sparetype};
14390: } else {
14391: $showoffload .= &mt('None');
14392: }
14393: $showoffload .= (' 'x3);
14394: }
14395: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 14396: }
14397: }
14398: }
1.160.6.7 raeburn 14399: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
14400: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
14401: foreach my $type (@{$alltypes}) {
14402: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
14403: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14404: my $balancetext;
14405: if ($rule eq '') {
14406: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 14407: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 14408: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
14409: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 14410: foreach my $sparetype (@sparestypes) {
14411: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14412: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14413: }
14414: }
1.160.6.55 raeburn 14415: foreach my $item (@{$alltypes}) {
14416: next if ($item =~ /^_LC_ipchange/);
14417: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
14418: if ($hasrule eq 'homeserver') {
14419: map { $toupdate{$_} = 1; } (keys(%libraryservers));
14420: } else {
14421: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
14422: if ($servers{$hasrule}) {
14423: $toupdate{$hasrule} = 1;
14424: }
14425: }
14426: }
14427: }
14428: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
14429: $balancetext = $ruletitles{$rule};
14430: } else {
14431: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14432: $balancetext = $ruletitles{'particular'}.' '.$receiver;
14433: if ($receiver) {
14434: $toupdate{$receiver};
14435: }
14436: }
14437: } else {
14438: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 14439: }
1.160.6.7 raeburn 14440: } else {
14441: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
14442: }
1.160.6.26 raeburn 14443: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 14444: }
14445: }
14446: }
14447: }
1.160.6.54 raeburn 14448: if (keys(%toupdate)) {
14449: my %thismachine;
14450: my $updatedhere;
14451: my $cachetime = 60*60*24;
14452: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
14453: foreach my $lonhost (keys(%toupdate)) {
14454: if ($thismachine{$lonhost}) {
14455: unless ($updatedhere) {
14456: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
14457: $defaultshash{'loadbalancing'},
14458: $cachetime);
14459: $updatedhere = 1;
14460: }
14461: } else {
14462: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
14463: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
14464: }
14465: }
14466: }
1.150 raeburn 14467: }
1.160.6.7 raeburn 14468: }
14469: if ($resulttext ne '') {
14470: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 14471: } else {
14472: $resulttext = $nochgmsg;
14473: }
14474: } else {
1.160.6.7 raeburn 14475: $resulttext = $nochgmsg;
1.150 raeburn 14476: }
14477: } else {
1.160.6.7 raeburn 14478: $resulttext = '<span class="LC_error">'.
14479: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 14480: }
14481: } else {
1.160.6.7 raeburn 14482: $resulttext = $nochgmsg;
1.150 raeburn 14483: }
14484: return $resulttext;
14485: }
14486:
1.48 raeburn 14487: sub recurse_check {
14488: my ($chkcats,$categories,$depth,$name) = @_;
14489: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
14490: my $chg = 0;
14491: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
14492: my $category = $chkcats->[$depth]{$name}[$j];
14493: my $item;
14494: if ($category eq '') {
14495: $chg ++;
14496: } else {
14497: my $deeper = $depth + 1;
14498: $item = &escape($category).':'.&escape($name).':'.$depth;
14499: if ($chg) {
14500: $categories->{$item} -= $chg;
14501: }
14502: &recurse_check($chkcats,$categories,$deeper,$category);
14503: $deeper --;
14504: }
14505: }
14506: }
14507: return;
14508: }
14509:
14510: sub recurse_cat_deletes {
14511: my ($item,$coursecategories,$deletions) = @_;
14512: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14513: my $subdepth = $depth + 1;
14514: if (ref($coursecategories) eq 'HASH') {
14515: foreach my $subitem (keys(%{$coursecategories})) {
14516: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
14517: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
14518: delete($coursecategories->{$subitem});
14519: $deletions->{$subitem} = 1;
14520: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 14521: }
1.48 raeburn 14522: }
14523: }
14524: return;
14525: }
14526:
1.125 raeburn 14527: sub active_dc_picker {
1.160.6.16 raeburn 14528: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 14529: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 14530: my @domcoord = keys(%domcoords);
14531: if (keys(%currhash)) {
14532: foreach my $dc (keys(%currhash)) {
14533: unless (exists($domcoords{$dc})) {
14534: push(@domcoord,$dc);
14535: }
14536: }
14537: }
14538: @domcoord = sort(@domcoord);
14539: my $numdcs = scalar(@domcoord);
14540: my $rows = 0;
14541: my $table;
1.125 raeburn 14542: if ($numdcs > 1) {
1.160.6.16 raeburn 14543: $table = '<table>';
14544: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 14545: my $rem = $i%($numinrow);
14546: if ($rem == 0) {
14547: if ($i > 0) {
1.160.6.16 raeburn 14548: $table .= '</tr>';
1.125 raeburn 14549: }
1.160.6.16 raeburn 14550: $table .= '<tr>';
14551: $rows ++;
1.125 raeburn 14552: }
1.160.6.16 raeburn 14553: my $check = '';
14554: if ($inputtype eq 'radio') {
14555: if (keys(%currhash) == 0) {
14556: if (!$i) {
14557: $check = ' checked="checked"';
14558: }
14559: } elsif (exists($currhash{$domcoord[$i]})) {
14560: $check = ' checked="checked"';
14561: }
14562: } else {
14563: if (exists($currhash{$domcoord[$i]})) {
14564: $check = ' checked="checked"';
1.125 raeburn 14565: }
14566: }
1.160.6.16 raeburn 14567: if ($i == @domcoord - 1) {
1.125 raeburn 14568: my $colsleft = $numinrow - $rem;
14569: if ($colsleft > 1) {
1.160.6.16 raeburn 14570: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 14571: } else {
1.160.6.16 raeburn 14572: $table .= '<td class="LC_left_item">';
1.125 raeburn 14573: }
14574: } else {
1.160.6.16 raeburn 14575: $table .= '<td class="LC_left_item">';
14576: }
14577: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
14578: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
14579: $table .= '<span class="LC_nobreak"><label>'.
14580: '<input type="'.$inputtype.'" name="'.$name.'"'.
14581: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
14582: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 14583: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 14584: }
1.160.6.33 raeburn 14585: $table .= '</label></span></td>';
1.125 raeburn 14586: }
1.160.6.16 raeburn 14587: $table .= '</tr></table>';
14588: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 14589: my ($dcname,$dcdom) = split(':',$domcoord[0]);
14590: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 14591: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 14592: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 14593: if ($user ne $dcname.':'.$dcdom) {
14594: $table .= ' ('.$dcname.':'.$dcdom.')';
14595: }
1.160.6.16 raeburn 14596: } else {
14597: my $check;
14598: if (exists($currhash{$domcoord[0]})) {
14599: $check = ' checked="checked"';
14600: }
1.160.6.50 raeburn 14601: $table = '<span class="LC_nobreak"><label>'.
14602: '<input type="checkbox" name="'.$name.'" '.
14603: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 14604: if ($user ne $dcname.':'.$dcdom) {
14605: $table .= ' ('.$dcname.':'.$dcdom.')';
14606: }
14607: $table .= '</label></span>';
1.160.6.16 raeburn 14608: $rows ++;
14609: }
1.125 raeburn 14610: }
1.160.6.16 raeburn 14611: return ($numdcs,$table,$rows);
1.125 raeburn 14612: }
14613:
1.137 raeburn 14614: sub usersession_titles {
14615: return &Apache::lonlocal::texthash(
14616: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
14617: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 14618: spares => 'Servers offloaded to, when busy',
1.137 raeburn 14619: version => 'LON-CAPA version requirement',
1.138 raeburn 14620: excludedomain => 'Allow all, but exclude specific domains',
14621: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 14622: primary => 'Primary (checked first)',
1.154 raeburn 14623: default => 'Default',
1.137 raeburn 14624: );
14625: }
14626:
1.152 raeburn 14627: sub id_for_thisdom {
14628: my (%servers) = @_;
14629: my %altids;
14630: foreach my $server (keys(%servers)) {
14631: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
14632: if ($serverhome ne $server) {
14633: $altids{$serverhome} = $server;
14634: }
14635: }
14636: return %altids;
14637: }
14638:
1.150 raeburn 14639: sub count_servers {
14640: my ($currbalancer,%servers) = @_;
14641: my (@spares,$numspares);
14642: foreach my $lonhost (sort(keys(%servers))) {
14643: next if ($currbalancer eq $lonhost);
14644: push(@spares,$lonhost);
14645: }
14646: if ($currbalancer) {
14647: $numspares = scalar(@spares);
14648: } else {
14649: $numspares = scalar(@spares) - 1;
14650: }
14651: return ($numspares,@spares);
14652: }
14653:
14654: sub lonbalance_targets_js {
1.160.6.7 raeburn 14655: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 14656: my $select = &mt('Select');
14657: my ($alltargets,$allishome,$allinsttypes,@alltypes);
14658: if (ref($servers) eq 'HASH') {
14659: $alltargets = join("','",sort(keys(%{$servers})));
14660: my @homedoms;
14661: foreach my $server (sort(keys(%{$servers}))) {
14662: if (&Apache::lonnet::host_domain($server) eq $dom) {
14663: push(@homedoms,'1');
14664: } else {
14665: push(@homedoms,'0');
14666: }
14667: }
14668: $allishome = join("','",@homedoms);
14669: }
14670: if (ref($types) eq 'ARRAY') {
14671: if (@{$types} > 0) {
14672: @alltypes = @{$types};
14673: }
14674: }
14675: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
14676: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 14677: my (%currbalancer,%currtargets,%currrules,%existing);
14678: if (ref($settings) eq 'HASH') {
14679: %existing = %{$settings};
14680: }
14681: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
14682: \%currtargets,\%currrules);
14683: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 14684: return <<"END";
14685:
14686: <script type="text/javascript">
14687: // <![CDATA[
14688:
1.160.6.7 raeburn 14689: currBalancers = new Array('$balancers');
14690:
14691: function toggleTargets(balnum) {
14692: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14693: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
14694: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
14695: var prevbalancer = prevhostitem.value;
14696: var baltotal = document.getElementById('loadbalancing_total').value;
14697: prevhostitem.value = balancer;
14698: if (prevbalancer != '') {
14699: var prevIdx = currBalancers.indexOf(prevbalancer);
14700: if (prevIdx != -1) {
14701: currBalancers.splice(prevIdx,1);
14702: }
14703: }
1.150 raeburn 14704: if (balancer == '') {
1.160.6.7 raeburn 14705: hideSpares(balnum);
1.150 raeburn 14706: } else {
1.160.6.7 raeburn 14707: var currIdx = currBalancers.indexOf(balancer);
14708: if (currIdx == -1) {
14709: currBalancers.push(balancer);
14710: }
1.150 raeburn 14711: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 14712: var ishomedom = homedoms[lonhostitem.selectedIndex];
14713: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 14714: }
1.160.6.7 raeburn 14715: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 14716: return;
14717: }
14718:
1.160.6.7 raeburn 14719: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 14720: var alltargets = new Array('$alltargets');
14721: var insttypes = new Array('$allinsttypes');
1.151 raeburn 14722: var offloadtypes = new Array('primary','default');
14723:
1.160.6.7 raeburn 14724: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
14725: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 14726:
1.151 raeburn 14727: for (var i=0; i<offloadtypes.length; i++) {
14728: var count = 0;
14729: for (var j=0; j<alltargets.length; j++) {
14730: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 14731: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
14732: item.value = alltargets[j];
14733: item.style.textAlign='left';
14734: item.style.textFace='normal';
14735: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
14736: if (currBalancers.indexOf(alltargets[j]) == -1) {
14737: item.disabled = '';
14738: } else {
14739: item.disabled = 'disabled';
14740: item.checked = false;
14741: }
1.151 raeburn 14742: count ++;
14743: }
1.150 raeburn 14744: }
14745: }
1.151 raeburn 14746: for (var k=0; k<insttypes.length; k++) {
14747: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 14748: if (ishomedom == 1) {
1.160.6.7 raeburn 14749: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14750: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14751: } else {
1.160.6.7 raeburn 14752: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14753: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 14754: }
14755: } else {
1.160.6.7 raeburn 14756: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14757: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14758: }
1.151 raeburn 14759: if ((insttypes[k] != '_LC_external') &&
14760: ((insttypes[k] != '_LC_internetdom') ||
14761: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 14762: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
14763: item.options.length = 0;
14764: item.options[0] = new Option("","",true,true);
14765: var idx = 0;
1.151 raeburn 14766: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 14767: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
14768: idx ++;
14769: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 14770: }
14771: }
14772: }
14773: }
14774: return;
14775: }
14776:
1.160.6.7 raeburn 14777: function hideSpares(balnum) {
1.150 raeburn 14778: var alltargets = new Array('$alltargets');
14779: var insttypes = new Array('$allinsttypes');
14780: var offloadtypes = new Array('primary','default');
14781:
1.160.6.7 raeburn 14782: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
14783: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 14784:
14785: var total = alltargets.length - 1;
14786: for (var i=0; i<offloadtypes; i++) {
14787: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 14788: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
14789: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
14790: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 14791: }
1.150 raeburn 14792: }
14793: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 14794: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14795: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 14796: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 14797: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
14798: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 14799: }
14800: }
14801: return;
14802: }
14803:
1.160.6.7 raeburn 14804: function checkOffloads(item,balnum,type) {
1.150 raeburn 14805: var alltargets = new Array('$alltargets');
14806: var offloadtypes = new Array('primary','default');
14807: if (item.checked) {
14808: var total = alltargets.length - 1;
14809: var other;
14810: if (type == offloadtypes[0]) {
1.151 raeburn 14811: other = offloadtypes[1];
1.150 raeburn 14812: } else {
1.151 raeburn 14813: other = offloadtypes[0];
1.150 raeburn 14814: }
14815: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 14816: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 14817: if (server == item.value) {
1.160.6.7 raeburn 14818: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
14819: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 14820: }
14821: }
14822: }
14823: }
14824: return;
14825: }
14826:
1.160.6.7 raeburn 14827: function singleServerToggle(balnum,type) {
14828: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 14829: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 14830: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
14831: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14832:
14833: } else {
1.160.6.7 raeburn 14834: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
14835: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 14836: }
14837: return;
14838: }
14839:
1.160.6.7 raeburn 14840: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 14841: if (type == '_LC_external') {
1.160.6.26 raeburn 14842: return;
1.150 raeburn 14843: }
1.160.6.7 raeburn 14844: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 14845: for (var i=0; i<typesRules.length; i++) {
14846: if (formname.elements[typesRules[i]].checked) {
14847: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 14848: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
14849: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14850: } else {
1.160.6.7 raeburn 14851: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
14852: }
14853: }
14854: }
14855: return;
14856: }
14857:
14858: function balancerDeleteChange(balnum) {
14859: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14860: var baltotal = document.getElementById('loadbalancing_total').value;
14861: var addtarget;
14862: var removetarget;
14863: var action = 'delete';
14864: if (document.getElementById('loadbalancing_delete_'+balnum)) {
14865: var lonhost = hostitem.value;
14866: var currIdx = currBalancers.indexOf(lonhost);
14867: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
14868: if (currIdx != -1) {
14869: currBalancers.splice(currIdx,1);
14870: }
14871: addtarget = lonhost;
14872: } else {
14873: if (currIdx == -1) {
14874: currBalancers.push(lonhost);
14875: }
14876: removetarget = lonhost;
14877: action = 'undelete';
14878: }
14879: balancerChange(balnum,baltotal,action,addtarget,removetarget);
14880: }
14881: return;
14882: }
14883:
14884: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
14885: if (baltotal > 1) {
14886: var offloadtypes = new Array('primary','default');
14887: var alltargets = new Array('$alltargets');
14888: var insttypes = new Array('$allinsttypes');
14889: for (var i=0; i<baltotal; i++) {
14890: if (i != balnum) {
14891: for (var j=0; j<offloadtypes.length; j++) {
14892: var total = alltargets.length - 1;
14893: for (var k=0; k<total; k++) {
14894: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
14895: var server = serveritem.value;
14896: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14897: if (server == addtarget) {
14898: serveritem.disabled = '';
14899: }
14900: }
14901: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14902: if (server == removetarget) {
14903: serveritem.disabled = 'disabled';
14904: serveritem.checked = false;
14905: }
14906: }
14907: }
14908: }
14909: for (var j=0; j<insttypes.length; j++) {
14910: if (insttypes[j] != '_LC_external') {
14911: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
14912: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
14913: var currSel = singleserver.selectedIndex;
14914: var currVal = singleserver.options[currSel].value;
14915: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14916: var numoptions = singleserver.options.length;
14917: var needsnew = 1;
14918: for (var k=0; k<numoptions; k++) {
14919: if (singleserver.options[k] == addtarget) {
14920: needsnew = 0;
14921: break;
14922: }
14923: }
14924: if (needsnew == 1) {
14925: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
14926: }
14927: }
14928: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14929: singleserver.options.length = 0;
14930: if ((currVal) && (currVal != removetarget)) {
14931: singleserver.options[0] = new Option("","",false,false);
14932: } else {
14933: singleserver.options[0] = new Option("","",true,true);
14934: }
14935: var idx = 0;
14936: for (var m=0; m<alltargets.length; m++) {
14937: if (currBalancers.indexOf(alltargets[m]) == -1) {
14938: idx ++;
14939: if (currVal == alltargets[m]) {
14940: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
14941: } else {
14942: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
14943: }
14944: }
14945: }
14946: }
14947: }
14948: }
14949: }
1.150 raeburn 14950: }
14951: }
14952: }
14953: return;
14954: }
14955:
1.152 raeburn 14956: // ]]>
14957: </script>
14958:
14959: END
14960: }
14961:
14962: sub new_spares_js {
14963: my @sparestypes = ('primary','default');
14964: my $types = join("','",@sparestypes);
14965: my $select = &mt('Select');
14966: return <<"END";
14967:
14968: <script type="text/javascript">
14969: // <![CDATA[
14970:
14971: function updateNewSpares(formname,lonhost) {
14972: var types = new Array('$types');
14973: var include = new Array();
14974: var exclude = new Array();
14975: for (var i=0; i<types.length; i++) {
14976: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
14977: for (var j=0; j<spareboxes.length; j++) {
14978: if (formname.elements[spareboxes[j]].checked) {
14979: exclude.push(formname.elements[spareboxes[j]].value);
14980: } else {
14981: include.push(formname.elements[spareboxes[j]].value);
14982: }
14983: }
14984: }
14985: for (var i=0; i<types.length; i++) {
14986: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
14987: var selIdx = newSpare.selectedIndex;
14988: var currnew = newSpare.options[selIdx].value;
14989: var okSpares = new Array();
14990: for (var j=0; j<newSpare.options.length; j++) {
14991: var possible = newSpare.options[j].value;
14992: if (possible != '') {
14993: if (exclude.indexOf(possible) == -1) {
14994: okSpares.push(possible);
14995: } else {
14996: if (currnew == possible) {
14997: selIdx = 0;
14998: }
14999: }
15000: }
15001: }
15002: for (var k=0; k<include.length; k++) {
15003: if (okSpares.indexOf(include[k]) == -1) {
15004: okSpares.push(include[k]);
15005: }
15006: }
15007: okSpares.sort();
15008: newSpare.options.length = 0;
15009: if (selIdx == 0) {
15010: newSpare.options[0] = new Option("$select","",true,true);
15011: } else {
15012: newSpare.options[0] = new Option("$select","",false,false);
15013: }
15014: for (var m=0; m<okSpares.length; m++) {
15015: var idx = m+1;
15016: var selThis = 0;
15017: if (selIdx != 0) {
15018: if (okSpares[m] == currnew) {
15019: selThis = 1;
15020: }
15021: }
15022: if (selThis == 1) {
15023: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
15024: } else {
15025: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
15026: }
15027: }
15028: }
15029: return;
15030: }
15031:
15032: function checkNewSpares(lonhost,type) {
15033: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
15034: var chosen = newSpare.options[newSpare.selectedIndex].value;
15035: if (chosen != '') {
15036: var othertype;
15037: var othernewSpare;
15038: if (type == 'primary') {
15039: othernewSpare = document.getElementById('newspare_default_'+lonhost);
15040: }
15041: if (type == 'default') {
15042: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
15043: }
15044: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
15045: othernewSpare.selectedIndex = 0;
15046: }
15047: }
15048: return;
15049: }
15050:
15051: // ]]>
15052: </script>
15053:
15054: END
15055:
15056: }
15057:
15058: sub common_domprefs_js {
15059: return <<"END";
15060:
15061: <script type="text/javascript">
15062: // <![CDATA[
15063:
1.150 raeburn 15064: function getIndicesByName(formname,item) {
1.152 raeburn 15065: var group = new Array();
1.150 raeburn 15066: for (var i=0;i<formname.elements.length;i++) {
15067: if (formname.elements[i].name == item) {
1.152 raeburn 15068: group.push(formname.elements[i].id);
1.150 raeburn 15069: }
15070: }
1.152 raeburn 15071: return group;
1.150 raeburn 15072: }
15073:
15074: // ]]>
15075: </script>
15076:
15077: END
1.152 raeburn 15078:
1.150 raeburn 15079: }
15080:
1.160.6.5 raeburn 15081: sub recaptcha_js {
15082: my %lt = &captcha_phrases();
15083: return <<"END";
15084:
15085: <script type="text/javascript">
15086: // <![CDATA[
15087:
15088: function updateCaptcha(caller,context) {
15089: var privitem;
15090: var pubitem;
15091: var privtext;
15092: var pubtext;
1.160.6.69 raeburn 15093: var versionitem;
15094: var versiontext;
1.160.6.5 raeburn 15095: if (document.getElementById(context+'_recaptchapub')) {
15096: pubitem = document.getElementById(context+'_recaptchapub');
15097: } else {
15098: return;
15099: }
15100: if (document.getElementById(context+'_recaptchapriv')) {
15101: privitem = document.getElementById(context+'_recaptchapriv');
15102: } else {
15103: return;
15104: }
15105: if (document.getElementById(context+'_recaptchapubtxt')) {
15106: pubtext = document.getElementById(context+'_recaptchapubtxt');
15107: } else {
15108: return;
15109: }
15110: if (document.getElementById(context+'_recaptchaprivtxt')) {
15111: privtext = document.getElementById(context+'_recaptchaprivtxt');
15112: } else {
15113: return;
15114: }
1.160.6.69 raeburn 15115: if (document.getElementById(context+'_recaptchaversion')) {
15116: versionitem = document.getElementById(context+'_recaptchaversion');
15117: } else {
15118: return;
15119: }
15120: if (document.getElementById(context+'_recaptchavertxt')) {
15121: versiontext = document.getElementById(context+'_recaptchavertxt');
15122: } else {
15123: return;
15124: }
1.160.6.5 raeburn 15125: if (caller.checked) {
15126: if (caller.value == 'recaptcha') {
15127: pubitem.type = 'text';
15128: privitem.type = 'text';
15129: pubitem.size = '40';
15130: privitem.size = '40';
15131: pubtext.innerHTML = "$lt{'pub'}";
15132: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 15133: versionitem.type = 'text';
15134: versionitem.size = '3';
15135: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 15136: } else {
15137: pubitem.type = 'hidden';
15138: privitem.type = 'hidden';
1.160.6.69 raeburn 15139: versionitem.type = 'hidden';
1.160.6.5 raeburn 15140: pubtext.innerHTML = '';
15141: privtext.innerHTML = '';
1.160.6.69 raeburn 15142: versiontext.innerHTML = '';
1.160.6.5 raeburn 15143: }
15144: }
15145: return;
15146: }
15147:
15148: // ]]>
15149: </script>
15150:
15151: END
15152:
15153: }
15154:
1.160.6.40 raeburn 15155: sub toggle_display_js {
1.160.6.16 raeburn 15156: return <<"END";
15157:
15158: <script type="text/javascript">
15159: // <![CDATA[
15160:
1.160.6.40 raeburn 15161: function toggleDisplay(domForm,caller) {
15162: if (document.getElementById(caller)) {
15163: var divitem = document.getElementById(caller);
15164: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 15165: var checkval = 1;
15166: var dispval = 'block';
1.160.6.40 raeburn 15167: if (caller == 'emailoptions') {
15168: optionsElement = domForm.cancreate_email;
15169: }
1.160.6.57 raeburn 15170: if (caller == 'studentsubmission') {
15171: optionsElement = domForm.postsubmit;
15172: }
1.160.6.64 raeburn 15173: if (caller == 'cloneinstcode') {
15174: optionsElement = domForm.canclone;
15175: checkval = 'instcode';
15176: }
1.160.6.40 raeburn 15177: if (optionsElement.length) {
1.160.6.16 raeburn 15178: var currval;
1.160.6.40 raeburn 15179: for (var i=0; i<optionsElement.length; i++) {
15180: if (optionsElement[i].checked) {
15181: currval = optionsElement[i].value;
1.160.6.16 raeburn 15182: }
15183: }
1.160.6.64 raeburn 15184: if (currval == checkval) {
15185: divitem.style.display = dispval;
1.160.6.16 raeburn 15186: } else {
1.160.6.40 raeburn 15187: divitem.style.display = 'none';
1.160.6.16 raeburn 15188: }
15189: }
15190: }
15191: return;
15192: }
15193:
15194: // ]]>
15195: </script>
15196:
15197: END
15198:
15199: }
15200:
1.160.6.5 raeburn 15201: sub captcha_phrases {
15202: return &Apache::lonlocal::texthash (
15203: priv => 'Private key',
15204: pub => 'Public key',
15205: original => 'original (CAPTCHA)',
15206: recaptcha => 'successor (ReCAPTCHA)',
15207: notused => 'unused',
1.160.6.69 raeburn 15208: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 15209: );
15210: }
15211:
1.160.6.24 raeburn 15212: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 15213: my ($dom,$cachekeys) = @_;
15214: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 15215: my %servers = &Apache::lonnet::internet_dom_servers($dom);
15216: my %thismachine;
15217: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.84.2. (raeburn 15218:): my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.160.6.61 raeburn 15219: if (keys(%servers)) {
1.160.6.24 raeburn 15220: foreach my $server (keys(%servers)) {
15221: next if ($thismachine{$server});
1.160.6.27 raeburn 15222: my @cached;
15223: foreach my $name (@posscached) {
15224: if ($cachekeys->{$name}) {
15225: push(@cached,&escape($name).':'.&escape($dom));
15226: }
15227: }
15228: if (@cached) {
15229: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
15230: }
1.160.6.24 raeburn 15231: }
15232: }
15233: return;
15234: }
15235:
1.3 raeburn 15236: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>