Annotation of loncom/interface/domainprefs.pm, revision 1.301
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.301 ! raeburn 4: # $Id: domainprefs.pm,v 1.300 2017/05/22 07:58:46 droeschl Exp $
1.2 albertel 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.286 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.297 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.183 bisitz 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.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 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.197 raeburn 98: used by course owners to request creation of a course, and to display/store
1.223 bisitz 99: default quota sizes for Authoring Spaces.
1.101 raeburn 100:
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.271 raeburn 107: (official, unofficial, community, textbook, and placement).
108: In each case the radio buttons 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.232 raeburn 168: use Apache::lonuserutils();
1.235 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.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.1 raeburn 179:
1.155 raeburn 180: my $registered_cleanup;
181: my $modified_urls;
182:
1.1 raeburn 183: sub handler {
184: my $r=shift;
185: if ($r->header_only) {
186: &Apache::loncommon::content_type($r,'text/html');
187: $r->send_http_header;
188: return OK;
189: }
190:
1.91 raeburn 191: my $context = 'domain';
1.1 raeburn 192: my $dom = $env{'request.role.domain'};
1.5 albertel 193: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 194: if (&Apache::lonnet::allowed('mau',$dom)) {
195: &Apache::loncommon::content_type($r,'text/html');
196: $r->send_http_header;
197: } else {
198: $env{'user.error.msg'}=
199: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
200: return HTTP_NOT_ACCEPTABLE;
201: }
1.155 raeburn 202:
203: $registered_cleanup=0;
204: @{$modified_urls}=();
205:
1.1 raeburn 206: &Apache::lonhtmlcommon::clear_breadcrumbs();
207: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 208: ['phase','actions']);
1.30 raeburn 209: my $phase = 'pickactions';
1.3 raeburn 210: if ( exists($env{'form.phase'}) ) {
211: $phase = $env{'form.phase'};
212: }
1.150 raeburn 213: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 214: my %domconfig =
1.6 raeburn 215: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 216: 'quotas','autoenroll','autoupdate','autocreate',
217: 'directorysrch','usercreation','usermodification',
218: 'contacts','defaults','scantron','coursecategories',
219: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 220: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 221: 'requestauthor','selfenrollment','inststatus',
1.279 raeburn 222: 'ltitools','ssl','trust'],$dom);
1.297 raeburn 223: if (ref($domconfig{'ltitools'}) eq 'HASH') {
224: my %encconfig =
225: &Apache::lonnet::get_dom('encconfig',['ltitools'],$dom);
226: if (ref($encconfig{'ltitools'}) eq 'HASH') {
227: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
228: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
229: foreach my $item ('key','secret') {
230: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
231: }
232: }
233: }
234: }
235: }
1.43 raeburn 236: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 237: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 238: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 239: 'requestcourses','requestauthor','coursecategories',
1.267 raeburn 240: 'serverstatuses','helpsettings','coursedefaults',
1.279 raeburn 241: 'ltitools','selfenrollment','usersessions','ssl','trust');
1.171 raeburn 242: my %existing;
243: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
244: %existing = %{$domconfig{'loadbalancing'}};
245: }
246: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 247: push(@prefs_order,'loadbalancing');
248: }
1.30 raeburn 249: my %prefs = (
250: 'rolecolors' =>
251: { text => 'Default color schemes',
1.67 raeburn 252: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 253: header => [{col1 => 'Student Settings',
254: col2 => '',},
255: {col1 => 'Coordinator Settings',
256: col2 => '',},
257: {col1 => 'Author Settings',
258: col2 => '',},
259: {col1 => 'Administrator Settings',
260: col2 => '',}],
1.230 raeburn 261: print => \&print_rolecolors,
262: modify => \&modify_rolecolors,
1.30 raeburn 263: },
1.110 raeburn 264: 'login' =>
1.30 raeburn 265: { text => 'Log-in page options',
1.67 raeburn 266: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 267: header => [{col1 => 'Log-in Page Items',
268: col2 => '',},
269: {col1 => 'Log-in Help',
1.256 raeburn 270: col2 => 'Value'},
271: {col1 => 'Custom HTML in document head',
1.168 raeburn 272: col2 => 'Value'}],
1.230 raeburn 273: print => \&print_login,
274: modify => \&modify_login,
1.30 raeburn 275: },
1.43 raeburn 276: 'defaults' =>
1.236 raeburn 277: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 278: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 279: header => [{col1 => 'Setting',
1.236 raeburn 280: col2 => 'Value'},
1.294 raeburn 281: {col1 => 'Internal Authentication',
282: col2 => 'Value'},
1.236 raeburn 283: {col1 => 'Institutional user types',
284: col2 => 'Assignable to e-mail usernames'}],
1.230 raeburn 285: print => \&print_defaults,
286: modify => \&modify_defaults,
1.43 raeburn 287: },
1.30 raeburn 288: 'quotas' =>
1.197 raeburn 289: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 290: help => 'Domain_Configuration_Quotas',
1.77 raeburn 291: header => [{col1 => 'User affiliation',
1.72 raeburn 292: col2 => 'Available tools',
1.213 raeburn 293: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 294: print => \&print_quotas,
295: modify => \&modify_quotas,
1.30 raeburn 296: },
297: 'autoenroll' =>
298: { text => 'Auto-enrollment settings',
1.67 raeburn 299: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 300: header => [{col1 => 'Configuration setting',
301: col2 => 'Value(s)'}],
1.230 raeburn 302: print => \&print_autoenroll,
303: modify => \&modify_autoenroll,
1.30 raeburn 304: },
305: 'autoupdate' =>
306: { text => 'Auto-update settings',
1.67 raeburn 307: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 308: header => [{col1 => 'Setting',
309: col2 => 'Value',},
1.131 raeburn 310: {col1 => 'Setting',
311: col2 => 'Affiliation'},
1.43 raeburn 312: {col1 => 'User population',
1.227 bisitz 313: col2 => 'Updatable user data'}],
1.230 raeburn 314: print => \&print_autoupdate,
315: modify => \&modify_autoupdate,
1.30 raeburn 316: },
1.125 raeburn 317: 'autocreate' =>
318: { text => 'Auto-course creation settings',
319: help => 'Domain_Configuration_Auto_Creation',
320: header => [{col1 => 'Configuration Setting',
321: col2 => 'Value',}],
1.230 raeburn 322: print => \&print_autocreate,
323: modify => \&modify_autocreate,
1.125 raeburn 324: },
1.30 raeburn 325: 'directorysrch' =>
1.277 raeburn 326: { text => 'Directory searches',
1.67 raeburn 327: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 328: header => [{col1 => 'Institutional Directory Setting',
329: col2 => 'Value',},
330: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 331: col2 => 'Value',}],
1.230 raeburn 332: print => \&print_directorysrch,
333: modify => \&modify_directorysrch,
1.30 raeburn 334: },
335: 'contacts' =>
1.286 raeburn 336: { text => 'E-mail addresses and helpform',
1.67 raeburn 337: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 338: header => [{col1 => 'Default e-mail addresses',
339: col2 => 'Value',},
340: {col1 => 'Recipient(s) for notifications',
341: col2 => 'Value',},
342: {col1 => 'Ask helpdesk form settings',
343: col2 => 'Value',},],
1.230 raeburn 344: print => \&print_contacts,
345: modify => \&modify_contacts,
1.30 raeburn 346: },
347: 'usercreation' =>
348: { text => 'User creation',
1.67 raeburn 349: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 350: header => [{col1 => 'Format rule type',
351: col2 => 'Format rules in force'},
1.34 raeburn 352: {col1 => 'User account creation',
353: col2 => 'Usernames which may be created',},
1.30 raeburn 354: {col1 => 'Context',
1.43 raeburn 355: col2 => 'Assignable authentication types'}],
1.230 raeburn 356: print => \&print_usercreation,
357: modify => \&modify_usercreation,
1.30 raeburn 358: },
1.224 raeburn 359: 'selfcreation' =>
360: { text => 'Users self-creating accounts',
361: help => 'Domain_Configuration_Self_Creation',
362: header => [{col1 => 'Self-creation with institutional username',
363: col2 => 'Enabled?'},
364: {col1 => 'Institutional user type (login/SSO self-creation)',
365: col2 => 'Information user can enter'},
366: {col1 => 'Self-creation with e-mail as username',
367: col2 => 'Settings'}],
1.230 raeburn 368: print => \&print_selfcreation,
369: modify => \&modify_selfcreation,
1.224 raeburn 370: },
1.69 raeburn 371: 'usermodification' =>
1.33 raeburn 372: { text => 'User modification',
1.67 raeburn 373: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 374: header => [{col1 => 'Target user has role',
1.227 bisitz 375: col2 => 'User information updatable in author context'},
1.33 raeburn 376: {col1 => 'Target user has role',
1.227 bisitz 377: col2 => 'User information updatable in course context'}],
1.230 raeburn 378: print => \&print_usermodification,
379: modify => \&modify_usermodification,
1.33 raeburn 380: },
1.69 raeburn 381: 'scantron' =>
1.95 www 382: { text => 'Bubblesheet format file',
1.67 raeburn 383: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 384: header => [ {col1 => 'Item',
385: col2 => '',
386: }],
1.230 raeburn 387: print => \&print_scantron,
388: modify => \&modify_scantron,
1.46 raeburn 389: },
1.86 raeburn 390: 'requestcourses' =>
391: {text => 'Request creation of courses',
392: help => 'Domain_Configuration_Request_Courses',
393: header => [{col1 => 'User affiliation',
1.102 raeburn 394: col2 => 'Availability/Processing of requests',},
395: {col1 => 'Setting',
1.216 raeburn 396: col2 => 'Value'},
397: {col1 => 'Available textbooks',
1.235 raeburn 398: col2 => ''},
1.242 raeburn 399: {col1 => 'Available templates',
400: col2 => ''},
1.235 raeburn 401: {col1 => 'Validation (not official courses)',
402: col2 => 'Value'},],
1.230 raeburn 403: print => \&print_quotas,
404: modify => \&modify_quotas,
1.86 raeburn 405: },
1.163 raeburn 406: 'requestauthor' =>
1.223 bisitz 407: {text => 'Request Authoring Space',
1.163 raeburn 408: help => 'Domain_Configuration_Request_Author',
409: header => [{col1 => 'User affiliation',
410: col2 => 'Availability/Processing of requests',},
411: {col1 => 'Setting',
412: col2 => 'Value'}],
1.230 raeburn 413: print => \&print_quotas,
414: modify => \&modify_quotas,
1.163 raeburn 415: },
1.69 raeburn 416: 'coursecategories' =>
1.120 raeburn 417: { text => 'Cataloging of courses/communities',
1.67 raeburn 418: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 419: header => [{col1 => 'Catalog type/availability',
420: col2 => '',},
421: {col1 => 'Category settings for standard catalog',
1.57 raeburn 422: col2 => '',},
423: {col1 => 'Categories',
424: col2 => '',
425: }],
1.230 raeburn 426: print => \&print_coursecategories,
427: modify => \&modify_coursecategories,
1.69 raeburn 428: },
429: 'serverstatuses' =>
1.77 raeburn 430: {text => 'Access to server status pages',
1.69 raeburn 431: help => 'Domain_Configuration_Server_Status',
432: header => [{col1 => 'Status Page',
433: col2 => 'Other named users',
434: col3 => 'Specific IPs',
435: }],
1.230 raeburn 436: print => \&print_serverstatuses,
437: modify => \&modify_serverstatuses,
1.69 raeburn 438: },
1.118 jms 439: 'helpsettings' =>
1.282 raeburn 440: {text => 'Support settings',
1.118 jms 441: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 442: header => [{col1 => 'Help Page Settings (logged-in users)',
443: col2 => 'Value'},
444: {col1 => 'Helpdesk Roles',
445: col2 => 'Settings'},],
1.230 raeburn 446: print => \&print_helpsettings,
447: modify => \&modify_helpsettings,
1.118 jms 448: },
1.121 raeburn 449: 'coursedefaults' =>
450: {text => 'Course/Community defaults',
451: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 452: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
453: col2 => 'Value',},
454: {col1 => 'Defaults which can be overridden for each course by a DC',
455: col2 => 'Value',},],
1.230 raeburn 456: print => \&print_coursedefaults,
457: modify => \&modify_coursedefaults,
1.121 raeburn 458: },
1.231 raeburn 459: 'selfenrollment' =>
460: {text => 'Self-enrollment in Course/Community',
461: help => 'Domain_Configuration_Selfenrollment',
462: header => [{col1 => 'Configuration Rights',
463: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
464: {col1 => 'Defaults',
465: col2 => 'Value'},
466: {col1 => 'Self-enrollment validation (optional)',
467: col2 => 'Value'},],
468: print => \&print_selfenrollment,
469: modify => \&modify_selfenrollment,
470: },
1.120 raeburn 471: 'privacy' =>
472: {text => 'User Privacy',
473: help => 'Domain_Configuration_User_Privacy',
474: header => [{col1 => 'Setting',
475: col2 => 'Value',}],
1.230 raeburn 476: print => \&print_privacy,
477: modify => \&modify_privacy,
1.120 raeburn 478: },
1.141 raeburn 479: 'usersessions' =>
1.145 raeburn 480: {text => 'User session hosting/offloading',
1.137 raeburn 481: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 482: header => [{col1 => 'Domain server',
483: col2 => 'Servers to offload sessions to when busy'},
484: {col1 => 'Hosting of users from other domains',
1.137 raeburn 485: col2 => 'Rules'},
486: {col1 => "Hosting domain's own users elsewhere",
487: col2 => 'Rules'}],
1.230 raeburn 488: print => \&print_usersessions,
489: modify => \&modify_usersessions,
1.137 raeburn 490: },
1.279 raeburn 491: 'loadbalancing' =>
1.185 raeburn 492: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 493: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 494: header => [{col1 => 'Balancers',
1.150 raeburn 495: col2 => 'Default destinations',
1.183 bisitz 496: col3 => 'User affiliation',
1.150 raeburn 497: col4 => 'Overrides'},
498: ],
1.230 raeburn 499: print => \&print_loadbalancing,
500: modify => \&modify_loadbalancing,
1.150 raeburn 501: },
1.279 raeburn 502: 'ltitools' =>
1.267 raeburn 503: {text => 'External Tools (LTI)',
1.296 raeburn 504: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 505: header => [{col1 => 'Setting',
506: col2 => 'Value',}],
507: print => \&print_ltitools,
508: modify => \&modify_ltitools,
509: },
1.279 raeburn 510: 'ssl' =>
1.275 raeburn 511: {text => 'LON-CAPA Network (SSL)',
512: help => 'Domain_Configuration_Network_SSL',
513: header => [{col1 => 'Server',
514: col2 => 'Certificate Status'},
515: {col1 => 'Connections to other servers',
516: col2 => 'Rules'},
1.293 raeburn 517: {col1 => 'Connections from other servers',
518: col2 => 'Rules'},
1.275 raeburn 519: {col1 => "Replicating domain's published content",
520: col2 => 'Rules'}],
521: print => \&print_ssl,
522: modify => \&modify_ssl,
523: },
1.279 raeburn 524: 'trust' =>
525: {text => 'Trust Settings',
526: help => 'Domain_Configuration_Trust',
527: header => [{col1 => "Access to this domain's content by others",
528: col2 => 'Rules'},
529: {col1 => "Access to other domain's content by this domain",
530: col2 => 'Rules'},
531: {col1 => "Enrollment in this domain's courses by others",
532: col2 => 'Rules',},
533: {col1 => "Co-author roles in this domain for others",
534: col2 => 'Rules',},
535: {col1 => "Co-author roles for this domain's users elsewhere",
536: col2 => 'Rules',},
537: {col1 => "Domain roles in this domain assignable to others",
538: col2 => 'Rules'},
539: {col1 => "Course catalog for this domain displayed elsewhere",
540: col2 => 'Rules'},
541: {col1 => "Requests for creation of courses in this domain by others",
542: col2 => 'Rules'},
543: {col1 => "Users in other domains can send messages to this domain",
544: col2 => 'Rules'},],
545: print => \&print_trust,
546: modify => \&modify_trust,
547: },
1.3 raeburn 548: );
1.110 raeburn 549: if (keys(%servers) > 1) {
550: $prefs{'login'} = { text => 'Log-in page options',
551: help => 'Domain_Configuration_Login_Page',
552: header => [{col1 => 'Log-in Service',
553: col2 => 'Server Setting',},
554: {col1 => 'Log-in Page Items',
1.168 raeburn 555: col2 => ''},
556: {col1 => 'Log-in Help',
1.256 raeburn 557: col2 => 'Value'},
558: {col1 => 'Custom HTML in document head',
1.168 raeburn 559: col2 => 'Value'}],
1.230 raeburn 560: print => \&print_login,
561: modify => \&modify_login,
1.110 raeburn 562: };
563: }
1.174 foxr 564:
1.6 raeburn 565: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 566: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 567: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 568: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 569: text=>"Settings to display/modify"});
1.9 raeburn 570: my $confname = $dom.'-domainconfig';
1.174 foxr 571:
1.3 raeburn 572: if ($phase eq 'process') {
1.212 raeburn 573: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
574: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 575: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 576: $r->rflush();
1.212 raeburn 577: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 578: }
1.30 raeburn 579: } elsif ($phase eq 'display') {
1.192 raeburn 580: my $js = &recaptcha_js().
1.236 raeburn 581: &toggle_display_js();
1.171 raeburn 582: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 583: my ($othertitle,$usertypes,$types) =
584: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 585: $js .= &lonbalance_targets_js($dom,$types,\%servers,
586: $domconfig{'loadbalancing'}).
1.170 raeburn 587: &new_spares_js().
588: &common_domprefs_js().
589: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 590: }
1.216 raeburn 591: if (grep(/^requestcourses$/,@actions)) {
592: my $javascript_validations;
593: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
594: $js .= <<END;
595: <script type="text/javascript">
596: $javascript_validations
597: </script>
598: $coursebrowserjs
599: END
600: }
1.286 raeburn 601: if (grep(/^contacts$/,@actions)) {
602: $js .= &contacts_javascript();
603: }
1.150 raeburn 604: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 605: } else {
1.180 raeburn 606: # check if domconfig user exists for the domain.
607: my $servadm = $r->dir_config('lonAdmEMail');
608: my ($configuserok,$author_ok,$switchserver) =
609: &config_check($dom,$confname,$servadm);
610: unless ($configuserok eq 'ok') {
1.181 raeburn 611: &Apache::lonconfigsettings::print_header($r,$phase,$context);
612: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 613: $confname).
1.181 raeburn 614: '<br />'
615: );
1.180 raeburn 616: if ($switchserver) {
1.181 raeburn 617: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
618: '<br />'.
619: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
620: '<br />'.
621: &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).
622: '<br />'.
623: &mt('To do that now, use the following link: [_1]',$switchserver)
624: );
625: } else {
626: $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.').
627: '<br />'.
628: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
629: );
1.180 raeburn 630: }
631: $r->print(&Apache::loncommon::end_page());
632: return OK;
633: }
1.21 raeburn 634: if (keys(%domconfig) == 0) {
635: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 636: my @ids=&Apache::lonnet::current_machine_ids();
637: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 638: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 639: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 640: my $custom_img_count = 0;
641: foreach my $img (@loginimages) {
642: if ($designhash{$dom.'.login.'.$img} ne '') {
643: $custom_img_count ++;
644: }
645: }
646: foreach my $role (@roles) {
647: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
648: $custom_img_count ++;
649: }
650: }
651: if ($custom_img_count > 0) {
1.94 raeburn 652: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 653: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 654: $r->print(
655: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
656: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
657: &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 />'.
658: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
659: if ($switch_server) {
1.30 raeburn 660: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 661: }
1.91 raeburn 662: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 663: return OK;
664: }
665: }
666: }
1.91 raeburn 667: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 668: }
669: return OK;
670: }
671:
672: sub process_changes {
1.205 raeburn 673: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 674: my %domconfig;
675: if (ref($values) eq 'HASH') {
676: %domconfig = %{$values};
677: }
1.3 raeburn 678: my $output;
679: if ($action eq 'login') {
1.205 raeburn 680: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 681: } elsif ($action eq 'rolecolors') {
1.9 raeburn 682: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 683: $lastactref,%domconfig);
1.3 raeburn 684: } elsif ($action eq 'quotas') {
1.216 raeburn 685: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 686: } elsif ($action eq 'autoenroll') {
1.205 raeburn 687: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 688: } elsif ($action eq 'autoupdate') {
689: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 690: } elsif ($action eq 'autocreate') {
691: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 692: } elsif ($action eq 'directorysrch') {
1.295 raeburn 693: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 694: } elsif ($action eq 'usercreation') {
1.28 raeburn 695: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 696: } elsif ($action eq 'selfcreation') {
697: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 698: } elsif ($action eq 'usermodification') {
699: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 700: } elsif ($action eq 'contacts') {
1.205 raeburn 701: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 702: } elsif ($action eq 'defaults') {
1.212 raeburn 703: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 704: } elsif ($action eq 'scantron') {
1.205 raeburn 705: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 706: } elsif ($action eq 'coursecategories') {
1.239 raeburn 707: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 708: } elsif ($action eq 'serverstatuses') {
709: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 710: } elsif ($action eq 'requestcourses') {
1.216 raeburn 711: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 712: } elsif ($action eq 'requestauthor') {
1.216 raeburn 713: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 714: } elsif ($action eq 'helpsettings') {
1.285 raeburn 715: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 716: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 717: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 718: } elsif ($action eq 'selfenrollment') {
719: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 720: } elsif ($action eq 'usersessions') {
1.212 raeburn 721: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 722: } elsif ($action eq 'loadbalancing') {
723: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 724: } elsif ($action eq 'ltitools') {
725: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 726: } elsif ($action eq 'ssl') {
727: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 728: } elsif ($action eq 'trust') {
729: $output = &modify_trust($dom,$lastactref,%domconfig);
1.3 raeburn 730: }
731: return $output;
732: }
733:
734: sub print_config_box {
1.9 raeburn 735: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 736: my $rowtotal = 0;
1.49 raeburn 737: my $output;
738: if ($action eq 'coursecategories') {
739: $output = &coursecategories_javascript($settings);
1.236 raeburn 740: } elsif ($action eq 'defaults') {
741: $output = &defaults_javascript($settings);
1.282 raeburn 742: } elsif ($action eq 'helpsettings') {
743: my (%privs,%levelscurrent);
744: my %full=();
745: my %levels=(
746: course => {},
747: domain => {},
748: system => {},
749: );
750: my $context = 'domain';
751: my $crstype = 'Course';
752: my $formname = 'display';
753: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
754: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
755: $output =
756: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
757: \@templateroles);
1.91 raeburn 758: }
1.236 raeburn 759: $output .=
1.30 raeburn 760: '<table class="LC_nested_outer">
1.3 raeburn 761: <tr>
1.66 raeburn 762: <th align="left" valign="middle"><span class="LC_nobreak">'.
763: &mt($item->{text}).' '.
764: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
765: '</tr>';
1.30 raeburn 766: $rowtotal ++;
1.110 raeburn 767: my $numheaders = 1;
768: if (ref($item->{'header'}) eq 'ARRAY') {
769: $numheaders = scalar(@{$item->{'header'}});
770: }
771: if ($numheaders > 1) {
1.64 raeburn 772: my $colspan = '';
1.145 raeburn 773: my $rightcolspan = '';
1.238 raeburn 774: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 775: ($action eq 'directorysrch') ||
1.256 raeburn 776: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 777: $colspan = ' colspan="2"';
778: }
1.145 raeburn 779: if ($action eq 'usersessions') {
780: $rightcolspan = ' colspan="3"';
781: }
1.30 raeburn 782: $output .= '
1.3 raeburn 783: <tr>
784: <td>
785: <table class="LC_nested">
786: <tr class="LC_info_row">
1.59 bisitz 787: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 788: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 789: </tr>';
1.69 raeburn 790: $rowtotal ++;
1.230 raeburn 791: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 792: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 793: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 794: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
795: ($action eq 'contacts')) {
1.230 raeburn 796: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 797: } elsif ($action eq 'coursecategories') {
1.230 raeburn 798: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 799: } elsif ($action eq 'login') {
1.256 raeburn 800: if ($numheaders == 4) {
1.168 raeburn 801: $colspan = ' colspan="2"';
802: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
803: } else {
804: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
805: }
1.230 raeburn 806: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 807: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 808: } elsif ($action eq 'rolecolors') {
1.30 raeburn 809: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 810: }
1.30 raeburn 811: $output .= '
1.6 raeburn 812: </table>
813: </td>
814: </tr>
815: <tr>
816: <td>
817: <table class="LC_nested">
818: <tr class="LC_info_row">
1.230 raeburn 819: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 820: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 821: </tr>';
822: $rowtotal ++;
1.230 raeburn 823: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
824: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 825: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.294 raeburn 826: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults')) {
1.238 raeburn 827: if ($action eq 'coursecategories') {
828: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
829: $colspan = ' colspan="2"';
1.279 raeburn 830: } elsif ($action eq 'trust') {
831: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.238 raeburn 832: } else {
833: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
834: }
1.279 raeburn 835: if ($action eq 'trust') {
836: $output .= '
837: </table>
838: </td>
839: </tr>';
840: my @trusthdrs = qw(2 3 4 5 6 7);
841: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
842: for (my $i=0; $i<@trusthdrs; $i++) {
843: $output .= '
844: <tr>
845: <td>
846: <table class="LC_nested">
847: <tr class="LC_info_row">
848: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
849: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
850: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
851: </table>
852: </td>
853: </tr>';
854: }
855: $output .= '
856: <tr>
857: <td>
858: <table class="LC_nested">
859: <tr class="LC_info_row">
860: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
861: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
862: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
863: } else {
864: $output .= '
1.63 raeburn 865: </table>
866: </td>
867: </tr>
868: <tr>
869: <td>
870: <table class="LC_nested">
871: <tr class="LC_info_row">
872: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 873: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 874: </tr>'."\n";
1.279 raeburn 875: if ($action eq 'coursecategories') {
876: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
877: } else {
878: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
879: }
1.238 raeburn 880: }
1.63 raeburn 881: $rowtotal ++;
1.236 raeburn 882: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 883: ($action eq 'defaults') || ($action eq 'directorysrch') ||
884: ($action eq 'helpsettings')) {
1.230 raeburn 885: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.293 raeburn 886: } elsif ($action eq 'ssl') {
887: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
888: </table>
889: </td>
890: </tr>
891: <tr>
892: <td>
893: <table class="LC_nested">
894: <tr class="LC_info_row">
895: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
896: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
897: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
898: </table>
899: </td>
900: </tr>
901: <tr>
902: <td>
903: <table class="LC_nested">
904: <tr class="LC_info_row">
905: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
906: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
907: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 908: } elsif ($action eq 'login') {
1.256 raeburn 909: if ($numheaders == 4) {
1.168 raeburn 910: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
911: </table>
912: </td>
913: </tr>
914: <tr>
915: <td>
916: <table class="LC_nested">
917: <tr class="LC_info_row">
918: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 919: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 920: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
921: $rowtotal ++;
922: } else {
923: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
924: }
1.256 raeburn 925: $output .= '
926: </table>
927: </td>
928: </tr>
929: <tr>
930: <td>
931: <table class="LC_nested">
932: <tr class="LC_info_row">';
933: if ($numheaders == 4) {
934: $output .= '
935: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
936: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
937: </tr>';
938: } else {
939: $output .= '
940: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
941: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
942: </tr>';
943: }
944: $rowtotal ++;
945: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 946: } elsif ($action eq 'requestcourses') {
1.247 raeburn 947: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
948: $rowtotal ++;
949: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 950: </table>
951: </td>
952: </tr>
953: <tr>
954: <td>
955: <table class="LC_nested">
956: <tr class="LC_info_row">
957: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
958: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 959: &textbookcourses_javascript($settings).
960: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
961: </table>
962: </td>
963: </tr>
964: <tr>
965: <td>
966: <table class="LC_nested">
967: <tr class="LC_info_row">
968: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
969: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
970: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 971: </table>
972: </td>
973: </tr>
974: <tr>
975: <td>
976: <table class="LC_nested">
977: <tr class="LC_info_row">
1.242 raeburn 978: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
979: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 980: </tr>'.
981: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 982: } elsif ($action eq 'requestauthor') {
983: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 984: $rowtotal ++;
1.122 jms 985: } elsif ($action eq 'rolecolors') {
1.30 raeburn 986: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 987: </table>
988: </td>
989: </tr>
990: <tr>
991: <td>
992: <table class="LC_nested">
993: <tr class="LC_info_row">
1.69 raeburn 994: <td class="LC_left_item"'.$colspan.' valign="top">'.
995: &mt($item->{'header'}->[2]->{'col1'}).'</td>
996: <td class="LC_right_item" valign="top">'.
997: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 998: </tr>'.
1.30 raeburn 999: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1000: </table>
1001: </td>
1002: </tr>
1003: <tr>
1004: <td>
1005: <table class="LC_nested">
1006: <tr class="LC_info_row">
1.59 bisitz 1007: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1008: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1009: </tr>'.
1.30 raeburn 1010: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1011: $rowtotal += 2;
1.6 raeburn 1012: }
1.3 raeburn 1013: } else {
1.30 raeburn 1014: $output .= '
1.3 raeburn 1015: <tr>
1016: <td>
1017: <table class="LC_nested">
1.30 raeburn 1018: <tr class="LC_info_row">';
1.277 raeburn 1019: if ($action eq 'login') {
1.30 raeburn 1020: $output .= '
1.59 bisitz 1021: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1022: } elsif ($action eq 'serverstatuses') {
1023: $output .= '
1024: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
1025: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1026:
1.6 raeburn 1027: } else {
1.30 raeburn 1028: $output .= '
1.69 raeburn 1029: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1030: }
1.72 raeburn 1031: if (defined($item->{'header'}->[0]->{'col3'})) {
1032: $output .= '<td class="LC_left_item" valign="top">'.
1033: &mt($item->{'header'}->[0]->{'col2'});
1034: if ($action eq 'serverstatuses') {
1035: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1036: }
1.69 raeburn 1037: } else {
1038: $output .= '<td class="LC_right_item" valign="top">'.
1039: &mt($item->{'header'}->[0]->{'col2'});
1040: }
1041: $output .= '</td>';
1042: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1043: if (defined($item->{'header'}->[0]->{'col4'})) {
1044: $output .= '<td class="LC_left_item" valign="top">'.
1045: &mt($item->{'header'}->[0]->{'col3'});
1046: } else {
1047: $output .= '<td class="LC_right_item" valign="top">'.
1048: &mt($item->{'header'}->[0]->{'col3'});
1049: }
1.69 raeburn 1050: if ($action eq 'serverstatuses') {
1051: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1052: }
1053: $output .= '</td>';
1.6 raeburn 1054: }
1.150 raeburn 1055: if ($item->{'header'}->[0]->{'col4'}) {
1056: $output .= '<td class="LC_right_item" valign="top">'.
1057: &mt($item->{'header'}->[0]->{'col4'});
1058: }
1.69 raeburn 1059: $output .= '</tr>';
1.48 raeburn 1060: $rowtotal ++;
1.168 raeburn 1061: if ($action eq 'quotas') {
1.86 raeburn 1062: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1063: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1064: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1065: ($action eq 'ltitools')) {
1.230 raeburn 1066: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 1067: } elsif ($action eq 'scantron') {
1068: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 1069: }
1.3 raeburn 1070: }
1.30 raeburn 1071: $output .= '
1.3 raeburn 1072: </table>
1073: </td>
1074: </tr>
1.30 raeburn 1075: </table><br />';
1076: return ($output,$rowtotal);
1.1 raeburn 1077: }
1078:
1.3 raeburn 1079: sub print_login {
1.168 raeburn 1080: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1081: my ($css_class,$datatable);
1.6 raeburn 1082: my %choices = &login_choices();
1.110 raeburn 1083:
1.168 raeburn 1084: if ($caller eq 'service') {
1.149 raeburn 1085: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1086: my $choice = $choices{'disallowlogin'};
1087: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1088: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1089: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1090: '<th>'.$choices{'server'}.'</th>'.
1091: '<th>'.$choices{'serverpath'}.'</th>'.
1092: '<th>'.$choices{'custompath'}.'</th>'.
1093: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1094: my %disallowed;
1095: if (ref($settings) eq 'HASH') {
1096: if (ref($settings->{'loginvia'}) eq 'HASH') {
1097: %disallowed = %{$settings->{'loginvia'}};
1098: }
1099: }
1100: foreach my $lonhost (sort(keys(%servers))) {
1101: my $direct = 'selected="selected"';
1.128 raeburn 1102: if (ref($disallowed{$lonhost}) eq 'HASH') {
1103: if ($disallowed{$lonhost}{'server'} ne '') {
1104: $direct = '';
1105: }
1.110 raeburn 1106: }
1.115 raeburn 1107: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1108: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1109: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1110: '</option>';
1.184 raeburn 1111: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1112: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1113: my $selected = '';
1.128 raeburn 1114: if (ref($disallowed{$lonhost}) eq 'HASH') {
1115: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1116: $selected = 'selected="selected"';
1117: }
1.110 raeburn 1118: }
1119: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1120: $servers{$hostid}.'</option>';
1121: }
1.128 raeburn 1122: $datatable .= '</select></td>'.
1123: '<td><select name="'.$lonhost.'_serverpath">';
1124: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1125: my $pathname = $path;
1126: if ($path eq 'custom') {
1127: $pathname = &mt('Custom Path').' ->';
1128: }
1129: my $selected = '';
1130: if (ref($disallowed{$lonhost}) eq 'HASH') {
1131: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1132: $selected = 'selected="selected"';
1133: }
1134: } elsif ($path eq '') {
1135: $selected = 'selected="selected"';
1136: }
1137: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1138: }
1139: $datatable .= '</select></td>';
1140: my ($custom,$exempt);
1141: if (ref($disallowed{$lonhost}) eq 'HASH') {
1142: $custom = $disallowed{$lonhost}{'custompath'};
1143: $exempt = $disallowed{$lonhost}{'exempt'};
1144: }
1145: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1146: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1147: '</tr>';
1.110 raeburn 1148: }
1149: $datatable .= '</table></td></tr>';
1150: return $datatable;
1.168 raeburn 1151: } elsif ($caller eq 'page') {
1152: my %defaultchecked = (
1153: 'coursecatalog' => 'on',
1.188 raeburn 1154: 'helpdesk' => 'on',
1.168 raeburn 1155: 'adminmail' => 'off',
1156: 'newuser' => 'off',
1157: );
1.188 raeburn 1158: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1159: my (%checkedon,%checkedoff);
1.42 raeburn 1160: foreach my $item (@toggles) {
1.168 raeburn 1161: if ($defaultchecked{$item} eq 'on') {
1162: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1163: $checkedoff{$item} = ' ';
1.168 raeburn 1164: } elsif ($defaultchecked{$item} eq 'off') {
1165: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1166: $checkedon{$item} = ' ';
1167: }
1.1 raeburn 1168: }
1.168 raeburn 1169: my @images = ('img','logo','domlogo','login');
1170: my @logintext = ('textcol','bgcol');
1171: my @bgs = ('pgbg','mainbg','sidebg');
1172: my @links = ('link','alink','vlink');
1173: my %designhash = &Apache::loncommon::get_domainconf($dom);
1174: my %defaultdesign = %Apache::loncommon::defaultdesign;
1175: my (%is_custom,%designs);
1176: my %defaults = (
1177: font => $defaultdesign{'login.font'},
1178: );
1.6 raeburn 1179: foreach my $item (@images) {
1.168 raeburn 1180: $defaults{$item} = $defaultdesign{'login.'.$item};
1181: $defaults{'showlogo'}{$item} = 1;
1182: }
1183: foreach my $item (@bgs) {
1184: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1185: }
1.41 raeburn 1186: foreach my $item (@logintext) {
1.168 raeburn 1187: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1188: }
1.168 raeburn 1189: foreach my $item (@links) {
1190: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1191: }
1.168 raeburn 1192: if (ref($settings) eq 'HASH') {
1193: foreach my $item (@toggles) {
1194: if ($settings->{$item} eq '1') {
1195: $checkedon{$item} = ' checked="checked" ';
1196: $checkedoff{$item} = ' ';
1197: } elsif ($settings->{$item} eq '0') {
1198: $checkedoff{$item} = ' checked="checked" ';
1199: $checkedon{$item} = ' ';
1200: }
1201: }
1202: foreach my $item (@images) {
1203: if (defined($settings->{$item})) {
1204: $designs{$item} = $settings->{$item};
1205: $is_custom{$item} = 1;
1206: }
1207: if (defined($settings->{'showlogo'}{$item})) {
1208: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1209: }
1210: }
1211: foreach my $item (@logintext) {
1212: if ($settings->{$item} ne '') {
1213: $designs{'logintext'}{$item} = $settings->{$item};
1214: $is_custom{$item} = 1;
1215: }
1216: }
1217: if ($settings->{'font'} ne '') {
1218: $designs{'font'} = $settings->{'font'};
1219: $is_custom{'font'} = 1;
1220: }
1221: foreach my $item (@bgs) {
1222: if ($settings->{$item} ne '') {
1223: $designs{'bgs'}{$item} = $settings->{$item};
1224: $is_custom{$item} = 1;
1225: }
1226: }
1227: foreach my $item (@links) {
1228: if ($settings->{$item} ne '') {
1229: $designs{'links'}{$item} = $settings->{$item};
1230: $is_custom{$item} = 1;
1231: }
1232: }
1233: } else {
1234: if ($designhash{$dom.'.login.font'} ne '') {
1235: $designs{'font'} = $designhash{$dom.'.login.font'};
1236: $is_custom{'font'} = 1;
1237: }
1238: foreach my $item (@images) {
1239: if ($designhash{$dom.'.login.'.$item} ne '') {
1240: $designs{$item} = $designhash{$dom.'.login.'.$item};
1241: $is_custom{$item} = 1;
1242: }
1243: }
1244: foreach my $item (@bgs) {
1245: if ($designhash{$dom.'.login.'.$item} ne '') {
1246: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1247: $is_custom{$item} = 1;
1248: }
1.6 raeburn 1249: }
1.168 raeburn 1250: foreach my $item (@links) {
1251: if ($designhash{$dom.'.login.'.$item} ne '') {
1252: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1253: $is_custom{$item} = 1;
1254: }
1.6 raeburn 1255: }
1256: }
1.168 raeburn 1257: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1258: logo => 'Institution Logo',
1259: domlogo => 'Domain Logo',
1260: login => 'Login box');
1261: my $itemcount = 1;
1262: foreach my $item (@toggles) {
1263: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1264: $datatable .=
1265: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1266: '</td><td>'.
1267: '<span class="LC_nobreak"><label><input type="radio" name="'.
1268: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1269: '</label> <label><input type="radio" name="'.$item.'"'.
1270: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1271: '</tr>';
1272: $itemcount ++;
1.6 raeburn 1273: }
1.168 raeburn 1274: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1275: $datatable .= '</tr></table></td></tr>';
1276: } elsif ($caller eq 'help') {
1277: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1278: my $switchserver = &check_switchserver($dom,$confname);
1279: my $itemcount = 1;
1280: $defaulturl = '/adm/loginproblems.html';
1281: $defaulttype = 'default';
1282: %lt = &Apache::lonlocal::texthash (
1283: del => 'Delete?',
1284: rep => 'Replace:',
1285: upl => 'Upload:',
1286: default => 'Default',
1287: custom => 'Custom',
1288: );
1289: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1290: my @currlangs;
1291: if (ref($settings) eq 'HASH') {
1292: if (ref($settings->{'helpurl'}) eq 'HASH') {
1293: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1294: next if ($settings->{'helpurl'}{$key} eq '');
1295: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1296: $type{$key} = 'custom';
1297: unless ($key eq 'nolang') {
1298: push(@currlangs,$key);
1299: }
1300: }
1301: } elsif ($settings->{'helpurl'} ne '') {
1302: $type{'nolang'} = 'custom';
1303: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1304: }
1305: }
1.168 raeburn 1306: foreach my $lang ('nolang',sort(@currlangs)) {
1307: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1308: $datatable .= '<tr'.$css_class.'>';
1309: if ($url{$lang} eq '') {
1310: $url{$lang} = $defaulturl;
1311: }
1312: if ($type{$lang} eq '') {
1313: $type{$lang} = $defaulttype;
1314: }
1315: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1316: if ($lang eq 'nolang') {
1317: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1318: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1319: } else {
1320: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1321: $langchoices{$lang},
1322: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1323: }
1324: $datatable .= '</span></td>'."\n".
1325: '<td class="LC_left_item">';
1326: if ($type{$lang} eq 'custom') {
1327: $datatable .= '<span class="LC_nobreak"><label>'.
1328: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1329: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1330: } else {
1331: $datatable .= $lt{'upl'};
1332: }
1333: $datatable .='<br />';
1334: if ($switchserver) {
1335: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1336: } else {
1337: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1338: }
1.168 raeburn 1339: $datatable .= '</td></tr>';
1340: $itemcount ++;
1.6 raeburn 1341: }
1.168 raeburn 1342: my @addlangs;
1343: foreach my $lang (sort(keys(%langchoices))) {
1344: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1345: push(@addlangs,$lang);
1346: }
1347: if (@addlangs > 0) {
1348: my %toadd;
1349: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1350: $toadd{''} = &mt('Select');
1351: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1352: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1353: &mt('Add log-in help page for a specific language:').' '.
1354: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1355: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1356: if ($switchserver) {
1357: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1358: } else {
1359: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1360: }
1.168 raeburn 1361: $datatable .= '</td></tr>';
1.169 raeburn 1362: $itemcount ++;
1.6 raeburn 1363: }
1.169 raeburn 1364: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1365: } elsif ($caller eq 'headtag') {
1366: my %domservers = &Apache::lonnet::get_servers($dom);
1367: my $choice = $choices{'headtag'};
1368: $css_class = ' class="LC_odd_row"';
1369: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1370: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1371: '<th>'.$choices{'current'}.'</th>'.
1372: '<th>'.$choices{'action'}.'</th>'.
1373: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1374: my (%currurls,%currexempt);
1375: if (ref($settings) eq 'HASH') {
1376: if (ref($settings->{'headtag'}) eq 'HASH') {
1377: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1378: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1379: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1380: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1381: }
1382: }
1383: }
1384: }
1385: my %lt = &Apache::lonlocal::texthash(
1386: del => 'Delete?',
1387: rep => 'Replace:',
1388: upl => 'Upload:',
1389: curr => 'View contents',
1390: none => 'None',
1391: );
1392: my $switchserver = &check_switchserver($dom,$confname);
1393: foreach my $lonhost (sort(keys(%domservers))) {
1394: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1395: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1396: if ($currurls{$lonhost}) {
1397: $datatable .= '<td class="LC_right_item"><a href="'.
1398: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1399: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1400: '">'.$lt{'curr'}.'</a></td>'.
1401: '<td><span class="LC_nobreak"><label>'.
1402: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1403: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1404: } else {
1405: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1406: }
1407: $datatable .='<br />';
1408: if ($switchserver) {
1409: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1410: } else {
1411: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1412: }
1413: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1414: }
1415: $datatable .= '</table></td></tr>';
1.1 raeburn 1416: }
1.6 raeburn 1417: return $datatable;
1418: }
1419:
1420: sub login_choices {
1421: my %choices =
1422: &Apache::lonlocal::texthash (
1.116 bisitz 1423: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1424: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1425: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1426: disallowlogin => "Login page requests redirected",
1427: hostid => "Server",
1.128 raeburn 1428: server => "Redirect to:",
1429: serverpath => "Path",
1430: custompath => "Custom",
1431: exempt => "Exempt IP(s)",
1.110 raeburn 1432: directlogin => "No redirect",
1433: newuser => "Link to create a user account",
1434: img => "Header",
1435: logo => "Main Logo",
1436: domlogo => "Domain Logo",
1437: login => "Log-in Header",
1438: textcol => "Text color",
1439: bgcol => "Box color",
1440: bgs => "Background colors",
1441: links => "Link colors",
1442: font => "Font color",
1443: pgbg => "Header",
1444: mainbg => "Page",
1445: sidebg => "Login box",
1446: link => "Link",
1447: alink => "Active link",
1448: vlink => "Visited link",
1.256 raeburn 1449: headtag => "Custom markup",
1450: action => "Action",
1451: current => "Current",
1.6 raeburn 1452: );
1453: return %choices;
1454: }
1455:
1456: sub print_rolecolors {
1.30 raeburn 1457: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1458: my %choices = &color_font_choices();
1459: my @bgs = ('pgbg','tabbg','sidebg');
1460: my @links = ('link','alink','vlink');
1461: my @images = ('img');
1462: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1463: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1464: my %defaultdesign = %Apache::loncommon::defaultdesign;
1465: my (%is_custom,%designs);
1.200 raeburn 1466: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1467: if (ref($settings) eq 'HASH') {
1468: if (ref($settings->{$role}) eq 'HASH') {
1469: if ($settings->{$role}->{'img'} ne '') {
1470: $designs{'img'} = $settings->{$role}->{'img'};
1471: $is_custom{'img'} = 1;
1472: }
1473: if ($settings->{$role}->{'font'} ne '') {
1474: $designs{'font'} = $settings->{$role}->{'font'};
1475: $is_custom{'font'} = 1;
1476: }
1.97 tempelho 1477: if ($settings->{$role}->{'fontmenu'} ne '') {
1478: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1479: $is_custom{'fontmenu'} = 1;
1480: }
1.6 raeburn 1481: foreach my $item (@bgs) {
1482: if ($settings->{$role}->{$item} ne '') {
1483: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1484: $is_custom{$item} = 1;
1485: }
1486: }
1487: foreach my $item (@links) {
1488: if ($settings->{$role}->{$item} ne '') {
1489: $designs{'links'}{$item} = $settings->{$role}->{$item};
1490: $is_custom{$item} = 1;
1491: }
1492: }
1493: }
1494: } else {
1495: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1496: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1497: $is_custom{'img'} = 1;
1498: }
1.97 tempelho 1499: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1500: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1501: $is_custom{'fontmenu'} = 1;
1502: }
1.6 raeburn 1503: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1504: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1505: $is_custom{'font'} = 1;
1506: }
1507: foreach my $item (@bgs) {
1508: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1509: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1510: $is_custom{$item} = 1;
1511:
1512: }
1513: }
1514: foreach my $item (@links) {
1515: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1516: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1517: $is_custom{$item} = 1;
1518: }
1519: }
1520: }
1521: my $itemcount = 1;
1.30 raeburn 1522: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1523: $datatable .= '</tr></table></td></tr>';
1524: return $datatable;
1525: }
1526:
1.200 raeburn 1527: sub role_defaults {
1528: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1529: my %defaults;
1530: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1531: return %defaults;
1532: }
1533: my %defaultdesign = %Apache::loncommon::defaultdesign;
1534: if ($role eq 'login') {
1535: %defaults = (
1536: font => $defaultdesign{$role.'.font'},
1537: );
1538: if (ref($logintext) eq 'ARRAY') {
1539: foreach my $item (@{$logintext}) {
1540: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1541: }
1542: }
1543: foreach my $item (@{$images}) {
1544: $defaults{'showlogo'}{$item} = 1;
1545: }
1546: } else {
1547: %defaults = (
1548: img => $defaultdesign{$role.'.img'},
1549: font => $defaultdesign{$role.'.font'},
1550: fontmenu => $defaultdesign{$role.'.fontmenu'},
1551: );
1552: }
1553: foreach my $item (@{$bgs}) {
1554: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1555: }
1556: foreach my $item (@{$links}) {
1557: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1558: }
1559: foreach my $item (@{$images}) {
1560: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1561: }
1562: return %defaults;
1563: }
1564:
1.6 raeburn 1565: sub display_color_options {
1.9 raeburn 1566: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1567: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1568: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1569: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1570: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1571: '<td>'.$choices->{'font'}.'</td>';
1572: if (!$is_custom->{'font'}) {
1.30 raeburn 1573: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1574: } else {
1575: $datatable .= '<td> </td>';
1576: }
1.174 foxr 1577: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1578:
1.8 raeburn 1579: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1580: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1581: ' value="'.$current_color.'" /> '.
1.174 foxr 1582: ' </td></tr>';
1.107 raeburn 1583: unless ($role eq 'login') {
1584: $datatable .= '<tr'.$css_class.'>'.
1585: '<td>'.$choices->{'fontmenu'}.'</td>';
1586: if (!$is_custom->{'fontmenu'}) {
1587: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1588: } else {
1589: $datatable .= '<td> </td>';
1590: }
1.202 raeburn 1591: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1592: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1593: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1594: '<input class="colorchooser" type="text" size="10" name="'
1595: .$role.'_fontmenu"'.
1596: ' value="'.$current_color.'" /> '.
1597: ' </td></tr>';
1.97 tempelho 1598: }
1.9 raeburn 1599: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1600: foreach my $img (@{$images}) {
1.18 albertel 1601: $itemcount ++;
1.6 raeburn 1602: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1603: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1604: '<td>'.$choices->{$img};
1.41 raeburn 1605: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1606: if ($role eq 'login') {
1607: if ($img eq 'login') {
1608: $login_hdr_pick =
1.135 bisitz 1609: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1610: $logincolors =
1611: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1612: $designs,$defaults);
1.70 raeburn 1613: } elsif ($img ne 'domlogo') {
1614: $datatable.= &logo_display_options($img,$defaults,$designs);
1615: }
1616: }
1617: $datatable .= '</td>';
1.6 raeburn 1618: if ($designs->{$img} ne '') {
1619: $imgfile = $designs->{$img};
1.18 albertel 1620: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1621: } else {
1622: $imgfile = $defaults->{$img};
1623: }
1624: if ($imgfile) {
1.9 raeburn 1625: my ($showfile,$fullsize);
1626: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1627: my $urldir = $1;
1628: my $filename = $2;
1629: my @info = &Apache::lonnet::stat_file($designs->{$img});
1630: if (@info) {
1631: my $thumbfile = 'tn-'.$filename;
1632: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1633: if (@thumb) {
1634: $showfile = $urldir.'/'.$thumbfile;
1635: } else {
1636: $showfile = $imgfile;
1637: }
1638: } else {
1639: $showfile = '';
1640: }
1641: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1642: $showfile = $imgfile;
1.6 raeburn 1643: my $imgdir = $1;
1644: my $filename = $2;
1.159 raeburn 1645: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1646: $showfile = "/$imgdir/tn-".$filename;
1647: } else {
1.159 raeburn 1648: my $input = $londocroot.$imgfile;
1649: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1650: if (!-e $output) {
1.9 raeburn 1651: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1652: my ($fullwidth,$fullheight) = &check_dimensions($input);
1653: if ($fullwidth ne '' && $fullheight ne '') {
1654: if ($fullwidth > $width && $fullheight > $height) {
1655: my $size = $width.'x'.$height;
1656: system("convert -sample $size $input $output");
1.159 raeburn 1657: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1658: }
1659: }
1.6 raeburn 1660: }
1661: }
1.16 raeburn 1662: }
1.6 raeburn 1663: if ($showfile) {
1.40 raeburn 1664: if ($showfile =~ m{^/(adm|res)/}) {
1665: if ($showfile =~ m{^/res/}) {
1666: my $local_showfile =
1667: &Apache::lonnet::filelocation('',$showfile);
1668: &Apache::lonnet::repcopy($local_showfile);
1669: }
1670: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1671: }
1672: if ($imgfile) {
1673: if ($imgfile =~ m{^/(adm|res)/}) {
1674: if ($imgfile =~ m{^/res/}) {
1675: my $local_imgfile =
1676: &Apache::lonnet::filelocation('',$imgfile);
1677: &Apache::lonnet::repcopy($local_imgfile);
1678: }
1679: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1680: } else {
1681: $fullsize = $imgfile;
1682: }
1683: }
1.41 raeburn 1684: $datatable .= '<td>';
1685: if ($img eq 'login') {
1.135 bisitz 1686: $datatable .= $login_hdr_pick;
1687: }
1.41 raeburn 1688: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1689: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1690: } else {
1.201 raeburn 1691: $datatable .= '<td> </td><td class="LC_left_item">'.
1692: &mt('Upload:').'<br />';
1.6 raeburn 1693: }
1694: } else {
1.201 raeburn 1695: $datatable .= '<td> </td><td class="LC_left_item">'.
1696: &mt('Upload:').'<br />';
1.6 raeburn 1697: }
1.9 raeburn 1698: if ($switchserver) {
1699: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1700: } else {
1.135 bisitz 1701: if ($img ne 'login') { # suppress file selection for Log-in header
1702: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1703: }
1.9 raeburn 1704: }
1705: $datatable .= '</td></tr>';
1.6 raeburn 1706: }
1707: $itemcount ++;
1708: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1709: $datatable .= '<tr'.$css_class.'>'.
1710: '<td>'.$choices->{'bgs'}.'</td>';
1711: my $bgs_def;
1712: foreach my $item (@{$bgs}) {
1713: if (!$is_custom->{$item}) {
1.70 raeburn 1714: $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 1715: }
1716: }
1717: if ($bgs_def) {
1.8 raeburn 1718: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1719: } else {
1720: $datatable .= '<td> </td>';
1721: }
1722: $datatable .= '<td class="LC_right_item">'.
1723: '<table border="0"><tr>';
1.174 foxr 1724:
1.6 raeburn 1725: foreach my $item (@{$bgs}) {
1.201 raeburn 1726: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1727: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1728: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1729: $datatable .= ' ';
1.6 raeburn 1730: }
1.174 foxr 1731: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1732: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1733: }
1734: $datatable .= '</tr></table></td></tr>';
1735: $itemcount ++;
1736: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1737: $datatable .= '<tr'.$css_class.'>'.
1738: '<td>'.$choices->{'links'}.'</td>';
1739: my $links_def;
1740: foreach my $item (@{$links}) {
1741: if (!$is_custom->{$item}) {
1.30 raeburn 1742: $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 1743: }
1744: }
1745: if ($links_def) {
1.8 raeburn 1746: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1747: } else {
1748: $datatable .= '<td> </td>';
1749: }
1750: $datatable .= '<td class="LC_right_item">'.
1751: '<table border="0"><tr>';
1752: foreach my $item (@{$links}) {
1.234 raeburn 1753: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1754: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1755: if ($designs->{'links'}{$item}) {
1.174 foxr 1756: $datatable.=' ';
1.6 raeburn 1757: }
1.174 foxr 1758: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1759: '" /></td>';
1760: }
1.30 raeburn 1761: $$rowtotal += $itemcount;
1.3 raeburn 1762: return $datatable;
1763: }
1764:
1.70 raeburn 1765: sub logo_display_options {
1766: my ($img,$defaults,$designs) = @_;
1767: my $checkedon;
1768: if (ref($defaults) eq 'HASH') {
1769: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1770: if ($defaults->{'showlogo'}{$img}) {
1771: $checkedon = 'checked="checked" ';
1772: }
1773: }
1774: }
1775: if (ref($designs) eq 'HASH') {
1776: if (ref($designs->{'showlogo'}) eq 'HASH') {
1777: if (defined($designs->{'showlogo'}{$img})) {
1778: if ($designs->{'showlogo'}{$img} == 0) {
1779: $checkedon = '';
1780: } elsif ($designs->{'showlogo'}{$img} == 1) {
1781: $checkedon = 'checked="checked" ';
1782: }
1783: }
1784: }
1785: }
1786: return '<br /><label> <input type="checkbox" name="'.
1787: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1788: &mt('show').'</label>'."\n";
1789: }
1790:
1.41 raeburn 1791: sub login_header_options {
1.135 bisitz 1792: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1793: my $output = '';
1.41 raeburn 1794: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1795: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1796: if (!$is_custom->{'textcol'}) {
1797: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1798: ' ';
1799: }
1800: if (!$is_custom->{'bgcol'}) {
1801: $output .= $choices->{'bgcol'}.': '.
1802: '<span id="css_'.$role.'_font" style="background-color: '.
1803: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1804: }
1805: $output .= '<br />';
1806: }
1807: $output .='<br />';
1808: return $output;
1809: }
1810:
1811: sub login_text_colors {
1.201 raeburn 1812: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1813: my $color_menu = '<table border="0"><tr>';
1814: foreach my $item (@{$logintext}) {
1.201 raeburn 1815: $color_menu .= '<td align="center">'.$choices->{$item};
1816: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1817: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1818: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1819: }
1820: $color_menu .= '</tr></table><br />';
1821: return $color_menu;
1822: }
1823:
1824: sub image_changes {
1825: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1826: my $output;
1.135 bisitz 1827: if ($img eq 'login') {
1828: # suppress image for Log-in header
1829: } elsif (!$is_custom) {
1.70 raeburn 1830: if ($img ne 'domlogo') {
1.41 raeburn 1831: $output .= &mt('Default image:').'<br />';
1832: } else {
1833: $output .= &mt('Default in use:').'<br />';
1834: }
1835: }
1.135 bisitz 1836: if ($img eq 'login') { # suppress image for Log-in header
1837: $output .= '<td>'.$logincolors;
1.41 raeburn 1838: } else {
1.135 bisitz 1839: if ($img_import) {
1840: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1841: }
1842: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1843: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1844: if ($is_custom) {
1845: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1846: '<input type="checkbox" name="'.
1847: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1848: '</label> '.&mt('Replace:').'</span><br />';
1849: } else {
1.201 raeburn 1850: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1851: }
1.41 raeburn 1852: }
1853: return $output;
1854: }
1855:
1.3 raeburn 1856: sub print_quotas {
1.86 raeburn 1857: my ($dom,$settings,$rowtotal,$action) = @_;
1858: my $context;
1859: if ($action eq 'quotas') {
1860: $context = 'tools';
1861: } else {
1862: $context = $action;
1863: }
1.197 raeburn 1864: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1865: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1866: my $typecount = 0;
1.101 raeburn 1867: my ($css_class,%titles);
1.86 raeburn 1868: if ($context eq 'requestcourses') {
1.271 raeburn 1869: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 1870: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1871: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1872: %titles = &courserequest_titles();
1.163 raeburn 1873: } elsif ($context eq 'requestauthor') {
1874: @usertools = ('author');
1875: @options = ('norequest','approval','automatic');
1.210 raeburn 1876: %titles = &authorrequest_titles();
1.86 raeburn 1877: } else {
1.162 raeburn 1878: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1879: %titles = &tool_titles();
1.86 raeburn 1880: }
1.26 raeburn 1881: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1882: foreach my $type (@{$types}) {
1.197 raeburn 1883: my ($currdefquota,$currauthorquota);
1.163 raeburn 1884: unless (($context eq 'requestcourses') ||
1885: ($context eq 'requestauthor')) {
1.86 raeburn 1886: if (ref($settings) eq 'HASH') {
1887: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1888: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1889: } else {
1890: $currdefquota = $settings->{$type};
1891: }
1.197 raeburn 1892: if (ref($settings->{authorquota}) eq 'HASH') {
1893: $currauthorquota = $settings->{authorquota}->{$type};
1894: }
1.78 raeburn 1895: }
1.72 raeburn 1896: }
1.3 raeburn 1897: if (defined($usertypes->{$type})) {
1898: $typecount ++;
1899: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1900: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1901: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1902: '<td class="LC_left_item">';
1.101 raeburn 1903: if ($context eq 'requestcourses') {
1904: $datatable .= '<table><tr>';
1905: }
1906: my %cell;
1.72 raeburn 1907: foreach my $item (@usertools) {
1.101 raeburn 1908: if ($context eq 'requestcourses') {
1909: my ($curroption,$currlimit);
1910: if (ref($settings) eq 'HASH') {
1911: if (ref($settings->{$item}) eq 'HASH') {
1912: $curroption = $settings->{$item}->{$type};
1913: if ($curroption =~ /^autolimit=(\d*)$/) {
1914: $currlimit = $1;
1915: }
1916: }
1917: }
1918: if (!$curroption) {
1919: $curroption = 'norequest';
1920: }
1921: $datatable .= '<th>'.$titles{$item}.'</th>';
1922: foreach my $option (@options) {
1923: my $val = $option;
1924: if ($option eq 'norequest') {
1925: $val = 0;
1926: }
1927: if ($option eq 'validate') {
1928: my $canvalidate = 0;
1929: if (ref($validations{$item}) eq 'HASH') {
1930: if ($validations{$item}{$type}) {
1931: $canvalidate = 1;
1932: }
1933: }
1934: next if (!$canvalidate);
1935: }
1936: my $checked = '';
1937: if ($option eq $curroption) {
1938: $checked = ' checked="checked"';
1939: } elsif ($option eq 'autolimit') {
1940: if ($curroption =~ /^autolimit/) {
1941: $checked = ' checked="checked"';
1942: }
1943: }
1944: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1945: '<input type="radio" name="crsreq_'.$item.
1946: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1947: $titles{$option}.'</label>';
1.101 raeburn 1948: if ($option eq 'autolimit') {
1.127 raeburn 1949: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1950: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1951: 'value="'.$currlimit.'" />';
1.101 raeburn 1952: }
1.127 raeburn 1953: $cell{$item} .= '</span> ';
1.103 raeburn 1954: if ($option eq 'autolimit') {
1.127 raeburn 1955: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1956: }
1.101 raeburn 1957: }
1.163 raeburn 1958: } elsif ($context eq 'requestauthor') {
1959: my $curroption;
1960: if (ref($settings) eq 'HASH') {
1961: $curroption = $settings->{$type};
1962: }
1963: if (!$curroption) {
1964: $curroption = 'norequest';
1965: }
1966: foreach my $option (@options) {
1967: my $val = $option;
1968: if ($option eq 'norequest') {
1969: $val = 0;
1970: }
1971: my $checked = '';
1972: if ($option eq $curroption) {
1973: $checked = ' checked="checked"';
1974: }
1975: $datatable .= '<span class="LC_nobreak"><label>'.
1976: '<input type="radio" name="authorreq_'.$type.
1977: '" value="'.$val.'"'.$checked.' />'.
1978: $titles{$option}.'</label></span> ';
1979: }
1.101 raeburn 1980: } else {
1981: my $checked = 'checked="checked" ';
1982: if (ref($settings) eq 'HASH') {
1983: if (ref($settings->{$item}) eq 'HASH') {
1984: if ($settings->{$item}->{$type} == 0) {
1985: $checked = '';
1986: } elsif ($settings->{$item}->{$type} == 1) {
1987: $checked = 'checked="checked" ';
1988: }
1.78 raeburn 1989: }
1.72 raeburn 1990: }
1.101 raeburn 1991: $datatable .= '<span class="LC_nobreak"><label>'.
1992: '<input type="checkbox" name="'.$context.'_'.$item.
1993: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1994: '</label></span> ';
1.72 raeburn 1995: }
1.101 raeburn 1996: }
1997: if ($context eq 'requestcourses') {
1998: $datatable .= '</tr><tr>';
1999: foreach my $item (@usertools) {
1.106 raeburn 2000: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2001: }
2002: $datatable .= '</tr></table>';
1.72 raeburn 2003: }
1.86 raeburn 2004: $datatable .= '</td>';
1.163 raeburn 2005: unless (($context eq 'requestcourses') ||
2006: ($context eq 'requestauthor')) {
1.86 raeburn 2007: $datatable .=
1.197 raeburn 2008: '<td class="LC_right_item">'.
2009: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2010: '<input type="text" name="quota_'.$type.
1.72 raeburn 2011: '" value="'.$currdefquota.
1.197 raeburn 2012: '" size="5" /></span>'.(' ' x 2).
2013: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2014: '<input type="text" name="authorquota_'.$type.
2015: '" value="'.$currauthorquota.
2016: '" size="5" /></span></td>';
1.86 raeburn 2017: }
2018: $datatable .= '</tr>';
1.3 raeburn 2019: }
2020: }
2021: }
1.163 raeburn 2022: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2023: $defaultquota = '20';
1.197 raeburn 2024: $authorquota = '500';
1.86 raeburn 2025: if (ref($settings) eq 'HASH') {
2026: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2027: $defaultquota = $settings->{'defaultquota'}->{'default'};
2028: } elsif (defined($settings->{'default'})) {
2029: $defaultquota = $settings->{'default'};
2030: }
1.197 raeburn 2031: if (ref($settings->{'authorquota'}) eq 'HASH') {
2032: $authorquota = $settings->{'authorquota'}->{'default'};
2033: }
1.3 raeburn 2034: }
2035: }
2036: $typecount ++;
2037: $css_class = $typecount%2?' class="LC_odd_row"':'';
2038: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2039: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2040: '<td class="LC_left_item">';
1.101 raeburn 2041: if ($context eq 'requestcourses') {
2042: $datatable .= '<table><tr>';
2043: }
2044: my %defcell;
1.72 raeburn 2045: foreach my $item (@usertools) {
1.101 raeburn 2046: if ($context eq 'requestcourses') {
2047: my ($curroption,$currlimit);
2048: if (ref($settings) eq 'HASH') {
2049: if (ref($settings->{$item}) eq 'HASH') {
2050: $curroption = $settings->{$item}->{'default'};
2051: if ($curroption =~ /^autolimit=(\d*)$/) {
2052: $currlimit = $1;
2053: }
2054: }
2055: }
2056: if (!$curroption) {
2057: $curroption = 'norequest';
2058: }
2059: $datatable .= '<th>'.$titles{$item}.'</th>';
2060: foreach my $option (@options) {
2061: my $val = $option;
2062: if ($option eq 'norequest') {
2063: $val = 0;
2064: }
2065: if ($option eq 'validate') {
2066: my $canvalidate = 0;
2067: if (ref($validations{$item}) eq 'HASH') {
2068: if ($validations{$item}{'default'}) {
2069: $canvalidate = 1;
2070: }
2071: }
2072: next if (!$canvalidate);
2073: }
2074: my $checked = '';
2075: if ($option eq $curroption) {
2076: $checked = ' checked="checked"';
2077: } elsif ($option eq 'autolimit') {
2078: if ($curroption =~ /^autolimit/) {
2079: $checked = ' checked="checked"';
2080: }
2081: }
2082: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2083: '<input type="radio" name="crsreq_'.$item.
2084: '_default" value="'.$val.'"'.$checked.' />'.
2085: $titles{$option}.'</label>';
2086: if ($option eq 'autolimit') {
1.127 raeburn 2087: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2088: $item.'_limit_default" size="1" '.
2089: 'value="'.$currlimit.'" />';
2090: }
1.127 raeburn 2091: $defcell{$item} .= '</span> ';
1.104 raeburn 2092: if ($option eq 'autolimit') {
1.127 raeburn 2093: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2094: }
1.101 raeburn 2095: }
1.163 raeburn 2096: } elsif ($context eq 'requestauthor') {
2097: my $curroption;
2098: if (ref($settings) eq 'HASH') {
1.172 raeburn 2099: $curroption = $settings->{'default'};
1.163 raeburn 2100: }
2101: if (!$curroption) {
2102: $curroption = 'norequest';
2103: }
2104: foreach my $option (@options) {
2105: my $val = $option;
2106: if ($option eq 'norequest') {
2107: $val = 0;
2108: }
2109: my $checked = '';
2110: if ($option eq $curroption) {
2111: $checked = ' checked="checked"';
2112: }
2113: $datatable .= '<span class="LC_nobreak"><label>'.
2114: '<input type="radio" name="authorreq_default"'.
2115: ' value="'.$val.'"'.$checked.' />'.
2116: $titles{$option}.'</label></span> ';
2117: }
1.101 raeburn 2118: } else {
2119: my $checked = 'checked="checked" ';
2120: if (ref($settings) eq 'HASH') {
2121: if (ref($settings->{$item}) eq 'HASH') {
2122: if ($settings->{$item}->{'default'} == 0) {
2123: $checked = '';
2124: } elsif ($settings->{$item}->{'default'} == 1) {
2125: $checked = 'checked="checked" ';
2126: }
1.78 raeburn 2127: }
1.72 raeburn 2128: }
1.101 raeburn 2129: $datatable .= '<span class="LC_nobreak"><label>'.
2130: '<input type="checkbox" name="'.$context.'_'.$item.
2131: '" value="default" '.$checked.'/>'.$titles{$item}.
2132: '</label></span> ';
2133: }
2134: }
2135: if ($context eq 'requestcourses') {
2136: $datatable .= '</tr><tr>';
2137: foreach my $item (@usertools) {
1.106 raeburn 2138: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2139: }
1.101 raeburn 2140: $datatable .= '</tr></table>';
1.72 raeburn 2141: }
1.86 raeburn 2142: $datatable .= '</td>';
1.163 raeburn 2143: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2144: $datatable .= '<td class="LC_right_item">'.
2145: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2146: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2147: $defaultquota.'" size="5" /></span>'.(' ' x2).
2148: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2149: '<input type="text" name="authorquota" value="'.
2150: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2151: }
2152: $datatable .= '</tr>';
1.72 raeburn 2153: $typecount ++;
2154: $css_class = $typecount%2?' class="LC_odd_row"':'';
2155: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2156: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2157: if ($context eq 'requestcourses') {
1.109 raeburn 2158: $datatable .= &mt('(overrides affiliation, if set)').
2159: '</td>'.
2160: '<td class="LC_left_item">'.
2161: '<table><tr>';
1.101 raeburn 2162: } else {
1.109 raeburn 2163: $datatable .= &mt('(overrides affiliation, if checked)').
2164: '</td>'.
2165: '<td class="LC_left_item" colspan="2">'.
2166: '<br />';
1.101 raeburn 2167: }
2168: my %advcell;
1.72 raeburn 2169: foreach my $item (@usertools) {
1.101 raeburn 2170: if ($context eq 'requestcourses') {
2171: my ($curroption,$currlimit);
2172: if (ref($settings) eq 'HASH') {
2173: if (ref($settings->{$item}) eq 'HASH') {
2174: $curroption = $settings->{$item}->{'_LC_adv'};
2175: if ($curroption =~ /^autolimit=(\d*)$/) {
2176: $currlimit = $1;
2177: }
2178: }
2179: }
2180: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2181: my $checked = '';
2182: if ($curroption eq '') {
2183: $checked = ' checked="checked"';
2184: }
2185: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2186: '<input type="radio" name="crsreq_'.$item.
2187: '__LC_adv" value=""'.$checked.' />'.
2188: &mt('No override set').'</label></span> ';
1.101 raeburn 2189: foreach my $option (@options) {
2190: my $val = $option;
2191: if ($option eq 'norequest') {
2192: $val = 0;
2193: }
2194: if ($option eq 'validate') {
2195: my $canvalidate = 0;
2196: if (ref($validations{$item}) eq 'HASH') {
2197: if ($validations{$item}{'_LC_adv'}) {
2198: $canvalidate = 1;
2199: }
2200: }
2201: next if (!$canvalidate);
2202: }
2203: my $checked = '';
1.104 raeburn 2204: if ($val eq $curroption) {
1.101 raeburn 2205: $checked = ' checked="checked"';
2206: } elsif ($option eq 'autolimit') {
2207: if ($curroption =~ /^autolimit/) {
2208: $checked = ' checked="checked"';
2209: }
2210: }
2211: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2212: '<input type="radio" name="crsreq_'.$item.
2213: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2214: $titles{$option}.'</label>';
2215: if ($option eq 'autolimit') {
1.127 raeburn 2216: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2217: $item.'_limit__LC_adv" size="1" '.
2218: 'value="'.$currlimit.'" />';
2219: }
1.127 raeburn 2220: $advcell{$item} .= '</span> ';
1.104 raeburn 2221: if ($option eq 'autolimit') {
1.127 raeburn 2222: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2223: }
1.101 raeburn 2224: }
1.163 raeburn 2225: } elsif ($context eq 'requestauthor') {
2226: my $curroption;
2227: if (ref($settings) eq 'HASH') {
2228: $curroption = $settings->{'_LC_adv'};
2229: }
2230: my $checked = '';
2231: if ($curroption eq '') {
2232: $checked = ' checked="checked"';
2233: }
2234: $datatable .= '<span class="LC_nobreak"><label>'.
2235: '<input type="radio" name="authorreq__LC_adv"'.
2236: ' value=""'.$checked.' />'.
2237: &mt('No override set').'</label></span> ';
2238: foreach my $option (@options) {
2239: my $val = $option;
2240: if ($option eq 'norequest') {
2241: $val = 0;
2242: }
2243: my $checked = '';
2244: if ($val eq $curroption) {
2245: $checked = ' checked="checked"';
2246: }
2247: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2248: '<input type="radio" name="authorreq__LC_adv"'.
2249: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2250: $titles{$option}.'</label></span> ';
2251: }
1.101 raeburn 2252: } else {
2253: my $checked = 'checked="checked" ';
2254: if (ref($settings) eq 'HASH') {
2255: if (ref($settings->{$item}) eq 'HASH') {
2256: if ($settings->{$item}->{'_LC_adv'} == 0) {
2257: $checked = '';
2258: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2259: $checked = 'checked="checked" ';
2260: }
1.79 raeburn 2261: }
1.72 raeburn 2262: }
1.101 raeburn 2263: $datatable .= '<span class="LC_nobreak"><label>'.
2264: '<input type="checkbox" name="'.$context.'_'.$item.
2265: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2266: '</label></span> ';
2267: }
2268: }
2269: if ($context eq 'requestcourses') {
2270: $datatable .= '</tr><tr>';
2271: foreach my $item (@usertools) {
1.106 raeburn 2272: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2273: }
1.101 raeburn 2274: $datatable .= '</tr></table>';
1.72 raeburn 2275: }
1.98 raeburn 2276: $datatable .= '</td></tr>';
1.30 raeburn 2277: $$rowtotal += $typecount;
1.3 raeburn 2278: return $datatable;
2279: }
2280:
1.163 raeburn 2281: sub print_requestmail {
2282: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2283: my ($now,$datatable,%currapp);
1.102 raeburn 2284: $now = time;
2285: if (ref($settings) eq 'HASH') {
2286: if (ref($settings->{'notify'}) eq 'HASH') {
2287: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2288: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2289: }
2290: }
2291: }
1.191 raeburn 2292: my $numinrow = 2;
1.224 raeburn 2293: my $css_class;
2294: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2295: my $text;
2296: if ($action eq 'requestcourses') {
2297: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2298: } elsif ($action eq 'requestauthor') {
2299: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2300: } else {
1.224 raeburn 2301: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2302: }
1.224 raeburn 2303: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2304: ' <td>'.$text.'</td>'.
1.102 raeburn 2305: ' <td class="LC_left_item">';
1.191 raeburn 2306: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2307: $action.'notifyapproval',%currapp);
1.191 raeburn 2308: if ($numdc > 0) {
2309: $datatable .= $table;
1.102 raeburn 2310: } else {
2311: $datatable .= &mt('There are no active Domain Coordinators');
2312: }
2313: $datatable .='</td></tr>';
2314: return $datatable;
2315: }
2316:
1.216 raeburn 2317: sub print_studentcode {
2318: my ($settings,$rowtotal) = @_;
2319: my $rownum = 0;
1.218 raeburn 2320: my ($output,%current);
1.271 raeburn 2321: my @crstypes = ('official','unofficial','community','textbook','placement');
1.248 raeburn 2322: if (ref($settings) eq 'HASH') {
2323: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2324: foreach my $type (@crstypes) {
2325: $current{$type} = $settings->{'uniquecode'}{$type};
2326: }
1.218 raeburn 2327: }
2328: }
2329: $output .= '<tr>'.
2330: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2331: '<td class="LC_left_item">';
2332: foreach my $type (@crstypes) {
2333: my $check = ' ';
2334: if ($current{$type}) {
2335: $check = ' checked="checked" ';
2336: }
2337: $output .= '<span class="LC_nobreak"><label>'.
2338: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2339: &mt($type).'</label></span>'.(' 'x2).' ';
2340: }
2341: $output .= '</td></tr>';
2342: $$rowtotal ++;
2343: return $output;
1.216 raeburn 2344: }
2345:
2346: sub print_textbookcourses {
1.242 raeburn 2347: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2348: my $rownum = 0;
2349: my $css_class;
2350: my $itemcount = 1;
2351: my $maxnum = 0;
2352: my $bookshash;
2353: if (ref($settings) eq 'HASH') {
1.242 raeburn 2354: $bookshash = $settings->{$type};
1.216 raeburn 2355: }
2356: my %ordered;
2357: if (ref($bookshash) eq 'HASH') {
2358: foreach my $item (keys(%{$bookshash})) {
2359: if (ref($bookshash->{$item}) eq 'HASH') {
2360: my $num = $bookshash->{$item}{'order'};
2361: $ordered{$num} = $item;
2362: }
2363: }
2364: }
2365: my $confname = $dom.'-domainconfig';
2366: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2367: my $maxnum = scalar(keys(%ordered));
2368: my $datatable;
1.216 raeburn 2369: if (keys(%ordered)) {
2370: my @items = sort { $a <=> $b } keys(%ordered);
2371: for (my $i=0; $i<@items; $i++) {
2372: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2373: my $key = $ordered{$items[$i]};
2374: my %coursehash=&Apache::lonnet::coursedescription($key);
2375: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2376: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2377: if (ref($bookshash->{$key}) eq 'HASH') {
2378: $subject = $bookshash->{$key}->{'subject'};
2379: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2380: if ($type eq 'textbooks') {
1.243 raeburn 2381: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2382: $author = $bookshash->{$key}->{'author'};
2383: $image = $bookshash->{$key}->{'image'};
2384: if ($image ne '') {
2385: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2386: my $imagethumb = "$path/tn-".$imagefile;
2387: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2388: }
1.216 raeburn 2389: }
2390: }
1.242 raeburn 2391: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2392: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2393: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2394: for (my $k=0; $k<=$maxnum; $k++) {
2395: my $vpos = $k+1;
2396: my $selstr;
2397: if ($k == $i) {
2398: $selstr = ' selected="selected" ';
2399: }
2400: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2401: }
2402: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2403: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2404: &mt('Delete?').'</label></span></td>'.
2405: '<td colspan="2">'.
1.242 raeburn 2406: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2407: (' 'x2).
1.242 raeburn 2408: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2409: if ($type eq 'textbooks') {
2410: $datatable .= (' 'x2).
1.243 raeburn 2411: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2412: (' 'x2).
1.242 raeburn 2413: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2414: (' 'x2).
2415: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2416: if ($image) {
1.267 raeburn 2417: $datatable .= $imgsrc.
1.242 raeburn 2418: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2419: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2420: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2421: }
2422: if ($switchserver) {
2423: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2424: } else {
2425: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2426: }
1.216 raeburn 2427: }
1.242 raeburn 2428: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2429: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2430: $coursetitle.'</span></td></tr>'."\n";
2431: $itemcount ++;
2432: }
2433: }
2434: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2435: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2436: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2437: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2438: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2439: for (my $k=0; $k<$maxnum+1; $k++) {
2440: my $vpos = $k+1;
2441: my $selstr;
2442: if ($k == $maxnum) {
2443: $selstr = ' selected="selected" ';
2444: }
2445: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2446: }
2447: $datatable .= '</select> '."\n".
1.242 raeburn 2448: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2449: '<td colspan="2">'.
1.242 raeburn 2450: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2451: (' 'x2).
1.242 raeburn 2452: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2453: (' 'x2);
2454: if ($type eq 'textbooks') {
1.243 raeburn 2455: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2456: (' 'x2).
2457: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2458: (' 'x2).
2459: '<span class="LC_nobreak">'.&mt('Image:').' ';
2460: if ($switchserver) {
2461: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2462: } else {
2463: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2464: }
1.216 raeburn 2465: }
2466: $datatable .= '</span>'."\n".
2467: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2468: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2469: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2470: &Apache::loncommon::selectcourse_link
1.242 raeburn 2471: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2472: '</span></td>'."\n".
2473: '</tr>'."\n";
2474: $itemcount ++;
2475: return $datatable;
2476: }
2477:
1.217 raeburn 2478: sub textbookcourses_javascript {
1.242 raeburn 2479: my ($settings) = @_;
2480: return unless(ref($settings) eq 'HASH');
2481: my (%ordered,%total,%jstext);
2482: foreach my $type ('textbooks','templates') {
2483: $total{$type} = 0;
2484: if (ref($settings->{$type}) eq 'HASH') {
2485: foreach my $item (keys(%{$settings->{$type}})) {
2486: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2487: my $num = $settings->{$type}->{$item}{'order'};
2488: $ordered{$type}{$num} = $item;
2489: }
2490: }
2491: $total{$type} = scalar(keys(%{$settings->{$type}}));
2492: }
2493: my @jsarray = ();
2494: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2495: push(@jsarray,$ordered{$type}{$item});
2496: }
2497: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2498: }
2499: return <<"ENDSCRIPT";
2500: <script type="text/javascript">
2501: // <![CDATA[
1.242 raeburn 2502: function reorderBooks(form,item,caller) {
1.217 raeburn 2503: var changedVal;
1.242 raeburn 2504: $jstext{'textbooks'};
2505: $jstext{'templates'};
2506: var newpos;
2507: var maxh;
2508: if (caller == 'textbooks') {
2509: newpos = 'textbooks_addbook_pos';
2510: maxh = 1 + $total{'textbooks'};
2511: } else {
2512: newpos = 'templates_addbook_pos';
2513: maxh = 1 + $total{'templates'};
2514: }
1.217 raeburn 2515: var current = new Array;
2516: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2517: if (item == newpos) {
2518: changedVal = newitemVal;
2519: } else {
2520: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2521: current[newitemVal] = newpos;
2522: }
1.242 raeburn 2523: if (caller == 'textbooks') {
2524: for (var i=0; i<textbooks.length; i++) {
2525: var elementName = 'textbooks_'+textbooks[i];
2526: if (elementName != item) {
2527: if (form.elements[elementName]) {
2528: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2529: current[currVal] = elementName;
2530: }
2531: }
2532: }
2533: }
2534: if (caller == 'templates') {
2535: for (var i=0; i<templates.length; i++) {
2536: var elementName = 'templates_'+templates[i];
2537: if (elementName != item) {
2538: if (form.elements[elementName]) {
2539: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2540: current[currVal] = elementName;
2541: }
1.217 raeburn 2542: }
2543: }
2544: }
2545: var oldVal;
2546: for (var j=0; j<maxh; j++) {
2547: if (current[j] == undefined) {
2548: oldVal = j;
2549: }
2550: }
2551: if (oldVal < changedVal) {
2552: for (var k=oldVal+1; k<=changedVal ; k++) {
2553: var elementName = current[k];
2554: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2555: }
2556: } else {
2557: for (var k=changedVal; k<oldVal; k++) {
2558: var elementName = current[k];
2559: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2560: }
2561: }
2562: return;
2563: }
2564:
2565: // ]]>
2566: </script>
2567:
2568: ENDSCRIPT
2569: }
2570:
1.267 raeburn 2571: sub ltitools_javascript {
2572: my ($settings) = @_;
2573: return unless(ref($settings) eq 'HASH');
2574: my (%ordered,$total,%jstext);
2575: $total = 0;
2576: foreach my $item (keys(%{$settings})) {
2577: if (ref($settings->{$item}) eq 'HASH') {
2578: my $num = $settings->{$item}{'order'};
2579: $ordered{$num} = $item;
2580: }
2581: }
2582: $total = scalar(keys(%{$settings}));
2583: my @jsarray = ();
2584: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2585: push(@jsarray,$ordered{$item});
2586: }
2587: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2588: return <<"ENDSCRIPT";
2589: <script type="text/javascript">
2590: // <![CDATA[
2591: function reorderLTI(form,item) {
2592: var changedVal;
2593: $jstext
2594: var newpos = 'ltitools_add_pos';
2595: var maxh = 1 + $total;
2596: var current = new Array;
2597: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2598: if (item == newpos) {
2599: changedVal = newitemVal;
2600: } else {
2601: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2602: current[newitemVal] = newpos;
2603: }
2604: for (var i=0; i<ltitools.length; i++) {
2605: var elementName = 'ltitools_'+ltitools[i];
2606: if (elementName != item) {
2607: if (form.elements[elementName]) {
2608: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2609: current[currVal] = elementName;
2610: }
2611: }
2612: }
2613: var oldVal;
2614: for (var j=0; j<maxh; j++) {
2615: if (current[j] == undefined) {
2616: oldVal = j;
2617: }
2618: }
2619: if (oldVal < changedVal) {
2620: for (var k=oldVal+1; k<=changedVal ; k++) {
2621: var elementName = current[k];
2622: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2623: }
2624: } else {
2625: for (var k=changedVal; k<oldVal; k++) {
2626: var elementName = current[k];
2627: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2628: }
2629: }
2630: return;
2631: }
2632:
2633: // ]]>
2634: </script>
2635:
2636: ENDSCRIPT
2637: }
2638:
1.3 raeburn 2639: sub print_autoenroll {
1.30 raeburn 2640: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2641: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2642: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2643: if (ref($settings) eq 'HASH') {
2644: if (exists($settings->{'run'})) {
2645: if ($settings->{'run'} eq '0') {
2646: $runoff = ' checked="checked" ';
2647: $runon = ' ';
2648: } else {
2649: $runon = ' checked="checked" ';
2650: $runoff = ' ';
2651: }
2652: } else {
2653: if ($autorun) {
2654: $runon = ' checked="checked" ';
2655: $runoff = ' ';
2656: } else {
2657: $runoff = ' checked="checked" ';
2658: $runon = ' ';
2659: }
2660: }
1.129 raeburn 2661: if (exists($settings->{'co-owners'})) {
2662: if ($settings->{'co-owners'} eq '0') {
2663: $coownersoff = ' checked="checked" ';
2664: $coownerson = ' ';
2665: } else {
2666: $coownerson = ' checked="checked" ';
2667: $coownersoff = ' ';
2668: }
2669: } else {
2670: $coownersoff = ' checked="checked" ';
2671: $coownerson = ' ';
2672: }
1.3 raeburn 2673: if (exists($settings->{'sender_domain'})) {
2674: $defdom = $settings->{'sender_domain'};
2675: }
1.274 raeburn 2676: if (exists($settings->{'autofailsafe'})) {
2677: $failsafe = $settings->{'autofailsafe'};
2678: }
1.14 raeburn 2679: } else {
2680: if ($autorun) {
2681: $runon = ' checked="checked" ';
2682: $runoff = ' ';
2683: } else {
2684: $runoff = ' checked="checked" ';
2685: $runon = ' ';
2686: }
1.3 raeburn 2687: }
2688: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2689: my $notif_sender;
2690: if (ref($settings) eq 'HASH') {
2691: $notif_sender = $settings->{'sender_uname'};
2692: }
1.3 raeburn 2693: my $datatable='<tr class="LC_odd_row">'.
2694: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2695: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2696: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2697: $runon.' value="1" />'.&mt('Yes').'</label> '.
2698: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2699: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2700: '</tr><tr>'.
2701: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2702: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2703: &mt('username').': '.
2704: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2705: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2706: ': '.$domform.'</span></td></tr>'.
2707: '<tr class="LC_odd_row">'.
2708: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2709: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2710: '<input type="radio" name="autoassign_coowners"'.
2711: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2712: '<label><input type="radio" name="autoassign_coowners"'.
2713: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 2714: '</tr><tr>'.
2715: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2716: '<td class="LC_right_item"><span class="LC_nobreak">'.
2717: '<input type="text" name="autoenroll_failsafe"'.
2718: ' value="'.$failsafe.'" size="4" /></td></tr>';
2719: $$rowtotal += 4;
1.3 raeburn 2720: return $datatable;
2721: }
2722:
2723: sub print_autoupdate {
1.30 raeburn 2724: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2725: my $datatable;
2726: if ($position eq 'top') {
2727: my $updateon = ' ';
2728: my $updateoff = ' checked="checked" ';
2729: my $classlistson = ' ';
2730: my $classlistsoff = ' checked="checked" ';
2731: if (ref($settings) eq 'HASH') {
2732: if ($settings->{'run'} eq '1') {
2733: $updateon = $updateoff;
2734: $updateoff = ' ';
2735: }
2736: if ($settings->{'classlists'} eq '1') {
2737: $classlistson = $classlistsoff;
2738: $classlistsoff = ' ';
2739: }
2740: }
2741: my %title = (
2742: run => 'Auto-update active?',
2743: classlists => 'Update information in classlists?',
2744: );
2745: $datatable = '<tr class="LC_odd_row">'.
2746: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2747: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2748: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2749: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2750: '<label><input type="radio" name="autoupdate_run"'.
2751: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2752: '</tr><tr>'.
2753: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2754: '<td class="LC_right_item"><span class="LC_nobreak">'.
2755: '<label><input type="radio" name="classlists"'.
2756: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2757: '<label><input type="radio" name="classlists"'.
2758: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2759: '</tr>';
1.30 raeburn 2760: $$rowtotal += 2;
1.131 raeburn 2761: } elsif ($position eq 'middle') {
2762: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2763: my $numinrow = 3;
2764: my $locknamesettings;
2765: $datatable .= &insttypes_row($settings,$types,$usertypes,
2766: $dom,$numinrow,$othertitle,
2767: 'lockablenames');
2768: $$rowtotal ++;
1.3 raeburn 2769: } else {
1.44 raeburn 2770: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2771: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2772: 'permanentemail','id');
1.33 raeburn 2773: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2774: my $numrows = 0;
1.26 raeburn 2775: if (ref($types) eq 'ARRAY') {
2776: if (@{$types} > 0) {
2777: $datatable =
2778: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2779: \@fields,$types,\$numrows);
1.30 raeburn 2780: $$rowtotal += @{$types};
1.26 raeburn 2781: }
1.3 raeburn 2782: }
2783: $datatable .=
2784: &usertype_update_row($settings,{'default' => $othertitle},
2785: \%fieldtitles,\@fields,['default'],
2786: \$numrows);
1.30 raeburn 2787: $$rowtotal ++;
1.3 raeburn 2788: }
2789: return $datatable;
2790: }
2791:
1.125 raeburn 2792: sub print_autocreate {
2793: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2794: my (%createon,%createoff,%currhash);
1.125 raeburn 2795: my @types = ('xml','req');
2796: if (ref($settings) eq 'HASH') {
2797: foreach my $item (@types) {
2798: $createoff{$item} = ' checked="checked" ';
2799: $createon{$item} = ' ';
2800: if (exists($settings->{$item})) {
2801: if ($settings->{$item}) {
2802: $createon{$item} = ' checked="checked" ';
2803: $createoff{$item} = ' ';
2804: }
2805: }
2806: }
1.210 raeburn 2807: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2808: $currhash{$settings->{'xmldc'}} = 1;
2809: }
1.125 raeburn 2810: } else {
2811: foreach my $item (@types) {
2812: $createoff{$item} = ' checked="checked" ';
2813: $createon{$item} = ' ';
2814: }
2815: }
2816: $$rowtotal += 2;
1.191 raeburn 2817: my $numinrow = 2;
1.125 raeburn 2818: my $datatable='<tr class="LC_odd_row">'.
2819: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2820: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2821: '<input type="radio" name="autocreate_xml"'.
2822: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2823: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2824: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2825: '</td></tr><tr>'.
2826: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2827: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2828: '<input type="radio" name="autocreate_req"'.
2829: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2830: '<label><input type="radio" name="autocreate_req"'.
2831: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2832: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2833: 'autocreate_xmldc',%currhash);
1.247 raeburn 2834: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2835: if ($numdc > 1) {
1.247 raeburn 2836: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2837: '</td><td class="LC_left_item">';
1.125 raeburn 2838: } else {
1.247 raeburn 2839: $datatable .= &mt('Course creation processed as:').
2840: '</td><td class="LC_right_item">';
1.125 raeburn 2841: }
1.247 raeburn 2842: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 2843: $$rowtotal += $rows;
1.125 raeburn 2844: return $datatable;
2845: }
2846:
1.23 raeburn 2847: sub print_directorysrch {
1.277 raeburn 2848: my ($position,$dom,$settings,$rowtotal) = @_;
2849: my $datatable;
2850: if ($position eq 'top') {
2851: my $instsrchon = ' ';
2852: my $instsrchoff = ' checked="checked" ';
2853: my ($exacton,$containson,$beginson);
2854: my $instlocalon = ' ';
2855: my $instlocaloff = ' checked="checked" ';
2856: if (ref($settings) eq 'HASH') {
2857: if ($settings->{'available'} eq '1') {
2858: $instsrchon = $instsrchoff;
2859: $instsrchoff = ' ';
2860: }
2861: if ($settings->{'localonly'} eq '1') {
2862: $instlocalon = $instlocaloff;
2863: $instlocaloff = ' ';
2864: }
2865: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2866: foreach my $type (@{$settings->{'searchtypes'}}) {
2867: if ($type eq 'exact') {
2868: $exacton = ' checked="checked" ';
2869: } elsif ($type eq 'contains') {
2870: $containson = ' checked="checked" ';
2871: } elsif ($type eq 'begins') {
2872: $beginson = ' checked="checked" ';
2873: }
2874: }
2875: } else {
2876: if ($settings->{'searchtypes'} eq 'exact') {
2877: $exacton = ' checked="checked" ';
2878: } elsif ($settings->{'searchtypes'} eq 'contains') {
2879: $containson = ' checked="checked" ';
2880: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2881: $exacton = ' checked="checked" ';
2882: $containson = ' checked="checked" ';
2883: }
2884: }
1.277 raeburn 2885: }
2886: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2887: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2888:
2889: my $numinrow = 4;
2890: my $cansrchrow = 0;
2891: $datatable='<tr class="LC_odd_row">'.
2892: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2893: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2894: '<input type="radio" name="dirsrch_available"'.
2895: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2896: '<label><input type="radio" name="dirsrch_available"'.
2897: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2898: '</tr><tr>'.
2899: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2900: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2901: '<input type="radio" name="dirsrch_instlocalonly"'.
2902: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2903: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2904: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2905: '</tr>';
2906: $$rowtotal += 2;
2907: if (ref($usertypes) eq 'HASH') {
2908: if (keys(%{$usertypes}) > 0) {
2909: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2910: $numinrow,$othertitle,'cansearch');
2911: $cansrchrow = 1;
1.25 raeburn 2912: }
1.23 raeburn 2913: }
1.277 raeburn 2914: if ($cansrchrow) {
2915: $$rowtotal ++;
2916: $datatable .= '<tr>';
2917: } else {
2918: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 2919: }
1.277 raeburn 2920: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2921: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2922: foreach my $title (@{$titleorder}) {
2923: if (defined($searchtitles->{$title})) {
2924: my $check = ' ';
2925: if (ref($settings) eq 'HASH') {
2926: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2927: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2928: $check = ' checked="checked" ';
2929: }
1.39 raeburn 2930: }
1.25 raeburn 2931: }
1.277 raeburn 2932: $datatable .= '<td class="LC_left_item">'.
2933: '<span class="LC_nobreak"><label>'.
2934: '<input type="checkbox" name="searchby" '.
2935: 'value="'.$title.'"'.$check.'/>'.
2936: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2937: }
2938: }
1.277 raeburn 2939: $datatable .= '</tr></table></td></tr>';
2940: $$rowtotal ++;
2941: if ($cansrchrow) {
2942: $datatable .= '<tr class="LC_odd_row">';
2943: } else {
2944: $datatable .= '<tr>';
2945: }
2946: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2947: '<td class="LC_left_item" colspan="2">'.
2948: '<span class="LC_nobreak"><label>'.
2949: '<input type="checkbox" name="searchtypes" '.
2950: $exacton.' value="exact" />'.&mt('Exact match').
2951: '</label> '.
2952: '<label><input type="checkbox" name="searchtypes" '.
2953: $beginson.' value="begins" />'.&mt('Begins with').
2954: '</label> '.
2955: '<label><input type="checkbox" name="searchtypes" '.
2956: $containson.' value="contains" />'.&mt('Contains').
2957: '</label></span></td></tr>';
2958: $$rowtotal ++;
1.26 raeburn 2959: } else {
1.277 raeburn 2960: my $domsrchon = ' checked="checked" ';
2961: my $domsrchoff = ' ';
2962: my $domlocalon = ' ';
2963: my $domlocaloff = ' checked="checked" ';
2964: if (ref($settings) eq 'HASH') {
2965: if ($settings->{'lclocalonly'} eq '1') {
2966: $domlocalon = $domlocaloff;
2967: $domlocaloff = ' ';
2968: }
2969: if ($settings->{'lcavailable'} eq '0') {
2970: $domsrchoff = $domsrchon;
2971: $domsrchon = ' ';
2972: }
2973: }
2974: $datatable='<tr class="LC_odd_row">'.
2975: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2976: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2977: '<input type="radio" name="dirsrch_domavailable"'.
2978: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2979: '<label><input type="radio" name="dirsrch_domavailable"'.
2980: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2981: '</tr><tr>'.
2982: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2983: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2984: '<input type="radio" name="dirsrch_domlocalonly"'.
2985: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2986: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2987: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2988: '</tr>';
2989: $$rowtotal += 2;
1.26 raeburn 2990: }
1.25 raeburn 2991: return $datatable;
2992: }
2993:
1.28 raeburn 2994: sub print_contacts {
1.286 raeburn 2995: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 2996: my $datatable;
2997: my @contacts = ('adminemail','supportemail');
1.286 raeburn 2998: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
2999: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
3000: if ($position eq 'top') {
3001: if (ref($settings) eq 'HASH') {
3002: foreach my $item (@contacts) {
3003: if (exists($settings->{$item})) {
3004: $to{$item} = $settings->{$item};
3005: }
3006: }
3007: }
3008: } elsif ($position eq 'middle') {
3009: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
3010: 'updatesmail','idconflictsmail');
1.288 raeburn 3011: foreach my $type (@mailings) {
3012: $otheremails{$type} = '';
3013: }
1.286 raeburn 3014: } else {
3015: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3016: foreach my $type (@mailings) {
3017: $otheremails{$type} = '';
3018: }
1.286 raeburn 3019: $bccemails{'helpdeskmail'} = '';
3020: $bccemails{'otherdomsmail'} = '';
3021: $includestr{'helpdeskmail'} = '';
3022: $includestr{'otherdomsmail'} = '';
3023: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3024: }
1.28 raeburn 3025: if (ref($settings) eq 'HASH') {
1.286 raeburn 3026: unless ($position eq 'top') {
3027: foreach my $type (@mailings) {
3028: if (exists($settings->{$type})) {
3029: if (ref($settings->{$type}) eq 'HASH') {
3030: foreach my $item (@contacts) {
3031: if ($settings->{$type}{$item}) {
3032: $checked{$type}{$item} = ' checked="checked" ';
3033: }
3034: }
3035: $otheremails{$type} = $settings->{$type}{'others'};
3036: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3037: $bccemails{$type} = $settings->{$type}{'bcc'};
3038: if ($settings->{$type}{'include'} ne '') {
3039: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3040: $includestr{$type} = &unescape($includestr{$type});
3041: }
3042: }
3043: }
3044: } elsif ($type eq 'lonstatusmail') {
3045: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3046: }
1.28 raeburn 3047: }
3048: }
1.286 raeburn 3049: if ($position eq 'bottom') {
3050: foreach my $type (@mailings) {
3051: $bccemails{$type} = $settings->{$type}{'bcc'};
3052: if ($settings->{$type}{'include'} ne '') {
3053: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3054: $includestr{$type} = &unescape($includestr{$type});
3055: }
3056: }
3057: if (ref($settings->{'helpform'}) eq 'HASH') {
3058: if (ref($fields) eq 'ARRAY') {
3059: foreach my $field (@{$fields}) {
3060: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3061: }
1.286 raeburn 3062: }
3063: if (exists($settings->{'helpform'}{'maxsize'})) {
3064: $maxsize = $settings->{'helpform'}{'maxsize'};
3065: } else {
1.289 raeburn 3066: $maxsize = '1.0';
1.286 raeburn 3067: }
3068: } else {
3069: if (ref($fields) eq 'ARRAY') {
3070: foreach my $field (@{$fields}) {
3071: $currfield{$field} = 'yes';
1.134 raeburn 3072: }
1.28 raeburn 3073: }
1.286 raeburn 3074: $maxsize = '1.0';
1.28 raeburn 3075: }
3076: }
3077: } else {
1.286 raeburn 3078: if ($position eq 'top') {
3079: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3080: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3081: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3082: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3083: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3084: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3085: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3086: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3087: } elsif ($position eq 'bottom') {
3088: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3089: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3090: if (ref($fields) eq 'ARRAY') {
3091: foreach my $field (@{$fields}) {
3092: $currfield{$field} = 'yes';
3093: }
3094: }
3095: $maxsize = '1.0';
3096: }
1.28 raeburn 3097: }
3098: my ($titles,$short_titles) = &contact_titles();
3099: my $rownum = 0;
3100: my $css_class;
1.286 raeburn 3101: if ($position eq 'top') {
3102: foreach my $item (@contacts) {
3103: $css_class = $rownum%2?' class="LC_odd_row"':'';
3104: $datatable .= '<tr'.$css_class.'>'.
3105: '<td><span class="LC_nobreak">'.$titles->{$item}.
3106: '</span></td><td class="LC_right_item">'.
3107: '<input type="text" name="'.$item.'" value="'.
3108: $to{$item}.'" /></td></tr>';
3109: $rownum ++;
3110: }
3111: } else {
3112: foreach my $type (@mailings) {
3113: $css_class = $rownum%2?' class="LC_odd_row"':'';
3114: $datatable .= '<tr'.$css_class.'>'.
3115: '<td><span class="LC_nobreak">'.
3116: $titles->{$type}.': </span></td>'.
3117: '<td class="LC_left_item">';
3118: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3119: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3120: }
3121: $datatable .= '<span class="LC_nobreak">';
3122: foreach my $item (@contacts) {
3123: $datatable .= '<label>'.
3124: '<input type="checkbox" name="'.$type.'"'.
3125: $checked{$type}{$item}.
3126: ' value="'.$item.'" />'.$short_titles->{$item}.
3127: '</label> ';
3128: }
3129: $datatable .= '</span><br />'.&mt('Others').': '.
3130: '<input type="text" name="'.$type.'_others" '.
3131: 'value="'.$otheremails{$type}.'" />';
3132: my %locchecked;
3133: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3134: foreach my $loc ('s','b') {
3135: if ($includeloc{$type} eq $loc) {
3136: $locchecked{$loc} = ' checked="checked"';
3137: last;
3138: }
3139: }
3140: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3141: '<input type="text" name="'.$type.'_bcc" '.
3142: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3143: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3144: &mt('Text automatically added to e-mail:').' '.
3145: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
3146: '<span class="LC_nobreak">'.&mt('Location:').' '.
3147: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3148: (' 'x2).
3149: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3150: '</span></fieldset>';
3151: }
3152: $datatable .= '</td></tr>'."\n";
3153: $rownum ++;
3154: }
1.28 raeburn 3155: }
1.286 raeburn 3156: if ($position eq 'middle') {
3157: my %choices;
3158: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
1.289 raeburn 3159: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3160: &mt('LON-CAPA core group - MSU'),600,500));
1.286 raeburn 3161: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3162: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3163: &mt('LON-CAPA core group - MSU'),600,500));
3164: my @toggles = ('reporterrors','reportupdates');
3165: my %defaultchecked = ('reporterrors' => 'on',
3166: 'reportupdates' => 'on');
3167: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3168: \%choices,$rownum);
3169: $datatable .= $reports;
3170: } elsif ($position eq 'bottom') {
1.69 raeburn 3171: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 3172: $datatable .= '<tr'.$css_class.'>'.
1.286 raeburn 3173: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3174: &mt('(e-mail, subject, and description always shown)').
3175: '</td><td class="LC_left_item">';
1.289 raeburn 3176: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
1.286 raeburn 3177: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3178: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3179: foreach my $field (@{$fields}) {
3180: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3181: if (($field eq 'screenshot') || ($field eq 'cc')) {
3182: $datatable .= ' '.&mt('(logged-in users)');
3183: }
3184: $datatable .='</td><td>';
3185: my $clickaction;
3186: if ($field eq 'screenshot') {
3187: $clickaction = ' onclick="screenshotSize(this);"';
3188: }
3189: if (ref($possoptions->{$field}) eq 'ARRAY') {
3190: foreach my $option (@{$possoptions->{$field}}) {
3191: my $checked;
3192: if ($currfield{$field} eq $option) {
3193: $checked = ' checked="checked"';
3194: }
3195: $datatable .= '<span class="LC_nobreak"><label>'.
3196: '<input type="radio" name="helpform_'.$field.'" '.
3197: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3198: '</label></span>'.(' 'x2);
3199: }
3200: }
3201: if ($field eq 'screenshot') {
3202: my $display;
3203: if ($currfield{$field} eq 'no') {
3204: $display = ' style="display:none"';
3205: }
3206: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
3207: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3208: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3209: }
3210: $datatable .= '</td></tr>';
3211: }
3212: $datatable .= '</table>';
1.134 raeburn 3213: }
3214: $datatable .= '</td></tr>'."\n";
1.203 raeburn 3215: $rownum ++;
1.28 raeburn 3216: }
1.30 raeburn 3217: $$rowtotal += $rownum;
1.28 raeburn 3218: return $datatable;
3219: }
3220:
1.286 raeburn 3221: sub contacts_javascript {
3222: return <<"ENDSCRIPT";
3223:
3224: <script type="text/javascript">
3225: // <![CDATA[
3226:
3227: function screenshotSize(field) {
3228: if (document.getElementById('help_screenshotsize')) {
3229: if (field.value == 'no') {
1.289 raeburn 3230: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3231: } else {
3232: document.getElementById('help_screenshotsize').style.display="";
3233: }
3234: }
3235: return;
3236: }
3237:
3238: // ]]>
3239: </script>
3240:
3241: ENDSCRIPT
3242: }
3243:
1.118 jms 3244: sub print_helpsettings {
1.282 raeburn 3245: my ($position,$dom,$settings,$rowtotal) = @_;
3246: my $confname = $dom.'-domainconfig';
1.285 raeburn 3247: my $formname = 'display';
1.168 raeburn 3248: my ($datatable,$itemcount);
1.282 raeburn 3249: if ($position eq 'top') {
3250: $itemcount = 1;
3251: my (%choices,%defaultchecked,@toggles);
3252: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3253: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3254: &mt('LON-CAPA bug tracker'),600,500));
3255: %defaultchecked = ('submitbugs' => 'on');
3256: @toggles = ('submitbugs');
3257: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3258: \%choices,$itemcount);
3259: $$rowtotal ++;
3260: } else {
3261: my $css_class;
3262: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3263: my (%customroles,%ordered,%current);
1.301 ! raeburn 3264: if (ref($settings) eq 'HASH') {
! 3265: if (ref($settings->{'adhoc'}) eq 'HASH') {
! 3266: %current = %{$settings->{'adhoc'}};
! 3267: }
1.285 raeburn 3268: }
3269: my $count = 0;
3270: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3271: if ($key=~/^rolesdef\_(\w+)$/) {
3272: my $rolename = $1;
1.285 raeburn 3273: my (%privs,$order);
1.282 raeburn 3274: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3275: $customroles{$rolename} = \%privs;
1.285 raeburn 3276: if (ref($current{$rolename}) eq 'HASH') {
3277: $order = $current{$rolename}{'order'};
3278: }
3279: if ($order eq '') {
3280: $order = $count;
3281: }
3282: $ordered{$order} = $rolename;
3283: $count++;
3284: }
3285: }
3286: my $maxnum = scalar(keys(%ordered));
3287: my @roles_by_num = ();
3288: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3289: push(@roles_by_num,$item);
3290: }
3291: my $context = 'domprefs';
3292: my $crstype = 'Course';
3293: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3294: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3295: my ($numstatustypes,@jsarray);
3296: if (ref($types) eq 'ARRAY') {
3297: if (@{$types} > 0) {
3298: $numstatustypes = scalar(@{$types});
3299: push(@accesstypes,'status');
3300: @jsarray = ('bystatus');
1.282 raeburn 3301: }
3302: }
1.290 raeburn 3303: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3304: if (keys(%domhelpdesk)) {
3305: push(@accesstypes,('inc','exc'));
3306: push(@jsarray,('notinc','notexc'));
3307: }
3308: my $hiddenstr = join("','",@jsarray);
3309: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.282 raeburn 3310: my $context = 'domprefs';
3311: my $crstype = 'Course';
1.285 raeburn 3312: my $prefix = 'helproles_';
3313: my $add_class = 'LC_hidden';
3314: foreach my $num (@roles_by_num) {
3315: my $role = $ordered{$num};
3316: my ($desc,$access,@statuses);
3317: if (ref($current{$role}) eq 'HASH') {
3318: $desc = $current{$role}{'desc'};
3319: $access = $current{$role}{'access'};
3320: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3321: @statuses = @{$current{$role}{'insttypes'}};
3322: }
3323: }
3324: if ($desc eq '') {
3325: $desc = $role;
3326: }
3327: my $identifier = 'custhelp'.$num;
1.282 raeburn 3328: my %full=();
3329: my %levels= (
3330: course => {},
3331: domain => {},
3332: system => {},
3333: );
3334: my %levelscurrent=(
3335: course => {},
3336: domain => {},
3337: system => {},
3338: );
3339: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3340: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3341: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 3342: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3343: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3344: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3345: for (my $k=0; $k<=$maxnum; $k++) {
3346: my $vpos = $k+1;
3347: my $selstr;
3348: if ($k == $num) {
3349: $selstr = ' selected="selected" ';
3350: }
3351: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3352: }
3353: $datatable .= '</select>'.(' 'x2).
3354: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3355: '</td>'.
3356: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3357: &mt('Name shown to users:').
3358: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3359: '</fieldset>'.
3360: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3361: $othertitle,$usertypes,$types,\%domhelpdesk).
3362: '<fieldset>'.
3363: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 3364: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 3365: \%levelscurrent,$identifier,
3366: 'LC_hidden',$prefix.$num.'_privs').
3367: '</fieldset></td>';
1.282 raeburn 3368: $itemcount ++;
3369: }
3370: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3371: my $newcust = 'custhelp'.$count;
3372: my (%privs,%levelscurrent);
3373: my %full=();
3374: my %levels= (
3375: course => {},
3376: domain => {},
3377: system => {},
3378: );
3379: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3380: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 3381: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3382: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3383: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3384: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3385: for (my $k=0; $k<$maxnum+1; $k++) {
3386: my $vpos = $k+1;
3387: my $selstr;
3388: if ($k == $maxnum) {
3389: $selstr = ' selected="selected" ';
3390: }
3391: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3392: }
3393: $datatable .= '</select> '."\n".
1.282 raeburn 3394: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3395: '</label></span></td>'.
1.285 raeburn 3396: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3397: '<span class="LC_nobreak">'.
3398: &mt('Internal name:').
3399: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3400: '</span>'.(' 'x4).
3401: '<span class="LC_nobreak">'.
3402: &mt('Name shown to users:').
3403: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3404: '</span></fieldset>'.
3405: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3406: $usertypes,$types,\%domhelpdesk).
3407: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 3408: &Apache::lonuserutils::custom_role_header($context,$crstype,
3409: \@templateroles,$newcust).
3410: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3411: \%levelscurrent,$newcust).
1.285 raeburn 3412: '</fieldset></td></tr>';
1.282 raeburn 3413: $count ++;
3414: $$rowtotal += $count;
3415: }
1.166 raeburn 3416: return $datatable;
1.121 raeburn 3417: }
3418:
1.285 raeburn 3419: sub adhocbutton {
3420: my ($prefix,$num,$field,$visibility) = @_;
3421: my %lt = &Apache::lonlocal::texthash(
3422: show => 'Show details',
3423: hide => 'Hide details',
3424: );
3425: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3426: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3427: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3428: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3429: }
3430:
3431: sub helpsettings_javascript {
3432: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3433: return unless(ref($roles_by_num) eq 'ARRAY');
3434: my %html_js_lt = &Apache::lonlocal::texthash(
3435: show => 'Show details',
3436: hide => 'Hide details',
3437: );
3438: &html_escape(\%html_js_lt);
3439: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3440: return <<"ENDSCRIPT";
3441: <script type="text/javascript">
3442: // <![CDATA[
3443:
3444: function reorderHelpRoles(form,item) {
3445: var changedVal;
3446: $jstext
3447: var newpos = 'helproles_${total}_pos';
3448: var maxh = 1 + $total;
3449: var current = new Array();
3450: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3451: if (item == newpos) {
3452: changedVal = newitemVal;
3453: } else {
3454: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3455: current[newitemVal] = newpos;
3456: }
3457: for (var i=0; i<helproles.length; i++) {
3458: var elementName = 'helproles_'+helproles[i]+'_pos';
3459: if (elementName != item) {
3460: if (form.elements[elementName]) {
3461: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3462: current[currVal] = elementName;
3463: }
3464: }
3465: }
3466: var oldVal;
3467: for (var j=0; j<maxh; j++) {
3468: if (current[j] == undefined) {
3469: oldVal = j;
3470: }
3471: }
3472: if (oldVal < changedVal) {
3473: for (var k=oldVal+1; k<=changedVal ; k++) {
3474: var elementName = current[k];
3475: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3476: }
3477: } else {
3478: for (var k=changedVal; k<oldVal; k++) {
3479: var elementName = current[k];
3480: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3481: }
3482: }
3483: return;
3484: }
3485:
3486: function helpdeskAccess(num) {
3487: var curraccess = null;
3488: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3489: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3490: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3491: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3492: }
3493: }
3494: }
3495: var shown = Array();
3496: var hidden = Array();
3497: if (curraccess == 'none') {
3498: hidden = Array('$hiddenstr');
3499: } else {
3500: if (curraccess == 'status') {
3501: shown = Array('bystatus');
3502: hidden = Array('notinc','notexc');
3503: } else {
3504: if (curraccess == 'exc') {
3505: shown = Array('notexc');
3506: hidden = Array('notinc','bystatus');
3507: }
3508: if (curraccess == 'inc') {
3509: shown = Array('notinc');
3510: hidden = Array('notexc','bystatus');
3511: }
1.293 raeburn 3512: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 3513: hidden = Array('notinc','notexc','bystatus');
3514: }
3515: }
3516: }
3517: if (hidden.length > 0) {
3518: for (var i=0; i<hidden.length; i++) {
3519: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3520: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3521: }
3522: }
3523: }
3524: if (shown.length > 0) {
3525: for (var i=0; i<shown.length; i++) {
3526: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3527: if (shown[i] == 'privs') {
3528: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3529: } else {
3530: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3531: }
3532: }
3533: }
3534: }
3535: return;
3536: }
3537:
3538: function toggleHelpdeskItem(num,field) {
3539: if (document.getElementById('helproles_'+num+'_'+field)) {
3540: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 3541: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 3542: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3543: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3544: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3545: }
3546: } else {
3547: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3548: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3549: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3550: }
3551: }
3552: }
3553: return;
3554: }
3555:
3556: // ]]>
3557: </script>
3558:
3559: ENDSCRIPT
3560: }
3561:
3562: sub helpdeskroles_access {
3563: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3564: $usertypes,$types,$domhelpdesk) = @_;
3565: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3566: my %lt = &Apache::lonlocal::texthash(
3567: 'rou' => 'Role usage',
3568: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 3569: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3570: 'dh' => 'All with domain helpdesk role',
3571: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 3572: 'none' => 'None',
3573: 'status' => 'Determined based on institutional status',
3574: 'inc' => 'Include all, but exclude specific personnel',
3575: 'exc' => 'Exclude all, but include specific personnel',
3576: );
3577: my %usecheck = (
3578: all => ' checked="checked"',
3579: );
3580: my %displaydiv = (
3581: status => 'none',
3582: inc => 'none',
3583: exc => 'none',
3584: priv => 'block',
3585: );
3586: my $output;
3587: if (ref($current) eq 'HASH') {
3588: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3589: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3590: $usecheck{$current->{access}} = $usecheck{'all'};
3591: delete($usecheck{'all'});
3592: if ($current->{access} =~ /^(status|inc|exc)$/) {
3593: my $access = $1;
3594: $displaydiv{$access} = 'inline';
3595: } elsif ($current->{access} eq 'none') {
3596: $displaydiv{'priv'} = 'none';
3597: }
3598: }
3599: }
3600: }
3601: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3602: '<p>'.$lt{'whi'}.'</p>';
3603: foreach my $access (@{$accesstypes}) {
3604: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3605: ' onclick="helpdeskAccess('."'$num'".');" />'.
3606: $lt{$access}.'</label>';
3607: if ($access eq 'status') {
3608: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3609: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3610: $othertitle,$usertypes,$types).
3611: '</div>';
3612: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3613: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3614: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3615: '</div>';
3616: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3617: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3618: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3619: '</div>';
3620: }
3621: $output .= '</p>';
3622: }
3623: $output .= '</fieldset>';
3624: return $output;
3625: }
3626:
1.121 raeburn 3627: sub radiobutton_prefs {
1.192 raeburn 3628: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 3629: $additional,$align) = @_;
1.121 raeburn 3630: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3631: (ref($choices) eq 'HASH'));
3632:
1.170 raeburn 3633: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 3634:
3635: foreach my $item (@{$toggles}) {
3636: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3637: $checkedon{$item} = ' checked="checked" ';
3638: $checkedoff{$item} = ' ';
1.121 raeburn 3639: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3640: $checkedoff{$item} = ' checked="checked" ';
3641: $checkedon{$item} = ' ';
3642: }
3643: }
3644: if (ref($settings) eq 'HASH') {
1.121 raeburn 3645: foreach my $item (@{$toggles}) {
1.118 jms 3646: if ($settings->{$item} eq '1') {
3647: $checkedon{$item} = ' checked="checked" ';
3648: $checkedoff{$item} = ' ';
3649: } elsif ($settings->{$item} eq '0') {
3650: $checkedoff{$item} = ' checked="checked" ';
3651: $checkedon{$item} = ' ';
3652: }
3653: }
1.121 raeburn 3654: }
1.192 raeburn 3655: if ($onclick) {
3656: $onclick = ' onclick="'.$onclick.'"';
3657: }
1.121 raeburn 3658: foreach my $item (@{$toggles}) {
1.118 jms 3659: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3660: $datatable .=
1.192 raeburn 3661: '<tr'.$css_class.'><td valign="top">'.
3662: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 3663: '</span></td>';
3664: if ($align eq 'left') {
3665: $datatable .= '<td class="LC_left_item">';
3666: } else {
3667: $datatable .= '<td class="LC_right_item">';
3668: }
1.289 raeburn 3669: $datatable .=
1.257 raeburn 3670: '<span class="LC_nobreak">'.
1.118 jms 3671: '<label><input type="radio" name="'.
1.192 raeburn 3672: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3673: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 3674: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3675: '</span>'.$additional.
3676: '</td>'.
1.118 jms 3677: '</tr>';
3678: $itemcount ++;
1.121 raeburn 3679: }
3680: return ($datatable,$itemcount);
3681: }
3682:
1.267 raeburn 3683: sub print_ltitools {
3684: my ($dom,$settings,$rowtotal) = @_;
3685: my $rownum = 0;
3686: my $css_class;
3687: my $itemcount = 1;
3688: my $maxnum = 0;
3689: my %ordered;
3690: if (ref($settings) eq 'HASH') {
3691: foreach my $item (keys(%{$settings})) {
3692: if (ref($settings->{$item}) eq 'HASH') {
3693: my $num = $settings->{$item}{'order'};
3694: $ordered{$num} = $item;
3695: }
3696: }
3697: }
3698: my $confname = $dom.'-domainconfig';
3699: my $switchserver = &check_switchserver($dom,$confname);
3700: my $maxnum = scalar(keys(%ordered));
3701: my $datatable = <itools_javascript($settings);
3702: my %lt = <itools_names();
3703: my @courseroles = ('cc','in','ta','ep','st');
3704: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3705: my @fields = ('fullname','firstname','lastname','email','user','roles');
3706: if (keys(%ordered)) {
3707: my @items = sort { $a <=> $b } keys(%ordered);
3708: for (my $i=0; $i<@items; $i++) {
3709: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3710: my $item = $ordered{$items[$i]};
3711: my ($title,$key,$secret,$url,$imgsrc,$version);
3712: if (ref($settings->{$item}) eq 'HASH') {
3713: $title = $settings->{$item}->{'title'};
3714: $url = $settings->{$item}->{'url'};
3715: $key = $settings->{$item}->{'key'};
3716: $secret = $settings->{$item}->{'secret'};
3717: my $image = $settings->{$item}->{'image'};
3718: if ($image ne '') {
3719: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3720: }
3721: }
3722: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3723: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3724: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3725: for (my $k=0; $k<=$maxnum; $k++) {
3726: my $vpos = $k+1;
3727: my $selstr;
3728: if ($k == $i) {
3729: $selstr = ' selected="selected" ';
3730: }
3731: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3732: }
3733: $datatable .= '</select>'.(' 'x2).
3734: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3735: &mt('Delete?').'</label></span></td>'.
3736: '<td colspan="2">'.
3737: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3738: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3739: (' 'x2).
3740: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3741: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3742: (' 'x2).
3743: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3744: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3745: '<br /><br />'.
3746: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3747: ' value="'.$url.'" /></span>'.
3748: (' 'x2).
3749: '<span class="LC_nobreak">'.$lt{'key'}.
3750: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3751: (' 'x2).
3752: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3753: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3754: '<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>'.
3755: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3756: '</fieldset>'.
3757: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3758: '<span class="LC_nobreak">'.&mt('Display target:');
3759: my %currdisp;
3760: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3761: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3762: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 3763: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
3764: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 3765: } else {
3766: $currdisp{'iframe'} = ' checked="checked"';
3767: }
3768: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3769: $currdisp{'width'} = $1;
3770: }
3771: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3772: $currdisp{'height'} = $1;
3773: }
1.296 raeburn 3774: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
3775: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 3776: } else {
3777: $currdisp{'iframe'} = ' checked="checked"';
3778: }
1.298 raeburn 3779: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 3780: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3781: $lt{$disp}.'</label>'.(' 'x2);
3782: }
3783: $datatable .= (' 'x4);
3784: foreach my $dimen ('width','height') {
3785: $datatable .= '<label>'.$lt{$dimen}.' '.
3786: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3787: (' 'x2);
3788: }
1.296 raeburn 3789: $datatable .= '<br />'.
3790: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
3791: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
3792: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
3793: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
3794: '</textarea></div><div style=""></div><br />';
1.267 raeburn 3795: $datatable .= '<br />';
3796: foreach my $extra ('passback','roster') {
3797: my $checkedon = '';
3798: my $checkedoff = ' checked="checked"';
3799: if ($settings->{$item}->{$extra}) {
3800: $checkedon = $checkedoff;
3801: $checkedoff = '';
3802: }
3803: $datatable .= $lt{$extra}.' '.
3804: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3805: &mt('Yes').'</label>'.(' 'x2).
3806: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3807: &mt('No').'</label>'.(' 'x4);
3808: }
3809: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3810: if ($imgsrc) {
3811: $datatable .= $imgsrc.
3812: '<label><input type="checkbox" name="ltitools_image_del"'.
3813: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3814: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3815: } else {
3816: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3817: }
3818: if ($switchserver) {
3819: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3820: } else {
3821: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3822: }
3823: $datatable .= '</span></fieldset>';
3824: my (%checkedfields,%rolemaps);
3825: if (ref($settings->{$item}) eq 'HASH') {
3826: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3827: %checkedfields = %{$settings->{$item}->{'fields'}};
3828: }
3829: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3830: %rolemaps = %{$settings->{$item}->{'roles'}};
3831: $checkedfields{'roles'} = 1;
3832: }
3833: }
3834: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3835: '<span class="LC_nobreak">';
3836: foreach my $field (@fields) {
3837: my $checked;
3838: if ($checkedfields{$field}) {
3839: $checked = ' checked="checked"';
3840: }
3841: $datatable .= '<label>'.
3842: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3843: $lt{$field}.'</label>'.(' ' x2);
3844: }
3845: $datatable .= '</span></fieldset>'.
3846: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3847: foreach my $role (@courseroles) {
3848: my ($selected,$selectnone);
3849: if (!$rolemaps{$role}) {
3850: $selectnone = ' selected="selected"';
3851: }
3852: $datatable .= '<td align="center">'.
3853: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3854: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3855: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3856: foreach my $ltirole (@ltiroles) {
3857: unless ($selectnone) {
3858: if ($rolemaps{$role} eq $ltirole) {
3859: $selected = ' selected="selected"';
3860: } else {
3861: $selected = '';
3862: }
3863: }
3864: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3865: }
3866: $datatable .= '</select></td>';
3867: }
1.273 raeburn 3868: $datatable .= '</tr></table></fieldset>';
3869: my %courseconfig;
3870: if (ref($settings->{$item}) eq 'HASH') {
3871: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3872: %courseconfig = %{$settings->{$item}->{'crsconf'}};
3873: }
3874: }
3875: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.296 raeburn 3876: foreach my $item ('label','title','target','linktext','explanation') {
1.273 raeburn 3877: my $checked;
3878: if ($courseconfig{$item}) {
3879: $checked = ' checked="checked"';
3880: }
3881: $datatable .= '<label>'.
3882: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3883: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3884: }
3885: $datatable .= '</span></fieldset>'.
1.267 raeburn 3886: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3887: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3888: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3889: my %custom = %{$settings->{$item}->{'custom'}};
3890: if (keys(%custom) > 0) {
3891: foreach my $key (sort(keys(%custom))) {
3892: $datatable .= '<tr><td><span class="LC_nobreak">'.
3893: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3894: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3895: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3896: ' value="'.$custom{$key}.'" /></td></tr>';
3897: }
3898: }
3899: }
3900: $datatable .= '<tr><td><span class="LC_nobreak">'.
3901: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3902: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3903: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3904: $datatable .= '</table></fieldset></td></tr>'."\n";
3905: $itemcount ++;
3906: }
3907: }
3908: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3909: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3910: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3911: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3912: '<select name="ltitools_add_pos"'.$chgstr.'>';
3913: for (my $k=0; $k<$maxnum+1; $k++) {
3914: my $vpos = $k+1;
3915: my $selstr;
3916: if ($k == $maxnum) {
3917: $selstr = ' selected="selected" ';
3918: }
3919: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3920: }
3921: $datatable .= '</select> '."\n".
3922: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3923: '<td colspan="2">'.
3924: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3925: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3926: (' 'x2).
3927: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3928: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3929: (' 'x2).
3930: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3931: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3932: '<br />'.
3933: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3934: (' 'x2).
3935: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3936: (' 'x2).
3937: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3938: '<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".
3939: '</fieldset>'.
3940: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3941: '<span class="LC_nobreak">'.&mt('Display target:');
3942: my %defaultdisp;
3943: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 3944: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 3945: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3946: $lt{$disp}.'</label>'.(' 'x2);
3947: }
3948: $datatable .= (' 'x4);
3949: foreach my $dimen ('width','height') {
3950: $datatable .= '<label>'.$lt{$dimen}.' '.
3951: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3952: (' 'x2);
3953: }
1.296 raeburn 3954: $datatable .= '<br />'.
3955: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
3956: '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
3957: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
3958: '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
3959: '</div><div style=""></div><br />';
1.267 raeburn 3960: foreach my $extra ('passback','roster') {
3961: $datatable .= $lt{$extra}.' '.
3962: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
3963: &mt('Yes').'</label>'.(' 'x2).
3964: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
3965: &mt('No').'</label>'.(' 'x4);
3966: }
3967: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
3968: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3969: if ($switchserver) {
3970: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3971: } else {
3972: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3973: }
3974: $datatable .= '</span></fieldset>'.
3975: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3976: '<span class="LC_nobreak">';
3977: foreach my $field (@fields) {
3978: $datatable .= '<label>'.
3979: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
3980: $lt{$field}.'</label>'.(' ' x2);
3981: }
3982: $datatable .= '</span></fieldset>'.
3983: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3984: foreach my $role (@courseroles) {
3985: my ($checked,$checkednone);
3986: $datatable .= '<td align="center">'.
3987: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3988: '<select name="ltitools_add_roles_'.$role.'">'.
3989: '<option value="" selected="selected">'.&mt('Select').'</option>';
3990: foreach my $ltirole (@ltiroles) {
3991: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
3992: }
3993: $datatable .= '</select></td>';
3994: }
3995: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 3996: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.296 raeburn 3997: foreach my $item ('label','title','target','linktext','explanation') {
3998: $datatable .= '<label>'.
3999: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4000: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4001: }
4002: $datatable .= '</span></fieldset>'.
1.267 raeburn 4003: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4004: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4005: '<tr><td><span class="LC_nobreak">'.
4006: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4007: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4008: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
4009: '</table></fieldset></td></tr>'."\n".
4010: '</td>'."\n".
4011: '</tr>'."\n";
4012: $itemcount ++;
4013: return $datatable;
4014: }
4015:
4016: sub ltitools_names {
4017: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4018: 'title' => 'Title',
4019: 'version' => 'Version',
4020: 'msgtype' => 'Message Type',
4021: 'url' => 'URL',
4022: 'key' => 'Key',
4023: 'secret' => 'Secret',
4024: 'icon' => 'Icon',
4025: 'user' => 'Username:domain',
4026: 'fullname' => 'Full Name',
4027: 'firstname' => 'First Name',
4028: 'lastname' => 'Last Name',
4029: 'email' => 'E-mail',
4030: 'roles' => 'Role',
1.298 raeburn 4031: 'window' => 'Window',
4032: 'tab' => 'Tab',
1.296 raeburn 4033: 'iframe' => 'iFrame',
4034: 'height' => 'Height',
4035: 'width' => 'Width',
4036: 'linktext' => 'Default Link Text',
4037: 'explanation' => 'Default Explanation',
4038: 'passback' => 'Tool can return grades:',
4039: 'roster' => 'Tool can retrieve roster:',
4040: 'crstarget' => 'Display target',
4041: 'crslabel' => 'Course label',
4042: 'crstitle' => 'Course title',
4043: 'crslinktext' => 'Link Text',
4044: 'crsexplanation' => 'Explanation',
1.267 raeburn 4045: );
4046: return %lt;
4047: }
4048:
1.121 raeburn 4049: sub print_coursedefaults {
1.139 raeburn 4050: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 4051: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4052: my $itemcount = 1;
1.192 raeburn 4053: my %choices = &Apache::lonlocal::texthash (
4054: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 4055: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 4056: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4057: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 4058: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4059: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
4060: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 4061: canclone => "People who may clone a course (besides course's owner and coordinators)",
4062: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 4063: );
1.198 raeburn 4064: my %staticdefaults = (
4065: anonsurvey_threshold => 10,
4066: uploadquota => 500,
1.257 raeburn 4067: postsubmit => 60,
1.276 raeburn 4068: mysqltables => 172800,
1.198 raeburn 4069: );
1.139 raeburn 4070: if ($position eq 'top') {
1.257 raeburn 4071: %defaultchecked = (
4072: 'canuse_pdfforms' => 'off',
4073: 'uselcmath' => 'on',
4074: 'usejsme' => 'on',
1.289 raeburn 4075: 'canclone' => 'none',
1.257 raeburn 4076: );
4077: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139 raeburn 4078: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 4079: \%choices,$itemcount);
1.264 raeburn 4080: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4081: $datatable .=
4082: '<tr'.$css_class.'><td valign="top">'.
4083: '<span class="LC_nobreak">'.$choices{'canclone'}.
4084: '</span></td><td class="LC_left_item">';
4085: my $currcanclone = 'none';
4086: my $onclick;
4087: my @cloneoptions = ('none','domain');
4088: my %clonetitles = (
4089: none => 'No additional course requesters',
4090: domain => "Any course requester in course's domain",
4091: instcode => 'Course requests for official courses ...',
4092: );
4093: my (%codedefaults,@code_order,@posscodes);
4094: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4095: \@code_order) eq 'ok') {
4096: if (@code_order > 0) {
4097: push(@cloneoptions,'instcode');
4098: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4099: }
4100: }
4101: if (ref($settings) eq 'HASH') {
4102: if ($settings->{'canclone'}) {
4103: if (ref($settings->{'canclone'}) eq 'HASH') {
4104: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4105: if (@code_order > 0) {
4106: $currcanclone = 'instcode';
4107: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4108: }
4109: }
4110: } elsif ($settings->{'canclone'} eq 'domain') {
4111: $currcanclone = $settings->{'canclone'};
4112: }
4113: }
1.289 raeburn 4114: }
1.264 raeburn 4115: foreach my $option (@cloneoptions) {
4116: my ($checked,$additional);
4117: if ($currcanclone eq $option) {
4118: $checked = ' checked="checked"';
4119: }
4120: if ($option eq 'instcode') {
4121: if (@code_order) {
4122: my $show = 'none';
4123: if ($checked) {
4124: $show = 'block';
4125: }
4126: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4127: &mt('Institutional codes for new and cloned course have identical:').
4128: '<br />';
4129: foreach my $item (@code_order) {
4130: my $codechk;
4131: if ($checked) {
4132: if (grep(/^\Q$item\E$/,@posscodes)) {
4133: $codechk = ' checked="checked"';
4134: }
4135: }
4136: $additional .= '<label>'.
4137: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4138: $item.'</label>';
4139: }
4140: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4141: }
4142: }
4143: $datatable .=
4144: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4145: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4146: '</label> '.$additional.'</span><br />';
4147: }
4148: $datatable .= '</td>'.
4149: '</tr>';
4150: $itemcount ++;
1.139 raeburn 4151: } else {
4152: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 4153: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 4154: my $currusecredits = 0;
1.257 raeburn 4155: my $postsubmitclient = 1;
1.271 raeburn 4156: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 4157: if (ref($settings) eq 'HASH') {
4158: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 4159: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4160: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4161: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4162: }
4163: }
1.192 raeburn 4164: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 4165: foreach my $type (@types) {
4166: next if ($type eq 'community');
4167: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4168: if ($defcredits{$type} ne '') {
4169: $currusecredits = 1;
4170: }
4171: }
4172: }
4173: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4174: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4175: $postsubmitclient = 0;
4176: foreach my $type (@types) {
4177: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4178: }
4179: } else {
4180: foreach my $type (@types) {
4181: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4182: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 4183: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 4184: } else {
4185: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4186: }
4187: } else {
4188: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4189: }
4190: }
4191: }
4192: } else {
4193: foreach my $type (@types) {
4194: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 4195: }
4196: }
1.276 raeburn 4197: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4198: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4199: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4200: }
4201: } else {
4202: foreach my $type (@types) {
4203: $currmysql{$type} = $staticdefaults{'mysqltables'};
4204: }
4205: }
1.258 raeburn 4206: } else {
4207: foreach my $type (@types) {
4208: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4209: }
1.139 raeburn 4210: }
4211: if (!$currdefresponder) {
1.198 raeburn 4212: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4213: } elsif ($currdefresponder < 1) {
4214: $currdefresponder = 1;
4215: }
1.198 raeburn 4216: foreach my $type (@types) {
4217: if ($curruploadquota{$type} eq '') {
4218: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4219: }
4220: }
1.139 raeburn 4221: $datatable .=
1.192 raeburn 4222: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4223: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4224: '</span></td>'.
4225: '<td class="LC_right_item"><span class="LC_nobreak">'.
4226: '<input type="text" name="anonsurvey_threshold"'.
4227: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 4228: '</td></tr>'."\n";
4229: $itemcount ++;
4230: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4231: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4232: $choices{'uploadquota'}.
4233: '</span></td>'.
4234: '<td align="right" class="LC_right_item">'.
4235: '<table><tr>';
1.198 raeburn 4236: foreach my $type (@types) {
4237: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4238: '<input type="text" name="uploadquota_'.$type.'"'.
4239: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4240: }
4241: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 4242: $itemcount ++;
1.236 raeburn 4243: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 4244: my $display = 'none';
1.192 raeburn 4245: if ($currusecredits) {
4246: $display = 'block';
4247: }
4248: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 4249: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4250: foreach my $type (@types) {
4251: next if ($type eq 'community');
4252: $additional .= '<td align="center">'.&mt($type).'<br />'.
4253: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 4254: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 4255: }
4256: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 4257: %defaultchecked = ('coursecredits' => 'off');
4258: @toggles = ('coursecredits');
4259: my $current = {
4260: 'coursecredits' => $currusecredits,
4261: };
4262: (my $table,$itemcount) =
4263: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 4264: \%choices,$itemcount,$onclick,$additional,'left');
4265: $datatable .= $table;
4266: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4267: my $display = 'none';
4268: if ($postsubmitclient) {
4269: $display = 'block';
4270: }
4271: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 4272: &mt('Number of seconds submit is disabled').'<br />'.
4273: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4274: '<table><tr>';
1.257 raeburn 4275: foreach my $type (@types) {
4276: $additional .= '<td align="center">'.&mt($type).'<br />'.
4277: '<input type="text" name="'.$type.'_timeout" value="'.
4278: $deftimeout{$type}.'" size="5" /></td>';
4279: }
4280: $additional .= '</tr></table></div>'."\n";
4281: %defaultchecked = ('postsubmit' => 'on');
4282: @toggles = ('postsubmit');
1.280 raeburn 4283: $current = {
4284: 'postsubmit' => $postsubmitclient,
4285: };
1.257 raeburn 4286: ($table,$itemcount) =
4287: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4288: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 4289: $datatable .= $table;
1.276 raeburn 4290: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4291: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4292: $choices{'mysqltables'}.
4293: '</span></td>'.
4294: '<td align="right" class="LC_right_item">'.
4295: '<table><tr>';
4296: foreach my $type (@types) {
4297: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4298: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 4299: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 4300: }
4301: $datatable .= '</tr></table></td></tr>'."\n";
4302: $itemcount ++;
4303:
1.139 raeburn 4304: }
1.192 raeburn 4305: $$rowtotal += $itemcount;
1.121 raeburn 4306: return $datatable;
1.118 jms 4307: }
4308:
1.231 raeburn 4309: sub print_selfenrollment {
4310: my ($position,$dom,$settings,$rowtotal) = @_;
4311: my ($css_class,$datatable);
4312: my $itemcount = 1;
1.271 raeburn 4313: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 4314: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 4315: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4316: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 4317: my @rows;
4318: my $key;
4319: if ($position eq 'top') {
4320: $key = 'admin';
4321: if (ref($rowsref) eq 'ARRAY') {
4322: @rows = @{$rowsref};
4323: }
4324: } elsif ($position eq 'middle') {
4325: $key = 'default';
4326: @rows = ('types','registered','approval','limit');
4327: }
4328: foreach my $row (@rows) {
4329: if (defined($titlesref->{$row})) {
4330: $itemcount ++;
4331: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4332: $datatable .= '<tr'.$css_class.'>'.
4333: '<td>'.$titlesref->{$row}.'</td>'.
4334: '<td class="LC_left_item">'.
4335: '<table><tr>';
4336: my (%current,%currentcap);
4337: if (ref($settings) eq 'HASH') {
4338: if (ref($settings->{$key}) eq 'HASH') {
4339: foreach my $type (@types) {
4340: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4341: $current{$type} = $settings->{$key}->{$type}->{$row};
4342: }
4343: if (($row eq 'limit') && ($key eq 'default')) {
4344: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4345: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4346: }
4347: }
4348: }
4349: }
4350: }
4351: my %roles = (
4352: '0' => &Apache::lonnet::plaintext('dc'),
4353: );
4354:
4355: foreach my $type (@types) {
4356: unless (($row eq 'registered') && ($key eq 'default')) {
4357: $datatable .= '<th>'.&mt($type).'</th>';
4358: }
4359: }
4360: unless (($row eq 'registered') && ($key eq 'default')) {
4361: $datatable .= '</tr><tr>';
4362: }
4363: foreach my $type (@types) {
4364: if ($type eq 'community') {
4365: $roles{'1'} = &mt('Community personnel');
4366: } else {
4367: $roles{'1'} = &mt('Course personnel');
4368: }
4369: $datatable .= '<td style="vertical-align: top">';
4370: if ($position eq 'top') {
4371: my %checked;
4372: if ($current{$type} eq '0') {
4373: $checked{'0'} = ' checked="checked"';
4374: } else {
4375: $checked{'1'} = ' checked="checked"';
4376: }
4377: foreach my $role ('1','0') {
4378: $datatable .= '<span class="LC_nobreak"><label>'.
4379: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4380: 'value="'.$role.'"'.$checked{$role}.' />'.
4381: $roles{$role}.'</label></span> ';
4382: }
4383: } else {
4384: if ($row eq 'types') {
4385: my %checked;
4386: if ($current{$type} =~ /^(all|dom)$/) {
4387: $checked{$1} = ' checked="checked"';
4388: } else {
4389: $checked{''} = ' checked="checked"';
4390: }
4391: foreach my $val ('','dom','all') {
4392: $datatable .= '<span class="LC_nobreak"><label>'.
4393: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4394: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4395: }
4396: } elsif ($row eq 'registered') {
4397: my %checked;
4398: if ($current{$type} eq '1') {
4399: $checked{'1'} = ' checked="checked"';
4400: } else {
4401: $checked{'0'} = ' checked="checked"';
4402: }
4403: foreach my $val ('0','1') {
4404: $datatable .= '<span class="LC_nobreak"><label>'.
4405: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4406: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4407: }
4408: } elsif ($row eq 'approval') {
4409: my %checked;
4410: if ($current{$type} =~ /^([12])$/) {
4411: $checked{$1} = ' checked="checked"';
4412: } else {
4413: $checked{'0'} = ' checked="checked"';
4414: }
4415: for my $val (0..2) {
4416: $datatable .= '<span class="LC_nobreak"><label>'.
4417: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4418: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4419: }
4420: } elsif ($row eq 'limit') {
4421: my %checked;
4422: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4423: $checked{$1} = ' checked="checked"';
4424: } else {
4425: $checked{'none'} = ' checked="checked"';
4426: }
4427: my $cap;
4428: if ($currentcap{$type} =~ /^\d+$/) {
4429: $cap = $currentcap{$type};
4430: }
4431: foreach my $val ('none','allstudents','selfenrolled') {
4432: $datatable .= '<span class="LC_nobreak"><label>'.
4433: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4434: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4435: }
4436: $datatable .= '<br />'.
4437: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4438: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4439: '</span>';
4440: }
4441: }
4442: $datatable .= '</td>';
4443: }
4444: $datatable .= '</tr>';
4445: }
4446: $datatable .= '</table></td></tr>';
4447: }
4448: } elsif ($position eq 'bottom') {
1.235 raeburn 4449: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4450: }
4451: $$rowtotal += $itemcount;
4452: return $datatable;
4453: }
4454:
4455: sub print_validation_rows {
4456: my ($caller,$dom,$settings,$rowtotal) = @_;
4457: my ($itemsref,$namesref,$fieldsref);
4458: if ($caller eq 'selfenroll') {
4459: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4460: } elsif ($caller eq 'requestcourses') {
4461: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4462: }
4463: my %currvalidation;
4464: if (ref($settings) eq 'HASH') {
4465: if (ref($settings->{'validation'}) eq 'HASH') {
4466: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 4467: }
1.235 raeburn 4468: }
4469: my $datatable;
4470: my $itemcount = 0;
4471: foreach my $item (@{$itemsref}) {
4472: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4473: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4474: $namesref->{$item}.
4475: '</span></td>'.
4476: '<td class="LC_left_item">';
4477: if (($item eq 'url') || ($item eq 'button')) {
4478: $datatable .= '<span class="LC_nobreak">'.
4479: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4480: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4481: } elsif ($item eq 'fields') {
4482: my @currfields;
4483: if (ref($currvalidation{$item}) eq 'ARRAY') {
4484: @currfields = @{$currvalidation{$item}};
4485: }
4486: foreach my $field (@{$fieldsref}) {
4487: my $check = '';
4488: if (grep(/^\Q$field\E$/,@currfields)) {
4489: $check = ' checked="checked"';
4490: }
4491: $datatable .= '<span class="LC_nobreak"><label>'.
4492: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4493: ' value="'.$field.'"'.$check.' />'.$field.
4494: '</label></span> ';
4495: }
4496: } elsif ($item eq 'markup') {
4497: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
4498: $currvalidation{$item}.
1.231 raeburn 4499: '</textarea>';
1.235 raeburn 4500: }
4501: $datatable .= '</td></tr>'."\n";
4502: if (ref($rowtotal)) {
1.231 raeburn 4503: $itemcount ++;
4504: }
4505: }
1.235 raeburn 4506: if ($caller eq 'requestcourses') {
4507: my %currhash;
1.248 raeburn 4508: if (ref($settings) eq 'HASH') {
4509: if (ref($settings->{'validation'}) eq 'HASH') {
4510: if ($settings->{'validation'}{'dc'} ne '') {
4511: $currhash{$settings->{'validation'}{'dc'}} = 1;
4512: }
1.235 raeburn 4513: }
4514: }
4515: my $numinrow = 2;
4516: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4517: 'validationdc',%currhash);
1.247 raeburn 4518: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4519: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 4520: if ($numdc > 1) {
1.247 raeburn 4521: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 4522: } else {
1.247 raeburn 4523: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 4524: }
1.247 raeburn 4525: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 4526: $itemcount ++;
4527: }
4528: if (ref($rowtotal)) {
4529: $$rowtotal += $itemcount;
4530: }
1.231 raeburn 4531: return $datatable;
4532: }
4533:
1.137 raeburn 4534: sub print_usersessions {
4535: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 4536: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 4537: my (%by_ip,%by_location,@intdoms,@instdoms);
4538: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 4539:
4540: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4541: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4542: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4543: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4544: if ($position eq 'top') {
1.152 raeburn 4545: if (keys(%serverhomes) > 1) {
1.145 raeburn 4546: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 4547: my $curroffloadnow;
4548: if (ref($settings) eq 'HASH') {
4549: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4550: $curroffloadnow = $settings->{'offloadnow'};
4551: }
4552: }
4553: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4554: } else {
1.140 raeburn 4555: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 4556: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
4557: '</td></tr>';
1.140 raeburn 4558: }
1.137 raeburn 4559: } else {
1.279 raeburn 4560: my %titles = &usersession_titles();
4561: my ($prefix,@types);
4562: if ($position eq 'bottom') {
4563: $prefix = 'remote';
4564: @types = ('version','excludedomain','includedomain');
1.145 raeburn 4565: } else {
1.279 raeburn 4566: $prefix = 'hosted';
4567: @types = ('excludedomain','includedomain');
4568: }
4569: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4570: }
4571: $$rowtotal += $itemcount;
4572: return $datatable;
4573: }
4574:
4575: sub rules_by_location {
4576: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
4577: my ($datatable,$itemcount,$css_class);
4578: if (keys(%{$by_location}) == 0) {
4579: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4580: $datatable = '<tr'.$css_class.'><td colspan="2">'.
4581: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
4582: '</td></tr>';
4583: $itemcount = 1;
4584: } else {
4585: $itemcount = 0;
4586: my $numinrow = 5;
4587: my (%current,%checkedon,%checkedoff);
4588: my @locations = sort(keys(%{$by_location}));
4589: foreach my $type (@{$types}) {
4590: $checkedon{$type} = '';
4591: $checkedoff{$type} = ' checked="checked"';
4592: }
4593: if (ref($settings) eq 'HASH') {
4594: if (ref($settings->{$prefix}) eq 'HASH') {
4595: foreach my $key (keys(%{$settings->{$prefix}})) {
4596: $current{$key} = $settings->{$prefix}{$key};
4597: if ($key eq 'version') {
4598: if ($current{$key} ne '') {
1.145 raeburn 4599: $checkedon{$key} = ' checked="checked"';
4600: $checkedoff{$key} = '';
4601: }
1.279 raeburn 4602: } elsif (ref($current{$key}) eq 'ARRAY') {
4603: $checkedon{$key} = ' checked="checked"';
4604: $checkedoff{$key} = '';
1.137 raeburn 4605: }
4606: }
4607: }
1.279 raeburn 4608: }
4609: foreach my $type (@{$types}) {
4610: next if ($type ne 'version' && !@locations);
4611: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4612: $datatable .= '<tr'.$css_class.'>
4613: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
4614: <span class="LC_nobreak">
4615: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4616: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4617: if ($type eq 'version') {
4618: my @lcversions = &Apache::lonnet::all_loncaparevs();
4619: my $selector = '<select name="'.$prefix.'_version">';
4620: foreach my $version (@lcversions) {
4621: my $selected = '';
4622: if ($current{'version'} eq $version) {
4623: $selected = ' selected="selected"';
1.145 raeburn 4624: }
1.279 raeburn 4625: $selector .= ' <option value="'.$version.'"'.
4626: $selected.'>'.$version.'</option>';
4627: }
4628: $selector .= '</select> ';
4629: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4630: } else {
4631: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4632: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4633: ' />'.(' 'x2).
4634: '<input type="button" value="'.&mt('uncheck all').'" '.
4635: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4636: "\n".
4637: '</div><div><table>';
4638: my $rem;
4639: for (my $i=0; $i<@locations; $i++) {
4640: my ($showloc,$value,$checkedtype);
4641: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
4642: my $ip = $by_location->{$locations[$i]}->[0];
4643: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4644: $value = join(':',@{$by_ip->{$ip}});
4645: $showloc = join(', ',@{$by_ip->{$ip}});
4646: if (ref($current{$type}) eq 'ARRAY') {
4647: foreach my $loc (@{$by_ip->{$ip}}) {
4648: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4649: $checkedtype = ' checked="checked"';
4650: last;
1.145 raeburn 4651: }
1.138 raeburn 4652: }
4653: }
4654: }
1.137 raeburn 4655: }
1.279 raeburn 4656: $rem = $i%($numinrow);
4657: if ($rem == 0) {
4658: if ($i > 0) {
4659: $datatable .= '</tr>';
4660: }
4661: $datatable .= '<tr>';
4662: }
4663: $datatable .= '<td class="LC_left_item">'.
4664: '<span class="LC_nobreak"><label>'.
4665: '<input type="checkbox" name="'.$prefix.'_'.$type.
4666: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4667: '</label></span></td>';
4668: }
4669: $rem = @locations%($numinrow);
4670: my $colsleft = $numinrow - $rem;
4671: if ($colsleft > 1 ) {
4672: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4673: ' </td>';
4674: } elsif ($colsleft == 1) {
4675: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4676: }
1.279 raeburn 4677: $datatable .= '</tr></table>';
1.137 raeburn 4678: }
1.279 raeburn 4679: $datatable .= '</td></tr>';
4680: $itemcount ++;
1.137 raeburn 4681: }
4682: }
1.279 raeburn 4683: return ($datatable,$itemcount);
1.137 raeburn 4684: }
4685:
1.275 raeburn 4686: sub print_ssl {
4687: my ($position,$dom,$settings,$rowtotal) = @_;
4688: my ($css_class,$datatable);
4689: my $itemcount = 1;
4690: if ($position eq 'top') {
1.281 raeburn 4691: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4692: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4693: my $same_institution;
4694: if ($intdom ne '') {
4695: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
4696: if (ref($internet_names) eq 'ARRAY') {
4697: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4698: $same_institution = 1;
4699: }
4700: }
4701: }
1.275 raeburn 4702: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 4703: $datatable = '<tr'.$css_class.'><td colspan="2">';
4704: if ($same_institution) {
4705: my %domservers = &Apache::lonnet::get_servers($dom);
4706: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
4707: } else {
4708: $datatable .= &mt("You need to be logged into one of your own domain's servers to display information about the status of LON-CAPA SSL certificates.");
4709: }
4710: $datatable .= '</td></tr>';
1.275 raeburn 4711: $itemcount ++;
4712: } else {
4713: my %titles = &ssl_titles();
4714: my (%by_ip,%by_location,@intdoms,@instdoms);
4715: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4716: my @alldoms = &Apache::lonnet::all_domains();
4717: my %serverhomes = %Apache::lonnet::serverhomeIDs;
4718: my @domservers = &Apache::lonnet::get_servers($dom);
4719: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4720: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 4721: if (($position eq 'connto') || ($position eq 'connfrom')) {
4722: my $legacy;
4723: unless (ref($settings) eq 'HASH') {
4724: my $name;
4725: if ($position eq 'connto') {
4726: $name = 'loncAllowInsecure';
4727: } else {
4728: $name = 'londAllowInsecure';
4729: }
4730: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
4731: my @ids=&Apache::lonnet::current_machine_ids();
4732: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
4733: my %what = (
4734: $name => 1,
4735: );
4736: my ($result,$returnhash) =
4737: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
4738: if ($result eq 'ok') {
4739: if (ref($returnhash) eq 'HASH') {
4740: $legacy = $returnhash->{$name};
4741: }
4742: }
4743: } else {
4744: $legacy = $Apache::lonnet::perlvar{$name};
4745: }
4746: }
1.275 raeburn 4747: foreach my $type ('dom','intdom','other') {
4748: my %checked;
4749: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4750: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
4751: '<td class="LC_right_item">';
4752: my $skip;
4753: if ($type eq 'dom') {
4754: unless (keys(%servers) > 1) {
4755: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
4756: $skip = 1;
4757: }
4758: }
4759: if ($type eq 'intdom') {
4760: unless (@instdoms > 1) {
4761: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
4762: $skip = 1;
4763: }
4764: } elsif ($type eq 'other') {
4765: if (keys(%by_location) == 0) {
4766: $datatable .= &mt('Nothing to set here, as there are no other institutions');
4767: $skip = 1;
4768: }
4769: }
4770: unless ($skip) {
4771: $checked{'yes'} = ' checked="checked"';
4772: if (ref($settings) eq 'HASH') {
1.293 raeburn 4773: if (ref($settings->{$position}) eq 'HASH') {
4774: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 4775: $checked{$1} = $checked{'yes'};
4776: delete($checked{'yes'});
4777: }
4778: }
1.293 raeburn 4779: } else {
4780: if ($legacy == 0) {
4781: $checked{'req'} = $checked{'yes'};
4782: delete($checked{'yes'});
4783: }
1.275 raeburn 4784: }
4785: foreach my $option ('no','yes','req') {
4786: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 4787: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 4788: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
4789: '</label></span>'.(' 'x2);
4790: }
4791: }
4792: $datatable .= '</td></tr>';
4793: $itemcount ++;
4794: }
4795: } else {
4796: my $prefix = 'replication';
4797: my @types = ('certreq','nocertreq');
1.279 raeburn 4798: if (keys(%by_location) == 0) {
4799: $datatable .= '<tr'.$css_class.'><td>'.
4800: &mt('Nothing to set here, as there are no other institutions').
4801: '</td></tr>';
4802: $itemcount ++;
1.275 raeburn 4803: } else {
1.279 raeburn 4804: ($datatable,$itemcount) =
4805: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 4806: }
4807: }
4808: }
4809: $$rowtotal += $itemcount;
4810: return $datatable;
4811: }
4812:
4813: sub ssl_titles {
4814: return &Apache::lonlocal::texthash (
4815: dom => 'LON-CAPA servers/VMs from same domain',
4816: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
4817: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 4818: connto => 'Connections to other servers',
4819: connfrom => 'Connections from other servers',
1.275 raeburn 4820: replication => 'Replicating content to other institutions',
4821: certreq => 'Client certificate required, but specific domains exempt',
4822: nocertreq => 'No client certificate required, except for specific domains',
4823: no => 'SSL not used',
4824: yes => 'SSL Optional (used if available)',
4825: req => 'SSL Required',
4826: );
1.279 raeburn 4827: }
4828:
4829: sub print_trust {
4830: my ($prefix,$dom,$settings,$rowtotal) = @_;
4831: my ($css_class,$datatable,%checked,%choices);
4832: my (%by_ip,%by_location,@intdoms,@instdoms);
4833: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4834: my $itemcount = 1;
4835: my %titles = &trust_titles();
4836: my @types = ('exc','inc');
4837: if ($prefix eq 'top') {
4838: $prefix = 'content';
4839: } elsif ($prefix eq 'bottom') {
4840: $prefix = 'msg';
4841: }
4842: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4843: $$rowtotal += $itemcount;
4844: return $datatable;
4845: }
4846:
4847: sub trust_titles {
4848: return &Apache::lonlocal::texthash(
4849: content => "Access to this domain's content by others",
4850: shared => "Access to other domain's content by this domain",
4851: enroll => "Enrollment in this domain's courses by others",
4852: othcoau => "Co-author roles in this domain for others",
4853: coaurem => "Co-author roles for this domain's users elsewhere",
4854: domroles => "Domain roles in this domain assignable to others",
4855: catalog => "Course Catalog for this domain displayed elsewhere",
4856: reqcrs => "Requests for creation of courses in this domain by others",
4857: msg => "Users in other domains can send messages to this domain",
4858: exc => "Allow all, but exclude specific domains",
4859: inc => "Deny all, but include specific domains",
4860: );
1.275 raeburn 4861: }
4862:
1.138 raeburn 4863: sub build_location_hashes {
1.275 raeburn 4864: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 4865: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 4866: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 4867: my %iphost = &Apache::lonnet::get_iphost();
4868: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4869: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4870: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4871: foreach my $id (@{$iphost{$primary_ip}}) {
4872: my $intdom = &Apache::lonnet::internet_dom($id);
4873: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4874: push(@{$intdoms},$intdom);
4875: }
4876: }
4877: }
4878: foreach my $ip (keys(%iphost)) {
4879: if (ref($iphost{$ip}) eq 'ARRAY') {
4880: foreach my $id (@{$iphost{$ip}}) {
4881: my $location = &Apache::lonnet::internet_dom($id);
4882: if ($location) {
1.275 raeburn 4883: if (grep(/^\Q$location\E$/,@{$intdoms})) {
4884: my $dom = &Apache::lonnet::host_domain($id);
4885: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
4886: push(@{$instdoms},$dom);
4887: }
4888: next;
4889: }
1.138 raeburn 4890: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4891: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4892: push(@{$by_ip->{$ip}},$location);
4893: }
4894: } else {
4895: $by_ip->{$ip} = [$location];
4896: }
4897: }
4898: }
4899: }
4900: }
4901: foreach my $ip (sort(keys(%{$by_ip}))) {
4902: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4903: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4904: my $first = $by_ip->{$ip}->[0];
4905: if (ref($by_location->{$first}) eq 'ARRAY') {
4906: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4907: push(@{$by_location->{$first}},$ip);
4908: }
4909: } else {
4910: $by_location->{$first} = [$ip];
4911: }
4912: }
4913: }
4914: return;
4915: }
4916:
1.145 raeburn 4917: sub current_offloads_to {
4918: my ($dom,$settings,$servers) = @_;
4919: my (%spareid,%otherdomconfigs);
1.152 raeburn 4920: if (ref($servers) eq 'HASH') {
1.145 raeburn 4921: foreach my $lonhost (sort(keys(%{$servers}))) {
4922: my $gotspares;
1.152 raeburn 4923: if (ref($settings) eq 'HASH') {
4924: if (ref($settings->{'spares'}) eq 'HASH') {
4925: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4926: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4927: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4928: $gotspares = 1;
4929: }
1.145 raeburn 4930: }
4931: }
4932: unless ($gotspares) {
4933: my $gotspares;
4934: my $serverhomeID =
4935: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4936: my $serverhomedom =
4937: &Apache::lonnet::host_domain($serverhomeID);
4938: if ($serverhomedom ne $dom) {
4939: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4940: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4941: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4942: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4943: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4944: $gotspares = 1;
4945: }
4946: }
4947: } else {
4948: $otherdomconfigs{$serverhomedom} =
4949: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4950: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4951: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4952: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4953: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4954: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4955: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4956: $gotspares = 1;
4957: }
4958: }
4959: }
4960: }
4961: }
4962: }
4963: }
4964: unless ($gotspares) {
4965: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4966: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4967: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4968: } else {
4969: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4970: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4971: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4972: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4973: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4974: } else {
1.150 raeburn 4975: my %what = (
4976: spareid => 1,
4977: );
4978: my ($result,$returnhash) =
4979: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4980: if ($result eq 'ok') {
4981: if (ref($returnhash) eq 'HASH') {
4982: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4983: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4984: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4985: }
4986: }
1.145 raeburn 4987: }
4988: }
4989: }
4990: }
4991: }
4992: }
4993: return %spareid;
4994: }
4995:
4996: sub spares_row {
1.261 raeburn 4997: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4998: my $css_class;
4999: my $numinrow = 4;
5000: my $itemcount = 1;
5001: my $datatable;
1.152 raeburn 5002: my %typetitles = &sparestype_titles();
5003: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 5004: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 5005: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5006: my ($othercontrol,$serverdom);
5007: if ($serverhome ne $server) {
5008: $serverdom = &Apache::lonnet::host_domain($serverhome);
5009: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5010: } else {
5011: $serverdom = &Apache::lonnet::host_domain($server);
5012: if ($serverdom ne $dom) {
5013: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5014: }
5015: }
5016: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 5017: my $checkednow;
5018: if (ref($curroffloadnow) eq 'HASH') {
5019: if ($curroffloadnow->{$server}) {
5020: $checkednow = ' checked="checked"';
5021: }
5022: }
1.145 raeburn 5023: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5024: $datatable .= '<tr'.$css_class.'>
5025: <td rowspan="2">
1.183 bisitz 5026: <span class="LC_nobreak">'.
5027: &mt('[_1] when busy, offloads to:'
1.261 raeburn 5028: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 5029: '<span class="LC_nobreak">'."\n".
1.261 raeburn 5030: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
5031: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 5032: "\n";
1.145 raeburn 5033: my (%current,%canselect);
1.152 raeburn 5034: my @choices =
5035: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5036: foreach my $type ('primary','default') {
5037: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 5038: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5039: my @spares = @{$spareid->{$server}{$type}};
5040: if (@spares > 0) {
1.152 raeburn 5041: if ($othercontrol) {
5042: $current{$type} = join(', ',@spares);
5043: } else {
5044: $current{$type} .= '<table>';
5045: my $numspares = scalar(@spares);
5046: for (my $i=0; $i<@spares; $i++) {
5047: my $rem = $i%($numinrow);
5048: if ($rem == 0) {
5049: if ($i > 0) {
5050: $current{$type} .= '</tr>';
5051: }
5052: $current{$type} .= '<tr>';
1.145 raeburn 5053: }
1.152 raeburn 5054: $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'".');" /> '.
5055: $spareid->{$server}{$type}[$i].
5056: '</label></td>'."\n";
5057: }
5058: my $rem = @spares%($numinrow);
5059: my $colsleft = $numinrow - $rem;
5060: if ($colsleft > 1 ) {
5061: $current{$type} .= '<td colspan="'.$colsleft.
5062: '" class="LC_left_item">'.
5063: ' </td>';
5064: } elsif ($colsleft == 1) {
5065: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 5066: }
1.152 raeburn 5067: $current{$type} .= '</tr></table>';
1.150 raeburn 5068: }
1.145 raeburn 5069: }
5070: }
5071: if ($current{$type} eq '') {
5072: $current{$type} = &mt('None specified');
5073: }
1.152 raeburn 5074: if ($othercontrol) {
5075: if ($type eq 'primary') {
5076: $canselect{$type} = $othercontrol;
5077: }
5078: } else {
5079: $canselect{$type} =
5080: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
5081: '<select name="newspare_'.$type.'_'.$server.'" '.
5082: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
5083: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
5084: if (@choices > 0) {
5085: foreach my $lonhost (@choices) {
5086: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
5087: }
5088: }
5089: $canselect{$type} .= '</select>'."\n";
5090: }
5091: } else {
5092: $current{$type} = &mt('Could not be determined');
5093: if ($type eq 'primary') {
5094: $canselect{$type} = $othercontrol;
5095: }
1.145 raeburn 5096: }
1.152 raeburn 5097: if ($type eq 'default') {
5098: $datatable .= '<tr'.$css_class.'>';
5099: }
5100: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5101: '<td>'.$current{$type}.'</td>'."\n".
5102: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 5103: }
5104: $itemcount ++;
5105: }
5106: }
5107: $$rowtotal += $itemcount;
5108: return $datatable;
5109: }
5110:
1.152 raeburn 5111: sub possible_newspares {
5112: my ($server,$currspares,$serverhomes,$altids) = @_;
5113: my $serverhostname = &Apache::lonnet::hostname($server);
5114: my %excluded;
5115: if ($serverhostname ne '') {
5116: %excluded = (
5117: $serverhostname => 1,
5118: );
5119: }
5120: if (ref($currspares) eq 'HASH') {
5121: foreach my $type (keys(%{$currspares})) {
5122: if (ref($currspares->{$type}) eq 'ARRAY') {
5123: if (@{$currspares->{$type}} > 0) {
5124: foreach my $curr (@{$currspares->{$type}}) {
5125: my $hostname = &Apache::lonnet::hostname($curr);
5126: $excluded{$hostname} = 1;
5127: }
5128: }
5129: }
5130: }
5131: }
5132: my @choices;
5133: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5134: if (keys(%{$serverhomes}) > 1) {
5135: foreach my $name (sort(keys(%{$serverhomes}))) {
5136: unless ($excluded{$name}) {
5137: if (exists($altids->{$serverhomes->{$name}})) {
5138: push(@choices,$altids->{$serverhomes->{$name}});
5139: } else {
5140: push(@choices,$serverhomes->{$name});
1.145 raeburn 5141: }
5142: }
5143: }
5144: }
5145: }
1.152 raeburn 5146: return sort(@choices);
1.145 raeburn 5147: }
5148:
1.150 raeburn 5149: sub print_loadbalancing {
5150: my ($dom,$settings,$rowtotal) = @_;
5151: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5152: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5153: my $numinrow = 1;
5154: my $datatable;
5155: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 5156: my (%currbalancer,%currtargets,%currrules,%existing);
5157: if (ref($settings) eq 'HASH') {
5158: %existing = %{$settings};
5159: }
5160: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5161: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
5162: \%currtargets,\%currrules);
1.150 raeburn 5163: } else {
5164: return;
5165: }
5166: my ($othertitle,$usertypes,$types) =
5167: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 5168: my $rownum = 8;
1.150 raeburn 5169: if (ref($types) eq 'ARRAY') {
5170: $rownum += scalar(@{$types});
5171: }
1.171 raeburn 5172: my @css_class = ('LC_odd_row','LC_even_row');
5173: my $balnum = 0;
5174: my $islast;
5175: my (@toshow,$disabledtext);
5176: if (keys(%currbalancer) > 0) {
5177: @toshow = sort(keys(%currbalancer));
5178: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5179: push(@toshow,'');
5180: }
5181: } else {
5182: @toshow = ('');
5183: $disabledtext = &mt('No existing load balancer');
5184: }
5185: foreach my $lonhost (@toshow) {
5186: if ($balnum == scalar(@toshow)-1) {
5187: $islast = 1;
5188: } else {
5189: $islast = 0;
5190: }
5191: my $cssidx = $balnum%2;
5192: my $targets_div_style = 'display: none';
5193: my $disabled_div_style = 'display: block';
5194: my $homedom_div_style = 'display: none';
5195: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
5196: '<td rowspan="'.$rownum.'" valign="top">'.
5197: '<p>';
5198: if ($lonhost eq '') {
1.210 raeburn 5199: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 5200: if (keys(%currbalancer) > 0) {
5201: $datatable .= &mt('Add balancer:');
5202: } else {
5203: $datatable .= &mt('Enable balancer:');
5204: }
5205: $datatable .= ' '.
5206: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5207: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5208: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5209: '<option value="" selected="selected">'.&mt('None').
5210: '</option>'."\n";
5211: foreach my $server (sort(keys(%servers))) {
5212: next if ($currbalancer{$server});
5213: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5214: }
1.210 raeburn 5215: $datatable .=
1.171 raeburn 5216: '</select>'."\n".
5217: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5218: } else {
5219: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5220: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5221: &mt('Stop balancing').'</label>'.
5222: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5223: $targets_div_style = 'display: block';
5224: $disabled_div_style = 'display: none';
5225: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5226: $homedom_div_style = 'display: block';
5227: }
5228: }
5229: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
5230: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5231: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5232: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5233: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5234: my @sparestypes = ('primary','default');
5235: my %typetitles = &sparestype_titles();
1.284 raeburn 5236: my %hostherechecked = (
5237: no => ' checked="checked"',
5238: );
1.171 raeburn 5239: foreach my $sparetype (@sparestypes) {
5240: my $targettable;
5241: for (my $i=0; $i<$numspares; $i++) {
5242: my $checked;
5243: if (ref($currtargets{$lonhost}) eq 'HASH') {
5244: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5245: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5246: $checked = ' checked="checked"';
5247: }
5248: }
5249: }
5250: my ($chkboxval,$disabled);
5251: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5252: $chkboxval = $spares[$i];
5253: }
5254: if (exists($currbalancer{$spares[$i]})) {
5255: $disabled = ' disabled="disabled"';
5256: }
1.210 raeburn 5257: $targettable .=
1.253 raeburn 5258: '<td><span class="LC_nobreak"><label>'.
5259: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 5260: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
1.253 raeburn 5261: '</span></label></span></td>';
1.171 raeburn 5262: my $rem = $i%($numinrow);
5263: if ($rem == 0) {
5264: if (($i > 0) && ($i < $numspares-1)) {
5265: $targettable .= '</tr>';
5266: }
5267: if ($i < $numspares-1) {
5268: $targettable .= '<tr>';
1.150 raeburn 5269: }
5270: }
5271: }
1.171 raeburn 5272: if ($targettable ne '') {
5273: my $rem = $numspares%($numinrow);
5274: my $colsleft = $numinrow - $rem;
5275: if ($colsleft > 1 ) {
5276: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5277: ' </td>';
5278: } elsif ($colsleft == 1) {
5279: $targettable .= '<td class="LC_left_item"> </td>';
5280: }
5281: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5282: '<table><tr>'.$targettable.'</tr></table><br />';
5283: }
1.284 raeburn 5284: $hostherechecked{$sparetype} = '';
5285: if (ref($currtargets{$lonhost}) eq 'HASH') {
5286: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5287: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5288: $hostherechecked{$sparetype} = ' checked="checked"';
5289: $hostherechecked{'no'} = '';
5290: }
5291: }
5292: }
5293: }
5294: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5295: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5296: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5297: foreach my $sparetype (@sparestypes) {
5298: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5299: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5300: '</i></label><br />';
1.171 raeburn 5301: }
5302: $datatable .= '</div></td></tr>'.
5303: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5304: $othertitle,$usertypes,$types,\%servers,
5305: \%currbalancer,$lonhost,
5306: $targets_div_style,$homedom_div_style,
5307: $css_class[$cssidx],$balnum,$islast);
5308: $$rowtotal += $rownum;
5309: $balnum ++;
5310: }
5311: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5312: return $datatable;
5313: }
5314:
5315: sub get_loadbalancers_config {
5316: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
5317: return unless ((ref($servers) eq 'HASH') &&
5318: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
5319: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
5320: if (keys(%{$existing}) > 0) {
5321: my $oldlonhost;
5322: foreach my $key (sort(keys(%{$existing}))) {
5323: if ($key eq 'lonhost') {
5324: $oldlonhost = $existing->{'lonhost'};
5325: $currbalancer->{$oldlonhost} = 1;
5326: } elsif ($key eq 'targets') {
5327: if ($oldlonhost) {
5328: $currtargets->{$oldlonhost} = $existing->{'targets'};
5329: }
5330: } elsif ($key eq 'rules') {
5331: if ($oldlonhost) {
5332: $currrules->{$oldlonhost} = $existing->{'rules'};
5333: }
5334: } elsif (ref($existing->{$key}) eq 'HASH') {
5335: $currbalancer->{$key} = 1;
5336: $currtargets->{$key} = $existing->{$key}{'targets'};
5337: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 5338: }
5339: }
1.171 raeburn 5340: } else {
5341: my ($balancerref,$targetsref) =
5342: &Apache::lonnet::get_lonbalancer_config($servers);
5343: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5344: foreach my $server (sort(keys(%{$balancerref}))) {
5345: $currbalancer->{$server} = 1;
5346: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5347: }
5348: }
5349: }
1.171 raeburn 5350: return;
1.150 raeburn 5351: }
5352:
5353: sub loadbalancing_rules {
5354: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 5355: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5356: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5357: my $output;
1.171 raeburn 5358: my $num = 0;
1.210 raeburn 5359: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5360: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5361: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5362: foreach my $type (@{$alltypes}) {
1.171 raeburn 5363: $num ++;
1.150 raeburn 5364: my $current;
5365: if (ref($currrules) eq 'HASH') {
5366: $current = $currrules->{$type};
5367: }
1.253 raeburn 5368: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 5369: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5370: $current = '';
5371: }
5372: }
5373: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 5374: $servers,$currbalancer,$lonhost,$dom,
5375: $targets_div_style,$homedom_div_style,
5376: $css_class,$balnum,$num,$islast);
1.150 raeburn 5377: }
5378: }
5379: return $output;
5380: }
5381:
5382: sub loadbalancing_titles {
5383: my ($dom,$intdom,$usertypes,$types) = @_;
5384: my %othertypes = (
5385: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5386: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5387: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5388: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 5389: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5390: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5391: );
1.209 raeburn 5392: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 5393: if (ref($types) eq 'ARRAY') {
5394: unshift(@alltypes,@{$types},'default');
5395: }
5396: my %titles;
5397: foreach my $type (@alltypes) {
5398: if ($type =~ /^_LC_/) {
5399: $titles{$type} = $othertypes{$type};
5400: } elsif ($type eq 'default') {
5401: $titles{$type} = &mt('All users from [_1]',$dom);
5402: if (ref($types) eq 'ARRAY') {
5403: if (@{$types} > 0) {
5404: $titles{$type} = &mt('Other users from [_1]',$dom);
5405: }
5406: }
5407: } elsif (ref($usertypes) eq 'HASH') {
5408: $titles{$type} = $usertypes->{$type};
5409: }
5410: }
5411: return (\@alltypes,\%othertypes,\%titles);
5412: }
5413:
5414: sub loadbalance_rule_row {
1.171 raeburn 5415: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5416: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 5417: my @rulenames;
1.150 raeburn 5418: my %ruletitles = &offloadtype_text();
1.209 raeburn 5419: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 5420: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 5421: } else {
1.209 raeburn 5422: @rulenames = ('default','homeserver');
5423: if ($type eq '_LC_external') {
5424: push(@rulenames,'externalbalancer');
5425: } else {
5426: push(@rulenames,'specific');
5427: }
5428: push(@rulenames,'none');
1.150 raeburn 5429: }
5430: my $style = $targets_div_style;
1.253 raeburn 5431: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 5432: $style = $homedom_div_style;
5433: }
1.171 raeburn 5434: my $space;
5435: if ($islast && $num == 1) {
5436: $space = '<div display="inline-block"> </div>';
5437: }
1.210 raeburn 5438: my $output =
1.171 raeburn 5439: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
5440: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5441: '<td valaign="top">'.$space.
5442: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 5443: for (my $i=0; $i<@rulenames; $i++) {
5444: my $rule = $rulenames[$i];
5445: my ($checked,$extra);
5446: if ($rulenames[$i] eq 'default') {
5447: $rule = '';
5448: }
5449: if ($rulenames[$i] eq 'specific') {
5450: if (ref($servers) eq 'HASH') {
5451: my $default;
5452: if (($current ne '') && (exists($servers->{$current}))) {
5453: $checked = ' checked="checked"';
5454: }
5455: unless ($checked) {
5456: $default = ' selected="selected"';
5457: }
1.210 raeburn 5458: $extra =
1.171 raeburn 5459: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5460: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5461: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5462: '<option value=""'.$default.'></option>'."\n";
5463: foreach my $server (sort(keys(%{$servers}))) {
5464: if (ref($currbalancer) eq 'HASH') {
5465: next if (exists($currbalancer->{$server}));
5466: }
1.150 raeburn 5467: my $selected;
1.171 raeburn 5468: if ($server eq $current) {
1.150 raeburn 5469: $selected = ' selected="selected"';
5470: }
1.171 raeburn 5471: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 5472: }
5473: $extra .= '</select>';
5474: }
5475: } elsif ($rule eq $current) {
5476: $checked = ' checked="checked"';
5477: }
5478: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 5479: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5480: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5481: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 5482: ')"'.$checked.' /> ';
5483: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
5484: $output .= $ruletitles{'particular'};
5485: } else {
5486: $output .= $ruletitles{$rulenames[$i]};
5487: }
5488: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 5489: }
5490: $output .= '</div></td></tr>'."\n";
5491: return $output;
5492: }
5493:
5494: sub offloadtype_text {
5495: my %ruletitles = &Apache::lonlocal::texthash (
5496: 'default' => 'Offloads to default destinations',
5497: 'homeserver' => "Offloads to user's home server",
5498: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5499: 'specific' => 'Offloads to specific server',
1.161 raeburn 5500: 'none' => 'No offload',
1.209 raeburn 5501: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5502: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 5503: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 5504: );
5505: return %ruletitles;
5506: }
5507:
5508: sub sparestype_titles {
5509: my %typestitles = &Apache::lonlocal::texthash (
5510: 'primary' => 'primary',
5511: 'default' => 'default',
5512: );
5513: return %typestitles;
5514: }
5515:
1.28 raeburn 5516: sub contact_titles {
5517: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 5518: 'supportemail' => 'Support E-mail address',
5519: 'adminemail' => 'Default Server Admin E-mail address',
5520: 'errormail' => 'Error reports to be e-mailed to',
5521: 'packagesmail' => 'Package update alerts to be e-mailed to',
5522: 'helpdeskmail' => "Helpdesk requests for this domain's users",
1.289 raeburn 5523: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
1.286 raeburn 5524: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5525: 'requestsmail' => 'E-mail from course requests requiring approval',
5526: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 5527: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 5528: );
5529: my %short_titles = &Apache::lonlocal::texthash (
5530: adminemail => 'Admin E-mail address',
5531: supportemail => 'Support E-mail',
5532: );
5533: return (\%titles,\%short_titles);
5534: }
5535:
1.286 raeburn 5536: sub helpform_fields {
5537: my %titles = &Apache::lonlocal::texthash (
5538: 'username' => 'Name',
5539: 'user' => 'Username/domain',
5540: 'phone' => 'Phone',
5541: 'cc' => 'Cc e-mail',
5542: 'course' => 'Course Details',
5543: 'section' => 'Sections',
1.289 raeburn 5544: 'screenshot' => 'File upload',
1.286 raeburn 5545: );
5546: my @fields = ('username','phone','user','course','section','cc','screenshot');
5547: my %possoptions = (
5548: username => ['yes','no','req'],
1.289 raeburn 5549: phone => ['yes','no','req'],
1.286 raeburn 5550: user => ['yes','no'],
1.289 raeburn 5551: cc => ['yes','no'],
1.286 raeburn 5552: course => ['yes','no'],
5553: section => ['yes','no'],
5554: screenshot => ['yes','no'],
5555: );
5556: my %fieldoptions = &Apache::lonlocal::texthash (
5557: 'yes' => 'Optional',
5558: 'req' => 'Required',
5559: 'no' => "Not shown",
5560: );
5561: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5562: }
5563:
1.72 raeburn 5564: sub tool_titles {
5565: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 5566: aboutme => 'Personal web page',
1.86 raeburn 5567: blog => 'Blog',
1.162 raeburn 5568: webdav => 'WebDAV',
1.86 raeburn 5569: portfolio => 'Portfolio',
1.88 bisitz 5570: official => 'Official courses (with institutional codes)',
5571: unofficial => 'Unofficial courses',
1.98 raeburn 5572: community => 'Communities',
1.216 raeburn 5573: textbook => 'Textbook courses',
1.271 raeburn 5574: placement => 'Placement tests',
1.86 raeburn 5575: );
1.72 raeburn 5576: return %titles;
5577: }
5578:
1.101 raeburn 5579: sub courserequest_titles {
5580: my %titles = &Apache::lonlocal::texthash (
5581: official => 'Official',
5582: unofficial => 'Unofficial',
5583: community => 'Communities',
1.216 raeburn 5584: textbook => 'Textbook',
1.271 raeburn 5585: placement => 'Placement tests',
1.101 raeburn 5586: norequest => 'Not allowed',
1.104 raeburn 5587: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5588: validate => 'With validation',
5589: autolimit => 'Numerical limit',
1.103 raeburn 5590: unlimited => '(blank for unlimited)',
1.101 raeburn 5591: );
5592: return %titles;
5593: }
5594:
1.163 raeburn 5595: sub authorrequest_titles {
5596: my %titles = &Apache::lonlocal::texthash (
5597: norequest => 'Not allowed',
5598: approval => 'Approval by Dom. Coord.',
5599: automatic => 'Automatic approval',
5600: );
5601: return %titles;
1.210 raeburn 5602: }
1.163 raeburn 5603:
1.101 raeburn 5604: sub courserequest_conditions {
5605: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5606: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 5607: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 5608: );
5609: return %conditions;
5610: }
5611:
5612:
1.27 raeburn 5613: sub print_usercreation {
1.30 raeburn 5614: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 5615: my $numinrow = 4;
1.28 raeburn 5616: my $datatable;
5617: if ($position eq 'top') {
1.30 raeburn 5618: $$rowtotal ++;
1.34 raeburn 5619: my $rowcount = 0;
1.32 raeburn 5620: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 5621: if (ref($rules) eq 'HASH') {
5622: if (keys(%{$rules}) > 0) {
1.32 raeburn 5623: $datatable .= &user_formats_row('username',$settings,$rules,
5624: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 5625: $$rowtotal ++;
1.32 raeburn 5626: $rowcount ++;
5627: }
5628: }
5629: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5630: if (ref($idrules) eq 'HASH') {
5631: if (keys(%{$idrules}) > 0) {
5632: $datatable .= &user_formats_row('id',$settings,$idrules,
5633: $idruleorder,$numinrow,$rowcount);
5634: $$rowtotal ++;
5635: $rowcount ++;
1.28 raeburn 5636: }
5637: }
1.39 raeburn 5638: if ($rowcount == 0) {
5639: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5640: $$rowtotal ++;
5641: $rowcount ++;
5642: }
1.34 raeburn 5643: } elsif ($position eq 'middle') {
1.224 raeburn 5644: my @creators = ('author','course','requestcrs');
1.37 raeburn 5645: my ($rules,$ruleorder) =
5646: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 5647: my %lt = &usercreation_types();
5648: my %checked;
5649: if (ref($settings) eq 'HASH') {
5650: if (ref($settings->{'cancreate'}) eq 'HASH') {
5651: foreach my $item (@creators) {
5652: $checked{$item} = $settings->{'cancreate'}{$item};
5653: }
5654: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5655: foreach my $item (@creators) {
5656: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5657: $checked{$item} = 'none';
5658: }
5659: }
5660: }
5661: }
5662: my $rownum = 0;
5663: foreach my $item (@creators) {
5664: $rownum ++;
1.224 raeburn 5665: if ($checked{$item} eq '') {
5666: $checked{$item} = 'any';
1.34 raeburn 5667: }
5668: my $css_class;
5669: if ($rownum%2) {
5670: $css_class = '';
5671: } else {
5672: $css_class = ' class="LC_odd_row" ';
5673: }
5674: $datatable .= '<tr'.$css_class.'>'.
5675: '<td><span class="LC_nobreak">'.$lt{$item}.
5676: '</span></td><td align="right">';
1.224 raeburn 5677: my @options = ('any');
5678: if (ref($rules) eq 'HASH') {
5679: if (keys(%{$rules}) > 0) {
5680: push(@options,('official','unofficial'));
1.37 raeburn 5681: }
5682: }
1.224 raeburn 5683: push(@options,'none');
1.37 raeburn 5684: foreach my $option (@options) {
1.50 raeburn 5685: my $type = 'radio';
1.34 raeburn 5686: my $check = ' ';
1.224 raeburn 5687: if ($checked{$item} eq $option) {
5688: $check = ' checked="checked" ';
1.34 raeburn 5689: }
5690: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5691: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5692: $item.'" value="'.$option.'"'.$check.'/> '.
5693: $lt{$option}.'</label> </span>';
5694: }
5695: $datatable .= '</td></tr>';
5696: }
1.28 raeburn 5697: } else {
5698: my @contexts = ('author','course','domain');
5699: my @authtypes = ('int','krb4','krb5','loc');
5700: my %checked;
5701: if (ref($settings) eq 'HASH') {
5702: if (ref($settings->{'authtypes'}) eq 'HASH') {
5703: foreach my $item (@contexts) {
5704: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5705: foreach my $auth (@authtypes) {
5706: if ($settings->{'authtypes'}{$item}{$auth}) {
5707: $checked{$item}{$auth} = ' checked="checked" ';
5708: }
5709: }
5710: }
5711: }
1.27 raeburn 5712: }
1.35 raeburn 5713: } else {
5714: foreach my $item (@contexts) {
1.36 raeburn 5715: foreach my $auth (@authtypes) {
1.35 raeburn 5716: $checked{$item}{$auth} = ' checked="checked" ';
5717: }
5718: }
1.27 raeburn 5719: }
1.28 raeburn 5720: my %title = &context_names();
5721: my %authname = &authtype_names();
5722: my $rownum = 0;
5723: my $css_class;
5724: foreach my $item (@contexts) {
5725: if ($rownum%2) {
5726: $css_class = '';
5727: } else {
5728: $css_class = ' class="LC_odd_row" ';
5729: }
1.30 raeburn 5730: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5731: '<td>'.$title{$item}.
5732: '</td><td class="LC_left_item">'.
5733: '<span class="LC_nobreak">';
5734: foreach my $auth (@authtypes) {
5735: $datatable .= '<label>'.
5736: '<input type="checkbox" name="'.$item.'_auth" '.
5737: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5738: $authname{$auth}.'</label> ';
5739: }
5740: $datatable .= '</span></td></tr>';
5741: $rownum ++;
1.27 raeburn 5742: }
1.30 raeburn 5743: $$rowtotal += $rownum;
1.27 raeburn 5744: }
5745: return $datatable;
5746: }
5747:
1.224 raeburn 5748: sub print_selfcreation {
5749: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 5750: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 5751: if (ref($settings) eq 'HASH') {
5752: if (ref($settings->{'cancreate'}) eq 'HASH') {
5753: $createsettings = $settings->{'cancreate'};
1.236 raeburn 5754: if (ref($createsettings) eq 'HASH') {
5755: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5756: @selfcreate = @{$createsettings->{'selfcreate'}};
5757: } elsif ($createsettings->{'selfcreate'} ne '') {
5758: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5759: @selfcreate = ('email','login','sso');
5760: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5761: @selfcreate = ($createsettings->{'selfcreate'});
5762: }
5763: }
5764: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5765: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 5766: }
5767: }
5768: }
5769: }
5770: my %radiohash;
5771: my $numinrow = 4;
5772: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5773: if ($position eq 'top') {
5774: my %choices = &Apache::lonlocal::texthash (
5775: cancreate_login => 'Institutional Login',
5776: cancreate_sso => 'Institutional Single Sign On',
5777: );
5778: my @toggles = sort(keys(%choices));
5779: my %defaultchecked = (
5780: 'cancreate_login' => 'off',
5781: 'cancreate_sso' => 'off',
5782: );
1.228 raeburn 5783: my ($onclick,$itemcount);
1.224 raeburn 5784: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5785: \%choices,$itemcount,$onclick);
1.228 raeburn 5786: $$rowtotal += $itemcount;
5787:
1.224 raeburn 5788: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5789:
5790: if (ref($usertypes) eq 'HASH') {
5791: if (keys(%{$usertypes}) > 0) {
5792: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5793: $dom,$numinrow,$othertitle,
1.228 raeburn 5794: 'statustocreate',$$rowtotal);
1.224 raeburn 5795: $$rowtotal ++;
5796: }
5797: }
1.240 raeburn 5798: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5799: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5800: $fieldtitles{'inststatus'} = &mt('Institutional status');
5801: my $rem;
5802: my $numperrow = 2;
5803: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5804: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 5805: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 5806: '<td class="LC_left_item">'."\n".
5807: '<table><tr><td>'."\n";
5808: for (my $i=0; $i<@fields; $i++) {
5809: $rem = $i%($numperrow);
5810: if ($rem == 0) {
5811: if ($i > 0) {
5812: $datatable .= '</tr>';
5813: }
5814: $datatable .= '<tr>';
5815: }
5816: my $currval;
1.248 raeburn 5817: if (ref($createsettings) eq 'HASH') {
5818: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5819: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5820: }
1.240 raeburn 5821: }
5822: $datatable .= '<td class="LC_left_item">'.
5823: '<span class="LC_nobreak">'.
5824: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5825: 'value="'.$currval.'" size="10" /> '.
5826: $fieldtitles{$fields[$i]}.'</span></td>';
5827: }
5828: my $colsleft = $numperrow - $rem;
5829: if ($colsleft > 1 ) {
5830: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5831: ' </td>';
5832: } elsif ($colsleft == 1) {
5833: $datatable .= '<td class="LC_left_item"> </td>';
5834: }
5835: $datatable .= '</tr></table></td></tr>';
5836: $$rowtotal ++;
1.224 raeburn 5837: } elsif ($position eq 'middle') {
5838: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5839: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5840: $usertypes->{'default'} = $othertitle;
5841: if (ref($types) eq 'ARRAY') {
5842: push(@{$types},'default');
5843: $usertypes->{'default'} = $othertitle;
5844: foreach my $status (@{$types}) {
5845: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 5846: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 5847: $$rowtotal ++;
1.224 raeburn 5848: }
5849: }
5850: } else {
1.236 raeburn 5851: my %choices = &Apache::lonlocal::texthash (
5852: cancreate_email => 'E-mail address as username',
5853: );
5854: my @toggles = sort(keys(%choices));
5855: my %defaultchecked = (
5856: 'cancreate_email' => 'off',
5857: );
5858: my $itemcount = 0;
5859: my $display = 'none';
5860: if (grep(/^\Qemail\E$/,@selfcreate)) {
5861: $display = 'block';
5862: }
5863: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5864: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5865: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5866: my $usertypes = {};
5867: my $order = [];
5868: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
5869: $usertypes = $domdefaults{'inststatustypes'};
5870: $order = $domdefaults{'inststatusguest'};
5871: }
5872: if (ref($order) eq 'ARRAY') {
5873: push(@{$order},'default');
5874: if (@{$order} > 1) {
5875: $usertypes->{'default'} = &mt('Other users');
5876: $additional .= '<table><tr>';
5877: foreach my $status (@{$order}) {
5878: $additional .= '<th>'.$usertypes->{$status}.'</th>';
5879: }
5880: $additional .= '</tr><tr>';
5881: foreach my $status (@{$order}) {
5882: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 5883: }
1.236 raeburn 5884: $additional .= '</tr></table>';
1.224 raeburn 5885: } else {
1.236 raeburn 5886: $usertypes->{'default'} = &mt('All users');
5887: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 5888: }
5889: }
1.236 raeburn 5890: $additional .= '</div>'."\n";
5891:
5892: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 5893: \%choices,$$rowtotal,$onclick,$additional);
5894: $$rowtotal ++;
1.236 raeburn 5895: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 5896: $$rowtotal ++;
1.224 raeburn 5897: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 5898: $numinrow = 1;
1.236 raeburn 5899: if (ref($order) eq 'ARRAY') {
5900: foreach my $status (@{$order}) {
1.228 raeburn 5901: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5902: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
5903: $$rowtotal ++;
5904: }
5905: }
1.224 raeburn 5906: my ($emailrules,$emailruleorder) =
5907: &Apache::lonnet::inst_userrules($dom,'email');
5908: if (ref($emailrules) eq 'HASH') {
5909: if (keys(%{$emailrules}) > 0) {
5910: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 5911: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 5912: $$rowtotal ++;
5913: }
5914: }
1.228 raeburn 5915: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 5916: }
5917: return $datatable;
5918: }
5919:
1.236 raeburn 5920: sub email_as_username {
5921: my ($rowtotal,$processing,$type) = @_;
5922: my %choices =
5923: &Apache::lonlocal::texthash (
5924: automatic => 'Automatic approval',
5925: approval => 'Queued for approval',
5926: );
5927: my $output;
5928: foreach my $option ('automatic','approval') {
5929: my $checked;
5930: if (ref($processing) eq 'HASH') {
5931: if ($type eq '') {
5932: if (!exists($processing->{'default'})) {
5933: if ($option eq 'automatic') {
5934: $checked = ' checked="checked"';
5935: }
5936: } else {
5937: if ($processing->{'default'} eq $option) {
5938: $checked = ' checked="checked"';
5939: }
5940: }
5941: } else {
5942: if (!exists($processing->{$type})) {
5943: if ($option eq 'automatic') {
5944: $checked = ' checked="checked"';
5945: }
5946: } else {
5947: if ($processing->{$type} eq $option) {
5948: $checked = ' checked="checked"';
5949: }
5950: }
5951: }
5952: } elsif ($option eq 'automatic') {
5953: $checked = ' checked="checked"';
5954: }
5955: my $name = 'cancreate_emailprocess';
5956: if (($type ne '') && ($type ne 'default')) {
5957: $name .= '_'.$type;
5958: }
5959: $output .= '<span class="LC_nobreak"><label>'.
5960: '<input type="radio" name="'.$name.'"'.
5961: $checked.' value="'.$option.'" />'.
5962: $choices{$option}.'</label></span>';
5963: if ($type eq '') {
5964: $output .= ' ';
5965: } else {
5966: $output .= '<br />';
5967: }
5968: }
5969: $$rowtotal ++;
5970: return $output;
5971: }
5972:
1.165 raeburn 5973: sub captcha_choice {
1.169 raeburn 5974: my ($context,$settings,$itemcount) = @_;
1.269 raeburn 5975: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5976: $vertext,$currver);
1.165 raeburn 5977: my %lt = &captcha_phrases();
5978: $keyentry = 'hidden';
5979: if ($context eq 'cancreate') {
1.224 raeburn 5980: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 5981: } elsif ($context eq 'login') {
5982: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 5983: }
5984: if (ref($settings) eq 'HASH') {
5985: if ($settings->{'captcha'}) {
5986: $checked{$settings->{'captcha'}} = ' checked="checked"';
5987: } else {
5988: $checked{'original'} = ' checked="checked"';
5989: }
5990: if ($settings->{'captcha'} eq 'recaptcha') {
5991: $pubtext = $lt{'pub'};
5992: $privtext = $lt{'priv'};
5993: $keyentry = 'text';
1.269 raeburn 5994: $vertext = $lt{'ver'};
5995: $currver = $settings->{'recaptchaversion'};
5996: if ($currver ne '2') {
5997: $currver = 1;
5998: }
1.165 raeburn 5999: }
6000: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
6001: $currpub = $settings->{'recaptchakeys'}{'public'};
6002: $currpriv = $settings->{'recaptchakeys'}{'private'};
6003: }
6004: } else {
6005: $checked{'original'} = ' checked="checked"';
6006: }
1.169 raeburn 6007: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
6008: my $output = '<tr'.$css_class.'>'.
6009: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 6010: '<table><tr><td>'."\n";
6011: foreach my $option ('original','recaptcha','notused') {
6012: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
6013: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
6014: $lt{$option}.'</label></span>';
6015: unless ($option eq 'notused') {
6016: $output .= (' 'x2)."\n";
6017: }
6018: }
6019: #
6020: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
6021: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 6022: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 6023: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 6024: #
1.165 raeburn 6025: $output .= '</td></tr>'."\n".
6026: '<tr><td>'."\n".
6027: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
6028: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
6029: $currpub.'" size="40" /></span><br />'."\n".
6030: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
6031: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 6032: $currpriv.'" size="40" /></span><br />'.
6033: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
6034: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
6035: $currver.'" size="3" /></span><br />'.
6036: '</td></tr></table>'."\n".
1.165 raeburn 6037: '</td></tr>';
6038: return $output;
6039: }
6040:
1.32 raeburn 6041: sub user_formats_row {
6042: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
6043: my $output;
6044: my %text = (
6045: 'username' => 'new usernames',
6046: 'id' => 'IDs',
1.45 raeburn 6047: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 6048: );
6049: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6050: $output = '<tr '.$css_class.'>'.
1.63 raeburn 6051: '<td><span class="LC_nobreak">';
6052: if ($type eq 'email') {
6053: $output .= &mt("Formats disallowed for $text{$type}: ");
6054: } else {
6055: $output .= &mt("Format rules to check for $text{$type}: ");
6056: }
6057: $output .= '</span></td>'.
6058: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 6059: my $rem;
6060: if (ref($ruleorder) eq 'ARRAY') {
6061: for (my $i=0; $i<@{$ruleorder}; $i++) {
6062: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
6063: my $rem = $i%($numinrow);
6064: if ($rem == 0) {
6065: if ($i > 0) {
6066: $output .= '</tr>';
6067: }
6068: $output .= '<tr>';
6069: }
6070: my $check = ' ';
1.39 raeburn 6071: if (ref($settings) eq 'HASH') {
6072: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
6073: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
6074: $check = ' checked="checked" ';
6075: }
1.27 raeburn 6076: }
6077: }
6078: $output .= '<td class="LC_left_item">'.
6079: '<span class="LC_nobreak"><label>'.
1.32 raeburn 6080: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 6081: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
6082: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
6083: }
6084: }
6085: $rem = @{$ruleorder}%($numinrow);
6086: }
6087: my $colsleft = $numinrow - $rem;
6088: if ($colsleft > 1 ) {
6089: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6090: ' </td>';
6091: } elsif ($colsleft == 1) {
6092: $output .= '<td class="LC_left_item"> </td>';
6093: }
6094: $output .= '</tr></table></td></tr>';
6095: return $output;
6096: }
6097:
1.34 raeburn 6098: sub usercreation_types {
6099: my %lt = &Apache::lonlocal::texthash (
6100: author => 'When adding a co-author',
6101: course => 'When adding a user to a course',
1.100 raeburn 6102: requestcrs => 'When requesting a course',
1.34 raeburn 6103: any => 'Any',
6104: official => 'Institutional only ',
6105: unofficial => 'Non-institutional only',
6106: none => 'None',
6107: );
6108: return %lt;
1.48 raeburn 6109: }
1.34 raeburn 6110:
1.224 raeburn 6111: sub selfcreation_types {
6112: my %lt = &Apache::lonlocal::texthash (
6113: selfcreate => 'User creates own account',
6114: any => 'Any',
6115: official => 'Institutional only ',
6116: unofficial => 'Non-institutional only',
6117: email => 'E-mail address',
6118: login => 'Institutional Login',
6119: sso => 'SSO',
6120: );
6121: }
6122:
1.28 raeburn 6123: sub authtype_names {
6124: my %lt = &Apache::lonlocal::texthash(
6125: int => 'Internal',
6126: krb4 => 'Kerberos 4',
6127: krb5 => 'Kerberos 5',
6128: loc => 'Local',
6129: );
6130: return %lt;
6131: }
6132:
6133: sub context_names {
6134: my %context_title = &Apache::lonlocal::texthash(
6135: author => 'Creating users when an Author',
6136: course => 'Creating users when in a course',
6137: domain => 'Creating users when a Domain Coordinator',
6138: );
6139: return %context_title;
6140: }
6141:
1.33 raeburn 6142: sub print_usermodification {
6143: my ($position,$dom,$settings,$rowtotal) = @_;
6144: my $numinrow = 4;
6145: my ($context,$datatable,$rowcount);
6146: if ($position eq 'top') {
6147: $rowcount = 0;
6148: $context = 'author';
6149: foreach my $role ('ca','aa') {
6150: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6151: $numinrow,$rowcount);
6152: $$rowtotal ++;
6153: $rowcount ++;
6154: }
1.230 raeburn 6155: } elsif ($position eq 'bottom') {
1.33 raeburn 6156: $context = 'course';
6157: $rowcount = 0;
6158: foreach my $role ('st','ep','ta','in','cr') {
6159: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6160: $numinrow,$rowcount);
6161: $$rowtotal ++;
6162: $rowcount ++;
6163: }
6164: }
6165: return $datatable;
6166: }
6167:
1.43 raeburn 6168: sub print_defaults {
1.236 raeburn 6169: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 6170: my $rownum = 0;
1.294 raeburn 6171: my ($datatable,$css_class,$titles);
6172: unless ($position eq 'bottom') {
6173: $titles = &defaults_titles($dom);
6174: }
1.236 raeburn 6175: if ($position eq 'top') {
6176: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6177: 'datelocale_def','portal_def');
6178: my %defaults;
6179: if (ref($settings) eq 'HASH') {
6180: %defaults = %{$settings};
1.43 raeburn 6181: } else {
1.236 raeburn 6182: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6183: foreach my $item (@items) {
6184: $defaults{$item} = $domdefaults{$item};
6185: }
1.43 raeburn 6186: }
1.236 raeburn 6187: foreach my $item (@items) {
6188: if ($rownum%2) {
6189: $css_class = '';
6190: } else {
6191: $css_class = ' class="LC_odd_row" ';
6192: }
6193: $datatable .= '<tr'.$css_class.'>'.
6194: '<td><span class="LC_nobreak">'.$titles->{$item}.
6195: '</span></td><td class="LC_right_item" colspan="3">';
6196: if ($item eq 'auth_def') {
6197: my @authtypes = ('internal','krb4','krb5','localauth');
6198: my %shortauth = (
6199: internal => 'int',
6200: krb4 => 'krb4',
6201: krb5 => 'krb5',
6202: localauth => 'loc'
6203: );
6204: my %authnames = &authtype_names();
6205: foreach my $auth (@authtypes) {
6206: my $checked = ' ';
6207: if ($defaults{$item} eq $auth) {
6208: $checked = ' checked="checked" ';
6209: }
6210: $datatable .= '<label><input type="radio" name="'.$item.
6211: '" value="'.$auth.'"'.$checked.'/>'.
6212: $authnames{$shortauth{$auth}}.'</label> ';
6213: }
6214: } elsif ($item eq 'timezone_def') {
6215: my $includeempty = 1;
6216: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6217: } elsif ($item eq 'datelocale_def') {
6218: my $includeempty = 1;
6219: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
6220: } elsif ($item eq 'lang_def') {
1.263 raeburn 6221: my $includeempty = 1;
6222: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 6223: } else {
6224: my $size;
6225: if ($item eq 'portal_def') {
6226: $size = ' size="25"';
6227: }
6228: $datatable .= '<input type="text" name="'.$item.'" value="'.
6229: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 6230: }
1.236 raeburn 6231: $datatable .= '</td></tr>';
6232: $rownum ++;
6233: }
1.294 raeburn 6234: } elsif ($position eq 'middle') {
6235: my @items = ('intauth_cost','intauth_check','intauth_switch');
6236: my %defaults;
6237: if (ref($settings) eq 'HASH') {
6238: %defaults = %{$settings};
6239: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6240: $defaults{'intauth_cost'} = 10;
6241: }
6242: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6243: $defaults{'intauth_check'} = 0;
6244: }
6245: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6246: $defaults{'intauth_switch'} = 0;
6247: }
6248: } else {
6249: %defaults = (
6250: 'intauth_cost' => 10,
6251: 'intauth_check' => 0,
6252: 'intauth_switch' => 0,
6253: );
6254: }
6255: foreach my $item (@items) {
6256: if ($rownum%2) {
6257: $css_class = '';
6258: } else {
6259: $css_class = ' class="LC_odd_row" ';
6260: }
6261: $datatable .= '<tr'.$css_class.'>'.
6262: '<td><span class="LC_nobreak">'.$titles->{$item}.
6263: '</span></td><td class="LC_left_item" colspan="3">';
6264: if ($item eq 'intauth_switch') {
6265: my @options = (0,1,2);
6266: my %optiondesc = &Apache::lonlocal::texthash (
6267: 0 => 'No',
6268: 1 => 'Yes',
6269: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6270: );
6271: $datatable .= '<table width="100%">';
6272: foreach my $option (@options) {
6273: my $checked = ' ';
6274: if ($defaults{$item} eq $option) {
6275: $checked = ' checked="checked"';
6276: }
6277: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6278: '<label><input type="radio" name="'.$item.
6279: '" value="'.$option.'"'.$checked.' />'.
6280: $optiondesc{$option}.'</label></span></td></tr>';
6281: }
6282: $datatable .= '</table>';
6283: } elsif ($item eq 'intauth_check') {
6284: my @options = (0,1,2);
6285: my %optiondesc = &Apache::lonlocal::texthash (
6286: 0 => 'No',
6287: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6288: 2 => 'Yes, disallow login if stored cost is less than domain default',
6289: );
6290: $datatable .= '<table wisth="100%">';
6291: foreach my $option (@options) {
6292: my $checked = ' ';
6293: my $onclick;
6294: if ($defaults{$item} eq $option) {
6295: $checked = ' checked="checked"';
6296: }
6297: if ($option == 2) {
6298: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6299: }
6300: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6301: '<label><input type="radio" name="'.$item.
6302: '" value="'.$option.'"'.$checked.$onclick.' />'.
6303: $optiondesc{$option}.'</label></span></td></tr>';
6304: }
6305: $datatable .= '</table>';
6306: } else {
6307: $datatable .= '<input type="text" name="'.$item.'" value="'.
6308: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6309: }
6310: $datatable .= '</td></tr>';
6311: $rownum ++;
6312: }
1.236 raeburn 6313: } else {
1.294 raeburn 6314: my %defaults;
1.236 raeburn 6315: if (ref($settings) eq 'HASH') {
6316: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
6317: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
6318: my $maxnum = @{$settings->{'inststatusorder'}};
6319: for (my $i=0; $i<$maxnum; $i++) {
6320: $css_class = $rownum%2?' class="LC_odd_row"':'';
6321: my $item = $settings->{'inststatusorder'}->[$i];
6322: my $title = $settings->{'inststatustypes'}->{$item};
6323: my $guestok;
6324: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
6325: $guestok = 1;
6326: }
6327: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6328: $datatable .= '<tr'.$css_class.'>'.
6329: '<td><span class="LC_nobreak">'.
6330: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6331: for (my $k=0; $k<=$maxnum; $k++) {
6332: my $vpos = $k+1;
6333: my $selstr;
6334: if ($k == $i) {
6335: $selstr = ' selected="selected" ';
6336: }
6337: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6338: }
6339: my ($checkedon,$checkedoff);
6340: $checkedoff = ' checked="checked"';
6341: if ($guestok) {
6342: $checkedon = $checkedoff;
6343: $checkedoff = '';
6344: }
6345: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6346: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6347: &mt('delete').'</span></td>'.
6348: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
6349: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
6350: '</span></td>'.
6351: '<td class="LC_right_item"><span class="LC_nobreak">'.
6352: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
6353: &mt('Yes').'</label>'.(' 'x2).
6354: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
6355: &mt('No').'</label></span></td></tr>';
6356: }
6357: $css_class = $rownum%2?' class="LC_odd_row"':'';
6358: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6359: $datatable .= '<tr '.$css_class.'>'.
6360: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6361: for (my $k=0; $k<=$maxnum; $k++) {
6362: my $vpos = $k+1;
6363: my $selstr;
6364: if ($k == $maxnum) {
6365: $selstr = ' selected="selected" ';
6366: }
6367: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6368: }
6369: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 6370: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 6371: ' '.&mt('(new)').
6372: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
6373: &mt('Name displayed:').
6374: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6375: '<td class="LC_right_item"><span class="LC_nobreak">'.
6376: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
6377: &mt('Yes').'</label>'.(' 'x2).
6378: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
6379: &mt('No').'</label></span></td></tr>';
6380: '</tr>'."\n";
6381: $rownum ++;
1.141 raeburn 6382: }
1.43 raeburn 6383: }
6384: }
6385: $$rowtotal += $rownum;
6386: return $datatable;
6387: }
6388:
1.168 raeburn 6389: sub get_languages_hash {
6390: my %langchoices;
6391: foreach my $id (&Apache::loncommon::languageids()) {
6392: my $code = &Apache::loncommon::supportedlanguagecode($id);
6393: if ($code ne '') {
6394: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6395: }
6396: }
6397: return %langchoices;
6398: }
6399:
1.43 raeburn 6400: sub defaults_titles {
1.141 raeburn 6401: my ($dom) = @_;
1.43 raeburn 6402: my %titles = &Apache::lonlocal::texthash (
6403: 'auth_def' => 'Default authentication type',
6404: 'auth_arg_def' => 'Default authentication argument',
6405: 'lang_def' => 'Default language',
1.54 raeburn 6406: 'timezone_def' => 'Default timezone',
1.68 raeburn 6407: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6408: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 6409: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
6410: 'intauth_check' => 'Check bcrypt cost if authenticated',
6411: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 6412: );
1.141 raeburn 6413: if ($dom) {
6414: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6415: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6416: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6417: $protocol = 'http' if ($protocol ne 'https');
6418: if ($uint_dom) {
6419: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6420: $uint_dom);
6421: }
6422: }
1.43 raeburn 6423: return (\%titles);
6424: }
6425:
1.46 raeburn 6426: sub print_scantronformat {
6427: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6428: my $itemcount = 1;
1.60 raeburn 6429: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6430: %confhash);
1.46 raeburn 6431: my $switchserver = &check_switchserver($dom,$confname);
6432: my %lt = &Apache::lonlocal::texthash (
1.95 www 6433: default => 'Default bubblesheet format file error',
6434: custom => 'Custom bubblesheet format file error',
1.46 raeburn 6435: );
6436: my %scantronfiles = (
6437: default => 'default.tab',
6438: custom => 'custom.tab',
6439: );
6440: foreach my $key (keys(%scantronfiles)) {
6441: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6442: .$scantronfiles{$key};
6443: }
6444: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6445: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6446: if (!$switchserver) {
6447: my $servadm = $r->dir_config('lonAdmEMail');
6448: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6449: if ($configuserok eq 'ok') {
6450: if ($author_ok eq 'ok') {
6451: my %legacyfile = (
6452: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6453: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
6454: );
6455: my %md5chk;
6456: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6457: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6458: chomp($md5chk{$type});
1.46 raeburn 6459: }
6460: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6461: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6462: ($scantronurls{$type},my $error) =
1.46 raeburn 6463: &legacy_scantronformat($r,$dom,$confname,
6464: $type,$legacyfile{$type},
6465: $scantronurls{$type},
6466: $scantronfiles{$type});
1.60 raeburn 6467: if ($error ne '') {
6468: $error{$type} = $error;
6469: }
6470: }
6471: if (keys(%error) == 0) {
6472: $is_custom = 1;
6473: $confhash{'scantron'}{'scantronformat'} =
6474: $scantronurls{'custom'};
6475: my $putresult =
6476: &Apache::lonnet::put_dom('configuration',
6477: \%confhash,$dom);
6478: if ($putresult ne 'ok') {
6479: $error{'custom'} =
6480: '<span class="LC_error">'.
6481: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6482: }
1.46 raeburn 6483: }
6484: } else {
1.60 raeburn 6485: ($scantronurls{'default'},my $error) =
1.46 raeburn 6486: &legacy_scantronformat($r,$dom,$confname,
6487: 'default',$legacyfile{'default'},
6488: $scantronurls{'default'},
6489: $scantronfiles{'default'});
1.60 raeburn 6490: if ($error eq '') {
6491: $confhash{'scantron'}{'scantronformat'} = '';
6492: my $putresult =
6493: &Apache::lonnet::put_dom('configuration',
6494: \%confhash,$dom);
6495: if ($putresult ne 'ok') {
6496: $error{'default'} =
6497: '<span class="LC_error">'.
6498: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6499: }
6500: } else {
6501: $error{'default'} = $error;
6502: }
1.46 raeburn 6503: }
6504: }
6505: }
6506: } else {
1.95 www 6507: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 6508: }
6509: }
6510: if (ref($settings) eq 'HASH') {
6511: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6512: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
6513: if ((!@info) || ($info[0] eq 'no_such_dir')) {
6514: $scantronurl = '';
6515: } else {
6516: $scantronurl = $settings->{'scantronformat'};
6517: }
6518: $is_custom = 1;
6519: } else {
6520: $scantronurl = $scantronurls{'default'};
6521: }
6522: } else {
1.60 raeburn 6523: if ($is_custom) {
6524: $scantronurl = $scantronurls{'custom'};
6525: } else {
6526: $scantronurl = $scantronurls{'default'};
6527: }
1.46 raeburn 6528: }
6529: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6530: $datatable .= '<tr'.$css_class.'>';
6531: if (!$is_custom) {
1.65 raeburn 6532: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6533: '<span class="LC_nobreak">';
1.46 raeburn 6534: if ($scantronurl) {
1.199 raeburn 6535: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6536: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 6537: } else {
6538: $datatable = &mt('File unavailable for display');
6539: }
1.65 raeburn 6540: $datatable .= '</span></td>';
1.60 raeburn 6541: if (keys(%error) == 0) {
6542: $datatable .= '<td valign="bottom">';
6543: if (!$switchserver) {
6544: $datatable .= &mt('Upload:').'<br />';
6545: }
6546: } else {
6547: my $errorstr;
6548: foreach my $key (sort(keys(%error))) {
6549: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6550: }
6551: $datatable .= '<td>'.$errorstr;
6552: }
1.46 raeburn 6553: } else {
6554: if (keys(%error) > 0) {
6555: my $errorstr;
6556: foreach my $key (sort(keys(%error))) {
6557: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6558: }
1.60 raeburn 6559: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 6560: } elsif ($scantronurl) {
1.199 raeburn 6561: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
6562: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 6563: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 6564: $link.
6565: '<label><input type="checkbox" name="scantronformat_del"'.
6566: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 6567: '<td><span class="LC_nobreak"> '.
6568: &mt('Replace:').'</span><br />';
1.46 raeburn 6569: }
6570: }
6571: if (keys(%error) == 0) {
6572: if ($switchserver) {
6573: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6574: } else {
1.65 raeburn 6575: $datatable .='<span class="LC_nobreak"> '.
6576: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 6577: }
6578: }
6579: $datatable .= '</td></tr>';
6580: $$rowtotal ++;
6581: return $datatable;
6582: }
6583:
6584: sub legacy_scantronformat {
6585: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6586: my ($url,$error);
6587: my @statinfo = &Apache::lonnet::stat_file($newurl);
6588: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6589: (my $result,$url) =
6590: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6591: '','',$newfile);
6592: if ($result ne 'ok') {
1.130 raeburn 6593: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 6594: }
6595: }
6596: return ($url,$error);
6597: }
1.43 raeburn 6598:
1.49 raeburn 6599: sub print_coursecategories {
1.57 raeburn 6600: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6601: my $datatable;
6602: if ($position eq 'top') {
1.238 raeburn 6603: my (%checked);
6604: my @catitems = ('unauth','auth');
6605: my @cattypes = ('std','domonly','codesrch','none');
6606: $checked{'unauth'} = 'std';
6607: $checked{'auth'} = 'std';
6608: if (ref($settings) eq 'HASH') {
6609: foreach my $type (@cattypes) {
6610: if ($type eq $settings->{'unauth'}) {
6611: $checked{'unauth'} = $type;
6612: }
6613: if ($type eq $settings->{'auth'}) {
6614: $checked{'auth'} = $type;
6615: }
6616: }
6617: }
6618: my %lt = &Apache::lonlocal::texthash (
6619: unauth => 'Catalog type for unauthenticated users',
6620: auth => 'Catalog type for authenticated users',
6621: none => 'No catalog',
6622: std => 'Standard catalog',
6623: domonly => 'Domain-only catalog',
6624: codesrch => "Code search form",
6625: );
6626: my $itemcount = 0;
6627: foreach my $item (@catitems) {
6628: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6629: $datatable .= '<tr '.$css_class.'>'.
6630: '<td>'.$lt{$item}.'</td>'.
6631: '<td class="LC_right_item"><span class="LC_nobreak">';
6632: foreach my $type (@cattypes) {
6633: my $ischecked;
6634: if ($checked{$item} eq $type) {
6635: $ischecked=' checked="checked"';
6636: }
6637: $datatable .= '<label>'.
6638: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6639: ' />'.$lt{$type}.'</label> ';
6640: }
6641: $datatable .= '</td></tr>';
6642: $itemcount ++;
6643: }
6644: $$rowtotal += $itemcount;
6645: } elsif ($position eq 'middle') {
1.57 raeburn 6646: my $toggle_cats_crs = ' ';
6647: my $toggle_cats_dom = ' checked="checked" ';
6648: my $can_cat_crs = ' ';
6649: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 6650: my $toggle_catscomm_comm = ' ';
6651: my $toggle_catscomm_dom = ' checked="checked" ';
6652: my $can_catcomm_comm = ' ';
6653: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 6654: my $toggle_catsplace_place = ' ';
6655: my $toggle_catsplace_dom = ' checked="checked" ';
6656: my $can_catplace_place = ' ';
6657: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 6658:
1.57 raeburn 6659: if (ref($settings) eq 'HASH') {
6660: if ($settings->{'togglecats'} eq 'crs') {
6661: $toggle_cats_crs = $toggle_cats_dom;
6662: $toggle_cats_dom = ' ';
6663: }
6664: if ($settings->{'categorize'} eq 'crs') {
6665: $can_cat_crs = $can_cat_dom;
6666: $can_cat_dom = ' ';
6667: }
1.120 raeburn 6668: if ($settings->{'togglecatscomm'} eq 'comm') {
6669: $toggle_catscomm_comm = $toggle_catscomm_dom;
6670: $toggle_catscomm_dom = ' ';
6671: }
6672: if ($settings->{'categorizecomm'} eq 'comm') {
6673: $can_catcomm_comm = $can_catcomm_dom;
6674: $can_catcomm_dom = ' ';
6675: }
1.272 raeburn 6676: if ($settings->{'togglecatsplace'} eq 'place') {
6677: $toggle_catsplace_place = $toggle_catsplace_dom;
6678: $toggle_catsplace_dom = ' ';
6679: }
6680: if ($settings->{'categorizeplace'} eq 'place') {
6681: $can_catplace_place = $can_catplace_dom;
6682: $can_catplace_dom = ' ';
6683: }
1.57 raeburn 6684: }
6685: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 6686: togglecats => 'Show/Hide a course in catalog',
6687: togglecatscomm => 'Show/Hide a community in catalog',
6688: togglecatsplace => 'Show/Hide a placement test in catalog',
6689: categorize => 'Assign a category to a course',
6690: categorizecomm => 'Assign a category to a community',
6691: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 6692: );
6693: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 6694: dom => 'Set in Domain',
6695: crs => 'Set in Course',
6696: comm => 'Set in Community',
6697: place => 'Set in Placement Test',
1.57 raeburn 6698: );
6699: $datatable = '<tr class="LC_odd_row">'.
6700: '<td>'.$title{'togglecats'}.'</td>'.
6701: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6702: '<input type="radio" name="togglecats"'.
6703: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6704: '<label><input type="radio" name="togglecats"'.
6705: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
6706: '</tr><tr>'.
6707: '<td>'.$title{'categorize'}.'</td>'.
6708: '<td class="LC_right_item"><span class="LC_nobreak">'.
6709: '<label><input type="radio" name="categorize"'.
6710: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6711: '<label><input type="radio" name="categorize"'.
6712: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 6713: '</tr><tr class="LC_odd_row">'.
6714: '<td>'.$title{'togglecatscomm'}.'</td>'.
6715: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6716: '<input type="radio" name="togglecatscomm"'.
6717: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6718: '<label><input type="radio" name="togglecatscomm"'.
6719: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
6720: '</tr><tr>'.
6721: '<td>'.$title{'categorizecomm'}.'</td>'.
6722: '<td class="LC_right_item"><span class="LC_nobreak">'.
6723: '<label><input type="radio" name="categorizecomm"'.
6724: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6725: '<label><input type="radio" name="categorizecomm"'.
6726: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 6727: '</tr><tr>'.
6728: '<td>'.$title{'togglecatsplace'}.'</td>'.
6729: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6730: '<input type="radio" name="togglecatsplace"'.
6731: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6732: '<label><input type="radio" name="togglecatscomm"'.
6733: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
6734: '</tr><tr>'.
6735: '<td>'.$title{'categorizeplace'}.'</td>'.
6736: '<td class="LC_right_item"><span class="LC_nobreak">'.
6737: '<label><input type="radio" name="categorizeplace"'.
6738: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6739: '<label><input type="radio" name="categorizeplace"'.
6740: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 6741: '</tr>';
1.272 raeburn 6742: $$rowtotal += 6;
1.57 raeburn 6743: } else {
6744: my $css_class;
6745: my $itemcount = 1;
6746: my $cathash;
6747: if (ref($settings) eq 'HASH') {
6748: $cathash = $settings->{'cats'};
6749: }
6750: if (ref($cathash) eq 'HASH') {
6751: my (@cats,@trails,%allitems,%idx,@jsarray);
6752: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
6753: \%allitems,\%idx,\@jsarray);
6754: my $maxdepth = scalar(@cats);
6755: my $colattrib = '';
6756: if ($maxdepth > 2) {
6757: $colattrib = ' colspan="2" ';
6758: }
6759: my @path;
6760: if (@cats > 0) {
6761: if (ref($cats[0]) eq 'ARRAY') {
6762: my $numtop = @{$cats[0]};
6763: my $maxnum = $numtop;
1.120 raeburn 6764: my %default_names = (
6765: instcode => &mt('Official courses'),
6766: communities => &mt('Communities'),
1.272 raeburn 6767: placement => &mt('Placement Tests'),
1.120 raeburn 6768: );
6769:
6770: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6771: ($cathash->{'instcode::0'} eq '') ||
6772: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 6773: ($cathash->{'communities::0'} eq '') ||
6774: (!grep(/^placement$/,@{$cats[0]})) ||
6775: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 6776: $maxnum ++;
6777: }
6778: my $lastidx;
6779: for (my $i=0; $i<$numtop; $i++) {
6780: my $parent = $cats[0][$i];
6781: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6782: my $item = &escape($parent).'::0';
6783: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6784: $lastidx = $idx{$item};
6785: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6786: .'<select name="'.$item.'"'.$chgstr.'>';
6787: for (my $k=0; $k<=$maxnum; $k++) {
6788: my $vpos = $k+1;
6789: my $selstr;
6790: if ($k == $i) {
6791: $selstr = ' selected="selected" ';
6792: }
6793: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6794: }
1.214 raeburn 6795: $datatable .= '</select></span></td><td>';
1.272 raeburn 6796: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 6797: $datatable .= '<span class="LC_nobreak">'
6798: .$default_names{$parent}.'</span>';
6799: if ($parent eq 'instcode') {
6800: $datatable .= '<br /><span class="LC_nobreak">('
6801: .&mt('with institutional codes')
6802: .')</span></td><td'.$colattrib.'>';
6803: } else {
6804: $datatable .= '<table><tr><td>';
6805: }
6806: $datatable .= '<span class="LC_nobreak">'
6807: .'<label><input type="radio" name="'
6808: .$parent.'" value="1" checked="checked" />'
6809: .&mt('Display').'</label>';
6810: if ($parent eq 'instcode') {
6811: $datatable .= ' ';
6812: } else {
6813: $datatable .= '</span></td></tr><tr><td>'
6814: .'<span class="LC_nobreak">';
6815: }
6816: $datatable .= '<label><input type="radio" name="'
6817: .$parent.'" value="0" />'
6818: .&mt('Do not display').'</label></span>';
1.272 raeburn 6819: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 6820: $datatable .= '</td></tr></table>';
6821: }
6822: $datatable .= '</td>';
1.57 raeburn 6823: } else {
6824: $datatable .= $parent
1.214 raeburn 6825: .' <span class="LC_nobreak"><label>'
6826: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6827: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6828: }
6829: my $depth = 1;
6830: push(@path,$parent);
6831: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6832: pop(@path);
6833: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6834: $itemcount ++;
6835: }
1.48 raeburn 6836: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6837: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6838: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6839: for (my $k=0; $k<=$maxnum; $k++) {
6840: my $vpos = $k+1;
6841: my $selstr;
1.57 raeburn 6842: if ($k == $numtop) {
1.48 raeburn 6843: $selstr = ' selected="selected" ';
6844: }
6845: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6846: }
1.59 bisitz 6847: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6848: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6849: .'</tr>'."\n";
1.48 raeburn 6850: $itemcount ++;
1.272 raeburn 6851: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6852: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6853: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6854: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6855: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6856: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6857: for (my $k=0; $k<=$maxnum; $k++) {
6858: my $vpos = $k+1;
6859: my $selstr;
6860: if ($k == $maxnum) {
6861: $selstr = ' selected="selected" ';
6862: }
6863: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6864: }
1.120 raeburn 6865: $datatable .= '</select></span></td>'.
6866: '<td><span class="LC_nobreak">'.
6867: $default_names{$default}.'</span>';
6868: if ($default eq 'instcode') {
6869: $datatable .= '<br /><span class="LC_nobreak">('
6870: .&mt('with institutional codes').')</span>';
6871: }
6872: $datatable .= '</td>'
6873: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6874: .&mt('Display').'</label> '
6875: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6876: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6877: }
6878: }
6879: }
1.57 raeburn 6880: } else {
6881: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6882: }
6883: } else {
1.238 raeburn 6884: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6885: .&initialize_categories($itemcount);
1.48 raeburn 6886: }
1.57 raeburn 6887: $$rowtotal += $itemcount;
1.48 raeburn 6888: }
6889: return $datatable;
6890: }
6891:
1.69 raeburn 6892: sub print_serverstatuses {
6893: my ($dom,$settings,$rowtotal) = @_;
6894: my $datatable;
6895: my @pages = &serverstatus_pages();
6896: my (%namedaccess,%machineaccess);
6897: foreach my $type (@pages) {
6898: $namedaccess{$type} = '';
6899: $machineaccess{$type}= '';
6900: }
6901: if (ref($settings) eq 'HASH') {
6902: foreach my $type (@pages) {
6903: if (exists($settings->{$type})) {
6904: if (ref($settings->{$type}) eq 'HASH') {
6905: foreach my $key (keys(%{$settings->{$type}})) {
6906: if ($key eq 'namedusers') {
6907: $namedaccess{$type} = $settings->{$type}->{$key};
6908: } elsif ($key eq 'machines') {
6909: $machineaccess{$type} = $settings->{$type}->{$key};
6910: }
6911: }
6912: }
6913: }
6914: }
6915: }
1.81 raeburn 6916: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6917: my $rownum = 0;
6918: my $css_class;
6919: foreach my $type (@pages) {
6920: $rownum ++;
6921: $css_class = $rownum%2?' class="LC_odd_row"':'';
6922: $datatable .= '<tr'.$css_class.'>'.
6923: '<td><span class="LC_nobreak">'.
6924: $titles->{$type}.'</span></td>'.
6925: '<td class="LC_left_item">'.
6926: '<input type="text" name="'.$type.'_namedusers" '.
6927: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6928: '<td class="LC_right_item">'.
6929: '<span class="LC_nobreak">'.
6930: '<input type="text" name="'.$type.'_machines" '.
6931: 'value="'.$machineaccess{$type}.'" size="10" />'.
6932: '</td></tr>'."\n";
6933: }
6934: $$rowtotal += $rownum;
6935: return $datatable;
6936: }
6937:
6938: sub serverstatus_pages {
6939: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 6940: 'checksums','clusterstatus','certstatus','metadata_keywords',
6941: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
6942: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6943: }
6944:
1.236 raeburn 6945: sub defaults_javascript {
6946: my ($settings) = @_;
1.294 raeburn 6947: 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.');
6948: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
6949: &js_escape(\$intauthcheck);
6950: &js_escape(\$intauthcost);
6951: my $intauthjs = <<"ENDSCRIPT";
6952:
6953: function warnIntAuth(field) {
6954: if (field.name == 'intauth_check') {
6955: if (field.value == '2') {
6956: alert('$intauthcheck');
6957: }
6958: }
6959: if (field.name == 'intauth_cost') {
6960: field.value.replace(/\s/g,'');
6961: if (field.value != '') {
6962: var regexdigit=/^\\d+\$/;
6963: if (!regexdigit.test(field.value)) {
6964: alert('$intauthcost');
6965: }
6966: }
6967: }
6968: return;
6969: }
6970:
6971: ENDSCRIPT
6972:
6973: if (ref($settings) ne 'HASH') {
6974: return &Apache::lonhtmlcommon::scripttag($intauthjs);
6975: }
1.236 raeburn 6976: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6977: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6978: if ($maxnum eq '') {
6979: $maxnum = 0;
6980: }
6981: $maxnum ++;
1.249 raeburn 6982: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 6983: return <<"ENDSCRIPT";
6984: <script type="text/javascript">
6985: // <![CDATA[
6986: function reorderTypes(form,caller) {
6987: var changedVal;
6988: $jstext
6989: var newpos = 'addinststatus_pos';
6990: var current = new Array;
6991: var maxh = $maxnum;
6992: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6993: var oldVal;
6994: if (caller == newpos) {
6995: changedVal = newitemVal;
6996: } else {
6997: var curritem = 'inststatus_pos_'+caller;
6998: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6999: current[newitemVal] = newpos;
7000: }
7001: for (var i=0; i<inststatuses.length; i++) {
7002: if (inststatuses[i] != caller) {
7003: var elementName = 'inststatus_pos_'+inststatuses[i];
7004: if (form.elements[elementName]) {
7005: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7006: current[currVal] = elementName;
7007: }
7008: }
7009: }
7010: for (var j=0; j<maxh; j++) {
7011: if (current[j] == undefined) {
7012: oldVal = j;
7013: }
7014: }
7015: if (oldVal < changedVal) {
7016: for (var k=oldVal+1; k<=changedVal ; k++) {
7017: var elementName = current[k];
7018: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7019: }
7020: } else {
7021: for (var k=changedVal; k<oldVal; k++) {
7022: var elementName = current[k];
7023: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7024: }
7025: }
7026: return;
7027: }
7028:
1.294 raeburn 7029: $intauthjs
7030:
1.236 raeburn 7031: // ]]>
7032: </script>
7033:
7034: ENDSCRIPT
1.294 raeburn 7035: } else {
7036: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 7037: }
7038: }
7039:
1.49 raeburn 7040: sub coursecategories_javascript {
7041: my ($settings) = @_;
1.57 raeburn 7042: my ($output,$jstext,$cathash);
1.49 raeburn 7043: if (ref($settings) eq 'HASH') {
1.57 raeburn 7044: $cathash = $settings->{'cats'};
7045: }
7046: if (ref($cathash) eq 'HASH') {
1.49 raeburn 7047: my (@cats,@jsarray,%idx);
1.57 raeburn 7048: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 7049: if (@jsarray > 0) {
7050: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
7051: for (my $i=0; $i<@jsarray; $i++) {
7052: if (ref($jsarray[$i]) eq 'ARRAY') {
7053: my $catstr = join('","',@{$jsarray[$i]});
7054: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
7055: }
7056: }
7057: }
7058: } else {
7059: $jstext = ' var categories = Array(1);'."\n".
7060: ' categories[0] = Array("instcode_pos");'."\n";
7061: }
1.237 bisitz 7062: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
7063: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 7064: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 7065: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
7066: &js_escape(\$instcode_reserved);
7067: &js_escape(\$communities_reserved);
1.272 raeburn 7068: &js_escape(\$placement_reserved);
1.265 damieng 7069: &js_escape(\$choose_again);
1.49 raeburn 7070: $output = <<"ENDSCRIPT";
7071: <script type="text/javascript">
1.109 raeburn 7072: // <![CDATA[
1.49 raeburn 7073: function reorderCats(form,parent,item,idx) {
7074: var changedVal;
7075: $jstext
7076: var newpos = 'addcategory_pos';
7077: if (parent == '') {
7078: var has_instcode = 0;
7079: var maxtop = categories[idx].length;
7080: for (var j=0; j<maxtop; j++) {
7081: if (categories[idx][j] == 'instcode::0') {
7082: has_instcode == 1;
7083: }
7084: }
7085: if (has_instcode == 0) {
7086: categories[idx][maxtop] = 'instcode_pos';
7087: }
7088: } else {
7089: newpos += '_'+parent;
7090: }
7091: var maxh = 1 + categories[idx].length;
7092: var current = new Array;
7093: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7094: if (item == newpos) {
7095: changedVal = newitemVal;
7096: } else {
7097: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
7098: current[newitemVal] = newpos;
7099: }
7100: for (var i=0; i<categories[idx].length; i++) {
7101: var elementName = categories[idx][i];
7102: if (elementName != item) {
7103: if (form.elements[elementName]) {
7104: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7105: current[currVal] = elementName;
7106: }
7107: }
7108: }
7109: var oldVal;
7110: for (var j=0; j<maxh; j++) {
7111: if (current[j] == undefined) {
7112: oldVal = j;
7113: }
7114: }
7115: if (oldVal < changedVal) {
7116: for (var k=oldVal+1; k<=changedVal ; k++) {
7117: var elementName = current[k];
7118: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7119: }
7120: } else {
7121: for (var k=changedVal; k<oldVal; k++) {
7122: var elementName = current[k];
7123: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7124: }
7125: }
7126: return;
7127: }
1.120 raeburn 7128:
7129: function categoryCheck(form) {
7130: if (form.elements['addcategory_name'].value == 'instcode') {
7131: alert('$instcode_reserved\\n$choose_again');
7132: return false;
7133: }
7134: if (form.elements['addcategory_name'].value == 'communities') {
7135: alert('$communities_reserved\\n$choose_again');
7136: return false;
7137: }
1.272 raeburn 7138: if (form.elements['addcategory_name'].value == 'placement') {
7139: alert('$placement_reserved\\n$choose_again');
7140: return false;
7141: }
1.120 raeburn 7142: return true;
7143: }
7144:
1.109 raeburn 7145: // ]]>
1.49 raeburn 7146: </script>
7147:
7148: ENDSCRIPT
7149: return $output;
7150: }
7151:
1.48 raeburn 7152: sub initialize_categories {
7153: my ($itemcount) = @_;
1.120 raeburn 7154: my ($datatable,$css_class,$chgstr);
7155: my %default_names = (
7156: instcode => 'Official courses (with institutional codes)',
7157: communities => 'Communities',
1.272 raeburn 7158: placement => 'Placement Tests',
1.120 raeburn 7159: );
7160: my $select0 = ' selected="selected"';
7161: my $select1 = '';
1.272 raeburn 7162: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 7163: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7164: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 7165: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 7166: $select1 = $select0;
7167: $select0 = '';
7168: }
7169: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7170: .'<select name="'.$default.'_pos">'
7171: .'<option value="0"'.$select0.'>1</option>'
7172: .'<option value="1"'.$select1.'>2</option>'
7173: .'<option value="2">3</option></select> '
7174: .$default_names{$default}
7175: .'</span></td><td><span class="LC_nobreak">'
7176: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
7177: .&mt('Display').'</label> <label>'
7178: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 7179: .'</label></span></td></tr>';
1.120 raeburn 7180: $itemcount ++;
7181: }
1.48 raeburn 7182: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 7183: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 7184: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 7185: .'<select name="addcategory_pos"'.$chgstr.'>'
7186: .'<option value="0">1</option>'
7187: .'<option value="1">2</option>'
7188: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 7189: .&mt('Add category').'</td><td>'.&mt('Name:')
7190: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
7191: return $datatable;
7192: }
7193:
7194: sub build_category_rows {
1.49 raeburn 7195: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
7196: my ($text,$name,$item,$chgstr);
1.48 raeburn 7197: if (ref($cats) eq 'ARRAY') {
7198: my $maxdepth = scalar(@{$cats});
7199: if (ref($cats->[$depth]) eq 'HASH') {
7200: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
7201: my $numchildren = @{$cats->[$depth]{$parent}};
7202: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 7203: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 7204: my ($idxnum,$parent_name,$parent_item);
7205: my $higher = $depth - 1;
7206: if ($higher == 0) {
7207: $parent_name = &escape($parent).'::'.$higher;
7208: } else {
7209: if (ref($path) eq 'ARRAY') {
7210: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7211: }
7212: }
7213: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 7214: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 7215: if ($j < $numchildren) {
1.48 raeburn 7216: $name = $cats->[$depth]{$parent}[$j];
7217: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 7218: $idxnum = $idx->{$item};
7219: } else {
7220: $name = $parent_name;
7221: $item = $parent_item;
1.48 raeburn 7222: }
1.49 raeburn 7223: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
7224: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 7225: for (my $i=0; $i<=$numchildren; $i++) {
7226: my $vpos = $i+1;
7227: my $selstr;
7228: if ($j == $i) {
7229: $selstr = ' selected="selected" ';
7230: }
7231: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
7232: }
7233: $text .= '</select> ';
7234: if ($j < $numchildren) {
7235: my $deeper = $depth+1;
7236: $text .= $name.' '
7237: .'<label><input type="checkbox" name="deletecategory" value="'
7238: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
7239: if(ref($path) eq 'ARRAY') {
7240: push(@{$path},$name);
1.49 raeburn 7241: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 7242: pop(@{$path});
7243: }
7244: } else {
1.59 bisitz 7245: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 7246: if ($j == $numchildren) {
7247: $text .= $name;
7248: } else {
7249: $text .= $item;
7250: }
7251: $text .= '" value="" />';
7252: }
7253: $text .= '</td></tr>';
7254: }
7255: $text .= '</table></td>';
7256: } else {
7257: my $higher = $depth-1;
7258: if ($higher == 0) {
7259: $name = &escape($parent).'::'.$higher;
7260: } else {
7261: if (ref($path) eq 'ARRAY') {
7262: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7263: }
7264: }
7265: my $colspan;
7266: if ($parent ne 'instcode') {
7267: $colspan = $maxdepth - $depth - 1;
7268: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
7269: }
7270: }
7271: }
7272: }
7273: return $text;
7274: }
7275:
1.33 raeburn 7276: sub modifiable_userdata_row {
1.228 raeburn 7277: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
7278: my ($role,$rolename,$statustype);
7279: $role = $item;
1.224 raeburn 7280: if ($context eq 'cancreate') {
1.228 raeburn 7281: if ($item =~ /^emailusername_(.+)$/) {
7282: $statustype = $1;
7283: $role = 'emailusername';
7284: if (ref($usertypes) eq 'HASH') {
7285: if ($usertypes->{$statustype}) {
7286: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7287: } else {
7288: $rolename = &mt('Data provided by user');
7289: }
7290: }
1.224 raeburn 7291: }
7292: } elsif ($context eq 'selfcreate') {
1.63 raeburn 7293: if (ref($usertypes) eq 'HASH') {
7294: $rolename = $usertypes->{$role};
7295: } else {
7296: $rolename = $role;
7297: }
1.33 raeburn 7298: } else {
1.63 raeburn 7299: if ($role eq 'cr') {
7300: $rolename = &mt('Custom role');
7301: } else {
7302: $rolename = &Apache::lonnet::plaintext($role);
7303: }
1.33 raeburn 7304: }
1.224 raeburn 7305: my (@fields,%fieldtitles);
7306: if (ref($fieldsref) eq 'ARRAY') {
7307: @fields = @{$fieldsref};
7308: } else {
7309: @fields = ('lastname','firstname','middlename','generation',
7310: 'permanentemail','id');
7311: }
7312: if ((ref($titlesref) eq 'HASH')) {
7313: %fieldtitles = %{$titlesref};
7314: } else {
7315: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7316: }
1.33 raeburn 7317: my $output;
7318: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7319: $output = '<tr '.$css_class.'>'.
7320: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7321: '<td class="LC_left_item" colspan="2"><table>';
7322: my $rem;
7323: my %checks;
7324: if (ref($settings) eq 'HASH') {
7325: if (ref($settings->{$context}) eq 'HASH') {
7326: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 7327: my $hashref = $settings->{$context}->{$role};
7328: if ($role eq 'emailusername') {
7329: if ($statustype) {
7330: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7331: $hashref = $settings->{$context}->{$role}->{$statustype};
7332: if (ref($hashref) eq 'HASH') {
7333: foreach my $field (@fields) {
7334: if ($hashref->{$field}) {
7335: $checks{$field} = $hashref->{$field};
7336: }
7337: }
7338: }
7339: }
7340: }
7341: } else {
7342: if (ref($hashref) eq 'HASH') {
7343: foreach my $field (@fields) {
7344: if ($hashref->{$field}) {
7345: $checks{$field} = ' checked="checked" ';
7346: }
7347: }
1.33 raeburn 7348: }
7349: }
7350: }
7351: }
7352: }
1.228 raeburn 7353:
1.33 raeburn 7354: for (my $i=0; $i<@fields; $i++) {
7355: my $rem = $i%($numinrow);
7356: if ($rem == 0) {
7357: if ($i > 0) {
7358: $output .= '</tr>';
7359: }
7360: $output .= '<tr>';
7361: }
7362: my $check = ' ';
1.228 raeburn 7363: unless ($role eq 'emailusername') {
7364: if (exists($checks{$fields[$i]})) {
7365: $check = $checks{$fields[$i]}
7366: } else {
7367: if ($role eq 'st') {
7368: if (ref($settings) ne 'HASH') {
7369: $check = ' checked="checked" ';
7370: }
1.33 raeburn 7371: }
7372: }
7373: }
7374: $output .= '<td class="LC_left_item">'.
1.228 raeburn 7375: '<span class="LC_nobreak">';
7376: if ($role eq 'emailusername') {
7377: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7378: $checks{$fields[$i]} = 'omit';
7379: }
7380: foreach my $option ('required','optional','omit') {
7381: my $checked='';
7382: if ($checks{$fields[$i]} eq $option) {
7383: $checked='checked="checked" ';
7384: }
7385: $output .= '<label>'.
7386: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7387: &mt($option).'</label>'.(' ' x2);
7388: }
7389: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7390: } else {
7391: $output .= '<label>'.
7392: '<input type="checkbox" name="canmodify_'.$role.'" '.
7393: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7394: '</label>';
7395: }
7396: $output .= '</span></td>';
1.33 raeburn 7397: $rem = @fields%($numinrow);
7398: }
7399: my $colsleft = $numinrow - $rem;
7400: if ($colsleft > 1 ) {
7401: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7402: ' </td>';
7403: } elsif ($colsleft == 1) {
7404: $output .= '<td class="LC_left_item"> </td>';
7405: }
7406: $output .= '</tr></table></td></tr>';
7407: return $output;
7408: }
1.28 raeburn 7409:
1.93 raeburn 7410: sub insttypes_row {
1.224 raeburn 7411: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 7412: my %lt = &Apache::lonlocal::texthash (
7413: cansearch => 'Users allowed to search',
7414: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 7415: lockablenames => 'User preference to lock name',
1.93 raeburn 7416: );
7417: my $showdom;
7418: if ($context eq 'cansearch') {
7419: $showdom = ' ('.$dom.')';
7420: }
1.165 raeburn 7421: my $class = 'LC_left_item';
7422: if ($context eq 'statustocreate') {
7423: $class = 'LC_right_item';
7424: }
1.224 raeburn 7425: my $css_class = ' class="LC_odd_row"';
7426: if ($rownum ne '') {
7427: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
7428: }
7429: my $output = '<tr'.$css_class.'>'.
7430: '<td>'.$lt{$context}.$showdom.
7431: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7432: my $rem;
7433: if (ref($types) eq 'ARRAY') {
7434: for (my $i=0; $i<@{$types}; $i++) {
7435: if (defined($usertypes->{$types->[$i]})) {
7436: my $rem = $i%($numinrow);
7437: if ($rem == 0) {
7438: if ($i > 0) {
7439: $output .= '</tr>';
7440: }
7441: $output .= '<tr>';
1.23 raeburn 7442: }
1.26 raeburn 7443: my $check = ' ';
1.99 raeburn 7444: if (ref($settings) eq 'HASH') {
7445: if (ref($settings->{$context}) eq 'ARRAY') {
7446: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7447: $check = ' checked="checked" ';
7448: }
7449: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7450: $check = ' checked="checked" ';
7451: }
1.23 raeburn 7452: }
1.26 raeburn 7453: $output .= '<td class="LC_left_item">'.
7454: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7455: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 7456: 'value="'.$types->[$i].'"'.$check.'/>'.
7457: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7458: }
7459: }
1.26 raeburn 7460: $rem = @{$types}%($numinrow);
1.23 raeburn 7461: }
7462: my $colsleft = $numinrow - $rem;
1.131 raeburn 7463: if (($rem == 0) && (@{$types} > 0)) {
7464: $output .= '<tr>';
7465: }
1.23 raeburn 7466: if ($colsleft > 1) {
1.25 raeburn 7467: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 7468: } else {
1.25 raeburn 7469: $output .= '<td class="LC_left_item">';
1.23 raeburn 7470: }
7471: my $defcheck = ' ';
1.99 raeburn 7472: if (ref($settings) eq 'HASH') {
7473: if (ref($settings->{$context}) eq 'ARRAY') {
7474: if (grep(/^default$/,@{$settings->{$context}})) {
7475: $defcheck = ' checked="checked" ';
7476: }
7477: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7478: $defcheck = ' checked="checked" ';
7479: }
1.23 raeburn 7480: }
1.25 raeburn 7481: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 7482: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 7483: 'value="default"'.$defcheck.'/>'.
7484: $othertitle.'</label></span></td>'.
7485: '</tr></table></td></tr>';
7486: return $output;
1.23 raeburn 7487: }
7488:
7489: sub sorted_searchtitles {
7490: my %searchtitles = &Apache::lonlocal::texthash(
7491: 'uname' => 'username',
7492: 'lastname' => 'last name',
7493: 'lastfirst' => 'last name, first name',
7494: );
7495: my @titleorder = ('uname','lastname','lastfirst');
7496: return (\%searchtitles,\@titleorder);
7497: }
7498:
1.25 raeburn 7499: sub sorted_searchtypes {
7500: my %srchtypes_desc = (
7501: exact => 'is exact match',
7502: contains => 'contains ..',
7503: begins => 'begins with ..',
7504: );
7505: my @srchtypeorder = ('exact','begins','contains');
7506: return (\%srchtypes_desc,\@srchtypeorder);
7507: }
7508:
1.3 raeburn 7509: sub usertype_update_row {
7510: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7511: my $datatable;
7512: my $numinrow = 4;
7513: foreach my $type (@{$types}) {
7514: if (defined($usertypes->{$type})) {
7515: $$rownums ++;
7516: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7517: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7518: '</td><td class="LC_left_item"><table>';
7519: for (my $i=0; $i<@{$fields}; $i++) {
7520: my $rem = $i%($numinrow);
7521: if ($rem == 0) {
7522: if ($i > 0) {
7523: $datatable .= '</tr>';
7524: }
7525: $datatable .= '<tr>';
7526: }
7527: my $check = ' ';
1.39 raeburn 7528: if (ref($settings) eq 'HASH') {
7529: if (ref($settings->{'fields'}) eq 'HASH') {
7530: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7531: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7532: $check = ' checked="checked" ';
7533: }
1.3 raeburn 7534: }
7535: }
7536: }
7537:
7538: if ($i == @{$fields}-1) {
7539: my $colsleft = $numinrow - $rem;
7540: if ($colsleft > 1) {
7541: $datatable .= '<td colspan="'.$colsleft.'">';
7542: } else {
7543: $datatable .= '<td>';
7544: }
7545: } else {
7546: $datatable .= '<td>';
7547: }
1.8 raeburn 7548: $datatable .= '<span class="LC_nobreak"><label>'.
7549: '<input type="checkbox" name="updateable_'.$type.
7550: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7551: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 7552: }
7553: $datatable .= '</tr></table></td></tr>';
7554: }
7555: }
7556: return $datatable;
1.1 raeburn 7557: }
7558:
7559: sub modify_login {
1.205 raeburn 7560: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 7561: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7562: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7563: %title = ( coursecatalog => 'Display course catalog',
7564: adminmail => 'Display administrator E-mail address',
1.188 raeburn 7565: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 7566: newuser => 'Link for visitors to create a user account',
7567: loginheader => 'Log-in box header');
7568: @offon = ('off','on');
1.112 raeburn 7569: if (ref($domconfig{login}) eq 'HASH') {
7570: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7571: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7572: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7573: }
7574: }
7575: }
1.9 raeburn 7576: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7577: \%domconfig,\%loginhash);
1.188 raeburn 7578: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7579: foreach my $item (@toggles) {
7580: $loginhash{login}{$item} = $env{'form.'.$item};
7581: }
1.41 raeburn 7582: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 7583: if (ref($colchanges{'login'}) eq 'HASH') {
7584: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7585: \%loginhash);
7586: }
1.110 raeburn 7587:
1.149 raeburn 7588: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 7589: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 7590: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 7591: if (keys(%servers) > 1) {
7592: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 7593: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7594: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7595: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7596: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7597: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7598: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7599: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7600: $changes{'loginvia'}{$lonhost} = 1;
7601: } else {
7602: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7603: $changes{'loginvia'}{$lonhost} = 1;
7604: }
7605: } else {
7606: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7607: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7608: $changes{'loginvia'}{$lonhost} = 1;
7609: }
7610: }
7611: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7612: foreach my $item (@loginvia_attribs) {
7613: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7614: }
7615: } else {
7616: foreach my $item (@loginvia_attribs) {
7617: my $new = $env{'form.'.$lonhost.'_'.$item};
7618: if (($item eq 'serverpath') && ($new eq 'custom')) {
7619: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7620: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7621: $new = '/';
7622: }
7623: }
7624: if (($item eq 'custompath') &&
7625: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7626: $new = '';
7627: }
7628: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7629: $changes{'loginvia'}{$lonhost} = 1;
7630: }
7631: if ($item eq 'exempt') {
1.256 raeburn 7632: $new = &check_exempt_addresses($new);
1.128 raeburn 7633: }
7634: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7635: }
7636: }
1.112 raeburn 7637: } else {
1.128 raeburn 7638: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7639: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 7640: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 7641: foreach my $item (@loginvia_attribs) {
7642: my $new = $env{'form.'.$lonhost.'_'.$item};
7643: if (($item eq 'serverpath') && ($new eq 'custom')) {
7644: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7645: $new = '/';
7646: }
7647: }
7648: if (($item eq 'custompath') &&
7649: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7650: $new = '';
7651: }
7652: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7653: }
1.110 raeburn 7654: }
7655: }
7656: }
7657: }
1.119 raeburn 7658:
1.168 raeburn 7659: my $servadm = $r->dir_config('lonAdmEMail');
7660: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
7661: if (ref($domconfig{'login'}) eq 'HASH') {
7662: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
7663: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
7664: if ($lang eq 'nolang') {
7665: push(@currlangs,$lang);
7666: } elsif (defined($langchoices{$lang})) {
7667: push(@currlangs,$lang);
7668: } else {
7669: next;
7670: }
7671: }
7672: }
7673: }
7674: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
7675: if (@currlangs > 0) {
7676: foreach my $lang (@currlangs) {
7677: if (grep(/^\Q$lang\E$/,@delurls)) {
7678: $changes{'helpurl'}{$lang} = 1;
7679: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
7680: $changes{'helpurl'}{$lang} = 1;
7681: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
7682: push(@newlangs,$lang);
7683: } else {
7684: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7685: }
7686: }
7687: }
7688: unless (grep(/^nolang$/,@currlangs)) {
7689: if ($env{'form.loginhelpurl_nolang.filename'}) {
7690: $changes{'helpurl'}{'nolang'} = 1;
7691: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
7692: push(@newlangs,'nolang');
7693: }
7694: }
7695: if ($env{'form.loginhelpurl_add_lang'}) {
7696: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
7697: ($env{'form.loginhelpurl_add_file.filename'})) {
7698: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
7699: $addedfile = $env{'form.loginhelpurl_add_lang'};
7700: }
7701: }
7702: if ((@newlangs > 0) || ($addedfile)) {
7703: my $error;
7704: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7705: if ($configuserok eq 'ok') {
7706: if ($switchserver) {
7707: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7708: } elsif ($author_ok eq 'ok') {
7709: my @allnew = @newlangs;
7710: if ($addedfile ne '') {
7711: push(@allnew,$addedfile);
7712: }
7713: foreach my $lang (@allnew) {
7714: my $formelem = 'loginhelpurl_'.$lang;
7715: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
7716: $formelem = 'loginhelpurl_add_file';
7717: }
7718: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7719: "help/$lang",'','',$newfile{$lang});
7720: if ($result eq 'ok') {
7721: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
7722: $changes{'helpurl'}{$lang} = 1;
7723: } else {
7724: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
7725: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 7726: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 7727: (!grep(/^\Q$lang\E$/,@delurls))) {
7728: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7729: }
7730: }
7731: }
7732: } else {
7733: $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);
7734: }
7735: } else {
7736: $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);
7737: }
7738: if ($error) {
7739: &Apache::lonnet::logthis($error);
7740: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7741: }
7742: }
1.256 raeburn 7743:
7744: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
7745: if (ref($domconfig{'login'}) eq 'HASH') {
7746: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
7747: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
7748: if ($domservers{$lonhost}) {
7749: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7750: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 7751: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 7752: }
7753: }
7754: }
7755: }
7756: }
7757: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
7758: foreach my $lonhost (sort(keys(%domservers))) {
7759: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7760: $changes{'headtag'}{$lonhost} = 1;
7761: } else {
7762: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
7763: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
7764: }
7765: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
7766: push(@newhosts,$lonhost);
7767: } elsif ($currheadtagurls{$lonhost}) {
7768: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
7769: if ($currexempt{$lonhost}) {
1.289 raeburn 7770: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 7771: $changes{'headtag'}{$lonhost} = 1;
7772: }
7773: } elsif ($possexempt{$lonhost}) {
7774: $changes{'headtag'}{$lonhost} = 1;
7775: }
7776: if ($possexempt{$lonhost}) {
7777: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7778: }
7779: }
7780: }
7781: }
7782: if (@newhosts) {
7783: my $error;
7784: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7785: if ($configuserok eq 'ok') {
7786: if ($switchserver) {
7787: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
7788: } elsif ($author_ok eq 'ok') {
7789: foreach my $lonhost (@newhosts) {
7790: my $formelem = 'loginheadtag_'.$lonhost;
7791: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7792: "login/headtag/$lonhost",'','',
7793: $env{'form.loginheadtag_'.$lonhost.'.filename'});
7794: if ($result eq 'ok') {
7795: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
7796: $changes{'headtag'}{$lonhost} = 1;
7797: if ($possexempt{$lonhost}) {
7798: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7799: }
7800: } else {
7801: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7802: $newheadtagurls{$lonhost},$result);
7803: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7804: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7805: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7806: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7807: }
7808: }
7809: }
7810: } else {
7811: $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);
7812: }
7813: } else {
7814: $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);
7815: }
7816: if ($error) {
7817: &Apache::lonnet::logthis($error);
7818: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7819: }
7820: }
1.169 raeburn 7821: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 7822:
7823: my $defaulthelpfile = '/adm/loginproblems.html';
7824: my $defaulttext = &mt('Default in use');
7825:
1.1 raeburn 7826: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7827: $dom);
7828: if ($putresult eq 'ok') {
1.188 raeburn 7829: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7830: my %defaultchecked = (
7831: 'coursecatalog' => 'on',
1.188 raeburn 7832: 'helpdesk' => 'on',
1.42 raeburn 7833: 'adminmail' => 'off',
1.43 raeburn 7834: 'newuser' => 'off',
1.42 raeburn 7835: );
1.55 raeburn 7836: if (ref($domconfig{'login'}) eq 'HASH') {
7837: foreach my $item (@toggles) {
7838: if ($defaultchecked{$item} eq 'on') {
7839: if (($domconfig{'login'}{$item} eq '0') &&
7840: ($env{'form.'.$item} eq '1')) {
7841: $changes{$item} = 1;
7842: } elsif (($domconfig{'login'}{$item} eq '' ||
7843: $domconfig{'login'}{$item} eq '1') &&
7844: ($env{'form.'.$item} eq '0')) {
7845: $changes{$item} = 1;
7846: }
7847: } elsif ($defaultchecked{$item} eq 'off') {
7848: if (($domconfig{'login'}{$item} eq '1') &&
7849: ($env{'form.'.$item} eq '0')) {
7850: $changes{$item} = 1;
7851: } elsif (($domconfig{'login'}{$item} eq '' ||
7852: $domconfig{'login'}{$item} eq '0') &&
7853: ($env{'form.'.$item} eq '1')) {
7854: $changes{$item} = 1;
7855: }
1.42 raeburn 7856: }
7857: }
1.41 raeburn 7858: }
1.6 raeburn 7859: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7860: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7861: if (ref($lastactref) eq 'HASH') {
7862: $lastactref->{'domainconfig'} = 1;
7863: }
1.1 raeburn 7864: $resulttext = &mt('Changes made:').'<ul>';
7865: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7866: if ($item eq 'loginvia') {
1.112 raeburn 7867: if (ref($changes{$item}) eq 'HASH') {
7868: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7869: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7870: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7871: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7872: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7873: $protocol = 'http' if ($protocol ne 'https');
7874: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7875:
7876: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7877: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7878: } else {
7879: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7880: }
7881: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7882: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7883: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7884: }
7885: $resulttext .= '</li>';
7886: } else {
7887: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7888: }
1.112 raeburn 7889: } else {
1.128 raeburn 7890: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7891: }
7892: }
1.128 raeburn 7893: $resulttext .= '</ul></li>';
1.112 raeburn 7894: }
1.168 raeburn 7895: } elsif ($item eq 'helpurl') {
7896: if (ref($changes{$item}) eq 'HASH') {
7897: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7898: if (grep(/^\Q$lang\E$/,@delurls)) {
7899: my ($chg,$link);
7900: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7901: if ($lang eq 'nolang') {
7902: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7903: } else {
7904: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7905: }
7906: $resulttext .= '<li>'.$chg.'</li>';
7907: } else {
7908: my $chg;
7909: if ($lang eq 'nolang') {
7910: $chg = &mt('custom log-in help file for no preferred language');
7911: } else {
7912: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7913: }
7914: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7915: $loginhash{'login'}{'helpurl'}{$lang}.
7916: '?inhibitmenu=yes',$chg,600,500).
7917: '</li>';
7918: }
7919: }
7920: }
1.256 raeburn 7921: } elsif ($item eq 'headtag') {
7922: if (ref($changes{$item}) eq 'HASH') {
7923: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7924: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7925: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7926: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7927: $resulttext .= '<li><a href="'.
7928: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7929: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7930: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7931: if ($possexempt{$lonhost}) {
7932: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7933: } else {
7934: $resulttext .= &mt('included for any client IP');
7935: }
7936: $resulttext .= '</li>';
7937: }
7938: }
7939: }
1.169 raeburn 7940: } elsif ($item eq 'captcha') {
7941: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 7942: my $chgtxt;
1.169 raeburn 7943: if ($loginhash{'login'}{$item} eq 'notused') {
7944: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7945: } else {
7946: my %captchas = &captcha_phrases();
7947: if ($captchas{$loginhash{'login'}{$item}}) {
7948: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7949: } else {
7950: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7951: }
7952: }
7953: $resulttext .= '<li>'.$chgtxt.'</li>';
7954: }
7955: } elsif ($item eq 'recaptchakeys') {
7956: if (ref($loginhash{'login'}) eq 'HASH') {
7957: my ($privkey,$pubkey);
7958: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7959: $pubkey = $loginhash{'login'}{$item}{'public'};
7960: $privkey = $loginhash{'login'}{$item}{'private'};
7961: }
7962: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7963: if (!$pubkey) {
7964: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7965: } else {
7966: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7967: }
7968: if (!$privkey) {
7969: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7970: } else {
1.251 raeburn 7971: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 7972: }
7973: $chgtxt .= '</ul>';
7974: $resulttext .= '<li>'.$chgtxt.'</li>';
7975: }
1.269 raeburn 7976: } elsif ($item eq 'recaptchaversion') {
7977: if (ref($loginhash{'login'}) eq 'HASH') {
7978: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 7979: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 7980: '</li>';
7981: }
7982: }
1.41 raeburn 7983: } else {
7984: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7985: }
1.1 raeburn 7986: }
1.6 raeburn 7987: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7988: } else {
7989: $resulttext = &mt('No changes made to log-in page settings');
7990: }
7991: } else {
1.11 albertel 7992: $resulttext = '<span class="LC_error">'.
7993: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7994: }
1.6 raeburn 7995: if ($errors) {
1.9 raeburn 7996: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7997: $errors.'</ul>';
7998: }
7999: return $resulttext;
8000: }
8001:
1.256 raeburn 8002: sub check_exempt_addresses {
8003: my ($iplist) = @_;
8004: $iplist =~ s/^\s+//;
8005: $iplist =~ s/\s+$//;
8006: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
8007: my (@okips,$new);
8008: foreach my $ip (@poss_ips) {
8009: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
8010: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
8011: push(@okips,$ip);
8012: }
8013: }
8014: }
8015: if (@okips > 0) {
8016: $new = join(',',@okips);
8017: } else {
8018: $new = '';
8019: }
8020: return $new;
8021: }
8022:
1.6 raeburn 8023: sub color_font_choices {
8024: my %choices =
8025: &Apache::lonlocal::texthash (
8026: img => "Header",
8027: bgs => "Background colors",
8028: links => "Link colors",
1.55 raeburn 8029: images => "Images",
1.6 raeburn 8030: font => "Font color",
1.201 raeburn 8031: fontmenu => "Font menu",
1.76 raeburn 8032: pgbg => "Page",
1.6 raeburn 8033: tabbg => "Header",
8034: sidebg => "Border",
8035: link => "Link",
8036: alink => "Active link",
8037: vlink => "Visited link",
8038: );
8039: return %choices;
8040: }
8041:
8042: sub modify_rolecolors {
1.205 raeburn 8043: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 8044: my ($resulttext,%rolehash);
8045: $rolehash{'rolecolors'} = {};
1.55 raeburn 8046: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
8047: if ($domconfig{'rolecolors'} eq '') {
8048: $domconfig{'rolecolors'} = {};
8049: }
8050: }
1.9 raeburn 8051: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 8052: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
8053: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
8054: $dom);
8055: if ($putresult eq 'ok') {
8056: if (keys(%changes) > 0) {
1.41 raeburn 8057: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8058: if (ref($lastactref) eq 'HASH') {
8059: $lastactref->{'domainconfig'} = 1;
8060: }
1.6 raeburn 8061: $resulttext = &display_colorchgs($dom,\%changes,$roles,
8062: $rolehash{'rolecolors'});
8063: } else {
8064: $resulttext = &mt('No changes made to default color schemes');
8065: }
8066: } else {
1.11 albertel 8067: $resulttext = '<span class="LC_error">'.
8068: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 8069: }
8070: if ($errors) {
8071: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8072: $errors.'</ul>';
8073: }
8074: return $resulttext;
8075: }
8076:
8077: sub modify_colors {
1.9 raeburn 8078: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 8079: my (%changes,%choices);
1.51 raeburn 8080: my @bgs;
1.6 raeburn 8081: my @links = ('link','alink','vlink');
1.41 raeburn 8082: my @logintext;
1.6 raeburn 8083: my @images;
8084: my $servadm = $r->dir_config('lonAdmEMail');
8085: my $errors;
1.200 raeburn 8086: my %defaults;
1.6 raeburn 8087: foreach my $role (@{$roles}) {
8088: if ($role eq 'login') {
1.12 raeburn 8089: %choices = &login_choices();
1.41 raeburn 8090: @logintext = ('textcol','bgcol');
1.12 raeburn 8091: } else {
8092: %choices = &color_font_choices();
8093: }
8094: if ($role eq 'login') {
1.41 raeburn 8095: @images = ('img','logo','domlogo','login');
1.51 raeburn 8096: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 8097: } else {
8098: @images = ('img');
1.200 raeburn 8099: @bgs = ('pgbg','tabbg','sidebg');
8100: }
8101: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
8102: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
8103: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
8104: }
8105: if ($role eq 'login') {
8106: foreach my $item (@logintext) {
1.234 raeburn 8107: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8108: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8109: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8110: }
8111: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 8112: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8113: }
8114: }
8115: } else {
1.234 raeburn 8116: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
8117: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
8118: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
8119: }
8120: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 8121: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
8122: }
1.6 raeburn 8123: }
1.200 raeburn 8124: foreach my $item (@bgs) {
1.234 raeburn 8125: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8126: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8127: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8128: }
8129: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 8130: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8131: }
8132: }
8133: foreach my $item (@links) {
1.234 raeburn 8134: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8135: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8136: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8137: }
8138: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 8139: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8140: }
1.6 raeburn 8141: }
1.46 raeburn 8142: my ($configuserok,$author_ok,$switchserver) =
8143: &config_check($dom,$confname,$servadm);
1.9 raeburn 8144: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 8145: if (ref($domconfig->{$role}) ne 'HASH') {
8146: $domconfig->{$role} = {};
8147: }
1.8 raeburn 8148: foreach my $img (@images) {
1.70 raeburn 8149: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
8150: if (defined($env{'form.login_showlogo_'.$img})) {
8151: $confhash->{$role}{'showlogo'}{$img} = 1;
8152: } else {
8153: $confhash->{$role}{'showlogo'}{$img} = 0;
8154: }
8155: }
1.18 albertel 8156: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
8157: && !defined($domconfig->{$role}{$img})
8158: && !$env{'form.'.$role.'_del_'.$img}
8159: && $env{'form.'.$role.'_import_'.$img}) {
8160: # import the old configured image from the .tab setting
8161: # if they haven't provided a new one
8162: $domconfig->{$role}{$img} =
8163: $env{'form.'.$role.'_import_'.$img};
8164: }
1.6 raeburn 8165: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 8166: my $error;
1.6 raeburn 8167: if ($configuserok eq 'ok') {
1.9 raeburn 8168: if ($switchserver) {
1.12 raeburn 8169: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 8170: } else {
8171: if ($author_ok eq 'ok') {
8172: my ($result,$logourl) =
8173: &publishlogo($r,'upload',$role.'_'.$img,
8174: $dom,$confname,$img,$width,$height);
8175: if ($result eq 'ok') {
8176: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 8177: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8178: } else {
1.12 raeburn 8179: $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 8180: }
8181: } else {
1.46 raeburn 8182: $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 8183: }
8184: }
8185: } else {
1.46 raeburn 8186: $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 8187: }
8188: if ($error) {
1.8 raeburn 8189: &Apache::lonnet::logthis($error);
1.11 albertel 8190: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 8191: }
8192: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 8193: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
8194: my $error;
8195: if ($configuserok eq 'ok') {
8196: # is confname an author?
8197: if ($switchserver eq '') {
8198: if ($author_ok eq 'ok') {
8199: my ($result,$logourl) =
8200: &publishlogo($r,'copy',$domconfig->{$role}{$img},
8201: $dom,$confname,$img,$width,$height);
8202: if ($result eq 'ok') {
8203: $confhash->{$role}{$img} = $logourl;
1.18 albertel 8204: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8205: }
8206: }
8207: }
8208: }
1.6 raeburn 8209: }
8210: }
8211: }
8212: if (ref($domconfig) eq 'HASH') {
8213: if (ref($domconfig->{$role}) eq 'HASH') {
8214: foreach my $img (@images) {
8215: if ($domconfig->{$role}{$img} ne '') {
8216: if ($env{'form.'.$role.'_del_'.$img}) {
8217: $confhash->{$role}{$img} = '';
1.12 raeburn 8218: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8219: } else {
1.9 raeburn 8220: if ($confhash->{$role}{$img} eq '') {
8221: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8222: }
1.6 raeburn 8223: }
8224: } else {
8225: if ($env{'form.'.$role.'_del_'.$img}) {
8226: $confhash->{$role}{$img} = '';
1.12 raeburn 8227: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8228: }
8229: }
1.70 raeburn 8230: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8231: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8232: if ($confhash->{$role}{'showlogo'}{$img} ne
8233: $domconfig->{$role}{'showlogo'}{$img}) {
8234: $changes{$role}{'showlogo'}{$img} = 1;
8235: }
8236: } else {
8237: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8238: $changes{$role}{'showlogo'}{$img} = 1;
8239: }
8240: }
8241: }
8242: }
1.6 raeburn 8243: if ($domconfig->{$role}{'font'} ne '') {
8244: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8245: $changes{$role}{'font'} = 1;
8246: }
8247: } else {
8248: if ($confhash->{$role}{'font'}) {
8249: $changes{$role}{'font'} = 1;
8250: }
8251: }
1.107 raeburn 8252: if ($role ne 'login') {
8253: if ($domconfig->{$role}{'fontmenu'} ne '') {
8254: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8255: $changes{$role}{'fontmenu'} = 1;
8256: }
8257: } else {
8258: if ($confhash->{$role}{'fontmenu'}) {
8259: $changes{$role}{'fontmenu'} = 1;
8260: }
1.97 tempelho 8261: }
8262: }
1.6 raeburn 8263: foreach my $item (@bgs) {
8264: if ($domconfig->{$role}{$item} ne '') {
8265: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8266: $changes{$role}{'bgs'}{$item} = 1;
8267: }
8268: } else {
8269: if ($confhash->{$role}{$item}) {
8270: $changes{$role}{'bgs'}{$item} = 1;
8271: }
8272: }
8273: }
8274: foreach my $item (@links) {
8275: if ($domconfig->{$role}{$item} ne '') {
8276: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8277: $changes{$role}{'links'}{$item} = 1;
8278: }
8279: } else {
8280: if ($confhash->{$role}{$item}) {
8281: $changes{$role}{'links'}{$item} = 1;
8282: }
8283: }
8284: }
1.41 raeburn 8285: foreach my $item (@logintext) {
8286: if ($domconfig->{$role}{$item} ne '') {
8287: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8288: $changes{$role}{'logintext'}{$item} = 1;
8289: }
8290: } else {
8291: if ($confhash->{$role}{$item}) {
8292: $changes{$role}{'logintext'}{$item} = 1;
8293: }
8294: }
8295: }
1.6 raeburn 8296: } else {
8297: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8298: \@logintext,$confhash,\%changes);
1.6 raeburn 8299: }
8300: } else {
8301: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8302: \@logintext,$confhash,\%changes);
1.6 raeburn 8303: }
8304: }
8305: return ($errors,%changes);
8306: }
8307:
1.46 raeburn 8308: sub config_check {
8309: my ($dom,$confname,$servadm) = @_;
8310: my ($configuserok,$author_ok,$switchserver,%currroles);
8311: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8312: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8313: $confname,$servadm);
8314: if ($configuserok eq 'ok') {
8315: $switchserver = &check_switchserver($dom,$confname);
8316: if ($switchserver eq '') {
8317: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8318: }
8319: }
8320: return ($configuserok,$author_ok,$switchserver);
8321: }
8322:
1.6 raeburn 8323: sub default_change_checker {
1.41 raeburn 8324: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8325: foreach my $item (@{$links}) {
8326: if ($confhash->{$role}{$item}) {
8327: $changes->{$role}{'links'}{$item} = 1;
8328: }
8329: }
8330: foreach my $item (@{$bgs}) {
8331: if ($confhash->{$role}{$item}) {
8332: $changes->{$role}{'bgs'}{$item} = 1;
8333: }
8334: }
1.41 raeburn 8335: foreach my $item (@{$logintext}) {
8336: if ($confhash->{$role}{$item}) {
8337: $changes->{$role}{'logintext'}{$item} = 1;
8338: }
8339: }
1.6 raeburn 8340: foreach my $img (@{$images}) {
8341: if ($env{'form.'.$role.'_del_'.$img}) {
8342: $confhash->{$role}{$img} = '';
1.12 raeburn 8343: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8344: }
1.70 raeburn 8345: if ($role eq 'login') {
8346: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8347: $changes->{$role}{'showlogo'}{$img} = 1;
8348: }
8349: }
1.6 raeburn 8350: }
8351: if ($confhash->{$role}{'font'}) {
8352: $changes->{$role}{'font'} = 1;
8353: }
1.48 raeburn 8354: }
1.6 raeburn 8355:
8356: sub display_colorchgs {
8357: my ($dom,$changes,$roles,$confhash) = @_;
8358: my (%choices,$resulttext);
8359: if (!grep(/^login$/,@{$roles})) {
8360: $resulttext = &mt('Changes made:').'<br />';
8361: }
8362: foreach my $role (@{$roles}) {
8363: if ($role eq 'login') {
8364: %choices = &login_choices();
8365: } else {
8366: %choices = &color_font_choices();
8367: }
8368: if (ref($changes->{$role}) eq 'HASH') {
8369: if ($role ne 'login') {
8370: $resulttext .= '<h4>'.&mt($role).'</h4>';
8371: }
8372: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8373: if ($role ne 'login') {
8374: $resulttext .= '<ul>';
8375: }
8376: if (ref($changes->{$role}{$key}) eq 'HASH') {
8377: if ($role ne 'login') {
8378: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8379: }
8380: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8381: if (($role eq 'login') && ($key eq 'showlogo')) {
8382: if ($confhash->{$role}{$key}{$item}) {
8383: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8384: } else {
8385: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8386: }
8387: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8388: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8389: } else {
1.12 raeburn 8390: my $newitem = $confhash->{$role}{$item};
8391: if ($key eq 'images') {
8392: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
8393: }
8394: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8395: }
8396: }
8397: if ($role ne 'login') {
8398: $resulttext .= '</ul></li>';
8399: }
8400: } else {
8401: if ($confhash->{$role}{$key} eq '') {
8402: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8403: } else {
8404: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8405: }
8406: }
8407: if ($role ne 'login') {
8408: $resulttext .= '</ul>';
8409: }
8410: }
8411: }
8412: }
1.3 raeburn 8413: return $resulttext;
1.1 raeburn 8414: }
8415:
1.9 raeburn 8416: sub thumb_dimensions {
8417: return ('200','50');
8418: }
8419:
1.16 raeburn 8420: sub check_dimensions {
8421: my ($inputfile) = @_;
8422: my ($fullwidth,$fullheight);
8423: if ($inputfile =~ m|^[/\w.\-]+$|) {
8424: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8425: my $imageinfo = <PIPE>;
8426: if (!close(PIPE)) {
8427: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8428: }
8429: chomp($imageinfo);
8430: my ($fullsize) =
1.21 raeburn 8431: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8432: if ($fullsize) {
8433: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8434: }
8435: }
8436: }
8437: return ($fullwidth,$fullheight);
8438: }
8439:
1.9 raeburn 8440: sub check_configuser {
8441: my ($uhome,$dom,$confname,$servadm) = @_;
8442: my ($configuserok,%currroles);
8443: if ($uhome eq 'no_host') {
8444: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
8445: my $configpass = &LONCAPA::Enrollment::create_password();
8446: $configuserok =
8447: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8448: $configpass,'','','','','',undef,$servadm);
8449: } else {
8450: $configuserok = 'ok';
8451: %currroles =
8452: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8453: }
8454: return ($configuserok,%currroles);
8455: }
8456:
8457: sub check_authorstatus {
8458: my ($dom,$confname,%currroles) = @_;
8459: my $author_ok;
1.40 raeburn 8460: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8461: my $start = time;
8462: my $end = 0;
8463: $author_ok =
8464: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8465: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8466: } else {
8467: $author_ok = 'ok';
8468: }
8469: return $author_ok;
8470: }
8471:
8472: sub publishlogo {
1.46 raeburn 8473: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 8474: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 8475: if ($action eq 'upload') {
8476: $fname=$env{'form.'.$formname.'.filename'};
8477: chop($env{'form.'.$formname});
8478: } else {
8479: ($fname) = ($formname =~ /([^\/]+)$/);
8480: }
1.46 raeburn 8481: if ($savefileas ne '') {
8482: $fname = $savefileas;
8483: }
1.9 raeburn 8484: $fname=&Apache::lonnet::clean_filename($fname);
8485: # See if there is anything left
8486: unless ($fname) { return ('error: no uploaded file'); }
8487: $fname="$subdir/$fname";
1.210 raeburn 8488: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 8489: my $filepath="$docroot/priv";
8490: my $relpath = "$dom/$confname";
1.9 raeburn 8491: my ($fnamepath,$file,$fetchthumb);
8492: $file=$fname;
8493: if ($fname=~m|/|) {
8494: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8495: }
1.164 raeburn 8496: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8497: my $count;
1.164 raeburn 8498: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8499: $filepath.="/$parts[$count]";
8500: if ((-e $filepath)!=1) {
8501: mkdir($filepath,02770);
8502: }
8503: }
8504: # Check for bad extension and disallow upload
8505: if ($file=~/\.(\w+)$/ &&
8506: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8507: $output =
1.207 bisitz 8508: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8509: } elsif ($file=~/\.(\w+)$/ &&
8510: !defined(&Apache::loncommon::fileembstyle($1))) {
8511: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8512: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 8513: $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 8514: } elsif (-d "$filepath/$file") {
1.195 bisitz 8515: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8516: } else {
8517: my $source = $filepath.'/'.$file;
8518: my $logfile;
8519: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 8520: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8521: }
8522: print $logfile
8523: "\n================= Publish ".localtime()." ================\n".
8524: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8525: # Save the file
8526: if (!open(FH,'>'.$source)) {
8527: &Apache::lonnet::logthis('Failed to create '.$source);
8528: return (&mt('Failed to create file'));
8529: }
8530: if ($action eq 'upload') {
8531: if (!print FH ($env{'form.'.$formname})) {
8532: &Apache::lonnet::logthis('Failed to write to '.$source);
8533: return (&mt('Failed to write file'));
8534: }
8535: } else {
8536: my $original = &Apache::lonnet::filelocation('',$formname);
8537: if(!copy($original,$source)) {
8538: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8539: return (&mt('Failed to write file'));
8540: }
8541: }
8542: close(FH);
8543: chmod(0660, $source); # Permissions to rw-rw---.
8544:
8545: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8546: my $copyfile=$targetdir.'/'.$file;
8547:
8548: my @parts=split(/\//,$targetdir);
8549: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8550: for (my $count=5;$count<=$#parts;$count++) {
8551: $path.="/$parts[$count]";
8552: if (!-e $path) {
8553: print $logfile "\nCreating directory ".$path;
8554: mkdir($path,02770);
8555: }
8556: }
8557: my $versionresult;
8558: if (-e $copyfile) {
8559: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8560: } else {
8561: $versionresult = 'ok';
8562: }
8563: if ($versionresult eq 'ok') {
8564: if (copy($source,$copyfile)) {
8565: print $logfile "\nCopied original source to ".$copyfile."\n";
8566: $output = 'ok';
8567: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8568: push(@{$modified_urls},[$copyfile,$source]);
8569: my $metaoutput =
8570: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8571: unless ($registered_cleanup) {
8572: my $handlers = $r->get_handlers('PerlCleanupHandler');
8573: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8574: $registered_cleanup=1;
8575: }
1.9 raeburn 8576: } else {
8577: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8578: $output = &mt('Failed to copy file to RES space').", $!";
8579: }
8580: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8581: my $inputfile = $filepath.'/'.$file;
8582: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8583: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8584: if ($fullwidth ne '' && $fullheight ne '') {
8585: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8586: my $thumbsize = $thumbwidth.'x'.$thumbheight;
8587: system("convert -sample $thumbsize $inputfile $outfile");
8588: chmod(0660, $filepath.'/tn-'.$file);
8589: if (-e $outfile) {
8590: my $copyfile=$targetdir.'/tn-'.$file;
8591: if (copy($outfile,$copyfile)) {
8592: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8593: my $thumb_metaoutput =
8594: &write_metadata($dom,$confname,$formname,
8595: $targetdir,'tn-'.$file,$logfile);
8596: push(@{$modified_urls},[$copyfile,$outfile]);
8597: unless ($registered_cleanup) {
8598: my $handlers = $r->get_handlers('PerlCleanupHandler');
8599: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8600: $registered_cleanup=1;
8601: }
1.267 raeburn 8602: $madethumb = 1;
1.16 raeburn 8603: } else {
8604: print $logfile "\nUnable to write ".$copyfile.
8605: ':'.$!."\n";
8606: }
8607: }
1.9 raeburn 8608: }
8609: }
8610: }
8611: } else {
8612: $output = $versionresult;
8613: }
8614: }
1.267 raeburn 8615: return ($output,$logourl,$madethumb);
1.9 raeburn 8616: }
8617:
8618: sub logo_versioning {
8619: my ($targetdir,$file,$logfile) = @_;
8620: my $target = $targetdir.'/'.$file;
8621: my ($maxversion,$fn,$extn,$output);
8622: $maxversion = 0;
8623: if ($file =~ /^(.+)\.(\w+)$/) {
8624: $fn=$1;
8625: $extn=$2;
8626: }
8627: opendir(DIR,$targetdir);
8628: while (my $filename=readdir(DIR)) {
8629: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8630: $maxversion=($1>$maxversion)?$1:$maxversion;
8631: }
8632: }
8633: $maxversion++;
8634: print $logfile "\nCreating old version ".$maxversion."\n";
8635: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8636: if (copy($target,$copyfile)) {
8637: print $logfile "Copied old target to ".$copyfile."\n";
8638: $copyfile=$copyfile.'.meta';
8639: if (copy($target.'.meta',$copyfile)) {
8640: print $logfile "Copied old target metadata to ".$copyfile."\n";
8641: $output = 'ok';
8642: } else {
8643: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8644: $output = &mt('Failed to copy old meta').", $!, ";
8645: }
8646: } else {
8647: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8648: $output = &mt('Failed to copy old target').", $!, ";
8649: }
8650: return $output;
8651: }
8652:
8653: sub write_metadata {
8654: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
8655: my (%metadatafields,%metadatakeys,$output);
8656: $metadatafields{'title'}=$formname;
8657: $metadatafields{'creationdate'}=time;
8658: $metadatafields{'lastrevisiondate'}=time;
8659: $metadatafields{'copyright'}='public';
8660: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
8661: $env{'user.domain'};
8662: $metadatafields{'authorspace'}=$confname.':'.$dom;
8663: $metadatafields{'domain'}=$dom;
8664: {
8665: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
8666: my $mfh;
1.155 raeburn 8667: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 8668: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 8669: unless ($_=~/\./) {
8670: my $unikey=$_;
8671: $unikey=~/^([A-Za-z]+)/;
8672: my $tag=$1;
8673: $tag=~tr/A-Z/a-z/;
8674: print $mfh "\n\<$tag";
8675: foreach (split(/\,/,$metadatakeys{$unikey})) {
8676: my $value=$metadatafields{$unikey.'.'.$_};
8677: $value=~s/\"/\'\'/g;
8678: print $mfh ' '.$_.'="'.$value.'"';
8679: }
8680: print $mfh '>'.
8681: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
8682: .'</'.$tag.'>';
8683: }
8684: }
8685: $output = 'ok';
8686: print $logfile "\nWrote metadata";
8687: close($mfh);
8688: } else {
8689: print $logfile "\nFailed to open metadata file";
1.9 raeburn 8690: $output = &mt('Could not write metadata');
8691: }
8692: }
1.155 raeburn 8693: return $output;
8694: }
8695:
8696: sub notifysubscribed {
8697: foreach my $targetsource (@{$modified_urls}){
8698: next unless (ref($targetsource) eq 'ARRAY');
8699: my ($target,$source)=@{$targetsource};
8700: if ($source ne '') {
8701: if (open(my $logfh,'>>'.$source.'.log')) {
8702: print $logfh "\nCleanup phase: Notifications\n";
8703: my @subscribed=&subscribed_hosts($target);
8704: foreach my $subhost (@subscribed) {
8705: print $logfh "\nNotifying host ".$subhost.':';
8706: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
8707: print $logfh $reply;
8708: }
8709: my @subscribedmeta=&subscribed_hosts("$target.meta");
8710: foreach my $subhost (@subscribedmeta) {
8711: print $logfh "\nNotifying host for metadata only ".$subhost.':';
8712: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
8713: $subhost);
8714: print $logfh $reply;
8715: }
8716: print $logfh "\n============ Done ============\n";
1.160 raeburn 8717: close($logfh);
1.155 raeburn 8718: }
8719: }
8720: }
8721: return OK;
8722: }
8723:
8724: sub subscribed_hosts {
8725: my ($target) = @_;
8726: my @subscribed;
8727: if (open(my $fh,"<$target.subscription")) {
8728: while (my $subline=<$fh>) {
8729: if ($subline =~ /^($match_lonid):/) {
8730: my $host = $1;
8731: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
8732: unless (grep(/^\Q$host\E$/,@subscribed)) {
8733: push(@subscribed,$host);
8734: }
8735: }
8736: }
8737: }
8738: }
8739: return @subscribed;
1.9 raeburn 8740: }
8741:
8742: sub check_switchserver {
8743: my ($dom,$confname) = @_;
8744: my ($allowed,$switchserver);
8745: my $home = &Apache::lonnet::homeserver($confname,$dom);
8746: if ($home eq 'no_host') {
8747: $home = &Apache::lonnet::domain($dom,'primary');
8748: }
8749: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 8750: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
8751: if (!$allowed) {
1.180 raeburn 8752: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 8753: }
8754: return $switchserver;
8755: }
8756:
1.1 raeburn 8757: sub modify_quotas {
1.216 raeburn 8758: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 8759: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 8760: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 8761: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8762: $validationfieldsref);
1.86 raeburn 8763: if ($action eq 'quotas') {
8764: $context = 'tools';
1.163 raeburn 8765: } else {
1.86 raeburn 8766: $context = $action;
8767: }
8768: if ($context eq 'requestcourses') {
1.271 raeburn 8769: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 8770: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 8771: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8772: %titles = &courserequest_titles();
8773: $toolregexp = join('|',@usertools);
8774: %conditions = &courserequest_conditions();
1.216 raeburn 8775: $confname = $dom.'-domainconfig';
8776: my $servadm = $r->dir_config('lonAdmEMail');
8777: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 8778: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8779: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 8780: } elsif ($context eq 'requestauthor') {
8781: @usertools = ('author');
8782: %titles = &authorrequest_titles();
1.86 raeburn 8783: } else {
1.162 raeburn 8784: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 8785: %titles = &tool_titles();
1.86 raeburn 8786: }
1.212 raeburn 8787: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 8788: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8789: foreach my $key (keys(%env)) {
1.101 raeburn 8790: if ($context eq 'requestcourses') {
8791: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8792: my $item = $1;
8793: my $type = $2;
8794: if ($type =~ /^limit_(.+)/) {
8795: $limithash{$item}{$1} = $env{$key};
8796: } else {
8797: $confhash{$item}{$type} = $env{$key};
8798: }
8799: }
1.163 raeburn 8800: } elsif ($context eq 'requestauthor') {
8801: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8802: $confhash{$1} = $env{$key};
8803: }
1.101 raeburn 8804: } else {
1.86 raeburn 8805: if ($key =~ /^form\.quota_(.+)$/) {
8806: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 8807: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8808: $confhash{'authorquota'}{$1} = $env{$key};
8809: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8810: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8811: }
1.72 raeburn 8812: }
8813: }
1.163 raeburn 8814: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 8815: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8816: @approvalnotify = sort(@approvalnotify);
8817: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 8818: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 8819: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8820: foreach my $type (@hasuniquecode) {
8821: if (grep(/^\Q$type\E$/,@crstypes)) {
8822: $confhash{'uniquecode'}{$type} = 1;
8823: }
1.216 raeburn 8824: }
1.242 raeburn 8825: my (%newbook,%allpos);
1.216 raeburn 8826: if ($context eq 'requestcourses') {
1.242 raeburn 8827: foreach my $type ('textbooks','templates') {
8828: @{$allpos{$type}} = ();
8829: my $invalid;
8830: if ($type eq 'textbooks') {
8831: $invalid = &mt('Invalid LON-CAPA course for textbook');
8832: } else {
8833: $invalid = &mt('Invalid LON-CAPA course for template');
8834: }
8835: if ($env{'form.'.$type.'_addbook'}) {
8836: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8837: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8838: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8839: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8840: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8841: } else {
8842: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8843: my $position = $env{'form.'.$type.'_addbook_pos'};
8844: $position =~ s/\D+//g;
8845: if ($position ne '') {
8846: $allpos{$type}[$position] = $newbook{$type};
8847: }
1.216 raeburn 8848: }
1.242 raeburn 8849: } else {
8850: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 8851: }
8852: }
1.242 raeburn 8853: }
1.216 raeburn 8854: }
1.102 raeburn 8855: if (ref($domconfig{$action}) eq 'HASH') {
8856: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8857: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8858: $changes{'notify'}{'approval'} = 1;
8859: }
8860: } else {
1.144 raeburn 8861: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8862: $changes{'notify'}{'approval'} = 1;
8863: }
8864: }
1.218 raeburn 8865: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8866: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8867: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8868: unless ($confhash{'uniquecode'}{$crstype}) {
8869: $changes{'uniquecode'} = 1;
8870: }
8871: }
8872: unless ($changes{'uniquecode'}) {
8873: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8874: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8875: $changes{'uniquecode'} = 1;
8876: }
8877: }
8878: }
8879: } else {
8880: $changes{'uniquecode'} = 1;
8881: }
8882: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8883: $changes{'uniquecode'} = 1;
1.216 raeburn 8884: }
8885: if ($context eq 'requestcourses') {
1.242 raeburn 8886: foreach my $type ('textbooks','templates') {
8887: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8888: my %deletions;
8889: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8890: if (@todelete) {
8891: map { $deletions{$_} = 1; } @todelete;
8892: }
8893: my %imgdeletions;
8894: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8895: if (@todeleteimages) {
8896: map { $imgdeletions{$_} = 1; } @todeleteimages;
8897: }
8898: my $maxnum = $env{'form.'.$type.'_maxnum'};
8899: for (my $i=0; $i<=$maxnum; $i++) {
8900: my $itemid = $env{'form.'.$type.'_id_'.$i};
8901: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8902: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8903: if ($deletions{$key}) {
8904: if ($domconfig{$action}{$type}{$key}{'image'}) {
8905: #FIXME need to obsolete item in RES space
8906: }
8907: next;
8908: } else {
8909: my $newpos = $env{'form.'.$itemid};
8910: $newpos =~ s/\D+//g;
1.243 raeburn 8911: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 8912: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 8913: ($type eq 'templates'));
1.242 raeburn 8914: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8915: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8916: $changes{$type}{$key} = 1;
8917: }
8918: }
8919: $allpos{$type}[$newpos] = $key;
8920: }
8921: if ($imgdeletions{$key}) {
8922: $changes{$type}{$key} = 1;
1.216 raeburn 8923: #FIXME need to obsolete item in RES space
1.242 raeburn 8924: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8925: my ($cdom,$cnum) = split(/_/,$key);
8926: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8927: $cdom,$cnum,$type,$configuserok,
8928: $switchserver,$author_ok);
8929: if ($imgurl) {
8930: $confhash{$type}{$key}{'image'} = $imgurl;
8931: $changes{$type}{$key} = 1;
1.216 raeburn 8932: }
1.242 raeburn 8933: if ($error) {
8934: &Apache::lonnet::logthis($error);
8935: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8936: }
8937: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8938: $confhash{$type}{$key}{'image'} =
8939: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 8940: }
8941: }
8942: }
8943: }
8944: }
8945: }
1.102 raeburn 8946: } else {
1.144 raeburn 8947: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8948: $changes{'notify'}{'approval'} = 1;
8949: }
1.218 raeburn 8950: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 8951: $changes{'uniquecode'} = 1;
8952: }
8953: }
8954: if ($context eq 'requestcourses') {
1.242 raeburn 8955: foreach my $type ('textbooks','templates') {
8956: if ($newbook{$type}) {
8957: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 8958: foreach my $item ('subject','title','publisher','author') {
8959: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8960: ($type eq 'template'));
1.242 raeburn 8961: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8962: if ($env{'form.'.$type.'_addbook_'.$item}) {
8963: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8964: }
8965: }
8966: if ($type eq 'textbooks') {
8967: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8968: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8969: my ($imageurl,$error) =
8970: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8971: $configuserok,$switchserver,$author_ok);
8972: if ($imageurl) {
8973: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8974: }
8975: if ($error) {
8976: &Apache::lonnet::logthis($error);
8977: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8978: }
8979: }
1.216 raeburn 8980: }
8981: }
1.242 raeburn 8982: if (@{$allpos{$type}} > 0) {
8983: my $idx = 0;
8984: foreach my $item (@{$allpos{$type}}) {
8985: if ($item ne '') {
8986: $confhash{$type}{$item}{'order'} = $idx;
8987: if (ref($domconfig{$action}) eq 'HASH') {
8988: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8989: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8990: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8991: $changes{$type}{$item} = 1;
8992: }
1.216 raeburn 8993: }
8994: }
8995: }
1.242 raeburn 8996: $idx ++;
1.216 raeburn 8997: }
8998: }
8999: }
9000: }
1.235 raeburn 9001: if (ref($validationitemsref) eq 'ARRAY') {
9002: foreach my $item (@{$validationitemsref}) {
9003: if ($item eq 'fields') {
9004: my @changed;
9005: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
9006: if (@{$confhash{'validation'}{$item}} > 0) {
9007: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
9008: }
1.266 raeburn 9009: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9010: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9011: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
9012: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
9013: $domconfig{'requestcourses'}{'validation'}{$item});
9014: } else {
9015: @changed = @{$confhash{'validation'}{$item}};
9016: }
1.235 raeburn 9017: } else {
9018: @changed = @{$confhash{'validation'}{$item}};
9019: }
9020: } else {
9021: @changed = @{$confhash{'validation'}{$item}};
9022: }
9023: if (@changed) {
9024: if ($confhash{'validation'}{$item}) {
9025: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
9026: } else {
9027: $changes{'validation'}{$item} = &mt('None');
9028: }
9029: }
9030: } else {
9031: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
9032: if ($item eq 'markup') {
9033: if ($env{'form.requestcourses_validation_'.$item}) {
9034: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
9035: }
9036: }
1.266 raeburn 9037: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9038: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9039: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
9040: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9041: }
9042: } else {
9043: if ($confhash{'validation'}{$item} ne '') {
9044: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9045: }
1.235 raeburn 9046: }
9047: } else {
9048: if ($confhash{'validation'}{$item} ne '') {
9049: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9050: }
9051: }
9052: }
9053: }
9054: }
9055: if ($env{'form.validationdc'}) {
9056: my $newval = $env{'form.validationdc'};
1.285 raeburn 9057: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 9058: if (exists($domcoords{$newval})) {
9059: $confhash{'validation'}{'dc'} = $newval;
9060: }
9061: }
9062: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 9063: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9064: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9065: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9066: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
9067: if ($confhash{'validation'}{'dc'} eq '') {
9068: $changes{'validation'}{'dc'} = &mt('None');
9069: } else {
9070: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9071: }
1.235 raeburn 9072: }
1.266 raeburn 9073: } elsif ($confhash{'validation'}{'dc'} ne '') {
9074: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 9075: }
9076: } elsif ($confhash{'validation'}{'dc'} ne '') {
9077: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9078: }
9079: } elsif ($confhash{'validation'}{'dc'} ne '') {
9080: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 9081: }
1.266 raeburn 9082: } else {
9083: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9084: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9085: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9086: $changes{'validation'}{'dc'} = &mt('None');
9087: }
9088: }
1.235 raeburn 9089: }
9090: }
1.102 raeburn 9091: }
9092: } else {
1.86 raeburn 9093: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 9094: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 9095: }
1.72 raeburn 9096: foreach my $item (@usertools) {
9097: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 9098: my $unset;
1.101 raeburn 9099: if ($context eq 'requestcourses') {
1.104 raeburn 9100: $unset = '0';
9101: if ($type eq '_LC_adv') {
9102: $unset = '';
9103: }
1.101 raeburn 9104: if ($confhash{$item}{$type} eq 'autolimit') {
9105: $confhash{$item}{$type} .= '=';
9106: unless ($limithash{$item}{$type} =~ /\D/) {
9107: $confhash{$item}{$type} .= $limithash{$item}{$type};
9108: }
9109: }
1.163 raeburn 9110: } elsif ($context eq 'requestauthor') {
9111: $unset = '0';
9112: if ($type eq '_LC_adv') {
9113: $unset = '';
9114: }
1.72 raeburn 9115: } else {
1.101 raeburn 9116: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
9117: $confhash{$item}{$type} = 1;
9118: } else {
9119: $confhash{$item}{$type} = 0;
9120: }
1.72 raeburn 9121: }
1.86 raeburn 9122: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 9123: if ($action eq 'requestauthor') {
9124: if ($domconfig{$action}{$type} ne $confhash{$type}) {
9125: $changes{$type} = 1;
9126: }
9127: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 9128: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
9129: $changes{$item}{$type} = 1;
9130: }
9131: } else {
9132: if ($context eq 'requestcourses') {
1.104 raeburn 9133: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 9134: $changes{$item}{$type} = 1;
9135: }
9136: } else {
9137: if (!$confhash{$item}{$type}) {
9138: $changes{$item}{$type} = 1;
9139: }
9140: }
9141: }
9142: } else {
9143: if ($context eq 'requestcourses') {
1.104 raeburn 9144: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 9145: $changes{$item}{$type} = 1;
9146: }
1.163 raeburn 9147: } elsif ($context eq 'requestauthor') {
9148: if ($confhash{$type} ne $unset) {
9149: $changes{$type} = 1;
9150: }
1.72 raeburn 9151: } else {
9152: if (!$confhash{$item}{$type}) {
9153: $changes{$item}{$type} = 1;
9154: }
9155: }
9156: }
1.1 raeburn 9157: }
9158: }
1.163 raeburn 9159: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 9160: if (ref($domconfig{'quotas'}) eq 'HASH') {
9161: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9162: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
9163: if (exists($confhash{'defaultquota'}{$key})) {
9164: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
9165: $changes{'defaultquota'}{$key} = 1;
9166: }
9167: } else {
9168: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 9169: }
9170: }
1.86 raeburn 9171: } else {
9172: foreach my $key (keys(%{$domconfig{'quotas'}})) {
9173: if (exists($confhash{'defaultquota'}{$key})) {
9174: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
9175: $changes{'defaultquota'}{$key} = 1;
9176: }
9177: } else {
9178: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 9179: }
1.1 raeburn 9180: }
9181: }
1.197 raeburn 9182: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9183: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
9184: if (exists($confhash{'authorquota'}{$key})) {
9185: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
9186: $changes{'authorquota'}{$key} = 1;
9187: }
9188: } else {
9189: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
9190: }
9191: }
9192: }
1.1 raeburn 9193: }
1.86 raeburn 9194: if (ref($confhash{'defaultquota'}) eq 'HASH') {
9195: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
9196: if (ref($domconfig{'quotas'}) eq 'HASH') {
9197: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9198: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
9199: $changes{'defaultquota'}{$key} = 1;
9200: }
9201: } else {
9202: if (!exists($domconfig{'quotas'}{$key})) {
9203: $changes{'defaultquota'}{$key} = 1;
9204: }
1.72 raeburn 9205: }
9206: } else {
1.86 raeburn 9207: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 9208: }
1.1 raeburn 9209: }
9210: }
1.197 raeburn 9211: if (ref($confhash{'authorquota'}) eq 'HASH') {
9212: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9213: if (ref($domconfig{'quotas'}) eq 'HASH') {
9214: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9215: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9216: $changes{'authorquota'}{$key} = 1;
9217: }
9218: } else {
9219: $changes{'authorquota'}{$key} = 1;
9220: }
9221: } else {
9222: $changes{'authorquota'}{$key} = 1;
9223: }
9224: }
9225: }
1.1 raeburn 9226: }
1.72 raeburn 9227:
1.163 raeburn 9228: if ($context eq 'requestauthor') {
9229: $domdefaults{'requestauthor'} = \%confhash;
9230: } else {
9231: foreach my $key (keys(%confhash)) {
1.242 raeburn 9232: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 9233: $domdefaults{$key} = $confhash{$key};
9234: }
1.163 raeburn 9235: }
1.72 raeburn 9236: }
1.163 raeburn 9237:
1.1 raeburn 9238: my %quotahash = (
1.86 raeburn 9239: $action => { %confhash }
1.1 raeburn 9240: );
9241: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9242: $dom);
9243: if ($putresult eq 'ok') {
9244: if (keys(%changes) > 0) {
1.72 raeburn 9245: my $cachetime = 24*60*60;
9246: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9247: if (ref($lastactref) eq 'HASH') {
9248: $lastactref->{'domdefaults'} = 1;
9249: }
1.1 raeburn 9250: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 9251: unless (($context eq 'requestcourses') ||
1.163 raeburn 9252: ($context eq 'requestauthor')) {
1.86 raeburn 9253: if (ref($changes{'defaultquota'}) eq 'HASH') {
9254: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9255: foreach my $type (@{$types},'default') {
9256: if (defined($changes{'defaultquota'}{$type})) {
9257: my $typetitle = $usertypes->{$type};
9258: if ($type eq 'default') {
9259: $typetitle = $othertitle;
9260: }
1.213 raeburn 9261: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9262: }
9263: }
1.86 raeburn 9264: $resulttext .= '</ul></li>';
1.72 raeburn 9265: }
1.197 raeburn 9266: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 9267: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 9268: foreach my $type (@{$types},'default') {
9269: if (defined($changes{'authorquota'}{$type})) {
9270: my $typetitle = $usertypes->{$type};
9271: if ($type eq 'default') {
9272: $typetitle = $othertitle;
9273: }
1.213 raeburn 9274: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 9275: }
9276: }
9277: $resulttext .= '</ul></li>';
9278: }
1.72 raeburn 9279: }
1.80 raeburn 9280: my %newenv;
1.72 raeburn 9281: foreach my $item (@usertools) {
1.163 raeburn 9282: my (%haschgs,%inconf);
9283: if ($context eq 'requestauthor') {
9284: %haschgs = %changes;
1.210 raeburn 9285: %inconf = %confhash;
1.163 raeburn 9286: } else {
9287: if (ref($changes{$item}) eq 'HASH') {
9288: %haschgs = %{$changes{$item}};
9289: }
9290: if (ref($confhash{$item}) eq 'HASH') {
9291: %inconf = %{$confhash{$item}};
9292: }
9293: }
9294: if (keys(%haschgs) > 0) {
1.80 raeburn 9295: my $newacc =
9296: &Apache::lonnet::usertools_access($env{'user.name'},
9297: $env{'user.domain'},
1.86 raeburn 9298: $item,'reload',$context);
1.210 raeburn 9299: if (($context eq 'requestcourses') ||
1.163 raeburn 9300: ($context eq 'requestauthor')) {
1.108 raeburn 9301: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9302: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9303: }
9304: } else {
9305: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9306: $newenv{'environment.availabletools.'.$item} = $newacc;
9307: }
1.80 raeburn 9308: }
1.163 raeburn 9309: unless ($context eq 'requestauthor') {
9310: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9311: }
1.72 raeburn 9312: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 9313: if ($haschgs{$type}) {
1.72 raeburn 9314: my $typetitle = $usertypes->{$type};
9315: if ($type eq 'default') {
9316: $typetitle = $othertitle;
9317: } elsif ($type eq '_LC_adv') {
9318: $typetitle = 'LON-CAPA Advanced Users';
9319: }
1.163 raeburn 9320: if ($inconf{$type}) {
1.101 raeburn 9321: if ($context eq 'requestcourses') {
9322: my $cond;
1.163 raeburn 9323: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9324: if ($1 eq '') {
9325: $cond = &mt('(Automatic processing of any request).');
9326: } else {
9327: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9328: }
9329: } else {
1.163 raeburn 9330: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9331: }
9332: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 9333: } elsif ($context eq 'requestauthor') {
9334: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9335: $titles{$inconf{$type}},$typetitle);
9336:
1.101 raeburn 9337: } else {
9338: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9339: }
1.72 raeburn 9340: } else {
1.104 raeburn 9341: if ($type eq '_LC_adv') {
1.163 raeburn 9342: if ($inconf{$type} eq '0') {
1.104 raeburn 9343: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9344: } else {
9345: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9346: }
9347: } else {
9348: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9349: }
1.72 raeburn 9350: }
9351: }
1.26 raeburn 9352: }
1.163 raeburn 9353: unless ($context eq 'requestauthor') {
9354: $resulttext .= '</ul></li>';
9355: }
1.26 raeburn 9356: }
1.1 raeburn 9357: }
1.163 raeburn 9358: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9359: if (ref($changes{'notify'}) eq 'HASH') {
9360: if ($changes{'notify'}{'approval'}) {
9361: if (ref($confhash{'notify'}) eq 'HASH') {
9362: if ($confhash{'notify'}{'approval'}) {
9363: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9364: } else {
1.163 raeburn 9365: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9366: }
9367: }
9368: }
9369: }
9370: }
1.216 raeburn 9371: if ($action eq 'requestcourses') {
9372: my @offon = ('off','on');
9373: if ($changes{'uniquecode'}) {
1.218 raeburn 9374: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9375: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9376: $resulttext .= '<li>'.
9377: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9378: '</li>';
9379: } else {
9380: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9381: '</li>';
9382: }
1.216 raeburn 9383: }
1.242 raeburn 9384: foreach my $type ('textbooks','templates') {
9385: if (ref($changes{$type}) eq 'HASH') {
9386: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9387: foreach my $key (sort(keys(%{$changes{$type}}))) {
9388: my %coursehash = &Apache::lonnet::coursedescription($key);
9389: my $coursetitle = $coursehash{'description'};
9390: my $position = $confhash{$type}{$key}{'order'} + 1;
9391: $resulttext .= '<li>';
1.243 raeburn 9392: foreach my $item ('subject','title','publisher','author') {
9393: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9394: ($type eq 'templates'));
1.242 raeburn 9395: my $name = $item.':';
9396: $name =~ s/^(\w)/\U$1/;
9397: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9398: }
9399: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9400: if ($type eq 'textbooks') {
9401: if ($confhash{$type}{$key}{'image'}) {
9402: $resulttext .= ' '.&mt('Image: [_1]',
9403: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9404: ' alt="Textbook cover" />').'<br />';
9405: }
9406: }
9407: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 9408: }
1.242 raeburn 9409: $resulttext .= '</ul></li>';
1.216 raeburn 9410: }
9411: }
1.235 raeburn 9412: if (ref($changes{'validation'}) eq 'HASH') {
9413: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9414: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9415: foreach my $item (@{$validationitemsref}) {
9416: if (exists($changes{'validation'}{$item})) {
9417: if ($item eq 'markup') {
9418: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9419: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9420: } else {
9421: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9422: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9423: }
9424: }
9425: }
9426: if (exists($changes{'validation'}{'dc'})) {
9427: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9428: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9429: }
9430: }
9431: }
1.216 raeburn 9432: }
1.1 raeburn 9433: $resulttext .= '</ul>';
1.80 raeburn 9434: if (keys(%newenv)) {
9435: &Apache::lonnet::appenv(\%newenv);
9436: }
1.1 raeburn 9437: } else {
1.86 raeburn 9438: if ($context eq 'requestcourses') {
9439: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 9440: } elsif ($context eq 'requestauthor') {
9441: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9442: } else {
1.90 weissno 9443: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9444: }
1.1 raeburn 9445: }
9446: } else {
1.11 albertel 9447: $resulttext = '<span class="LC_error">'.
9448: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9449: }
1.216 raeburn 9450: if ($errors) {
9451: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9452: '<ul>'.$errors.'</ul></p>';
9453: }
1.3 raeburn 9454: return $resulttext;
1.1 raeburn 9455: }
9456:
1.216 raeburn 9457: sub process_textbook_image {
1.242 raeburn 9458: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 9459: my $filename = $env{'form.'.$caller.'.filename'};
9460: my ($error,$url);
9461: my ($width,$height) = (50,50);
9462: if ($configuserok eq 'ok') {
9463: if ($switchserver) {
9464: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9465: $switchserver);
9466: } elsif ($author_ok eq 'ok') {
9467: my ($result,$imageurl) =
9468: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 9469: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 9470: if ($result eq 'ok') {
9471: $url = $imageurl;
9472: } else {
9473: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9474: }
9475: } else {
9476: $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);
9477: }
9478: } else {
9479: $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);
9480: }
9481: return ($url,$error);
9482: }
9483:
1.267 raeburn 9484: sub modify_ltitools {
9485: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
9486: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 9487: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 9488: my $confname = $dom.'-domainconfig';
9489: my $servadm = $r->dir_config('lonAdmEMail');
9490: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9491: my (%posslti,%possfield);
9492: my @courseroles = ('cc','in','ta','ep','st');
9493: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
9494: map { $posslti{$_} = 1; } @ltiroles;
9495: my @allfields = ('fullname','firstname','lastname','email','user','roles');
9496: map { $possfield{$_} = 1; } @allfields;
9497: my %lt = <itools_names();
9498: if ($env{'form.ltitools_add'}) {
9499: my $title = $env{'form.ltitools_add_title'};
9500: $title =~ s/(`)/'/g;
9501: ($newid,my $error) = &get_ltitools_id($dom,$title);
9502: if ($newid) {
9503: my $position = $env{'form.ltitools_add_pos'};
9504: $position =~ s/\D+//g;
9505: if ($position ne '') {
9506: $allpos[$position] = $newid;
9507: }
9508: $changes{$newid} = 1;
9509: foreach my $item ('title','url','key','secret') {
9510: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
9511: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 9512: if (($item eq 'key') || ($item eq 'secret')) {
9513: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9514: } else {
9515: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9516: }
1.267 raeburn 9517: }
9518: }
9519: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
9520: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
9521: }
9522: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
9523: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
9524: }
1.296 raeburn 9525: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 9526: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
9527: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 9528: if (($item eq 'width') || ($item eq 'height')) {
9529: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
9530: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9531: }
9532: } else {
9533: if ($env{'form.ltitools_add_'.$item} ne '') {
9534: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9535: }
1.267 raeburn 9536: }
9537: }
9538: if ($env{'form.ltitools_add_target'} eq 'window') {
9539: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 9540: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
9541: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 9542: } else {
9543: $confhash{$newid}{'display'}{'target'} = 'iframe';
9544: }
9545: foreach my $item ('passback','roster') {
9546: if ($env{'form.ltitools_add_'.$item}) {
9547: $confhash{$newid}{$item} = 1;
9548: }
9549: }
9550: if ($env{'form.ltitools_add_image.filename'} ne '') {
9551: my ($imageurl,$error) =
9552: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
9553: $configuserok,$switchserver,$author_ok);
9554: if ($imageurl) {
9555: $confhash{$newid}{'image'} = $imageurl;
9556: }
9557: if ($error) {
9558: &Apache::lonnet::logthis($error);
9559: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9560: }
9561: }
9562: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
9563: foreach my $field (@fields) {
9564: if ($possfield{$field}) {
9565: if ($field eq 'roles') {
9566: foreach my $role (@courseroles) {
9567: my $choice = $env{'form.ltitools_add_roles_'.$role};
9568: if (($choice ne '') && ($posslti{$choice})) {
9569: $confhash{$newid}{'roles'}{$role} = $choice;
9570: if ($role eq 'cc') {
9571: $confhash{$newid}{'roles'}{'co'} = $choice;
9572: }
9573: }
9574: }
9575: } else {
9576: $confhash{$newid}{'fields'}{$field} = 1;
9577: }
9578: }
9579: }
1.273 raeburn 9580: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
9581: foreach my $item (@courseconfig) {
9582: $confhash{$newid}{'crsconf'}{$item} = 1;
9583: }
1.267 raeburn 9584: if ($env{'form.ltitools_add_custom'}) {
9585: my $name = $env{'form.ltitools_add_custom_name'};
9586: my $value = $env{'form.ltitools_add_custom_value'};
9587: $value =~ s/(`)/'/g;
9588: $name =~ s/(`)/'/g;
9589: $confhash{$newid}{'custom'}{$name} = $value;
9590: }
9591: } else {
9592: my $error = &mt('Failed to acquire unique ID for new external tool');
9593: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9594: }
9595: }
9596: if (ref($domconfig{$action}) eq 'HASH') {
9597: my %deletions;
9598: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
9599: if (@todelete) {
9600: map { $deletions{$_} = 1; } @todelete;
9601: }
9602: my %customadds;
9603: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
9604: if (@newcustom) {
9605: map { $customadds{$_} = 1; } @newcustom;
9606: }
9607: my %imgdeletions;
9608: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
9609: if (@todeleteimages) {
9610: map { $imgdeletions{$_} = 1; } @todeleteimages;
9611: }
9612: my $maxnum = $env{'form.ltitools_maxnum'};
9613: for (my $i=0; $i<=$maxnum; $i++) {
9614: my $itemid = $env{'form.ltitools_id_'.$i};
9615: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9616: if ($deletions{$itemid}) {
9617: if ($domconfig{$action}{$itemid}{'image'}) {
9618: #FIXME need to obsolete item in RES space
9619: }
9620: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
9621: next;
9622: } else {
9623: my $newpos = $env{'form.ltitools_'.$itemid};
9624: $newpos =~ s/\D+//g;
1.297 raeburn 9625: foreach my $item ('title','url') {
1.267 raeburn 9626: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9627: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
9628: $changes{$itemid} = 1;
9629: }
9630: }
1.297 raeburn 9631: foreach my $item ('key','secret') {
9632: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9633: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
9634: $changes{$itemid} = 1;
9635: }
9636: }
1.267 raeburn 9637: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
9638: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
9639: }
9640: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
9641: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
9642: }
9643: foreach my $size ('width','height') {
9644: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
9645: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
9646: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
9647: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
9648: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9649: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
9650: $changes{$itemid} = 1;
9651: }
9652: } else {
9653: $changes{$itemid} = 1;
9654: }
1.296 raeburn 9655: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9656: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
9657: $changes{$itemid} = 1;
9658: }
9659: }
9660: }
9661: foreach my $item ('linktext','explanation') {
9662: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
9663: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
9664: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
9665: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9666: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9667: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
9668: $changes{$itemid} = 1;
9669: }
9670: } else {
9671: $changes{$itemid} = 1;
9672: }
9673: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9674: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
9675: $changes{$itemid} = 1;
9676: }
1.267 raeburn 9677: }
9678: }
9679: if ($env{'form.ltitools_target_'.$i} eq 'window') {
9680: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 9681: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
9682: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 9683: } else {
9684: $confhash{$itemid}{'display'}{'target'} = 'iframe';
9685: }
9686: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9687: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
9688: $changes{$itemid} = 1;
9689: }
9690: } else {
9691: $changes{$itemid} = 1;
9692: }
9693: foreach my $extra ('passback','roster') {
9694: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
9695: $confhash{$itemid}{$extra} = 1;
9696: }
9697: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
9698: $changes{$itemid} = 1;
9699: }
9700: }
1.273 raeburn 9701: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.296 raeburn 9702: foreach my $item ('label','title','target','linktext','explanation') {
1.273 raeburn 9703: if (grep(/^\Q$item\E$/,@courseconfig)) {
9704: $confhash{$itemid}{'crsconf'}{$item} = 1;
9705: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
9706: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
9707: $changes{$itemid} = 1;
9708: }
9709: } else {
9710: $changes{$itemid} = 1;
9711: }
9712: }
9713: }
1.267 raeburn 9714: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
9715: foreach my $field (@fields) {
9716: if ($possfield{$field}) {
9717: if ($field eq 'roles') {
9718: foreach my $role (@courseroles) {
9719: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
9720: if (($choice ne '') && ($posslti{$choice})) {
9721: $confhash{$itemid}{'roles'}{$role} = $choice;
9722: if ($role eq 'cc') {
9723: $confhash{$itemid}{'roles'}{'co'} = $choice;
9724: }
9725: }
9726: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
9727: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
9728: $changes{$itemid} = 1;
9729: }
9730: } elsif ($confhash{$itemid}{'roles'}{$role}) {
9731: $changes{$itemid} = 1;
9732: }
9733: }
9734: } else {
9735: $confhash{$itemid}{'fields'}{$field} = 1;
9736: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
9737: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
9738: $changes{$itemid} = 1;
9739: }
9740: } else {
9741: $changes{$itemid} = 1;
9742: }
9743: }
9744: }
9745: }
9746: $allpos[$newpos] = $itemid;
9747: }
9748: if ($imgdeletions{$itemid}) {
9749: $changes{$itemid} = 1;
9750: #FIXME need to obsolete item in RES space
9751: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
9752: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
9753: $itemid,$configuserok,$switchserver,
9754: $author_ok);
9755: if ($imgurl) {
9756: $confhash{$itemid}{'image'} = $imgurl;
9757: $changes{$itemid} = 1;
9758: }
9759: if ($error) {
9760: &Apache::lonnet::logthis($error);
9761: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9762: }
9763: } elsif ($domconfig{$action}{$itemid}{'image'}) {
9764: $confhash{$itemid}{'image'} =
9765: $domconfig{$action}{$itemid}{'image'};
9766: }
9767: if ($customadds{$i}) {
9768: my $name = $env{'form.ltitools_custom_name_'.$i};
9769: $name =~ s/(`)/'/g;
9770: $name =~ s/^\s+//;
9771: $name =~ s/\s+$//;
9772: my $value = $env{'form.ltitools_custom_value_'.$i};
9773: $value =~ s/(`)/'/g;
9774: $value =~ s/^\s+//;
9775: $value =~ s/\s+$//;
9776: if ($name ne '') {
9777: $confhash{$itemid}{'custom'}{$name} = $value;
9778: $changes{$itemid} = 1;
9779: }
9780: }
9781: my %customdels;
9782: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
9783: if (@customdeletions) {
9784: $changes{$itemid} = 1;
9785: }
9786: map { $customdels{$_} = 1; } @customdeletions;
9787: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
9788: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
9789: unless ($customdels{$key}) {
9790: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
9791: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
9792: }
9793: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
9794: $changes{$itemid} = 1;
9795: }
9796: }
9797: }
9798: }
9799: unless ($changes{$itemid}) {
9800: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
9801: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
9802: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
9803: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
9804: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
9805: $changes{$itemid} = 1;
9806: last;
9807: }
9808: }
9809: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
9810: $changes{$itemid} = 1;
9811: }
9812: }
9813: last if ($changes{$itemid});
9814: }
9815: }
9816: }
9817: }
9818: }
9819: if (@allpos > 0) {
9820: my $idx = 0;
9821: foreach my $itemid (@allpos) {
9822: if ($itemid ne '') {
9823: $confhash{$itemid}{'order'} = $idx;
9824: if (ref($domconfig{$action}) eq 'HASH') {
9825: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9826: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
9827: $changes{$itemid} = 1;
9828: }
9829: }
9830: }
9831: $idx ++;
9832: }
9833: }
9834: }
9835: my %ltitoolshash = (
9836: $action => { %confhash }
9837: );
9838: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
9839: $dom);
9840: if ($putresult eq 'ok') {
1.297 raeburn 9841: my %ltienchash = (
9842: $action => { %encconfig }
9843: );
9844: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 9845: if (keys(%changes) > 0) {
9846: my $cachetime = 24*60*60;
1.297 raeburn 9847: my %ltiall = %confhash;
9848: foreach my $id (keys(%ltiall)) {
9849: if (ref($encconfig{$id}) eq 'HASH') {
9850: foreach my $item ('key','secret') {
9851: $ltiall{$id}{$item} = $encconfig{$id}{$item};
9852: }
9853: }
9854: }
9855: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 9856: if (ref($lastactref) eq 'HASH') {
9857: $lastactref->{'ltitools'} = 1;
9858: }
9859: $resulttext = &mt('Changes made:').'<ul>';
9860: my %bynum;
9861: foreach my $itemid (sort(keys(%changes))) {
9862: my $position = $confhash{$itemid}{'order'};
9863: $bynum{$position} = $itemid;
9864: }
9865: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9866: my $itemid = $bynum{$pos};
9867: if (ref($confhash{$itemid}) ne 'HASH') {
9868: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9869: } else {
9870: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
9871: if ($confhash{$itemid}{'image'}) {
9872: $resulttext .= ' '.
9873: '<img src="'.$confhash{$itemid}{'image'}.'"'.
9874: ' alt="'.&mt('Tool Provider icon').'" />';
9875: }
9876: $resulttext .= '</li><ul>';
9877: my $position = $pos + 1;
9878: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.297 raeburn 9879: foreach my $item ('version','msgtype','url') {
1.267 raeburn 9880: if ($confhash{$itemid}{$item} ne '') {
9881: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
9882: }
9883: }
1.297 raeburn 9884: if ($encconfig{$itemid}{'key'} ne '') {
9885: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
9886: }
9887: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 9888: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 9889: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 9890: $resulttext .= ('*'x$num).'</li>';
9891: }
1.273 raeburn 9892: $resulttext .= '<li>'.&mt('Configurable in course:');
1.296 raeburn 9893: my @possconfig = ('label','title','target','linktext','explanation');
1.273 raeburn 9894: my $numconfig = 0;
9895: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
9896: foreach my $item (@possconfig) {
9897: if ($confhash{$itemid}{'crsconf'}{$item}) {
9898: $numconfig ++;
1.296 raeburn 9899: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 9900: }
9901: }
9902: }
9903: if (!$numconfig) {
9904: $resulttext .= &mt('None');
9905: }
9906: $resulttext .= '</li>';
1.267 raeburn 9907: foreach my $item ('passback','roster') {
9908: $resulttext .= '<li>'.$lt{$item}.' ';
9909: if ($confhash{$itemid}{$item}) {
9910: $resulttext .= &mt('Yes');
9911: } else {
9912: $resulttext .= &mt('No');
9913: }
9914: $resulttext .= '</li>';
9915: }
9916: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
9917: my $displaylist;
9918: if ($confhash{$itemid}{'display'}{'target'}) {
9919: $displaylist = &mt('Display target').': '.
9920: $confhash{$itemid}{'display'}{'target'}.',';
9921: }
9922: foreach my $size ('width','height') {
9923: if ($confhash{$itemid}{'display'}{$size}) {
9924: $displaylist .= (' 'x2).$lt{$size}.': '.
9925: $confhash{$itemid}{'display'}{$size}.',';
9926: }
9927: }
9928: if ($displaylist) {
9929: $displaylist =~ s/,$//;
9930: $resulttext .= '<li>'.$displaylist.'</li>';
9931: }
1.296 raeburn 9932: foreach my $item ('linktext','explanation') {
9933: if ($confhash{$itemid}{'display'}{$item}) {
9934: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
9935: }
9936: }
9937: }
1.267 raeburn 9938: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
9939: my $fieldlist;
9940: foreach my $field (@allfields) {
9941: if ($confhash{$itemid}{'fields'}{$field}) {
9942: $fieldlist .= (' 'x2).$lt{$field}.',';
9943: }
9944: }
9945: if ($fieldlist) {
9946: $fieldlist =~ s/,$//;
9947: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
9948: }
9949: }
9950: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
9951: my $rolemaps;
9952: foreach my $role (@courseroles) {
9953: if ($confhash{$itemid}{'roles'}{$role}) {
9954: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
9955: $confhash{$itemid}{'roles'}{$role}.',';
9956: }
9957: }
9958: if ($rolemaps) {
9959: $rolemaps =~ s/,$//;
9960: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
9961: }
9962: }
9963: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
9964: my $customlist;
9965: if (keys(%{$confhash{$itemid}{'custom'}})) {
9966: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
9967: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
9968: }
9969: }
9970: if ($customlist) {
9971: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
9972: }
9973: }
9974: $resulttext .= '</ul></li>';
9975: }
9976: }
9977: $resulttext .= '</ul>';
9978: } else {
9979: $resulttext = &mt('No changes made.');
9980: }
9981: } else {
9982: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9983: }
9984: if ($errors) {
9985: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9986: $errors.'</ul>';
9987: }
9988: return $resulttext;
9989: }
9990:
9991: sub process_ltitools_image {
9992: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
9993: my $filename = $env{'form.'.$caller.'.filename'};
9994: my ($error,$url);
9995: my ($width,$height) = (21,21);
9996: if ($configuserok eq 'ok') {
9997: if ($switchserver) {
9998: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
9999: $switchserver);
10000: } elsif ($author_ok eq 'ok') {
10001: my ($result,$imageurl,$madethumb) =
10002: &publishlogo($r,'upload',$caller,$dom,$confname,
10003: "ltitools/$itemid/icon",$width,$height);
10004: if ($result eq 'ok') {
10005: if ($madethumb) {
10006: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
10007: my $imagethumb = "$path/tn-".$imagefile;
10008: $url = $imagethumb;
10009: } else {
10010: $url = $imageurl;
10011: }
10012: } else {
10013: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10014: }
10015: } else {
10016: $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);
10017: }
10018: } else {
10019: $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);
10020: }
10021: return ($url,$error);
10022: }
10023:
10024: sub get_ltitools_id {
10025: my ($cdom,$title) = @_;
10026: # get lock on ltitools db
10027: my $lockhash = {
10028: lock => $env{'user.name'}.
10029: ':'.$env{'user.domain'},
10030: };
10031: my $tries = 0;
10032: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10033: my ($id,$error);
10034:
10035: while (($gotlock ne 'ok') && ($tries<10)) {
10036: $tries ++;
10037: sleep (0.1);
10038: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10039: }
10040: if ($gotlock eq 'ok') {
10041: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
10042: if ($currids{'lock'}) {
10043: delete($currids{'lock'});
10044: if (keys(%currids)) {
10045: my @curr = sort { $a <=> $b } keys(%currids);
10046: if ($curr[-1] =~ /^\d+$/) {
10047: $id = 1 + $curr[-1];
10048: }
10049: } else {
10050: $id = 1;
10051: }
10052: if ($id) {
10053: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
10054: $error = 'nostore';
10055: }
10056: } else {
10057: $error = 'nonumber';
10058: }
10059: }
10060: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
10061: } else {
10062: $error = 'nolock';
10063: }
10064: return ($id,$error);
10065: }
10066:
1.3 raeburn 10067: sub modify_autoenroll {
1.205 raeburn 10068: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 10069: my ($resulttext,%changes);
10070: my %currautoenroll;
10071: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
10072: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
10073: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
10074: }
10075: }
10076: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
10077: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 10078: sender => 'Sender for notification messages',
1.274 raeburn 10079: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
10080: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 10081: my @offon = ('off','on');
1.17 raeburn 10082: my $sender_uname = $env{'form.sender_uname'};
10083: my $sender_domain = $env{'form.sender_domain'};
10084: if ($sender_domain eq '') {
10085: $sender_uname = '';
10086: } elsif ($sender_uname eq '') {
10087: $sender_domain = '';
10088: }
1.129 raeburn 10089: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 10090: my $failsafe = $env{'form.autoenroll_failsafe'};
10091: $failsafe =~ s{^\s+|\s+$}{}g;
10092: if ($failsafe =~ /\D/) {
10093: undef($failsafe);
10094: }
1.1 raeburn 10095: my %autoenrollhash = (
1.129 raeburn 10096: autoenroll => { 'run' => $env{'form.autoenroll_run'},
10097: 'sender_uname' => $sender_uname,
10098: 'sender_domain' => $sender_domain,
10099: 'co-owners' => $coowners,
1.274 raeburn 10100: 'autofailsafe' => $failsafe,
1.1 raeburn 10101: }
10102: );
1.4 raeburn 10103: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
10104: $dom);
1.1 raeburn 10105: if ($putresult eq 'ok') {
10106: if (exists($currautoenroll{'run'})) {
10107: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
10108: $changes{'run'} = 1;
10109: }
10110: } elsif ($autorun) {
10111: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 10112: $changes{'run'} = 1;
1.1 raeburn 10113: }
10114: }
1.17 raeburn 10115: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 10116: $changes{'sender'} = 1;
10117: }
1.17 raeburn 10118: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 10119: $changes{'sender'} = 1;
10120: }
1.129 raeburn 10121: if ($currautoenroll{'co-owners'} ne '') {
10122: if ($currautoenroll{'co-owners'} ne $coowners) {
10123: $changes{'coowners'} = 1;
10124: }
10125: } elsif ($coowners) {
10126: $changes{'coowners'} = 1;
1.274 raeburn 10127: }
10128: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
10129: $changes{'autofailsafe'} = 1;
10130: }
1.1 raeburn 10131: if (keys(%changes) > 0) {
10132: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 10133: if ($changes{'run'}) {
1.1 raeburn 10134: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
10135: }
10136: if ($changes{'sender'}) {
1.17 raeburn 10137: if ($sender_uname eq '' || $sender_domain eq '') {
10138: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
10139: } else {
10140: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
10141: }
1.1 raeburn 10142: }
1.129 raeburn 10143: if ($changes{'coowners'}) {
10144: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
10145: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10146: if (ref($lastactref) eq 'HASH') {
10147: $lastactref->{'domainconfig'} = 1;
10148: }
1.129 raeburn 10149: }
1.274 raeburn 10150: if ($changes{'autofailsafe'}) {
10151: if ($failsafe ne '') {
1.299 raeburn 10152: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 10153: } else {
1.299 raeburn 10154: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 10155: }
10156: &Apache::lonnet::get_domain_defaults($dom,1);
10157: if (ref($lastactref) eq 'HASH') {
10158: $lastactref->{'domdefaults'} = 1;
10159: }
10160: }
1.1 raeburn 10161: $resulttext .= '</ul>';
10162: } else {
10163: $resulttext = &mt('No changes made to auto-enrollment settings');
10164: }
10165: } else {
1.11 albertel 10166: $resulttext = '<span class="LC_error">'.
10167: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10168: }
1.3 raeburn 10169: return $resulttext;
1.1 raeburn 10170: }
10171:
10172: sub modify_autoupdate {
1.3 raeburn 10173: my ($dom,%domconfig) = @_;
1.1 raeburn 10174: my ($resulttext,%currautoupdate,%fields,%changes);
10175: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
10176: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
10177: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
10178: }
10179: }
10180: my @offon = ('off','on');
10181: my %title = &Apache::lonlocal::texthash (
10182: run => 'Auto-update:',
10183: classlists => 'Updates to user information in classlists?'
10184: );
1.44 raeburn 10185: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10186: my %fieldtitles = &Apache::lonlocal::texthash (
10187: id => 'Student/Employee ID',
1.20 raeburn 10188: permanentemail => 'E-mail address',
1.1 raeburn 10189: lastname => 'Last Name',
10190: firstname => 'First Name',
10191: middlename => 'Middle Name',
1.132 raeburn 10192: generation => 'Generation',
1.1 raeburn 10193: );
1.142 raeburn 10194: $othertitle = &mt('All users');
1.1 raeburn 10195: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 10196: $othertitle = &mt('Other users');
1.1 raeburn 10197: }
10198: foreach my $key (keys(%env)) {
10199: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 10200: my ($usertype,$item) = ($1,$2);
10201: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
10202: if ($usertype eq 'default') {
10203: push(@{$fields{$1}},$2);
10204: } elsif (ref($types) eq 'ARRAY') {
10205: if (grep(/^\Q$usertype\E$/,@{$types})) {
10206: push(@{$fields{$1}},$2);
10207: }
10208: }
10209: }
1.1 raeburn 10210: }
10211: }
1.131 raeburn 10212: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
10213: @lockablenames = sort(@lockablenames);
10214: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
10215: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10216: if (@changed) {
10217: $changes{'lockablenames'} = 1;
10218: }
10219: } else {
10220: if (@lockablenames) {
10221: $changes{'lockablenames'} = 1;
10222: }
10223: }
1.1 raeburn 10224: my %updatehash = (
10225: autoupdate => { run => $env{'form.autoupdate_run'},
10226: classlists => $env{'form.classlists'},
10227: fields => {%fields},
1.131 raeburn 10228: lockablenames => \@lockablenames,
1.1 raeburn 10229: }
10230: );
10231: foreach my $key (keys(%currautoupdate)) {
10232: if (($key eq 'run') || ($key eq 'classlists')) {
10233: if (exists($updatehash{autoupdate}{$key})) {
10234: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
10235: $changes{$key} = 1;
10236: }
10237: }
10238: } elsif ($key eq 'fields') {
10239: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 10240: foreach my $item (@{$types},'default') {
1.1 raeburn 10241: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
10242: my $change = 0;
10243: foreach my $type (@{$currautoupdate{$key}{$item}}) {
10244: if (!exists($fields{$item})) {
10245: $change = 1;
1.132 raeburn 10246: last;
1.1 raeburn 10247: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 10248: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 10249: $change = 1;
1.132 raeburn 10250: last;
1.1 raeburn 10251: }
10252: }
10253: }
10254: if ($change) {
10255: push(@{$changes{$key}},$item);
10256: }
1.26 raeburn 10257: }
1.1 raeburn 10258: }
10259: }
1.131 raeburn 10260: } elsif ($key eq 'lockablenames') {
10261: if (ref($currautoupdate{$key}) eq 'ARRAY') {
10262: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10263: if (@changed) {
10264: $changes{'lockablenames'} = 1;
10265: }
10266: } else {
10267: if (@lockablenames) {
10268: $changes{'lockablenames'} = 1;
10269: }
10270: }
10271: }
10272: }
10273: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10274: if (@lockablenames) {
10275: $changes{'lockablenames'} = 1;
1.1 raeburn 10276: }
10277: }
1.26 raeburn 10278: foreach my $item (@{$types},'default') {
10279: if (defined($fields{$item})) {
10280: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 10281: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10282: my $change = 0;
10283: if (ref($fields{$item}) eq 'ARRAY') {
10284: foreach my $type (@{$fields{$item}}) {
10285: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10286: $change = 1;
10287: last;
10288: }
10289: }
10290: }
10291: if ($change) {
10292: push(@{$changes{'fields'}},$item);
10293: }
10294: } else {
1.26 raeburn 10295: push(@{$changes{'fields'}},$item);
10296: }
10297: } else {
10298: push(@{$changes{'fields'}},$item);
1.1 raeburn 10299: }
10300: }
10301: }
10302: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10303: $dom);
10304: if ($putresult eq 'ok') {
10305: if (keys(%changes) > 0) {
10306: $resulttext = &mt('Changes made:').'<ul>';
10307: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 10308: if ($key eq 'lockablenames') {
10309: $resulttext .= '<li>';
10310: if (@lockablenames) {
10311: $usertypes->{'default'} = $othertitle;
10312: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10313: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10314: } else {
10315: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10316: }
10317: $resulttext .= '</li>';
10318: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 10319: foreach my $item (@{$changes{$key}}) {
10320: my @newvalues;
10321: foreach my $type (@{$fields{$item}}) {
10322: push(@newvalues,$fieldtitles{$type});
10323: }
1.3 raeburn 10324: my $newvaluestr;
10325: if (@newvalues > 0) {
10326: $newvaluestr = join(', ',@newvalues);
10327: } else {
10328: $newvaluestr = &mt('none');
1.6 raeburn 10329: }
1.1 raeburn 10330: if ($item eq 'default') {
1.26 raeburn 10331: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 10332: } else {
1.26 raeburn 10333: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 10334: }
10335: }
10336: } else {
10337: my $newvalue;
10338: if ($key eq 'run') {
10339: $newvalue = $offon[$env{'form.autoupdate_run'}];
10340: } else {
10341: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 10342: }
1.1 raeburn 10343: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
10344: }
10345: }
10346: $resulttext .= '</ul>';
10347: } else {
1.3 raeburn 10348: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 10349: }
10350: } else {
1.11 albertel 10351: $resulttext = '<span class="LC_error">'.
10352: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10353: }
1.3 raeburn 10354: return $resulttext;
1.1 raeburn 10355: }
10356:
1.125 raeburn 10357: sub modify_autocreate {
10358: my ($dom,%domconfig) = @_;
10359: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10360: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10361: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10362: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10363: }
10364: }
10365: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10366: req => 'Auto-creation of validated requests for official courses',
10367: xmldc => 'Identity of course creator of courses from XML files',
10368: );
10369: my @types = ('xml','req');
10370: foreach my $item (@types) {
10371: $newvals{$item} = $env{'form.autocreate_'.$item};
10372: $newvals{$item} =~ s/\D//g;
10373: $newvals{$item} = 0 if ($newvals{$item} eq '');
10374: }
10375: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 10376: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 10377: unless (exists($domcoords{$newvals{'xmldc'}})) {
10378: $newvals{'xmldc'} = '';
10379: }
10380: %autocreatehash = (
10381: autocreate => { xml => $newvals{'xml'},
10382: req => $newvals{'req'},
10383: }
10384: );
10385: if ($newvals{'xmldc'} ne '') {
10386: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10387: }
10388: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10389: $dom);
10390: if ($putresult eq 'ok') {
10391: my @items = @types;
10392: if ($newvals{'xml'}) {
10393: push(@items,'xmldc');
10394: }
10395: foreach my $item (@items) {
10396: if (exists($currautocreate{$item})) {
10397: if ($currautocreate{$item} ne $newvals{$item}) {
10398: $changes{$item} = 1;
10399: }
10400: } elsif ($newvals{$item}) {
10401: $changes{$item} = 1;
10402: }
10403: }
10404: if (keys(%changes) > 0) {
10405: my @offon = ('off','on');
10406: $resulttext = &mt('Changes made:').'<ul>';
10407: foreach my $item (@types) {
10408: if ($changes{$item}) {
10409: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 10410: $resulttext .= '<li>'.
10411: &mt("$title{$item} set to [_1]$newtxt [_2]",
10412: '<b>','</b>').
10413: '</li>';
1.125 raeburn 10414: }
10415: }
10416: if ($changes{'xmldc'}) {
10417: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10418: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 10419: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 10420: }
10421: $resulttext .= '</ul>';
10422: } else {
10423: $resulttext = &mt('No changes made to auto-creation settings');
10424: }
10425: } else {
10426: $resulttext = '<span class="LC_error">'.
10427: &mt('An error occurred: [_1]',$putresult).'</span>';
10428: }
10429: return $resulttext;
10430: }
10431:
1.23 raeburn 10432: sub modify_directorysrch {
1.295 raeburn 10433: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 10434: my ($resulttext,%changes);
10435: my %currdirsrch;
10436: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10437: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10438: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10439: }
10440: }
1.277 raeburn 10441: my %title = ( available => 'Institutional directory search available',
10442: localonly => 'Other domains can search institution',
10443: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 10444: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 10445: searchby => 'Search types',
10446: searchtypes => 'Search latitude');
10447: my @offon = ('off','on');
1.24 raeburn 10448: my @otherdoms = ('Yes','No');
1.23 raeburn 10449:
1.25 raeburn 10450: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 10451: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10452: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10453:
1.44 raeburn 10454: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 10455: if (keys(%{$usertypes}) == 0) {
10456: @cansearch = ('default');
10457: } else {
10458: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10459: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10460: if (!grep(/^\Q$type\E$/,@cansearch)) {
10461: push(@{$changes{'cansearch'}},$type);
10462: }
1.23 raeburn 10463: }
1.26 raeburn 10464: foreach my $type (@cansearch) {
10465: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10466: push(@{$changes{'cansearch'}},$type);
10467: }
1.23 raeburn 10468: }
1.26 raeburn 10469: } else {
10470: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 10471: }
10472: }
10473:
10474: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10475: foreach my $by (@{$currdirsrch{'searchby'}}) {
10476: if (!grep(/^\Q$by\E$/,@searchby)) {
10477: push(@{$changes{'searchby'}},$by);
10478: }
10479: }
10480: foreach my $by (@searchby) {
10481: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10482: push(@{$changes{'searchby'}},$by);
10483: }
10484: }
10485: } else {
10486: push(@{$changes{'searchby'}},@searchby);
10487: }
1.25 raeburn 10488:
10489: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10490: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10491: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10492: push(@{$changes{'searchtypes'}},$type);
10493: }
10494: }
10495: foreach my $type (@searchtypes) {
10496: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10497: push(@{$changes{'searchtypes'}},$type);
10498: }
10499: }
10500: } else {
10501: if (exists($currdirsrch{'searchtypes'})) {
10502: foreach my $type (@searchtypes) {
10503: if ($type ne $currdirsrch{'searchtypes'}) {
10504: push(@{$changes{'searchtypes'}},$type);
10505: }
10506: }
10507: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10508: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10509: }
10510: } else {
10511: push(@{$changes{'searchtypes'}},@searchtypes);
10512: }
10513: }
10514:
1.23 raeburn 10515: my %dirsrch_hash = (
10516: directorysrch => { available => $env{'form.dirsrch_available'},
10517: cansearch => \@cansearch,
1.277 raeburn 10518: localonly => $env{'form.dirsrch_instlocalonly'},
10519: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10520: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 10521: searchby => \@searchby,
1.25 raeburn 10522: searchtypes => \@searchtypes,
1.23 raeburn 10523: }
10524: );
10525: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10526: $dom);
10527: if ($putresult eq 'ok') {
10528: if (exists($currdirsrch{'available'})) {
10529: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10530: $changes{'available'} = 1;
10531: }
10532: } else {
10533: if ($env{'form.dirsrch_available'} eq '1') {
10534: $changes{'available'} = 1;
10535: }
10536: }
1.277 raeburn 10537: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 10538: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
10539: $changes{'lcavailable'} = 1;
10540: }
1.277 raeburn 10541: } else {
10542: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10543: $changes{'lcavailable'} = 1;
10544: }
10545: }
1.24 raeburn 10546: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 10547: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
10548: $changes{'localonly'} = 1;
10549: }
1.24 raeburn 10550: } else {
1.277 raeburn 10551: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 10552: $changes{'localonly'} = 1;
10553: }
10554: }
1.277 raeburn 10555: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 10556: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
10557: $changes{'lclocalonly'} = 1;
10558: }
1.277 raeburn 10559: } else {
10560: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10561: $changes{'lclocalonly'} = 1;
10562: }
10563: }
1.23 raeburn 10564: if (keys(%changes) > 0) {
10565: $resulttext = &mt('Changes made:').'<ul>';
10566: if ($changes{'available'}) {
10567: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10568: }
1.277 raeburn 10569: if ($changes{'lcavailable'}) {
10570: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10571: }
1.24 raeburn 10572: if ($changes{'localonly'}) {
1.277 raeburn 10573: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 10574: }
1.277 raeburn 10575: if ($changes{'lclocalonly'}) {
10576: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 10577: }
1.23 raeburn 10578: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10579: my $chgtext;
1.26 raeburn 10580: if (ref($usertypes) eq 'HASH') {
10581: if (keys(%{$usertypes}) > 0) {
10582: foreach my $type (@{$types}) {
10583: if (grep(/^\Q$type\E$/,@cansearch)) {
10584: $chgtext .= $usertypes->{$type}.'; ';
10585: }
10586: }
10587: if (grep(/^default$/,@cansearch)) {
10588: $chgtext .= $othertitle;
10589: } else {
10590: $chgtext =~ s/\; $//;
10591: }
1.210 raeburn 10592: $resulttext .=
1.178 raeburn 10593: '<li>'.
10594: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10595: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10596: '</li>';
1.23 raeburn 10597: }
10598: }
10599: }
10600: if (ref($changes{'searchby'}) eq 'ARRAY') {
10601: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10602: my $chgtext;
10603: foreach my $type (@{$titleorder}) {
10604: if (grep(/^\Q$type\E$/,@searchby)) {
10605: if (defined($searchtitles->{$type})) {
10606: $chgtext .= $searchtitles->{$type}.'; ';
10607: }
10608: }
10609: }
10610: $chgtext =~ s/\; $//;
10611: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10612: }
1.25 raeburn 10613: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10614: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10615: my $chgtext;
10616: foreach my $type (@{$srchtypeorder}) {
10617: if (grep(/^\Q$type\E$/,@searchtypes)) {
10618: if (defined($srchtypes_desc->{$type})) {
10619: $chgtext .= $srchtypes_desc->{$type}.'; ';
10620: }
10621: }
10622: }
10623: $chgtext =~ s/\; $//;
1.178 raeburn 10624: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 10625: }
10626: $resulttext .= '</ul>';
1.295 raeburn 10627: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
10628: if (ref($lastactref) eq 'HASH') {
10629: $lastactref->{'directorysrch'} = 1;
10630: }
1.23 raeburn 10631: } else {
1.277 raeburn 10632: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 10633: }
10634: } else {
10635: $resulttext = '<span class="LC_error">'.
1.27 raeburn 10636: &mt('An error occurred: [_1]',$putresult).'</span>';
10637: }
10638: return $resulttext;
10639: }
10640:
1.28 raeburn 10641: sub modify_contacts {
1.205 raeburn 10642: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 10643: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10644: if (ref($domconfig{'contacts'}) eq 'HASH') {
10645: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10646: $currsetting{$key} = $domconfig{'contacts'}{$key};
10647: }
10648: }
1.286 raeburn 10649: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 10650: my @contacts = ('supportemail','adminemail');
1.286 raeburn 10651: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
10652: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 10653: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 10654: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 10655: foreach my $type (@mailings) {
10656: @{$newsetting{$type}} =
10657: &Apache::loncommon::get_env_multiple('form.'.$type);
10658: foreach my $item (@contacts) {
10659: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
10660: $contacts_hash{contacts}{$type}{$item} = 1;
10661: } else {
10662: $contacts_hash{contacts}{$type}{$item} = 0;
10663: }
1.289 raeburn 10664: }
1.28 raeburn 10665: $others{$type} = $env{'form.'.$type.'_others'};
10666: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 10667: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10668: $bcc{$type} = $env{'form.'.$type.'_bcc'};
10669: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 10670: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
10671: $includestr{$type} = $env{'form.'.$type.'_includestr'};
10672: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
10673: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10674: }
1.134 raeburn 10675: }
1.28 raeburn 10676: }
10677: foreach my $item (@contacts) {
10678: $to{$item} = $env{'form.'.$item};
10679: $contacts_hash{'contacts'}{$item} = $to{$item};
10680: }
1.203 raeburn 10681: foreach my $item (@toggles) {
10682: if ($env{'form.'.$item} =~ /^(0|1)$/) {
10683: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
10684: }
10685: }
1.286 raeburn 10686: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
10687: foreach my $field (@{$fields}) {
10688: if (ref($possoptions->{$field}) eq 'ARRAY') {
10689: my $value = $env{'form.helpform_'.$field};
10690: $value =~ s/^\s+|\s+$//g;
10691: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
10692: $contacts_hash{contacts}{'helpform'}{$field} = $value;
10693: if ($field eq 'screenshot') {
10694: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
10695: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
10696: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
10697: }
10698: }
10699: }
10700: }
10701: }
10702: }
1.28 raeburn 10703: if (keys(%currsetting) > 0) {
10704: foreach my $item (@contacts) {
10705: if ($to{$item} ne $currsetting{$item}) {
10706: $changes{$item} = 1;
10707: }
10708: }
10709: foreach my $type (@mailings) {
10710: foreach my $item (@contacts) {
10711: if (ref($currsetting{$type}) eq 'HASH') {
10712: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
10713: push(@{$changes{$type}},$item);
10714: }
10715: } else {
10716: push(@{$changes{$type}},@{$newsetting{$type}});
10717: }
10718: }
10719: if ($others{$type} ne $currsetting{$type}{'others'}) {
10720: push(@{$changes{$type}},'others');
10721: }
1.289 raeburn 10722: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10723: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
10724: push(@{$changes{$type}},'bcc');
10725: }
1.286 raeburn 10726: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
10727: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
10728: push(@{$changes{$type}},'include');
10729: }
10730: }
10731: }
10732: if (ref($fields) eq 'ARRAY') {
10733: if (ref($currsetting{'helpform'}) eq 'HASH') {
10734: foreach my $field (@{$fields}) {
10735: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
10736: push(@{$changes{'helpform'}},$field);
10737: }
10738: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10739: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
10740: push(@{$changes{'helpform'}},'maxsize');
10741: }
10742: }
10743: }
10744: } else {
10745: foreach my $field (@{$fields}) {
10746: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10747: push(@{$changes{'helpform'}},$field);
10748: }
10749: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10750: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10751: push(@{$changes{'helpform'}},'maxsize');
10752: }
10753: }
10754: }
1.134 raeburn 10755: }
1.28 raeburn 10756: }
10757: } else {
10758: my %default;
10759: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
10760: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
10761: $default{'errormail'} = 'adminemail';
10762: $default{'packagesmail'} = 'adminemail';
10763: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 10764: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 10765: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 10766: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 10767: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 10768: foreach my $item (@contacts) {
10769: if ($to{$item} ne $default{$item}) {
1.286 raeburn 10770: $changes{$item} = 1;
1.203 raeburn 10771: }
1.28 raeburn 10772: }
10773: foreach my $type (@mailings) {
10774: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
10775: push(@{$changes{$type}},@{$newsetting{$type}});
10776: }
10777: if ($others{$type} ne '') {
10778: push(@{$changes{$type}},'others');
1.134 raeburn 10779: }
1.286 raeburn 10780: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10781: if ($bcc{$type} ne '') {
10782: push(@{$changes{$type}},'bcc');
10783: }
1.286 raeburn 10784: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
10785: push(@{$changes{$type}},'include');
10786: }
1.134 raeburn 10787: }
1.28 raeburn 10788: }
1.286 raeburn 10789: if (ref($fields) eq 'ARRAY') {
10790: foreach my $field (@{$fields}) {
10791: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10792: push(@{$changes{'helpform'}},$field);
10793: }
10794: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10795: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10796: push(@{$changes{'helpform'}},'maxsize');
10797: }
10798: }
10799: }
1.289 raeburn 10800: }
1.28 raeburn 10801: }
1.203 raeburn 10802: foreach my $item (@toggles) {
10803: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
10804: $changes{$item} = 1;
10805: } elsif ((!$env{'form.'.$item}) &&
10806: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
10807: $changes{$item} = 1;
10808: }
10809: }
1.28 raeburn 10810: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
10811: $dom);
10812: if ($putresult eq 'ok') {
10813: if (keys(%changes) > 0) {
1.205 raeburn 10814: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10815: if (ref($lastactref) eq 'HASH') {
10816: $lastactref->{'domainconfig'} = 1;
10817: }
1.28 raeburn 10818: my ($titles,$short_titles) = &contact_titles();
10819: $resulttext = &mt('Changes made:').'<ul>';
10820: foreach my $item (@contacts) {
10821: if ($changes{$item}) {
10822: $resulttext .= '<li>'.$titles->{$item}.
10823: &mt(' set to: ').
10824: '<span class="LC_cusr_emph">'.
10825: $to{$item}.'</span></li>';
10826: }
10827: }
10828: foreach my $type (@mailings) {
10829: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 10830: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 10831: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 10832: } else {
10833: $resulttext .= '<li>'.$titles->{$type}.': ';
10834: }
1.28 raeburn 10835: my @text;
10836: foreach my $item (@{$newsetting{$type}}) {
10837: push(@text,$short_titles->{$item});
10838: }
10839: if ($others{$type} ne '') {
10840: push(@text,$others{$type});
10841: }
1.286 raeburn 10842: if (@text) {
10843: $resulttext .= '<span class="LC_cusr_emph">'.
10844: join(', ',@text).'</span>';
10845: }
10846: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10847: if ($bcc{$type} ne '') {
1.286 raeburn 10848: my $bcctext;
10849: if (@text) {
1.289 raeburn 10850: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 10851: } else {
10852: $bcctext = '(Bcc)';
10853: }
10854: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10855: } elsif (!@text) {
10856: $resulttext .= &mt('No one');
10857: }
1.289 raeburn 10858: if ($includestr{$type} ne '') {
1.286 raeburn 10859: if ($includeloc{$type} eq 'b') {
10860: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
10861: } elsif ($includeloc{$type} eq 's') {
10862: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
10863: }
1.134 raeburn 10864: }
1.286 raeburn 10865: } elsif (!@text) {
10866: $resulttext .= &mt('No recipients');
1.134 raeburn 10867: }
10868: $resulttext .= '</li>';
1.28 raeburn 10869: }
10870: }
1.203 raeburn 10871: my @offon = ('off','on');
10872: if ($changes{'reporterrors'}) {
10873: $resulttext .= '<li>'.
10874: &mt('E-mail error reports to [_1] set to "'.
10875: $offon[$env{'form.reporterrors'}].'".',
10876: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10877: &mt('LON-CAPA core group - MSU'),600,500)).
10878: '</li>';
10879: }
10880: if ($changes{'reportupdates'}) {
10881: $resulttext .= '<li>'.
10882: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
10883: $offon[$env{'form.reportupdates'}].'".',
10884: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10885: &mt('LON-CAPA core group - MSU'),600,500)).
10886: '</li>';
10887: }
1.286 raeburn 10888: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
10889: my (@optional,@required,@unused,$maxsizechg);
10890: foreach my $field (@{$changes{'helpform'}}) {
10891: if ($field eq 'maxsize') {
10892: $maxsizechg = 1;
10893: next;
10894: }
10895: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 10896: push(@optional,$field);
1.286 raeburn 10897: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
10898: push(@unused,$field);
10899: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 10900: push(@required,$field);
1.286 raeburn 10901: }
10902: }
10903: if (@optional) {
10904: $resulttext .= '<li>'.
10905: &mt('Help form fields changed to "Optional": [_1].',
10906: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
10907: '</li>';
10908: }
10909: if (@required) {
10910: $resulttext .= '<li>'.
10911: &mt('Help form fields changed to "Required": [_1].',
10912: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
10913: '</li>';
10914: }
10915: if (@unused) {
10916: $resulttext .= '<li>'.
10917: &mt('Help form fields changed to "Not shown": [_1].',
10918: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
10919: '</li>';
10920: }
10921: if ($maxsizechg) {
10922: $resulttext .= '<li>'.
10923: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
10924: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
10925: '</li>';
10926:
10927: }
10928: }
1.28 raeburn 10929: $resulttext .= '</ul>';
10930: } else {
1.288 raeburn 10931: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 10932: }
10933: } else {
10934: $resulttext = '<span class="LC_error">'.
10935: &mt('An error occurred: [_1].',$putresult).'</span>';
10936: }
10937: return $resulttext;
10938: }
10939:
10940: sub modify_usercreation {
1.27 raeburn 10941: my ($dom,%domconfig) = @_;
1.224 raeburn 10942: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 10943: my $warningmsg;
1.27 raeburn 10944: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10945: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 10946: if ($key eq 'cancreate') {
10947: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10948: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10949: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269 raeburn 10950: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
10951: ($item eq 'recaptchaversion')) {
1.224 raeburn 10952: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10953: } else {
10954: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10955: }
10956: }
10957: }
10958: } elsif ($key eq 'email_rule') {
10959: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10960: } else {
10961: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10962: }
1.27 raeburn 10963: }
10964: }
10965: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 10966: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 10967: my @contexts = ('author','course','requestcrs');
1.34 raeburn 10968: foreach my $item(@contexts) {
1.224 raeburn 10969: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 10970: }
1.34 raeburn 10971: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10972: foreach my $item (@contexts) {
1.224 raeburn 10973: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
10974: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 10975: }
1.27 raeburn 10976: }
1.34 raeburn 10977: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
10978: foreach my $item (@contexts) {
1.43 raeburn 10979: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 10980: if ($cancreate{$item} ne 'any') {
10981: push(@{$changes{'cancreate'}},$item);
10982: }
10983: } else {
10984: if ($cancreate{$item} ne 'none') {
10985: push(@{$changes{'cancreate'}},$item);
10986: }
1.27 raeburn 10987: }
10988: }
10989: } else {
1.43 raeburn 10990: foreach my $item (@contexts) {
1.34 raeburn 10991: push(@{$changes{'cancreate'}},$item);
10992: }
1.27 raeburn 10993: }
1.34 raeburn 10994:
1.27 raeburn 10995: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
10996: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
10997: if (!grep(/^\Q$type\E$/,@username_rule)) {
10998: push(@{$changes{'username_rule'}},$type);
10999: }
11000: }
11001: foreach my $type (@username_rule) {
11002: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
11003: push(@{$changes{'username_rule'}},$type);
11004: }
11005: }
11006: } else {
11007: push(@{$changes{'username_rule'}},@username_rule);
11008: }
11009:
1.32 raeburn 11010: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
11011: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
11012: if (!grep(/^\Q$type\E$/,@id_rule)) {
11013: push(@{$changes{'id_rule'}},$type);
11014: }
11015: }
11016: foreach my $type (@id_rule) {
11017: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
11018: push(@{$changes{'id_rule'}},$type);
11019: }
11020: }
11021: } else {
11022: push(@{$changes{'id_rule'}},@id_rule);
11023: }
11024:
1.43 raeburn 11025: my @authen_contexts = ('author','course','domain');
1.28 raeburn 11026: my @authtypes = ('int','krb4','krb5','loc');
11027: my %authhash;
1.43 raeburn 11028: foreach my $item (@authen_contexts) {
1.28 raeburn 11029: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
11030: foreach my $auth (@authtypes) {
11031: if (grep(/^\Q$auth\E$/,@authallowed)) {
11032: $authhash{$item}{$auth} = 1;
11033: } else {
11034: $authhash{$item}{$auth} = 0;
11035: }
11036: }
11037: }
11038: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 11039: foreach my $item (@authen_contexts) {
1.28 raeburn 11040: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
11041: foreach my $auth (@authtypes) {
11042: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
11043: push(@{$changes{'authtypes'}},$item);
11044: last;
11045: }
11046: }
11047: }
11048: }
11049: } else {
1.43 raeburn 11050: foreach my $item (@authen_contexts) {
1.28 raeburn 11051: push(@{$changes{'authtypes'}},$item);
11052: }
11053: }
11054:
1.224 raeburn 11055: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
11056: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
11057: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
11058: $save_usercreate{'id_rule'} = \@id_rule;
11059: $save_usercreate{'username_rule'} = \@username_rule,
11060: $save_usercreate{'authtypes'} = \%authhash;
11061:
1.27 raeburn 11062: my %usercreation_hash = (
1.224 raeburn 11063: usercreation => \%save_usercreate,
11064: );
1.27 raeburn 11065:
11066: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
11067: $dom);
1.50 raeburn 11068:
1.224 raeburn 11069: if ($putresult eq 'ok') {
11070: if (keys(%changes) > 0) {
11071: $resulttext = &mt('Changes made:').'<ul>';
11072: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11073: my %lt = &usercreation_types();
11074: foreach my $type (@{$changes{'cancreate'}}) {
11075: my $chgtext = $lt{$type}.', ';
11076: if ($cancreate{$type} eq 'none') {
11077: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
11078: } elsif ($cancreate{$type} eq 'any') {
11079: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
11080: } elsif ($cancreate{$type} eq 'official') {
11081: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
11082: } elsif ($cancreate{$type} eq 'unofficial') {
11083: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
11084: }
11085: $resulttext .= '<li>'.$chgtext.'</li>';
11086: }
11087: }
11088: if (ref($changes{'username_rule'}) eq 'ARRAY') {
11089: my ($rules,$ruleorder) =
11090: &Apache::lonnet::inst_userrules($dom,'username');
11091: my $chgtext = '<ul>';
11092: foreach my $type (@username_rule) {
11093: if (ref($rules->{$type}) eq 'HASH') {
11094: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
11095: }
11096: }
11097: $chgtext .= '</ul>';
11098: if (@username_rule > 0) {
11099: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11100: } else {
11101: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
11102: }
11103: }
11104: if (ref($changes{'id_rule'}) eq 'ARRAY') {
11105: my ($idrules,$idruleorder) =
11106: &Apache::lonnet::inst_userrules($dom,'id');
11107: my $chgtext = '<ul>';
11108: foreach my $type (@id_rule) {
11109: if (ref($idrules->{$type}) eq 'HASH') {
11110: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
11111: }
11112: }
11113: $chgtext .= '</ul>';
11114: if (@id_rule > 0) {
11115: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11116: } else {
11117: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
11118: }
11119: }
11120: my %authname = &authtype_names();
11121: my %context_title = &context_names();
11122: if (ref($changes{'authtypes'}) eq 'ARRAY') {
11123: my $chgtext = '<ul>';
11124: foreach my $type (@{$changes{'authtypes'}}) {
11125: my @allowed;
11126: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
11127: foreach my $auth (@authtypes) {
11128: if ($authhash{$type}{$auth}) {
11129: push(@allowed,$authname{$auth});
11130: }
11131: }
11132: if (@allowed > 0) {
11133: $chgtext .= join(', ',@allowed).'</li>';
11134: } else {
11135: $chgtext .= &mt('none').'</li>';
11136: }
11137: }
11138: $chgtext .= '</ul>';
11139: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
11140: $resulttext .= '</li>';
11141: }
11142: $resulttext .= '</ul>';
11143: } else {
11144: $resulttext = &mt('No changes made to user creation settings');
11145: }
11146: } else {
11147: $resulttext = '<span class="LC_error">'.
11148: &mt('An error occurred: [_1]',$putresult).'</span>';
11149: }
11150: if ($warningmsg ne '') {
11151: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11152: }
11153: return $resulttext;
11154: }
11155:
11156: sub modify_selfcreation {
11157: my ($dom,%domconfig) = @_;
11158: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
11159: my (%save_usercreate,%save_usermodify);
1.228 raeburn 11160: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11161: if (ref($types) eq 'ARRAY') {
11162: $usertypes->{'default'} = $othertitle;
11163: push(@{$types},'default');
11164: }
1.224 raeburn 11165: #
11166: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
11167: #
11168: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11169: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11170: if ($key eq 'cancreate') {
11171: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11172: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11173: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
11174: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.269 raeburn 11175: ($item eq 'recaptchaversion') ||
1.236 raeburn 11176: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 11177: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 11178: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11179: } else {
11180: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11181: }
11182: }
11183: }
11184: } elsif ($key eq 'email_rule') {
11185: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11186: } else {
11187: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11188: }
11189: }
11190: }
11191: #
11192: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
11193: #
11194: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11195: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11196: if ($key eq 'selfcreate') {
11197: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
11198: } else {
11199: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
11200: }
11201: }
11202: }
11203:
11204: my @contexts = ('selfcreate');
11205: @{$cancreate{'selfcreate'}} = ();
11206: %{$cancreate{'emailusername'}} = ();
11207: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 11208: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 11209: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 11210: my %selfcreatetypes = (
11211: sso => 'users authenticated by institutional single sign on',
11212: login => 'users authenticated by institutional log-in',
1.236 raeburn 11213: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 11214: );
1.224 raeburn 11215: #
11216: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
11217: # is permitted.
11218: #
1.236 raeburn 11219:
11220: my @statuses;
11221: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11222: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
11223: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
11224: }
11225: }
11226: push(@statuses,'default');
11227:
1.228 raeburn 11228: foreach my $item ('login','sso','email') {
1.224 raeburn 11229: if ($item eq 'email') {
1.236 raeburn 11230: if ($env{'form.cancreate_email'}) {
1.224 raeburn 11231: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 11232: push(@contexts,'selfcreateprocessing');
11233: foreach my $type (@statuses) {
11234: if ($type eq 'default') {
11235: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
11236: } else {
11237: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
11238: }
11239: }
1.224 raeburn 11240: }
11241: } else {
11242: if ($env{'form.cancreate_'.$item}) {
11243: push(@{$cancreate{'selfcreate'}},$item);
11244: }
11245: }
11246: }
11247: my (@email_rule,%userinfo,%savecaptcha);
11248: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
11249: #
1.228 raeburn 11250: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
11251: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 11252: #
1.236 raeburn 11253:
1.244 raeburn 11254: if ($env{'form.cancreate_email'}) {
1.228 raeburn 11255: push(@contexts,'emailusername');
11256: if (ref($types) eq 'ARRAY') {
11257: foreach my $type (@{$types}) {
11258: if (ref($infofields) eq 'ARRAY') {
11259: foreach my $field (@{$infofields}) {
11260: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
11261: $cancreate{'emailusername'}{$type}{$field} = $1;
11262: }
11263: }
1.224 raeburn 11264: }
11265: }
11266: }
11267: #
11268: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
11269: # queued requests for self-creation of account using e-mail address as username
11270: #
11271:
11272: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
11273: @approvalnotify = sort(@approvalnotify);
11274: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
11275: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11276: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11277: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11278: push(@{$changes{'cancreate'}},'notify');
11279: }
11280: } else {
11281: if ($cancreate{'notify'}{'approval'}) {
11282: push(@{$changes{'cancreate'}},'notify');
11283: }
11284: }
11285: } elsif ($cancreate{'notify'}{'approval'}) {
11286: push(@{$changes{'cancreate'}},'notify');
11287: }
11288:
11289: #
11290: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
11291: #
11292: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
11293: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11294: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11295: if (@{$curr_usercreation{'email_rule'}} > 0) {
11296: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
11297: if (!grep(/^\Q$type\E$/,@email_rule)) {
11298: push(@{$changes{'email_rule'}},$type);
11299: }
11300: }
11301: }
11302: if (@email_rule > 0) {
11303: foreach my $type (@email_rule) {
11304: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
11305: push(@{$changes{'email_rule'}},$type);
11306: }
11307: }
11308: }
11309: } elsif (@email_rule > 0) {
11310: push(@{$changes{'email_rule'}},@email_rule);
11311: }
11312: }
11313: #
1.236 raeburn 11314: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 11315: # institutional log-in.
11316: #
11317: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11318: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11319: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11320: ($domdefaults{'auth_def'} eq 'localauth'))) {
11321: $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.').' '.
11322: &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.');
11323: }
11324: }
11325: my @fields = ('lastname','firstname','middlename','generation',
11326: 'permanentemail','id');
1.240 raeburn 11327: my @shibfields = (@fields,'inststatus');
1.224 raeburn 11328: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11329: #
11330: # Where usernames may created for institutional log-in and/or institutional single sign on:
11331: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11332: # may self-create accounts
11333: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11334: # which the user may supply, if institutional data is unavailable.
11335: #
11336: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
11337: if (ref($types) eq 'ARRAY') {
1.228 raeburn 11338: if (@{$types} > 1) {
1.224 raeburn 11339: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11340: push(@contexts,'statustocreate');
11341: } else {
11342: undef($cancreate{'statustocreate'});
11343: }
11344: foreach my $type (@{$types}) {
11345: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11346: foreach my $field (@fields) {
11347: if (grep(/^\Q$field\E$/,@modifiable)) {
11348: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11349: } else {
11350: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11351: }
11352: }
11353: }
11354: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
11355: foreach my $type (@{$types}) {
11356: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11357: foreach my $field (@fields) {
11358: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11359: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11360: push(@{$changes{'selfcreate'}},$type);
11361: last;
11362: }
11363: }
11364: }
11365: }
11366: } else {
11367: foreach my $type (@{$types}) {
11368: push(@{$changes{'selfcreate'}},$type);
11369: }
11370: }
11371: }
1.240 raeburn 11372: foreach my $field (@shibfields) {
11373: if ($env{'form.shibenv_'.$field} ne '') {
11374: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11375: }
11376: }
11377: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11378: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11379: foreach my $field (@shibfields) {
11380: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11381: push(@{$changes{'cancreate'}},'shibenv');
11382: }
11383: }
11384: } else {
11385: foreach my $field (@shibfields) {
11386: if ($env{'form.shibenv_'.$field}) {
11387: push(@{$changes{'cancreate'}},'shibenv');
11388: last;
11389: }
11390: }
11391: }
11392: }
1.224 raeburn 11393: }
11394: foreach my $item (@contexts) {
11395: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11396: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11397: if (ref($cancreate{$item}) eq 'ARRAY') {
11398: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11399: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11400: push(@{$changes{'cancreate'}},$item);
11401: }
11402: }
11403: }
11404: }
11405: if (ref($cancreate{$item}) eq 'ARRAY') {
11406: foreach my $type (@{$cancreate{$item}}) {
11407: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11408: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11409: push(@{$changes{'cancreate'}},$item);
11410: }
11411: }
11412: }
11413: }
11414: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11415: if (ref($cancreate{$item}) eq 'HASH') {
11416: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 11417: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
11418: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
11419: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
11420: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11421: push(@{$changes{'cancreate'}},$item);
11422: }
11423: }
11424: }
1.236 raeburn 11425: } elsif ($item eq 'selfcreateprocessing') {
11426: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
11427: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11428: push(@{$changes{'cancreate'}},$item);
11429: }
11430: }
1.228 raeburn 11431: } else {
11432: if (!$cancreate{$item}{$curr}) {
11433: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11434: push(@{$changes{'cancreate'}},$item);
11435: }
1.224 raeburn 11436: }
11437: }
11438: }
11439: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 11440: if (ref($cancreate{$item}{$field}) eq 'HASH') {
11441: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
11442: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
11443: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
11444: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11445: push(@{$changes{'cancreate'}},$item);
11446: }
11447: }
11448: } else {
11449: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11450: push(@{$changes{'cancreate'}},$item);
11451: }
11452: }
11453: }
1.236 raeburn 11454: } elsif ($item eq 'selfcreateprocessing') {
11455: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
11456: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11457: push(@{$changes{'cancreate'}},$item);
11458: }
11459: }
1.228 raeburn 11460: } else {
11461: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
11462: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11463: push(@{$changes{'cancreate'}},$item);
11464: }
1.224 raeburn 11465: }
11466: }
11467: }
11468: }
11469: } elsif ($curr_usercreation{'cancreate'}{$item}) {
11470: if (ref($cancreate{$item}) eq 'ARRAY') {
11471: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
11472: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11473: push(@{$changes{'cancreate'}},$item);
11474: }
11475: }
11476: } elsif (ref($cancreate{$item}) eq 'HASH') {
11477: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
11478: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11479: push(@{$changes{'cancreate'}},$item);
11480: }
11481: }
11482: }
11483: } elsif ($item eq 'emailusername') {
1.228 raeburn 11484: if (ref($cancreate{$item}) eq 'HASH') {
11485: foreach my $type (keys(%{$cancreate{$item}})) {
11486: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11487: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11488: if ($cancreate{$item}{$type}{$field}) {
11489: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11490: push(@{$changes{'cancreate'}},$item);
11491: }
11492: last;
11493: }
11494: }
11495: }
11496: }
1.224 raeburn 11497: }
11498: }
11499: }
11500: #
11501: # Populate %save_usercreate hash with updates to self-creation configuration.
11502: #
11503: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
11504: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 11505: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 11506: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
11507: if (ref($cancreate{'notify'}) eq 'HASH') {
11508: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
11509: }
1.236 raeburn 11510: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
11511: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
11512: }
1.224 raeburn 11513: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11514: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
11515: }
1.240 raeburn 11516: if (ref($cancreate{'shibenv'}) eq 'HASH') {
11517: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
11518: }
1.224 raeburn 11519: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
11520: $save_usercreate{'emailrule'} = \@email_rule;
11521:
11522: my %userconfig_hash = (
11523: usercreation => \%save_usercreate,
11524: usermodification => \%save_usermodify,
11525: );
11526: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
11527: $dom);
11528: #
11529: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
11530: #
1.27 raeburn 11531: if ($putresult eq 'ok') {
11532: if (keys(%changes) > 0) {
11533: $resulttext = &mt('Changes made:').'<ul>';
11534: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 11535: my %lt = &selfcreation_types();
1.34 raeburn 11536: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 11537: my $chgtext;
1.45 raeburn 11538: if ($type eq 'selfcreate') {
1.50 raeburn 11539: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 11540: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 11541: } else {
1.224 raeburn 11542: $chgtext .= &mt('Self-creation of a new account is permitted for:').
11543: '<ul>';
1.50 raeburn 11544: foreach my $case (@{$cancreate{$type}}) {
11545: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
11546: }
11547: $chgtext .= '</ul>';
1.100 raeburn 11548: if (ref($cancreate{$type}) eq 'ARRAY') {
11549: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
11550: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11551: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 11552: $chgtext .= '<br />'.
11553: '<span class="LC_warning">'.
11554: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11555: '</span>';
1.100 raeburn 11556: }
11557: }
11558: }
11559: }
1.43 raeburn 11560: }
1.240 raeburn 11561: } elsif ($type eq 'shibenv') {
11562: if (keys(%{$cancreate{$type}}) == 0) {
11563: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
11564: } else {
11565: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
11566: '<ul>';
11567: foreach my $field (@shibfields) {
11568: next if ($cancreate{$type}{$field} eq '');
11569: if ($field eq 'inststatus') {
11570: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
11571: } else {
11572: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
11573: }
11574: }
11575: $chgtext .= '</ul>';
11576: }
1.93 raeburn 11577: } elsif ($type eq 'statustocreate') {
1.96 raeburn 11578: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
11579: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
11580: if (@{$cancreate{'selfcreate'}} > 0) {
11581: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 11582: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 11583: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 11584: $chgtext .= '<br />'.
11585: '<span class="LC_warning">'.
11586: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11587: '</span>';
11588: }
1.96 raeburn 11589: } elsif (ref($usertypes) eq 'HASH') {
11590: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 11591: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
11592: } else {
11593: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
11594: }
11595: $chgtext .= '<ul>';
11596: foreach my $case (@{$cancreate{$type}}) {
11597: if ($case eq 'default') {
11598: $chgtext .= '<li>'.$othertitle.'</li>';
11599: } else {
11600: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 11601: }
11602: }
1.100 raeburn 11603: $chgtext .= '</ul>';
11604: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 11605: $chgtext .= '<br /><span class="LC_warning">'.
11606: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
11607: '</span>';
1.100 raeburn 11608: }
11609: }
11610: } else {
11611: if (@{$cancreate{$type}} == 0) {
11612: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
11613: } else {
11614: $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 11615: }
11616: }
11617: }
1.236 raeburn 11618: } elsif ($type eq 'selfcreateprocessing') {
11619: my %choices = &Apache::lonlocal::texthash (
11620: automatic => 'Automatic approval',
11621: approval => 'Queued for approval',
11622: );
11623: if (@statuses > 1) {
11624: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
11625: '<ul>';
11626: foreach my $type (@statuses) {
11627: if ($type eq 'default') {
11628: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11629: } else {
11630: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11631: }
11632: }
11633: $chgtext .= '</ul>';
11634: } else {
11635: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
11636: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
11637: }
1.165 raeburn 11638: } elsif ($type eq 'captcha') {
1.224 raeburn 11639: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 11640: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
11641: } else {
11642: my %captchas = &captcha_phrases();
1.224 raeburn 11643: if ($captchas{$savecaptcha{$type}}) {
11644: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 11645: } else {
1.210 raeburn 11646: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 11647: }
11648: }
11649: } elsif ($type eq 'recaptchakeys') {
11650: my ($privkey,$pubkey);
1.224 raeburn 11651: if (ref($savecaptcha{$type}) eq 'HASH') {
11652: $pubkey = $savecaptcha{$type}{'public'};
11653: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 11654: }
11655: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
11656: if (!$pubkey) {
11657: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
11658: } else {
11659: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11660: }
11661: if (!$privkey) {
11662: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
11663: } else {
11664: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
11665: }
11666: $chgtext .= '</ul>';
1.269 raeburn 11667: } elsif ($type eq 'recaptchaversion') {
11668: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 11669: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 11670: }
1.224 raeburn 11671: } elsif ($type eq 'emailusername') {
11672: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 11673: if (ref($types) eq 'ARRAY') {
11674: foreach my $type (@{$types}) {
11675: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
11676: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 11677: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 11678: '<ul>';
11679: foreach my $field (@{$infofields}) {
11680: if ($cancreate{'emailusername'}{$type}{$field}) {
11681: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
11682: }
11683: }
1.245 raeburn 11684: $chgtext .= '</ul>';
11685: } else {
11686: $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.228 raeburn 11687: }
11688: } else {
1.245 raeburn 11689: $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.224 raeburn 11690: }
11691: }
11692: }
11693: }
11694: } elsif ($type eq 'notify') {
11695: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
11696: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11697: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
11698: if ($cancreate{'notify'}{'approval'}) {
11699: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
11700: }
11701: }
1.43 raeburn 11702: }
1.34 raeburn 11703: }
1.224 raeburn 11704: if ($chgtext) {
11705: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 11706: }
11707: }
11708: }
1.43 raeburn 11709: if (ref($changes{'email_rule'}) eq 'ARRAY') {
11710: my ($emailrules,$emailruleorder) =
11711: &Apache::lonnet::inst_userrules($dom,'email');
11712: my $chgtext = '<ul>';
11713: foreach my $type (@email_rule) {
11714: if (ref($emailrules->{$type}) eq 'HASH') {
11715: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
11716: }
11717: }
11718: $chgtext .= '</ul>';
11719: if (@email_rule > 0) {
1.224 raeburn 11720: $resulttext .= '<li>'.
11721: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
11722: $chgtext.
11723: '</li>';
1.43 raeburn 11724: } else {
1.224 raeburn 11725: $resulttext .= '<li>'.
11726: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
11727: '</li>';
1.43 raeburn 11728: }
11729: }
1.224 raeburn 11730: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
11731: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
11732: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11733: foreach my $type (@{$changes{'selfcreate'}}) {
11734: my $typename = $type;
11735: if (ref($usertypes) eq 'HASH') {
11736: if ($usertypes->{$type} ne '') {
11737: $typename = $usertypes->{$type};
11738: }
11739: }
11740: my @modifiable;
11741: $resulttext .= '<li>'.
11742: &mt('Self-creation of account by users with status: [_1]',
11743: '<span class="LC_cusr_emph">'.$typename.'</span>').
11744: ' - '.&mt('modifiable fields (if institutional data blank): ');
11745: foreach my $field (@fields) {
11746: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
11747: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 11748: }
11749: }
1.224 raeburn 11750: if (@modifiable > 0) {
11751: $resulttext .= join(', ',@modifiable);
1.43 raeburn 11752: } else {
1.224 raeburn 11753: $resulttext .= &mt('none');
1.43 raeburn 11754: }
1.224 raeburn 11755: $resulttext .= '</li>';
1.28 raeburn 11756: }
1.224 raeburn 11757: $resulttext .= '</ul></li>';
1.28 raeburn 11758: }
1.27 raeburn 11759: $resulttext .= '</ul>';
11760: } else {
1.224 raeburn 11761: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 11762: }
11763: } else {
11764: $resulttext = '<span class="LC_error">'.
1.23 raeburn 11765: &mt('An error occurred: [_1]',$putresult).'</span>';
11766: }
1.43 raeburn 11767: if ($warningmsg ne '') {
11768: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11769: }
1.23 raeburn 11770: return $resulttext;
11771: }
11772:
1.165 raeburn 11773: sub process_captcha {
11774: my ($container,$changes,$newsettings,$current) = @_;
11775: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
11776: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
11777: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
11778: $newsettings->{'captcha'} = 'original';
11779: }
11780: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 11781: if ($container eq 'cancreate') {
1.169 raeburn 11782: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11783: push(@{$changes->{'cancreate'}},'captcha');
11784: } elsif (!defined($changes->{'cancreate'})) {
11785: $changes->{'cancreate'} = ['captcha'];
11786: }
11787: } else {
11788: $changes->{'captcha'} = 1;
1.165 raeburn 11789: }
11790: }
1.269 raeburn 11791: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 11792: if ($newsettings->{'captcha'} eq 'recaptcha') {
11793: $newpub = $env{'form.'.$container.'_recaptchapub'};
11794: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 11795: $newpub =~ s/[^\w\-]//g;
11796: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 11797: $newsettings->{'recaptchakeys'} = {
11798: public => $newpub,
11799: private => $newpriv,
11800: };
1.269 raeburn 11801: $newversion = $env{'form.'.$container.'_recaptchaversion'};
11802: $newversion =~ s/\D//g;
11803: if ($newversion ne '2') {
11804: $newversion = 1;
11805: }
11806: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 11807: }
11808: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
11809: $currpub = $current->{'recaptchakeys'}{'public'};
11810: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 11811: unless ($newsettings->{'captcha'} eq 'recaptcha') {
11812: $newsettings->{'recaptchakeys'} = {
11813: public => '',
11814: private => '',
11815: }
11816: }
1.165 raeburn 11817: }
1.269 raeburn 11818: if ($current->{'captcha'} eq 'recaptcha') {
11819: $currversion = $current->{'recaptchaversion'};
11820: if ($currversion ne '2') {
11821: $currversion = 1;
11822: }
11823: }
11824: if ($currversion ne $newversion) {
11825: if ($container eq 'cancreate') {
11826: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11827: push(@{$changes->{'cancreate'}},'recaptchaversion');
11828: } elsif (!defined($changes->{'cancreate'})) {
11829: $changes->{'cancreate'} = ['recaptchaversion'];
11830: }
11831: } else {
11832: $changes->{'recaptchaversion'} = 1;
11833: }
11834: }
1.165 raeburn 11835: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 11836: if ($container eq 'cancreate') {
11837: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11838: push(@{$changes->{'cancreate'}},'recaptchakeys');
11839: } elsif (!defined($changes->{'cancreate'})) {
11840: $changes->{'cancreate'} = ['recaptchakeys'];
11841: }
11842: } else {
1.210 raeburn 11843: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 11844: }
11845: }
11846: return;
11847: }
11848:
1.33 raeburn 11849: sub modify_usermodification {
11850: my ($dom,%domconfig) = @_;
1.224 raeburn 11851: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 11852: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11853: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 11854: if ($key eq 'selfcreate') {
11855: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
11856: } else {
11857: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
11858: }
1.33 raeburn 11859: }
11860: }
1.224 raeburn 11861: my @contexts = ('author','course');
1.33 raeburn 11862: my %context_title = (
11863: author => 'In author context',
11864: course => 'In course context',
11865: );
11866: my @fields = ('lastname','firstname','middlename','generation',
11867: 'permanentemail','id');
11868: my %roles = (
11869: author => ['ca','aa'],
11870: course => ['st','ep','ta','in','cr'],
11871: );
11872: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11873: foreach my $context (@contexts) {
11874: foreach my $role (@{$roles{$context}}) {
11875: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
11876: foreach my $item (@fields) {
11877: if (grep(/^\Q$item\E$/,@modifiable)) {
11878: $modifyhash{$context}{$role}{$item} = 1;
11879: } else {
11880: $modifyhash{$context}{$role}{$item} = 0;
11881: }
11882: }
11883: }
11884: if (ref($curr_usermodification{$context}) eq 'HASH') {
11885: foreach my $role (@{$roles{$context}}) {
11886: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
11887: foreach my $field (@fields) {
11888: if ($modifyhash{$context}{$role}{$field} ne
11889: $curr_usermodification{$context}{$role}{$field}) {
11890: push(@{$changes{$context}},$role);
11891: last;
11892: }
11893: }
11894: }
11895: }
11896: } else {
11897: foreach my $context (@contexts) {
11898: foreach my $role (@{$roles{$context}}) {
11899: push(@{$changes{$context}},$role);
11900: }
11901: }
11902: }
11903: }
11904: my %usermodification_hash = (
11905: usermodification => \%modifyhash,
11906: );
11907: my $putresult = &Apache::lonnet::put_dom('configuration',
11908: \%usermodification_hash,$dom);
11909: if ($putresult eq 'ok') {
11910: if (keys(%changes) > 0) {
11911: $resulttext = &mt('Changes made: ').'<ul>';
11912: foreach my $context (@contexts) {
11913: if (ref($changes{$context}) eq 'ARRAY') {
11914: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
11915: if (ref($changes{$context}) eq 'ARRAY') {
11916: foreach my $role (@{$changes{$context}}) {
11917: my $rolename;
1.224 raeburn 11918: if ($role eq 'cr') {
11919: $rolename = &mt('Custom');
1.33 raeburn 11920: } else {
1.224 raeburn 11921: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 11922: }
11923: my @modifiable;
1.224 raeburn 11924: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 11925: foreach my $field (@fields) {
11926: if ($modifyhash{$context}{$role}{$field}) {
11927: push(@modifiable,$fieldtitles{$field});
11928: }
11929: }
11930: if (@modifiable > 0) {
11931: $resulttext .= join(', ',@modifiable);
11932: } else {
11933: $resulttext .= &mt('none');
11934: }
11935: $resulttext .= '</li>';
11936: }
11937: $resulttext .= '</ul></li>';
11938: }
11939: }
11940: }
11941: $resulttext .= '</ul>';
11942: } else {
11943: $resulttext = &mt('No changes made to user modification settings');
11944: }
11945: } else {
11946: $resulttext = '<span class="LC_error">'.
11947: &mt('An error occurred: [_1]',$putresult).'</span>';
11948: }
11949: return $resulttext;
11950: }
11951:
1.43 raeburn 11952: sub modify_defaults {
1.212 raeburn 11953: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 11954: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 11955: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 11956: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
11957: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 11958: my @authtypes = ('internal','krb4','krb5','localauth');
11959: foreach my $item (@items) {
11960: $newvalues{$item} = $env{'form.'.$item};
11961: if ($item eq 'auth_def') {
11962: if ($newvalues{$item} ne '') {
11963: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
11964: push(@errors,$item);
11965: }
11966: }
11967: } elsif ($item eq 'lang_def') {
11968: if ($newvalues{$item} ne '') {
11969: if ($newvalues{$item} =~ /^(\w+)/) {
11970: my $langcode = $1;
1.103 raeburn 11971: if ($langcode ne 'x_chef') {
11972: if (code2language($langcode) eq '') {
11973: push(@errors,$item);
11974: }
1.43 raeburn 11975: }
11976: } else {
11977: push(@errors,$item);
11978: }
11979: }
1.54 raeburn 11980: } elsif ($item eq 'timezone_def') {
11981: if ($newvalues{$item} ne '') {
1.62 raeburn 11982: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 11983: push(@errors,$item);
11984: }
11985: }
1.68 raeburn 11986: } elsif ($item eq 'datelocale_def') {
11987: if ($newvalues{$item} ne '') {
11988: my @datelocale_ids = DateTime::Locale->ids();
11989: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
11990: push(@errors,$item);
11991: }
11992: }
1.141 raeburn 11993: } elsif ($item eq 'portal_def') {
11994: if ($newvalues{$item} ne '') {
11995: 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])\/?$/) {
11996: push(@errors,$item);
11997: }
11998: }
1.294 raeburn 11999: } elsif ($item eq 'intauth_cost') {
12000: if ($newvalues{$item} ne '') {
12001: if ($newvalues{$item} =~ /\D/) {
12002: push(@errors,$item);
12003: }
12004: }
12005: } elsif ($item eq 'intauth_check') {
12006: if ($newvalues{$item} ne '') {
12007: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
12008: push(@errors,$item);
12009: }
12010: }
12011: } elsif ($item eq 'intauth_switch') {
12012: if ($newvalues{$item} ne '') {
12013: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
12014: push(@errors,$item);
12015: }
12016: }
1.43 raeburn 12017: }
12018: if (grep(/^\Q$item\E$/,@errors)) {
12019: $newvalues{$item} = $domdefaults{$item};
12020: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
12021: $changes{$item} = 1;
12022: }
1.72 raeburn 12023: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 12024: }
12025: my %defaults_hash = (
1.72 raeburn 12026: defaults => \%newvalues,
12027: );
1.43 raeburn 12028: my $title = &defaults_titles();
1.236 raeburn 12029:
12030: my $currinststatus;
12031: if (ref($domconfig{'inststatus'}) eq 'HASH') {
12032: $currinststatus = $domconfig{'inststatus'};
12033: } else {
12034: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12035: $currinststatus = {
12036: inststatustypes => $usertypes,
12037: inststatusorder => $types,
12038: inststatusguest => [],
12039: };
12040: }
12041: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
12042: my @allpos;
12043: my %guests;
12044: my %alltypes;
12045: my ($currtitles,$currguests,$currorder);
12046: if (ref($currinststatus) eq 'HASH') {
12047: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
12048: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
12049: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
12050: if ($currinststatus->{inststatustypes}->{$type} ne '') {
12051: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
12052: }
12053: }
12054: unless (grep(/^\Q$type\E$/,@todelete)) {
12055: my $position = $env{'form.inststatus_pos_'.$type};
12056: $position =~ s/\D+//g;
12057: $allpos[$position] = $type;
12058: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
12059: $alltypes{$type} =~ s/`//g;
12060: if ($env{'form.inststatus_guest_'.$type}) {
12061: $guests{$type} = 1;
12062: }
12063: }
12064: }
12065: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
12066: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
12067: }
12068: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
12069: $currtitles =~ s/,$//;
12070: }
12071: }
12072: if ($env{'form.addinststatus'}) {
12073: my $newtype = $env{'form.addinststatus'};
12074: $newtype =~ s/\W//g;
12075: unless (exists($alltypes{$newtype})) {
12076: if ($env{'form.addinststatus_guest'}) {
12077: $guests{$newtype} = 1;
12078: }
12079: $alltypes{$newtype} = $env{'form.addinststatus_title'};
12080: $alltypes{$newtype} =~ s/`//g;
12081: my $position = $env{'form.addinststatus_pos'};
12082: $position =~ s/\D+//g;
12083: if ($position ne '') {
12084: $allpos[$position] = $newtype;
12085: }
12086: }
12087: }
12088: my (@orderedstatus,@orderedguests);
12089: foreach my $type (@allpos) {
12090: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
12091: push(@orderedstatus,$type);
12092: if ($guests{$type}) {
12093: push(@orderedguests,$type);
12094: }
12095: }
12096: }
12097: foreach my $type (keys(%alltypes)) {
12098: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
12099: delete($alltypes{$type});
12100: }
12101: }
12102: $defaults_hash{'inststatus'} = {
12103: inststatustypes => \%alltypes,
12104: inststatusorder => \@orderedstatus,
12105: inststatusguest => \@orderedguests,
12106: };
12107: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
12108: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
12109: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
12110: }
12111: }
12112: if ($currorder ne join(',',@orderedstatus)) {
12113: $changes{'inststatus'}{'inststatusorder'} = 1;
12114: }
12115: if ($currguests ne join(',',@orderedguests)) {
12116: $changes{'inststatus'}{'inststatusguest'} = 1;
12117: }
12118: my $newtitles;
12119: foreach my $item (@orderedstatus) {
12120: $newtitles .= $alltypes{$item}.',';
12121: }
12122: $newtitles =~ s/,$//;
12123: if ($currtitles ne $newtitles) {
12124: $changes{'inststatus'}{'inststatustypes'} = 1;
12125: }
1.43 raeburn 12126: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
12127: $dom);
12128: if ($putresult eq 'ok') {
12129: if (keys(%changes) > 0) {
12130: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 12131: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 12132: 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";
12133: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 12134: if ($item eq 'inststatus') {
12135: if (ref($changes{'inststatus'}) eq 'HASH') {
12136: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
12137: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
12138: foreach my $type (@orderedstatus) {
12139: $resulttext .= $alltypes{$type}.', ';
12140: }
12141: $resulttext =~ s/, $//;
12142: $resulttext .= '</li>';
12143: }
12144: if ($changes{'inststatus'}{'inststatusguest'}) {
12145: $resulttext .= '<li>';
12146: if (@orderedguests) {
12147: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
12148: foreach my $type (@orderedguests) {
12149: $resulttext .= $alltypes{$type}.', ';
12150: }
12151: $resulttext =~ s/, $//;
12152: } else {
12153: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
12154: }
12155: $resulttext .= '</li>';
12156: }
12157: }
12158: } else {
12159: my $value = $env{'form.'.$item};
12160: if ($value eq '') {
12161: $value = &mt('none');
12162: } elsif ($item eq 'auth_def') {
12163: my %authnames = &authtype_names();
12164: my %shortauth = (
12165: internal => 'int',
12166: krb4 => 'krb4',
12167: krb5 => 'krb5',
12168: localauth => 'loc',
12169: );
12170: $value = $authnames{$shortauth{$value}};
1.294 raeburn 12171: } elsif ($item eq 'intauth_switch') {
12172: my %optiondesc = &Apache::lonlocal::texthash (
12173: 0 => 'No',
12174: 1 => 'Yes',
12175: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
12176: );
12177: if ($value =~ /^(0|1|2)$/) {
12178: $value = $optiondesc{$value};
12179: } else {
12180: $value = &mt('none -- defaults to No');
12181: }
12182: } elsif ($item eq 'intauth_check') {
12183: my %optiondesc = &Apache::lonlocal::texthash (
12184: 0 => 'No',
12185: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
12186: 2 => 'Yes, disallow login if stored cost is less than domain default',
12187: );
12188: if ($value =~ /^(0|1|2)$/) {
12189: $value = $optiondesc{$value};
12190: } else {
12191: $value = &mt('none -- defaults to No');
12192: }
1.236 raeburn 12193: }
12194: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
12195: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 12196: }
12197: }
12198: $resulttext .= '</ul>';
12199: $mailmsgtext .= "\n";
12200: my $cachetime = 24*60*60;
1.72 raeburn 12201: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12202: if (ref($lastactref) eq 'HASH') {
12203: $lastactref->{'domdefaults'} = 1;
12204: }
1.68 raeburn 12205: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 12206: my $notify = 1;
12207: if (ref($domconfig{'contacts'}) eq 'HASH') {
12208: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
12209: $notify = 0;
12210: }
12211: }
12212: if ($notify) {
12213: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
12214: "LON-CAPA Domain Settings Change - $dom",
12215: $mailmsgtext);
12216: }
1.54 raeburn 12217: }
1.43 raeburn 12218: } else {
1.54 raeburn 12219: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 12220: }
12221: } else {
12222: $resulttext = '<span class="LC_error">'.
12223: &mt('An error occurred: [_1]',$putresult).'</span>';
12224: }
12225: if (@errors > 0) {
12226: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
12227: foreach my $item (@errors) {
12228: $resulttext .= ' "'.$title->{$item}.'",';
12229: }
12230: $resulttext =~ s/,$//;
12231: }
12232: return $resulttext;
12233: }
12234:
1.46 raeburn 12235: sub modify_scantron {
1.205 raeburn 12236: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 12237: my ($resulttext,%confhash,%changes,$errors);
12238: my $custom = 'custom.tab';
12239: my $default = 'default.tab';
12240: my $servadm = $r->dir_config('lonAdmEMail');
12241: my ($configuserok,$author_ok,$switchserver) =
12242: &config_check($dom,$confname,$servadm);
12243: if ($env{'form.scantronformat.filename'} ne '') {
12244: my $error;
12245: if ($configuserok eq 'ok') {
12246: if ($switchserver) {
1.130 raeburn 12247: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 12248: } else {
12249: if ($author_ok eq 'ok') {
12250: my ($result,$scantronurl) =
12251: &publishlogo($r,'upload','scantronformat',$dom,
12252: $confname,'scantron','','',$custom);
12253: if ($result eq 'ok') {
12254: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 12255: $changes{'scantronformat'} = 1;
1.46 raeburn 12256: } else {
12257: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
12258: }
12259: } else {
12260: $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);
12261: }
12262: }
12263: } else {
12264: $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);
12265: }
12266: if ($error) {
12267: &Apache::lonnet::logthis($error);
12268: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12269: }
12270: }
1.48 raeburn 12271: if (ref($domconfig{'scantron'}) eq 'HASH') {
12272: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
12273: if ($env{'form.scantronformat_del'}) {
12274: $confhash{'scantron'}{'scantronformat'} = '';
12275: $changes{'scantronformat'} = 1;
1.46 raeburn 12276: }
12277: }
12278: }
12279: if (keys(%confhash) > 0) {
12280: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
12281: $dom);
12282: if ($putresult eq 'ok') {
12283: if (keys(%changes) > 0) {
1.48 raeburn 12284: if (ref($confhash{'scantron'}) eq 'HASH') {
12285: $resulttext = &mt('Changes made:').'<ul>';
12286: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 12287: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 12288: } else {
1.130 raeburn 12289: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 12290: }
1.48 raeburn 12291: $resulttext .= '</ul>';
12292: } else {
1.130 raeburn 12293: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 12294: }
12295: $resulttext .= '</ul>';
12296: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12297: if (ref($lastactref) eq 'HASH') {
12298: $lastactref->{'domainconfig'} = 1;
12299: }
1.46 raeburn 12300: } else {
1.130 raeburn 12301: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12302: }
12303: } else {
12304: $resulttext = '<span class="LC_error">'.
12305: &mt('An error occurred: [_1]',$putresult).'</span>';
12306: }
12307: } else {
1.130 raeburn 12308: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12309: }
12310: if ($errors) {
12311: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12312: $errors.'</ul>';
12313: }
12314: return $resulttext;
12315: }
12316:
1.48 raeburn 12317: sub modify_coursecategories {
1.239 raeburn 12318: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 12319: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
12320: $cathash);
1.48 raeburn 12321: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 12322: my @catitems = ('unauth','auth');
12323: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 12324: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 12325: $cathash = $domconfig{'coursecategories'}{'cats'};
12326: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
12327: $changes{'togglecats'} = 1;
12328: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
12329: }
12330: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
12331: $changes{'categorize'} = 1;
12332: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
12333: }
1.120 raeburn 12334: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
12335: $changes{'togglecatscomm'} = 1;
12336: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
12337: }
12338: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
12339: $changes{'categorizecomm'} = 1;
12340: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 12341:
12342: }
12343: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
12344: $changes{'togglecatsplace'} = 1;
12345: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
12346: }
12347: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
12348: $changes{'categorizeplace'} = 1;
12349: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 12350: }
1.238 raeburn 12351: foreach my $item (@catitems) {
12352: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12353: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
12354: $changes{$item} = 1;
12355: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12356: }
12357: }
12358: }
1.57 raeburn 12359: } else {
12360: $changes{'togglecats'} = 1;
12361: $changes{'categorize'} = 1;
1.124 raeburn 12362: $changes{'togglecatscomm'} = 1;
12363: $changes{'categorizecomm'} = 1;
1.272 raeburn 12364: $changes{'togglecatsplace'} = 1;
12365: $changes{'categorizeplace'} = 1;
1.87 raeburn 12366: $domconfig{'coursecategories'} = {
12367: togglecats => $env{'form.togglecats'},
12368: categorize => $env{'form.categorize'},
1.124 raeburn 12369: togglecatscomm => $env{'form.togglecatscomm'},
12370: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 12371: togglecatsplace => $env{'form.togglecatsplace'},
12372: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 12373: };
1.238 raeburn 12374: foreach my $item (@catitems) {
12375: if ($env{'form.coursecat_'.$item} ne 'std') {
12376: $changes{$item} = 1;
12377: }
12378: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12379: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12380: }
12381: }
1.57 raeburn 12382: }
12383: if (ref($cathash) eq 'HASH') {
12384: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 12385: push (@deletecategory,'instcode::0');
12386: }
1.120 raeburn 12387: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
12388: push(@deletecategory,'communities::0');
12389: }
1.272 raeburn 12390: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
12391: push(@deletecategory,'placement::0');
12392: }
1.48 raeburn 12393: }
1.57 raeburn 12394: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
12395: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12396: if (@deletecategory > 0) {
12397: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 12398: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 12399: foreach my $item (@deletecategory) {
1.57 raeburn 12400: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
12401: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 12402: $deletions{$item} = 1;
1.57 raeburn 12403: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 12404: }
12405: }
12406: }
1.57 raeburn 12407: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 12408: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 12409: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 12410: $reorderings{$item} = 1;
1.57 raeburn 12411: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 12412: }
12413: if ($env{'form.addcategory_name_'.$item} ne '') {
12414: my $newcat = $env{'form.addcategory_name_'.$item};
12415: my $newdepth = $depth+1;
12416: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12417: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 12418: $adds{$newitem} = 1;
12419: }
12420: if ($env{'form.subcat_'.$item} ne '') {
12421: my $newcat = $env{'form.subcat_'.$item};
12422: my $newdepth = $depth+1;
12423: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12424: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 12425: $adds{$newitem} = 1;
12426: }
12427: }
12428: }
12429: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 12430: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12431: my $newitem = 'instcode::0';
1.57 raeburn 12432: if ($cathash->{$newitem} eq '') {
12433: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12434: $adds{$newitem} = 1;
12435: }
12436: } else {
12437: my $newitem = 'instcode::0';
1.57 raeburn 12438: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12439: $adds{$newitem} = 1;
12440: }
12441: }
1.120 raeburn 12442: if ($env{'form.communities'} eq '1') {
12443: if (ref($cathash) eq 'HASH') {
12444: my $newitem = 'communities::0';
12445: if ($cathash->{$newitem} eq '') {
12446: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12447: $adds{$newitem} = 1;
12448: }
12449: } else {
12450: my $newitem = 'communities::0';
12451: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12452: $adds{$newitem} = 1;
12453: }
12454: }
1.272 raeburn 12455: if ($env{'form.placement'} eq '1') {
12456: if (ref($cathash) eq 'HASH') {
12457: my $newitem = 'placement::0';
12458: if ($cathash->{$newitem} eq '') {
12459: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12460: $adds{$newitem} = 1;
12461: }
12462: } else {
12463: my $newitem = 'placement::0';
12464: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12465: $adds{$newitem} = 1;
12466: }
12467: }
1.48 raeburn 12468: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 12469: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 12470: ($env{'form.addcategory_name'} ne 'communities') &&
12471: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 12472: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
12473: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
12474: $adds{$newitem} = 1;
12475: }
1.48 raeburn 12476: }
1.57 raeburn 12477: my $putresult;
1.48 raeburn 12478: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12479: if (keys(%deletions) > 0) {
12480: foreach my $key (keys(%deletions)) {
12481: if ($predelallitems{$key} ne '') {
12482: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
12483: }
12484: }
12485: }
12486: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 12487: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 12488: if (ref($chkcats[0]) eq 'ARRAY') {
12489: my $depth = 0;
12490: my $chg = 0;
12491: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
12492: my $name = $chkcats[0][$i];
12493: my $item;
12494: if ($name eq '') {
12495: $chg ++;
12496: } else {
12497: $item = &escape($name).'::0';
12498: if ($chg) {
1.57 raeburn 12499: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 12500: }
12501: $depth ++;
1.57 raeburn 12502: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 12503: $depth --;
12504: }
12505: }
12506: }
1.57 raeburn 12507: }
12508: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12509: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 12510: if ($putresult eq 'ok') {
1.57 raeburn 12511: my %title = (
1.120 raeburn 12512: togglecats => 'Show/Hide a course in catalog',
12513: categorize => 'Assign a category to a course',
12514: togglecatscomm => 'Show/Hide a community in catalog',
12515: categorizecomm => 'Assign a category to a community',
1.57 raeburn 12516: );
12517: my %level = (
1.120 raeburn 12518: dom => 'set in Domain ("Modify Course/Community")',
12519: crs => 'set in Course ("Course Configuration")',
12520: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 12521: none => 'No catalog',
12522: std => 'Standard catalog',
12523: domonly => 'Domain-only catalog',
12524: codesrch => 'Code search form',
1.57 raeburn 12525: );
1.48 raeburn 12526: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 12527: if ($changes{'togglecats'}) {
12528: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
12529: }
12530: if ($changes{'categorize'}) {
12531: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 12532: }
1.120 raeburn 12533: if ($changes{'togglecatscomm'}) {
12534: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
12535: }
12536: if ($changes{'categorizecomm'}) {
12537: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
12538: }
1.238 raeburn 12539: if ($changes{'unauth'}) {
12540: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
12541: }
12542: if ($changes{'auth'}) {
12543: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
12544: }
1.57 raeburn 12545: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12546: my $cathash;
12547: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
12548: $cathash = $domconfig{'coursecategories'}{'cats'};
12549: } else {
12550: $cathash = {};
12551: }
12552: my (@cats,@trails,%allitems);
12553: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
12554: if (keys(%deletions) > 0) {
12555: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
12556: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
12557: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
12558: }
12559: $resulttext .= '</ul></li>';
12560: }
12561: if (keys(%reorderings) > 0) {
12562: my %sort_by_trail;
12563: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
12564: foreach my $key (keys(%reorderings)) {
12565: if ($allitems{$key} ne '') {
12566: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12567: }
1.48 raeburn 12568: }
1.57 raeburn 12569: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12570: $resulttext .= '<li>'.$trails[$trail].'</li>';
12571: }
12572: $resulttext .= '</ul></li>';
1.48 raeburn 12573: }
1.57 raeburn 12574: if (keys(%adds) > 0) {
12575: my %sort_by_trail;
12576: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
12577: foreach my $key (keys(%adds)) {
12578: if ($allitems{$key} ne '') {
12579: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12580: }
12581: }
12582: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12583: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 12584: }
1.57 raeburn 12585: $resulttext .= '</ul></li>';
1.48 raeburn 12586: }
12587: }
12588: $resulttext .= '</ul>';
1.239 raeburn 12589: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 12590: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12591: if ($changes{'auth'}) {
12592: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
12593: }
12594: if ($changes{'unauth'}) {
12595: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
12596: }
12597: my $cachetime = 24*60*60;
12598: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 12599: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 12600: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 12601: }
12602: }
1.48 raeburn 12603: } else {
12604: $resulttext = '<span class="LC_error">'.
1.57 raeburn 12605: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 12606: }
12607: } else {
1.120 raeburn 12608: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 12609: }
12610: return $resulttext;
12611: }
12612:
1.69 raeburn 12613: sub modify_serverstatuses {
12614: my ($dom,%domconfig) = @_;
12615: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
12616: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
12617: %currserverstatus = %{$domconfig{'serverstatuses'}};
12618: }
12619: my @pages = &serverstatus_pages();
12620: foreach my $type (@pages) {
12621: $newserverstatus{$type}{'namedusers'} = '';
12622: $newserverstatus{$type}{'machines'} = '';
12623: if (defined($env{'form.'.$type.'_namedusers'})) {
12624: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
12625: my @okusers;
12626: foreach my $user (@users) {
12627: my ($uname,$udom) = split(/:/,$user);
12628: if (($udom =~ /^$match_domain$/) &&
12629: (&Apache::lonnet::domain($udom)) &&
12630: ($uname =~ /^$match_username$/)) {
12631: if (!grep(/^\Q$user\E/,@okusers)) {
12632: push(@okusers,$user);
12633: }
12634: }
12635: }
12636: if (@okusers > 0) {
12637: @okusers = sort(@okusers);
12638: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
12639: }
12640: }
12641: if (defined($env{'form.'.$type.'_machines'})) {
12642: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
12643: my @okmachines;
12644: foreach my $ip (@machines) {
12645: my @parts = split(/\./,$ip);
12646: next if (@parts < 4);
12647: my $badip = 0;
12648: for (my $i=0; $i<4; $i++) {
12649: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
12650: $badip = 1;
12651: last;
12652: }
12653: }
12654: if (!$badip) {
12655: push(@okmachines,$ip);
12656: }
12657: }
12658: @okmachines = sort(@okmachines);
12659: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
12660: }
12661: }
12662: my %serverstatushash = (
12663: serverstatuses => \%newserverstatus,
12664: );
12665: foreach my $type (@pages) {
1.83 raeburn 12666: foreach my $setting ('namedusers','machines') {
1.84 raeburn 12667: my (@current,@new);
1.83 raeburn 12668: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 12669: if ($currserverstatus{$type}{$setting} ne '') {
12670: @current = split(/,/,$currserverstatus{$type}{$setting});
12671: }
12672: }
12673: if ($newserverstatus{$type}{$setting} ne '') {
12674: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 12675: }
12676: if (@current > 0) {
12677: if (@new > 0) {
12678: foreach my $item (@current) {
12679: if (!grep(/^\Q$item\E$/,@new)) {
12680: $changes{$type}{$setting} = 1;
1.82 raeburn 12681: last;
12682: }
12683: }
1.84 raeburn 12684: foreach my $item (@new) {
12685: if (!grep(/^\Q$item\E$/,@current)) {
12686: $changes{$type}{$setting} = 1;
12687: last;
1.82 raeburn 12688: }
12689: }
12690: } else {
1.83 raeburn 12691: $changes{$type}{$setting} = 1;
1.69 raeburn 12692: }
1.83 raeburn 12693: } elsif (@new > 0) {
12694: $changes{$type}{$setting} = 1;
1.69 raeburn 12695: }
12696: }
12697: }
12698: if (keys(%changes) > 0) {
1.81 raeburn 12699: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 12700: my $putresult = &Apache::lonnet::put_dom('configuration',
12701: \%serverstatushash,$dom);
12702: if ($putresult eq 'ok') {
12703: $resulttext .= &mt('Changes made:').'<ul>';
12704: foreach my $type (@pages) {
1.84 raeburn 12705: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 12706: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 12707: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 12708: if ($newserverstatus{$type}{'namedusers'} eq '') {
12709: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
12710: } else {
12711: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
12712: }
1.84 raeburn 12713: }
12714: if ($changes{$type}{'machines'}) {
1.69 raeburn 12715: if ($newserverstatus{$type}{'machines'} eq '') {
12716: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
12717: } else {
12718: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
12719: }
12720:
12721: }
12722: $resulttext .= '</ul></li>';
12723: }
12724: }
12725: $resulttext .= '</ul>';
12726: } else {
12727: $resulttext = '<span class="LC_error">'.
12728: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
12729:
12730: }
12731: } else {
12732: $resulttext = &mt('No changes made to access to server status pages');
12733: }
12734: return $resulttext;
12735: }
12736:
1.118 jms 12737: sub modify_helpsettings {
1.285 raeburn 12738: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 12739: my ($resulttext,$errors,%changes,%helphash);
12740: my %defaultchecked = ('submitbugs' => 'on');
12741: my @offon = ('off','on');
1.118 jms 12742: my @toggles = ('submitbugs');
1.285 raeburn 12743: my %current = ('submitbugs' => '',
12744: 'adhoc' => {},
12745: );
1.118 jms 12746: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 12747: %current = %{$domconfig{'helpsettings'}};
12748: }
1.285 raeburn 12749: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 12750: foreach my $item (@toggles) {
12751: if ($defaultchecked{$item} eq 'on') {
12752: if ($current{$item} eq '') {
12753: if ($env{'form.'.$item} eq '0') {
12754: $changes{$item} = 1;
12755: }
12756: } elsif ($current{$item} ne $env{'form.'.$item}) {
12757: $changes{$item} = 1;
12758: }
12759: } elsif ($defaultchecked{$item} eq 'off') {
12760: if ($current{$item} eq '') {
12761: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 12762: $changes{$item} = 1;
12763: }
1.282 raeburn 12764: } elsif ($current{$item} ne $env{'form.'.$item}) {
12765: $changes{$item} = 1;
12766: }
12767: }
12768: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
12769: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
12770: }
12771: }
1.285 raeburn 12772: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 12773: my $confname = $dom.'-domainconfig';
12774: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 12775: my (@allpos,%newsettings,%changedprivs,$newrole);
12776: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 12777: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 12778: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 12779: my %lt = &Apache::lonlocal::texthash(
12780: s => 'system',
12781: d => 'domain',
12782: order => 'Display order',
12783: access => 'Role usage',
1.291 raeburn 12784: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 12785: dh => 'All with domain helpdesk role',
12786: da => 'All with domain helpdesk assistant role',
1.285 raeburn 12787: none => 'None',
12788: status => 'Determined based on institutional status',
12789: inc => 'Include all, but exclude specific personnel',
12790: exc => 'Exclude all, but include specific personnel',
12791: );
12792: for (my $num=0; $num<=$maxnum; $num++) {
12793: my ($prefix,$identifier,$rolename,%curr);
12794: if ($num == $maxnum) {
12795: next unless ($env{'form.newcusthelp'} == $maxnum);
12796: $identifier = 'custhelp'.$num;
12797: $prefix = 'helproles_'.$num;
12798: $rolename = $env{'form.custhelpname'.$num};
12799: $rolename=~s/[^A-Za-z0-9]//gs;
12800: next if ($rolename eq '');
12801: next if (exists($existing{'rolesdef_'.$rolename}));
12802: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12803: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12804: $newprivs{'c'},$confname,$dom);
12805: if ($result ne 'ok') {
12806: $errors .= '<li><span class="LC_error">'.
12807: &mt('An error occurred storing the new custom role: [_1]',
12808: $result).'</span></li>';
12809: next;
12810: } else {
12811: $changedprivs{$rolename} = \%newprivs;
12812: $newrole = $rolename;
12813: }
12814: } else {
12815: $prefix = 'helproles_'.$num;
12816: $rolename = $env{'form.'.$prefix};
12817: next if ($rolename eq '');
12818: next unless (exists($existing{'rolesdef_'.$rolename}));
12819: $identifier = 'custhelp'.$num;
12820: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12821: my %currprivs;
1.289 raeburn 12822: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 12823: split(/\_/,$existing{'rolesdef_'.$rolename});
12824: foreach my $level ('c','d','s') {
12825: if ($newprivs{$level} ne $currprivs{$level}) {
12826: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12827: $newprivs{'c'},$confname,$dom);
12828: if ($result ne 'ok') {
12829: $errors .= '<li><span class="LC_error">'.
12830: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
12831: $rolename,$result).'</span></li>';
12832: } else {
12833: $changedprivs{$rolename} = \%newprivs;
12834: }
12835: last;
12836: }
12837: }
12838: if (ref($current{'adhoc'}) eq 'HASH') {
12839: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12840: %curr = %{$current{'adhoc'}{$rolename}};
12841: }
12842: }
12843: }
12844: my $newpos = $env{'form.'.$prefix.'_pos'};
12845: $newpos =~ s/\D+//g;
12846: $allpos[$newpos] = $rolename;
12847: my $newdesc = $env{'form.'.$prefix.'_desc'};
12848: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
12849: if ($curr{'desc'}) {
12850: if ($curr{'desc'} ne $newdesc) {
12851: $changes{'customrole'}{$rolename}{'desc'} = 1;
12852: $newsettings{$rolename}{'desc'} = $newdesc;
12853: }
12854: } elsif ($newdesc ne '') {
12855: $changes{'customrole'}{$rolename}{'desc'} = 1;
12856: $newsettings{$rolename}{'desc'} = $newdesc;
12857: }
12858: my $access = $env{'form.'.$prefix.'_access'};
12859: if (grep(/^\Q$access\E$/,@accesstypes)) {
12860: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
12861: if ($access eq 'status') {
12862: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
12863: if (scalar(@statuses) == 0) {
1.289 raeburn 12864: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 12865: } else {
12866: my (@shownstatus,$numtypes);
12867: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12868: if (ref($types) eq 'ARRAY') {
12869: $numtypes = scalar(@{$types});
12870: foreach my $type (sort(@statuses)) {
12871: if ($type eq 'default') {
12872: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12873: } elsif (grep(/^\Q$type\E$/,@{$types})) {
12874: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12875: push(@shownstatus,$usertypes->{$type});
12876: }
12877: }
12878: }
12879: if (grep(/^default$/,@statuses)) {
12880: push(@shownstatus,$othertitle);
12881: }
12882: if (scalar(@shownstatus) == 1+$numtypes) {
12883: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
12884: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
12885: } else {
12886: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
12887: if (ref($curr{'status'}) eq 'ARRAY') {
12888: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12889: if (@diffs) {
12890: $changes{'customrole'}{$rolename}{$access} = 1;
12891: }
12892: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12893: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 12894: }
1.166 raeburn 12895: }
12896: }
1.285 raeburn 12897: } elsif (($access eq 'inc') || ($access eq 'exc')) {
12898: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
12899: my @newspecstaff;
12900: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12901: foreach my $person (sort(@personnel)) {
12902: if ($domhelpdesk{$person}) {
12903: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
12904: }
12905: }
12906: if (ref($curr{$access}) eq 'ARRAY') {
12907: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12908: if (@diffs) {
12909: $changes{'customrole'}{$rolename}{$access} = 1;
12910: }
12911: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12912: $changes{'customrole'}{$rolename}{$access} = 1;
12913: }
12914: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12915: my ($uname,$udom) = split(/:/,$person);
12916: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
12917: }
12918: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 12919: }
1.285 raeburn 12920: } else {
12921: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
12922: }
12923: unless ($curr{'access'} eq $access) {
12924: $changes{'customrole'}{$rolename}{'access'} = 1;
12925: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 12926: }
12927: }
1.285 raeburn 12928: if (@allpos > 0) {
12929: my $idx = 0;
12930: foreach my $rolename (@allpos) {
12931: if ($rolename ne '') {
12932: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
12933: if (ref($current{'adhoc'}) eq 'HASH') {
12934: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12935: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
12936: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 12937: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 12938: }
12939: }
1.282 raeburn 12940: }
1.285 raeburn 12941: $idx ++;
1.166 raeburn 12942: }
12943: }
1.118 jms 12944: }
1.123 jms 12945: my $putresult;
12946: if (keys(%changes) > 0) {
1.166 raeburn 12947: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 12948: if ($putresult eq 'ok') {
1.285 raeburn 12949: if (ref($helphash{'helpsettings'}) eq 'HASH') {
12950: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
12951: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
12952: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
12953: }
12954: }
12955: my $cachetime = 24*60*60;
12956: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12957: if (ref($lastactref) eq 'HASH') {
12958: $lastactref->{'domdefaults'} = 1;
12959: }
12960: } else {
12961: $errors .= '<li><span class="LC_error">'.
12962: &mt('An error occurred storing the settings: [_1]',
12963: $putresult).'</span></li>';
12964: }
12965: }
12966: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
12967: $resulttext = &mt('Changes made:').'<ul>';
12968: my (%shownprivs,@levelorder);
12969: @levelorder = ('c','d','s');
12970: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 12971: foreach my $item (sort(keys(%changes))) {
12972: if ($item eq 'submitbugs') {
12973: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
12974: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
12975: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 12976: } elsif ($item eq 'customrole') {
12977: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 12978: my @keyorder = ('order','desc','access','status','exc','inc');
12979: my %keytext = &Apache::lonlocal::texthash(
12980: order => 'Order',
12981: desc => 'Role description',
12982: access => 'Role usage',
1.300 droeschl 12983: status => 'Allowed institutional types',
1.285 raeburn 12984: exc => 'Allowed personnel',
12985: inc => 'Disallowed personnel',
12986: );
1.282 raeburn 12987: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 12988: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
12989: if ($role eq $newrole) {
12990: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
12991: $role).'<ul>';
12992: } else {
12993: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12994: $role).'<ul>';
12995: }
12996: foreach my $key (@keyorder) {
12997: if ($changes{'customrole'}{$role}{$key}) {
12998: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
12999: $keytext{$key},$newsettings{$role}{$key}).
13000: '</li>';
13001: }
13002: }
13003: if (ref($changedprivs{$role}) eq 'HASH') {
13004: $shownprivs{$role} = 1;
13005: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
13006: foreach my $level (@levelorder) {
13007: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13008: next if ($item eq '');
13009: my ($priv) = split(/\&/,$item,2);
13010: if (&Apache::lonnet::plaintext($priv)) {
13011: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13012: unless ($level eq 'c') {
13013: $resulttext .= ' ('.$lt{$level}.')';
13014: }
13015: $resulttext .= '</li>';
13016: }
13017: }
13018: }
13019: $resulttext .= '</ul>';
13020: }
13021: $resulttext .= '</ul></li>';
13022: }
13023: }
13024: }
13025: }
13026: }
13027: }
13028: if (keys(%changedprivs)) {
13029: foreach my $role (sort(keys(%changedprivs))) {
13030: unless ($shownprivs{$role}) {
13031: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13032: $role).'<ul>'.
13033: '<li>'.&mt('Privileges set to :').'<ul>';
13034: foreach my $level (@levelorder) {
13035: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13036: next if ($item eq '');
13037: my ($priv) = split(/\&/,$item,2);
13038: if (&Apache::lonnet::plaintext($priv)) {
13039: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13040: unless ($level eq 'c') {
13041: $resulttext .= ' ('.$lt{$level}.')';
13042: }
13043: $resulttext .= '</li>';
13044: }
1.282 raeburn 13045: }
13046: }
1.285 raeburn 13047: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 13048: }
13049: }
13050: }
1.285 raeburn 13051: $resulttext .= '</ul>';
13052: } else {
13053: $resulttext = &mt('No changes made to help settings');
1.118 jms 13054: }
13055: if ($errors) {
1.168 raeburn 13056: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 13057: $errors.'</ul>';
1.118 jms 13058: }
13059: return $resulttext;
13060: }
13061:
1.121 raeburn 13062: sub modify_coursedefaults {
1.212 raeburn 13063: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 13064: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 13065: my %defaultchecked = (
13066: 'canuse_pdfforms' => 'off',
13067: 'uselcmath' => 'on',
13068: 'usejsme' => 'on'
13069: );
13070: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 13071: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 13072: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
13073: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
13074: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 13075: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 13076: my %staticdefaults = (
13077: anonsurvey_threshold => 10,
13078: uploadquota => 500,
1.257 raeburn 13079: postsubmit => 60,
1.276 raeburn 13080: mysqltables => 172800,
1.198 raeburn 13081: );
1.121 raeburn 13082:
13083: $defaultshash{'coursedefaults'} = {};
13084:
13085: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
13086: if ($domconfig{'coursedefaults'} eq '') {
13087: $domconfig{'coursedefaults'} = {};
13088: }
13089: }
13090:
13091: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
13092: foreach my $item (@toggles) {
13093: if ($defaultchecked{$item} eq 'on') {
13094: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13095: ($env{'form.'.$item} eq '0')) {
13096: $changes{$item} = 1;
1.192 raeburn 13097: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 13098: $changes{$item} = 1;
13099: }
13100: } elsif ($defaultchecked{$item} eq 'off') {
13101: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13102: ($env{'form.'.$item} eq '1')) {
13103: $changes{$item} = 1;
13104: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
13105: $changes{$item} = 1;
13106: }
13107: }
13108: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
13109: }
1.198 raeburn 13110: foreach my $item (@numbers) {
13111: my ($currdef,$newdef);
1.208 raeburn 13112: $newdef = $env{'form.'.$item};
1.198 raeburn 13113: if ($item eq 'anonsurvey_threshold') {
13114: $currdef = $domconfig{'coursedefaults'}{$item};
13115: $newdef =~ s/\D//g;
13116: if ($newdef eq '' || $newdef < 1) {
13117: $newdef = 1;
13118: }
13119: $defaultshash{'coursedefaults'}{$item} = $newdef;
13120: } else {
1.276 raeburn 13121: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
13122: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
13123: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 13124: }
13125: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 13126: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 13127: }
13128: if ($currdef ne $newdef) {
13129: my $staticdef;
13130: if ($item eq 'anonsurvey_threshold') {
13131: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
13132: $changes{$item} = 1;
13133: }
1.276 raeburn 13134: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 13135: my $setting = $1;
1.276 raeburn 13136: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
13137: $changes{$setting} = 1;
1.198 raeburn 13138: }
13139: }
1.139 raeburn 13140: }
13141: }
1.264 raeburn 13142: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
13143: my @currclonecode;
13144: if (ref($currclone) eq 'HASH') {
13145: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
13146: @currclonecode = @{$currclone->{'instcode'}};
13147: }
13148: }
13149: my $newclone;
1.289 raeburn 13150: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 13151: $newclone = $env{'form.canclone'};
13152: }
13153: if ($newclone eq 'instcode') {
13154: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
13155: my (%codedefaults,@code_order,@clonecode);
13156: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
13157: \@code_order);
13158: foreach my $item (@code_order) {
13159: if (grep(/^\Q$item\E$/,@newcodes)) {
13160: push(@clonecode,$item);
13161: }
13162: }
13163: if (@clonecode) {
13164: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
13165: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
13166: if (@diffs) {
13167: $changes{'canclone'} = 1;
13168: }
13169: } else {
13170: $newclone eq '';
13171: }
13172: } elsif ($newclone ne '') {
1.289 raeburn 13173: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
13174: }
1.264 raeburn 13175: if ($newclone ne $currclone) {
13176: $changes{'canclone'} = 1;
13177: }
1.257 raeburn 13178: my %credits;
13179: foreach my $type (@types) {
13180: unless ($type eq 'community') {
13181: $credits{$type} = $env{'form.'.$type.'_credits'};
13182: $credits{$type} =~ s/[^\d.]+//g;
13183: }
13184: }
13185: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
13186: ($env{'form.coursecredits'} eq '1')) {
13187: $changes{'coursecredits'} = 1;
13188: foreach my $type (keys(%credits)) {
13189: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13190: }
13191: } else {
1.289 raeburn 13192: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 13193: foreach my $type (@types) {
13194: unless ($type eq 'community') {
1.289 raeburn 13195: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 13196: $changes{'coursecredits'} = 1;
13197: }
13198: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13199: }
13200: }
13201: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13202: foreach my $type (@types) {
13203: unless ($type eq 'community') {
13204: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
13205: $changes{'coursecredits'} = 1;
13206: last;
13207: }
13208: }
13209: }
13210: }
13211: }
13212: if ($env{'form.postsubmit'} eq '1') {
13213: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
13214: my %currtimeout;
13215: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13216: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
13217: $changes{'postsubmit'} = 1;
13218: }
13219: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13220: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
13221: }
13222: } else {
13223: $changes{'postsubmit'} = 1;
13224: }
13225: foreach my $type (@types) {
13226: my $timeout = $env{'form.'.$type.'_timeout'};
13227: $timeout =~ s/\D//g;
13228: if ($timeout == $staticdefaults{'postsubmit'}) {
13229: $timeout = '';
13230: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
13231: $timeout = '0';
13232: }
13233: unless ($timeout eq '') {
13234: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
13235: }
13236: if (exists($currtimeout{$type})) {
13237: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 13238: $changes{'postsubmit'} = 1;
1.257 raeburn 13239: }
13240: } elsif ($timeout ne '') {
13241: $changes{'postsubmit'} = 1;
13242: }
13243: }
13244: } else {
13245: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
13246: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13247: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
13248: $changes{'postsubmit'} = 1;
13249: }
13250: } else {
13251: $changes{'postsubmit'} = 1;
13252: }
1.192 raeburn 13253: }
1.121 raeburn 13254: }
13255: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13256: $dom);
13257: if ($putresult eq 'ok') {
13258: if (keys(%changes) > 0) {
1.213 raeburn 13259: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 13260: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 13261: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.276 raeburn 13262: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.257 raeburn 13263: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
13264: if ($changes{$item}) {
13265: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
13266: }
1.289 raeburn 13267: }
1.192 raeburn 13268: if ($changes{'coursecredits'}) {
13269: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 13270: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
13271: $domdefaults{$type.'credits'} =
13272: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
13273: }
13274: }
13275: }
13276: if ($changes{'postsubmit'}) {
13277: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13278: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
13279: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13280: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
13281: $domdefaults{$type.'postsubtimeout'} =
13282: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13283: }
13284: }
1.192 raeburn 13285: }
13286: }
1.198 raeburn 13287: if ($changes{'uploadquota'}) {
13288: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13289: foreach my $type (@types) {
13290: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
13291: }
13292: }
13293: }
1.264 raeburn 13294: if ($changes{'canclone'}) {
13295: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13296: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13297: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
13298: if (@clonecodes) {
13299: $domdefaults{'canclone'} = join('+',@clonecodes);
13300: }
13301: }
13302: } else {
13303: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
13304: }
13305: }
1.121 raeburn 13306: my $cachetime = 24*60*60;
13307: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13308: if (ref($lastactref) eq 'HASH') {
13309: $lastactref->{'domdefaults'} = 1;
13310: }
1.121 raeburn 13311: }
13312: $resulttext = &mt('Changes made:').'<ul>';
13313: foreach my $item (sort(keys(%changes))) {
13314: if ($item eq 'canuse_pdfforms') {
13315: if ($env{'form.'.$item} eq '1') {
13316: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
13317: } else {
13318: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
13319: }
1.257 raeburn 13320: } elsif ($item eq 'uselcmath') {
13321: if ($env{'form.'.$item} eq '1') {
13322: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
13323: } else {
13324: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
13325: }
13326: } elsif ($item eq 'usejsme') {
13327: if ($env{'form.'.$item} eq '1') {
13328: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
13329: } else {
1.289 raeburn 13330: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 13331: }
1.139 raeburn 13332: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 13333: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 13334: } elsif ($item eq 'uploadquota') {
13335: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13336: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
13337: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
13338: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 13339: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 13340: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 13341: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
13342: '</ul>'.
13343: '</li>';
13344: } else {
13345: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
13346: }
1.276 raeburn 13347: } elsif ($item eq 'mysqltables') {
13348: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
13349: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
13350: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
13351: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
13352: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
13353: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
13354: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
13355: '</ul>'.
13356: '</li>';
13357: } else {
13358: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
13359: }
1.257 raeburn 13360: } elsif ($item eq 'postsubmit') {
13361: if ($domdefaults{'postsubmit'} eq 'off') {
13362: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
13363: } else {
13364: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 13365: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 13366: $resulttext .= &mt('durations:').'<ul>';
13367: foreach my $type (@types) {
13368: $resulttext .= '<li>';
13369: my $timeout;
13370: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13371: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13372: }
13373: my $display;
13374: if ($timeout eq '0') {
13375: $display = &mt('unlimited');
13376: } elsif ($timeout eq '') {
13377: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
13378: } else {
13379: $display = &mt('[quant,_1,second]',$timeout);
13380: }
13381: if ($type eq 'community') {
13382: $resulttext .= &mt('Communities');
13383: } elsif ($type eq 'official') {
13384: $resulttext .= &mt('Official courses');
13385: } elsif ($type eq 'unofficial') {
13386: $resulttext .= &mt('Unofficial courses');
13387: } elsif ($type eq 'textbook') {
13388: $resulttext .= &mt('Textbook courses');
1.271 raeburn 13389: } elsif ($type eq 'placement') {
13390: $resulttext .= &mt('Placement tests');
1.257 raeburn 13391: }
13392: $resulttext .= ' -- '.$display.'</li>';
13393: }
13394: $resulttext .= '</ul>';
13395: }
1.289 raeburn 13396: $resulttext .= '</li>';
1.257 raeburn 13397: }
1.192 raeburn 13398: } elsif ($item eq 'coursecredits') {
13399: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13400: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 13401: ($domdefaults{'unofficialcredits'} eq '') &&
13402: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 13403: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13404: } else {
13405: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
13406: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
13407: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 13408: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 13409: '</ul>'.
13410: '</li>';
13411: }
13412: } else {
13413: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13414: }
1.264 raeburn 13415: } elsif ($item eq 'canclone') {
13416: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13417: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13418: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
13419: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
13420: }
13421: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
13422: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
13423: } else {
1.289 raeburn 13424: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 13425: }
1.140 raeburn 13426: }
1.121 raeburn 13427: }
13428: $resulttext .= '</ul>';
13429: } else {
13430: $resulttext = &mt('No changes made to course defaults');
13431: }
13432: } else {
13433: $resulttext = '<span class="LC_error">'.
13434: &mt('An error occurred: [_1]',$putresult).'</span>';
13435: }
13436: return $resulttext;
13437: }
13438:
1.231 raeburn 13439: sub modify_selfenrollment {
13440: my ($dom,$lastactref,%domconfig) = @_;
13441: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 13442: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 13443: my %titles = &tool_titles();
1.232 raeburn 13444: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
13445: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 13446: $ordered{'default'} = ['types','registered','approval','limit'];
13447:
13448: my (%roles,%shown,%toplevel);
13449: $roles{'0'} = &Apache::lonnet::plaintext('dc');
13450:
13451: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
13452: if ($domconfig{'selfenrollment'} eq '') {
13453: $domconfig{'selfenrollment'} = {};
13454: }
13455: }
13456: %toplevel = (
13457: admin => 'Configuration Rights',
13458: default => 'Default settings',
13459: validation => 'Validation of self-enrollment requests',
13460: );
1.233 raeburn 13461: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 13462:
13463: if (ref($ordered{'admin'}) eq 'ARRAY') {
13464: foreach my $item (@{$ordered{'admin'}}) {
13465: foreach my $type (@types) {
13466: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
13467: $selfenrollhash{'admin'}{$type}{$item} = 1;
13468: } else {
13469: $selfenrollhash{'admin'}{$type}{$item} = 0;
13470: }
13471: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
13472: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
13473: if ($selfenrollhash{'admin'}{$type}{$item} ne
13474: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
13475: push(@{$changes{'admin'}{$type}},$item);
13476: }
13477: } else {
13478: if (!$selfenrollhash{'admin'}{$type}{$item}) {
13479: push(@{$changes{'admin'}{$type}},$item);
13480: }
13481: }
13482: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
13483: push(@{$changes{'admin'}{$type}},$item);
13484: }
13485: }
13486: }
13487: }
13488:
13489: foreach my $item (@{$ordered{'default'}}) {
13490: foreach my $type (@types) {
13491: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
13492: if ($item eq 'types') {
13493: unless (($value eq 'all') || ($value eq 'dom')) {
13494: $value = '';
13495: }
13496: } elsif ($item eq 'registered') {
13497: unless ($value eq '1') {
13498: $value = 0;
13499: }
13500: } elsif ($item eq 'approval') {
13501: unless ($value =~ /^[012]$/) {
13502: $value = 0;
13503: }
13504: } else {
13505: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13506: $value = 'none';
13507: }
13508: }
13509: $selfenrollhash{'default'}{$type}{$item} = $value;
13510: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
13511: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13512: if ($selfenrollhash{'default'}{$type}{$item} ne
13513: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
13514: push(@{$changes{'default'}{$type}},$item);
13515: }
13516: } else {
13517: push(@{$changes{'default'}{$type}},$item);
13518: }
13519: } else {
13520: push(@{$changes{'default'}{$type}},$item);
13521: }
13522: if ($item eq 'limit') {
13523: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13524: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
13525: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
13526: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
13527: }
13528: } else {
13529: $selfenrollhash{'default'}{$type}{'cap'} = '';
13530: }
13531: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13532: if ($selfenrollhash{'default'}{$type}{'cap'} ne
13533: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
13534: push(@{$changes{'default'}{$type}},'cap');
13535: }
13536: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
13537: push(@{$changes{'default'}{$type}},'cap');
13538: }
13539: }
13540: }
13541: }
13542:
13543: foreach my $item (@{$itemsref}) {
13544: if ($item eq 'fields') {
13545: my @changed;
13546: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
13547: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
13548: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
13549: }
13550: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13551: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
13552: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
13553: $domconfig{'selfenrollment'}{'validation'}{$item});
13554: } else {
13555: @changed = @{$selfenrollhash{'validation'}{$item}};
13556: }
13557: } else {
13558: @changed = @{$selfenrollhash{'validation'}{$item}};
13559: }
13560: if (@changed) {
13561: if ($selfenrollhash{'validation'}{$item}) {
13562: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
13563: } else {
13564: $changes{'validation'}{$item} = &mt('None');
13565: }
13566: }
13567: } else {
13568: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
13569: if ($item eq 'markup') {
13570: if ($env{'form.selfenroll_validation_'.$item}) {
13571: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13572: }
13573: }
13574: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13575: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
13576: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
13577: }
13578: }
13579: }
13580: }
13581:
13582: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
13583: $dom);
13584: if ($putresult eq 'ok') {
13585: if (keys(%changes) > 0) {
13586: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13587: $resulttext = &mt('Changes made:').'<ul>';
13588: foreach my $key ('admin','default','validation') {
13589: if (ref($changes{$key}) eq 'HASH') {
13590: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
13591: if ($key eq 'validation') {
13592: foreach my $item (@{$itemsref}) {
13593: if (exists($changes{$key}{$item})) {
13594: if ($item eq 'markup') {
13595: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13596: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
13597: } else {
13598: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13599: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
13600: }
13601: }
13602: }
13603: } else {
13604: foreach my $type (@types) {
13605: if ($type eq 'community') {
13606: $roles{'1'} = &mt('Community personnel');
13607: } else {
13608: $roles{'1'} = &mt('Course personnel');
13609: }
13610: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 13611: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13612: if ($key eq 'admin') {
13613: my @mgrdc = ();
13614: if (ref($ordered{$key}) eq 'ARRAY') {
13615: foreach my $item (@{$ordered{'admin'}}) {
13616: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13617: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
13618: push(@mgrdc,$item);
13619: }
13620: }
13621: }
13622: if (@mgrdc) {
13623: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
13624: } else {
13625: delete($domdefaults{$type.'selfenrolladmdc'});
13626: }
13627: }
13628: } else {
13629: if (ref($ordered{$key}) eq 'ARRAY') {
13630: foreach my $item (@{$ordered{$key}}) {
13631: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13632: $domdefaults{$type.'selfenroll'.$item} =
13633: $selfenrollhash{$key}{$type}{$item};
13634: }
13635: }
13636: }
13637: }
13638: }
1.231 raeburn 13639: $resulttext .= '<li>'.$titles{$type}.'<ul>';
13640: foreach my $item (@{$ordered{$key}}) {
13641: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13642: $resulttext .= '<li>';
13643: if ($key eq 'admin') {
13644: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
13645: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
13646: } else {
13647: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
13648: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
13649: }
13650: $resulttext .= '</li>';
13651: }
13652: }
13653: $resulttext .= '</ul></li>';
13654: }
13655: }
13656: $resulttext .= '</ul></li>';
13657: }
13658: }
1.232 raeburn 13659: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
13660: my $cachetime = 24*60*60;
13661: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13662: if (ref($lastactref) eq 'HASH') {
13663: $lastactref->{'domdefaults'} = 1;
13664: }
13665: }
1.231 raeburn 13666: }
13667: $resulttext .= '</ul>';
13668: } else {
13669: $resulttext = &mt('No changes made to self-enrollment settings');
13670: }
13671: } else {
13672: $resulttext = '<span class="LC_error">'.
13673: &mt('An error occurred: [_1]',$putresult).'</span>';
13674: }
13675: return $resulttext;
13676: }
13677:
1.137 raeburn 13678: sub modify_usersessions {
1.212 raeburn 13679: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 13680: my @hostingtypes = ('version','excludedomain','includedomain');
13681: my @offloadtypes = ('primary','default');
13682: my %types = (
13683: remote => \@hostingtypes,
13684: hosted => \@hostingtypes,
13685: spares => \@offloadtypes,
13686: );
13687: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 13688: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 13689: my (%by_ip,%by_location,@intdoms,@instdoms);
13690: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 13691: my @locations = sort(keys(%by_location));
1.137 raeburn 13692: my (%defaultshash,%changes);
13693: foreach my $prefix (@prefixes) {
13694: $defaultshash{'usersessions'}{$prefix} = {};
13695: }
1.212 raeburn 13696: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 13697: my $resulttext;
1.138 raeburn 13698: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 13699: foreach my $prefix (@prefixes) {
1.145 raeburn 13700: next if ($prefix eq 'spares');
13701: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 13702: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13703: if ($type eq 'version') {
13704: my $value = $env{'form.'.$prefix.'_'.$type};
13705: my $okvalue;
13706: if ($value ne '') {
13707: if (grep(/^\Q$value\E$/,@lcversions)) {
13708: $okvalue = $value;
13709: }
13710: }
13711: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13712: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13713: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
13714: if ($inuse == 0) {
13715: $changes{$prefix}{$type} = 1;
13716: } else {
13717: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
13718: $changes{$prefix}{$type} = 1;
13719: }
13720: if ($okvalue ne '') {
13721: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13722: }
13723: }
13724: } else {
13725: if (($inuse == 1) && ($okvalue ne '')) {
13726: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13727: $changes{$prefix}{$type} = 1;
13728: }
13729: }
13730: } else {
13731: if (($inuse == 1) && ($okvalue ne '')) {
13732: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13733: $changes{$prefix}{$type} = 1;
13734: }
13735: }
13736: } else {
13737: if (($inuse == 1) && ($okvalue ne '')) {
13738: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13739: $changes{$prefix}{$type} = 1;
13740: }
13741: }
13742: } else {
13743: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13744: my @okvals;
13745: foreach my $val (@vals) {
1.138 raeburn 13746: if ($val =~ /:/) {
13747: my @items = split(/:/,$val);
13748: foreach my $item (@items) {
13749: if (ref($by_location{$item}) eq 'ARRAY') {
13750: push(@okvals,$item);
13751: }
13752: }
13753: } else {
13754: if (ref($by_location{$val}) eq 'ARRAY') {
13755: push(@okvals,$val);
13756: }
1.137 raeburn 13757: }
13758: }
13759: @okvals = sort(@okvals);
13760: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13761: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13762: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13763: if ($inuse == 0) {
13764: $changes{$prefix}{$type} = 1;
13765: } else {
13766: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13767: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
13768: if (@changed > 0) {
13769: $changes{$prefix}{$type} = 1;
13770: }
13771: }
13772: } else {
13773: if ($inuse == 1) {
13774: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13775: $changes{$prefix}{$type} = 1;
13776: }
13777: }
13778: } else {
13779: if ($inuse == 1) {
13780: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13781: $changes{$prefix}{$type} = 1;
13782: }
13783: }
13784: } else {
13785: if ($inuse == 1) {
13786: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13787: $changes{$prefix}{$type} = 1;
13788: }
13789: }
13790: }
13791: }
13792: }
1.145 raeburn 13793:
13794: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 13795: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 13796: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
13797: my $savespares;
13798:
13799: foreach my $lonhost (sort(keys(%servers))) {
13800: my $serverhomeID =
13801: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 13802: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 13803: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
13804: my %spareschg;
13805: foreach my $type (@{$types{'spares'}}) {
13806: my @okspares;
13807: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
13808: foreach my $server (@checked) {
1.152 raeburn 13809: if (&Apache::lonnet::hostname($server) ne '') {
13810: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
13811: unless (grep(/^\Q$server\E$/,@okspares)) {
13812: push(@okspares,$server);
13813: }
1.145 raeburn 13814: }
13815: }
13816: }
13817: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
13818: my $newspare;
1.152 raeburn 13819: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
13820: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 13821: $newspare = $new;
13822: }
13823: }
1.152 raeburn 13824: my @spares;
13825: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
13826: @spares = sort(@okspares,$newspare);
13827: } else {
13828: @spares = sort(@okspares);
13829: }
13830: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 13831: if (ref($spareid{$lonhost}) eq 'HASH') {
13832: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 13833: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 13834: if (@diffs > 0) {
13835: $spareschg{$type} = 1;
13836: }
13837: }
13838: }
13839: }
13840: if (keys(%spareschg) > 0) {
13841: $changes{'spares'}{$lonhost} = \%spareschg;
13842: }
13843: }
1.261 raeburn 13844: $defaultshash{'usersessions'}{'offloadnow'} = {};
13845: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
13846: my @okoffload;
13847: if (@offloadnow) {
13848: foreach my $server (@offloadnow) {
13849: if (&Apache::lonnet::hostname($server) ne '') {
13850: unless (grep(/^\Q$server\E$/,@okoffload)) {
13851: push(@okoffload,$server);
13852: }
13853: }
13854: }
13855: if (@okoffload) {
13856: foreach my $lonhost (@okoffload) {
13857: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
13858: }
13859: }
13860: }
1.145 raeburn 13861: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13862: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
13863: if (ref($changes{'spares'}) eq 'HASH') {
13864: if (keys(%{$changes{'spares'}}) > 0) {
13865: $savespares = 1;
13866: }
13867: }
13868: } else {
13869: $savespares = 1;
13870: }
1.261 raeburn 13871: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
13872: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
13873: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
13874: $changes{'offloadnow'} = 1;
13875: last;
13876: }
13877: }
13878: unless ($changes{'offloadnow'}) {
1.289 raeburn 13879: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 13880: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
13881: $changes{'offloadnow'} = 1;
13882: last;
13883: }
13884: }
13885: }
13886: } elsif (@okoffload) {
13887: $changes{'offloadnow'} = 1;
13888: }
13889: } elsif (@okoffload) {
13890: $changes{'offloadnow'} = 1;
1.145 raeburn 13891: }
1.147 raeburn 13892: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
13893: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 13894: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13895: $dom);
13896: if ($putresult eq 'ok') {
13897: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13898: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
13899: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
13900: }
13901: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
13902: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
13903: }
1.261 raeburn 13904: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13905: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
13906: }
1.137 raeburn 13907: }
13908: my $cachetime = 24*60*60;
13909: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 13910: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 13911: if (ref($lastactref) eq 'HASH') {
13912: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 13913: $lastactref->{'usersessions'} = 1;
1.212 raeburn 13914: }
1.147 raeburn 13915: if (keys(%changes) > 0) {
13916: my %lt = &usersession_titles();
13917: $resulttext = &mt('Changes made:').'<ul>';
13918: foreach my $prefix (@prefixes) {
13919: if (ref($changes{$prefix}) eq 'HASH') {
13920: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
13921: if ($prefix eq 'spares') {
13922: if (ref($changes{$prefix}) eq 'HASH') {
13923: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
13924: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 13925: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 13926: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
13927: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 13928: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
13929: foreach my $type (@{$types{$prefix}}) {
13930: if ($changes{$prefix}{$lonhost}{$type}) {
13931: my $offloadto = &mt('None');
13932: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
13933: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
13934: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
13935: }
1.145 raeburn 13936: }
1.147 raeburn 13937: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 13938: }
1.137 raeburn 13939: }
13940: }
1.147 raeburn 13941: $resulttext .= '</li>';
1.137 raeburn 13942: }
13943: }
1.147 raeburn 13944: } else {
13945: foreach my $type (@{$types{$prefix}}) {
13946: if (defined($changes{$prefix}{$type})) {
13947: my $newvalue;
13948: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13949: if (ref($defaultshash{'usersessions'}{$prefix})) {
13950: if ($type eq 'version') {
13951: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
13952: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13953: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
13954: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
13955: }
1.145 raeburn 13956: }
13957: }
13958: }
1.147 raeburn 13959: if ($newvalue eq '') {
13960: if ($type eq 'version') {
13961: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
13962: } else {
13963: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
13964: }
1.145 raeburn 13965: } else {
1.147 raeburn 13966: if ($type eq 'version') {
13967: $newvalue .= ' '.&mt('(or later)');
13968: }
13969: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 13970: }
1.137 raeburn 13971: }
13972: }
13973: }
1.147 raeburn 13974: $resulttext .= '</ul>';
1.137 raeburn 13975: }
13976: }
1.261 raeburn 13977: if ($changes{'offloadnow'}) {
13978: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13979: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
13980: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
13981: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
13982: $resulttext .= '<li>'.$lonhost.'</li>';
13983: }
13984: $resulttext .= '</ul>';
13985: } else {
13986: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
13987: }
13988: } else {
13989: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
13990: }
13991: }
1.147 raeburn 13992: $resulttext .= '</ul>';
13993: } else {
13994: $resulttext = $nochgmsg;
1.137 raeburn 13995: }
13996: } else {
13997: $resulttext = '<span class="LC_error">'.
13998: &mt('An error occurred: [_1]',$putresult).'</span>';
13999: }
14000: } else {
1.147 raeburn 14001: $resulttext = $nochgmsg;
1.137 raeburn 14002: }
14003: return $resulttext;
14004: }
14005:
1.275 raeburn 14006: sub modify_ssl {
14007: my ($dom,$lastactref,%domconfig) = @_;
14008: my (%by_ip,%by_location,@intdoms,@instdoms);
14009: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14010: my @locations = sort(keys(%by_location));
14011: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14012: my (%defaultshash,%changes);
14013: my $action = 'ssl';
1.293 raeburn 14014: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 14015: foreach my $prefix (@prefixes) {
14016: $defaultshash{$action}{$prefix} = {};
14017: }
14018: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14019: my $resulttext;
14020: my %iphost = &Apache::lonnet::get_iphost();
14021: my @reptypes = ('certreq','nocertreq');
14022: my @connecttypes = ('dom','intdom','other');
14023: my %types = (
1.293 raeburn 14024: connto => \@connecttypes,
14025: connfrom => \@connecttypes,
14026: replication => \@reptypes,
1.275 raeburn 14027: );
14028: foreach my $prefix (sort(keys(%types))) {
14029: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 14030: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 14031: my $value = 'yes';
14032: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
14033: $value = $env{'form.'.$prefix.'_'.$type};
14034: }
14035: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
14036: if ($domconfig{$action}{$prefix}{$type} ne '') {
14037: if ($value ne $domconfig{$action}{$prefix}{$type}) {
14038: $changes{$prefix}{$type} = 1;
14039: }
14040: $defaultshash{$action}{$prefix}{$type} = $value;
14041: } else {
14042: $defaultshash{$action}{$prefix}{$type} = $value;
14043: $changes{$prefix}{$type} = 1;
14044: }
14045: } else {
14046: $defaultshash{$action}{$prefix}{$type} = $value;
14047: $changes{$prefix}{$type} = 1;
14048: }
14049: if (($type eq 'dom') && (keys(%servers) == 1)) {
14050: delete($changes{$prefix}{$type});
14051: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
14052: delete($changes{$prefix}{$type});
14053: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
14054: delete($changes{$prefix}{$type});
14055: }
14056: } elsif ($prefix eq 'replication') {
14057: if (@locations > 0) {
14058: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14059: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14060: my @okvals;
14061: foreach my $val (@vals) {
14062: if ($val =~ /:/) {
14063: my @items = split(/:/,$val);
14064: foreach my $item (@items) {
14065: if (ref($by_location{$item}) eq 'ARRAY') {
14066: push(@okvals,$item);
14067: }
14068: }
14069: } else {
14070: if (ref($by_location{$val}) eq 'ARRAY') {
14071: push(@okvals,$val);
14072: }
14073: }
14074: }
14075: @okvals = sort(@okvals);
14076: if (ref($domconfig{$action}) eq 'HASH') {
14077: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
14078: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
14079: if ($inuse == 0) {
14080: $changes{$prefix}{$type} = 1;
14081: } else {
14082: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14083: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
14084: if (@changed > 0) {
14085: $changes{$prefix}{$type} = 1;
14086: }
14087: }
14088: } else {
14089: if ($inuse == 1) {
14090: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14091: $changes{$prefix}{$type} = 1;
14092: }
14093: }
14094: } else {
14095: if ($inuse == 1) {
14096: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14097: $changes{$prefix}{$type} = 1;
14098: }
14099: }
14100: } else {
14101: if ($inuse == 1) {
14102: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14103: $changes{$prefix}{$type} = 1;
14104: }
14105: }
14106: }
14107: }
14108: }
14109: }
14110: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
14111: if (keys(%changes) > 0) {
14112: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14113: $dom);
14114: if ($putresult eq 'ok') {
14115: if (ref($defaultshash{$action}) eq 'HASH') {
14116: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
14117: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
14118: }
1.293 raeburn 14119: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
14120: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
14121: }
14122: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
14123: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275 raeburn 14124: }
14125: }
14126: my $cachetime = 24*60*60;
14127: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14128: if (ref($lastactref) eq 'HASH') {
14129: $lastactref->{'domdefaults'} = 1;
14130: }
14131: if (keys(%changes) > 0) {
14132: my %titles = &ssl_titles();
14133: $resulttext = &mt('Changes made:').'<ul>';
14134: foreach my $prefix (@prefixes) {
14135: if (ref($changes{$prefix}) eq 'HASH') {
14136: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
14137: foreach my $type (@{$types{$prefix}}) {
14138: if (defined($changes{$prefix}{$type})) {
14139: my $newvalue;
14140: if (ref($defaultshash{$action}) eq 'HASH') {
14141: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 14142: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 14143: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
14144: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
14145: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
14146: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
14147: }
14148: }
14149: }
14150: if ($newvalue eq '') {
14151: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
14152: } else {
14153: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
14154: }
14155: }
14156: }
14157: }
14158: $resulttext .= '</ul>';
14159: }
14160: }
14161: } else {
14162: $resulttext = $nochgmsg;
14163: }
14164: } else {
14165: $resulttext = '<span class="LC_error">'.
14166: &mt('An error occurred: [_1]',$putresult).'</span>';
14167: }
14168: } else {
14169: $resulttext = $nochgmsg;
14170: }
14171: return $resulttext;
14172: }
14173:
1.279 raeburn 14174: sub modify_trust {
14175: my ($dom,$lastactref,%domconfig) = @_;
14176: my (%by_ip,%by_location,@intdoms,@instdoms);
14177: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14178: my @locations = sort(keys(%by_location));
14179: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
14180: my @types = ('exc','inc');
14181: my (%defaultshash,%changes);
14182: foreach my $prefix (@prefixes) {
14183: $defaultshash{'trust'}{$prefix} = {};
14184: }
14185: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14186: my $resulttext;
14187: foreach my $prefix (@prefixes) {
14188: foreach my $type (@types) {
14189: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14190: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14191: my @okvals;
14192: foreach my $val (@vals) {
14193: if ($val =~ /:/) {
14194: my @items = split(/:/,$val);
14195: foreach my $item (@items) {
14196: if (ref($by_location{$item}) eq 'ARRAY') {
14197: push(@okvals,$item);
14198: }
14199: }
14200: } else {
14201: if (ref($by_location{$val}) eq 'ARRAY') {
14202: push(@okvals,$val);
14203: }
14204: }
14205: }
14206: @okvals = sort(@okvals);
14207: if (ref($domconfig{'trust'}) eq 'HASH') {
14208: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
14209: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14210: if ($inuse == 0) {
14211: $changes{$prefix}{$type} = 1;
14212: } else {
14213: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14214: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
14215: if (@changed > 0) {
14216: $changes{$prefix}{$type} = 1;
14217: }
14218: }
14219: } else {
14220: if ($inuse == 1) {
14221: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14222: $changes{$prefix}{$type} = 1;
14223: }
14224: }
14225: } else {
14226: if ($inuse == 1) {
14227: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14228: $changes{$prefix}{$type} = 1;
14229: }
14230: }
14231: } else {
14232: if ($inuse == 1) {
14233: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14234: $changes{$prefix}{$type} = 1;
14235: }
14236: }
14237: }
14238: }
14239: my $nochgmsg = &mt('No changes made to trust settings.');
14240: if (keys(%changes) > 0) {
14241: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14242: $dom);
14243: if ($putresult eq 'ok') {
14244: if (ref($defaultshash{'trust'}) eq 'HASH') {
14245: foreach my $prefix (@prefixes) {
14246: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
14247: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
14248: }
14249: }
14250: }
14251: my $cachetime = 24*60*60;
14252: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14253: if (ref($lastactref) eq 'HASH') {
14254: $lastactref->{'domdefaults'} = 1;
14255: }
14256: if (keys(%changes) > 0) {
14257: my %lt = &trust_titles();
14258: $resulttext = &mt('Changes made:').'<ul>';
14259: foreach my $prefix (@prefixes) {
14260: if (ref($changes{$prefix}) eq 'HASH') {
14261: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14262: foreach my $type (@types) {
14263: if (defined($changes{$prefix}{$type})) {
14264: my $newvalue;
14265: if (ref($defaultshash{'trust'}) eq 'HASH') {
14266: if (ref($defaultshash{'trust'}{$prefix})) {
14267: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14268: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
14269: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
14270: }
14271: }
14272: }
14273: }
14274: if ($newvalue eq '') {
14275: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14276: } else {
14277: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
14278: }
14279: }
14280: }
14281: $resulttext .= '</ul>';
14282: }
14283: }
14284: $resulttext .= '</ul>';
14285: } else {
14286: $resulttext = $nochgmsg;
14287: }
14288: } else {
14289: $resulttext = '<span class="LC_error">'.
14290: &mt('An error occurred: [_1]',$putresult).'</span>';
14291: }
14292: } else {
14293: $resulttext = $nochgmsg;
14294: }
14295: return $resulttext;
14296: }
14297:
1.150 raeburn 14298: sub modify_loadbalancing {
14299: my ($dom,%domconfig) = @_;
14300: my $primary_id = &Apache::lonnet::domain($dom,'primary');
14301: my $intdom = &Apache::lonnet::internet_dom($primary_id);
14302: my ($othertitle,$usertypes,$types) =
14303: &Apache::loncommon::sorted_inst_types($dom);
14304: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 14305: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 14306: my @sparestypes = ('primary','default');
14307: my %typetitles = &sparestype_titles();
14308: my $resulttext;
1.171 raeburn 14309: my (%currbalancer,%currtargets,%currrules,%existing);
14310: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14311: %existing = %{$domconfig{'loadbalancing'}};
14312: }
14313: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
14314: \%currtargets,\%currrules);
14315: my ($saveloadbalancing,%defaultshash,%changes);
14316: my ($alltypes,$othertypes,$titles) =
14317: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
14318: my %ruletitles = &offloadtype_text();
14319: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
14320: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
14321: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
14322: if ($balancer eq '') {
14323: next;
14324: }
1.210 raeburn 14325: if (!exists($servers{$balancer})) {
1.171 raeburn 14326: if (exists($currbalancer{$balancer})) {
14327: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 14328: }
1.171 raeburn 14329: next;
14330: }
14331: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
14332: push(@{$changes{'delete'}},$balancer);
14333: next;
14334: }
14335: if (!exists($currbalancer{$balancer})) {
14336: push(@{$changes{'add'}},$balancer);
14337: }
14338: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
14339: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
14340: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
14341: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14342: $saveloadbalancing = 1;
14343: }
14344: foreach my $sparetype (@sparestypes) {
14345: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
14346: my @offloadto;
14347: foreach my $target (@targets) {
14348: if (($servers{$target}) && ($target ne $balancer)) {
14349: if ($sparetype eq 'default') {
14350: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
14351: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 14352: }
14353: }
1.171 raeburn 14354: unless(grep(/^\Q$target\E$/,@offloadto)) {
14355: push(@offloadto,$target);
14356: }
1.150 raeburn 14357: }
14358: }
1.284 raeburn 14359: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
14360: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
14361: push(@offloadto,$balancer);
14362: }
14363: }
14364: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 14365: }
1.171 raeburn 14366: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 14367: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14368: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
14369: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 14370: if (@targetdiffs > 0) {
1.171 raeburn 14371: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14372: }
1.171 raeburn 14373: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14374: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14375: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14376: }
14377: }
14378: }
14379: } else {
1.171 raeburn 14380: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 14381: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14382: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14383: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14384: $changes{'curr'}{$balancer}{'targets'} = 1;
14385: }
1.150 raeburn 14386: }
14387: }
1.210 raeburn 14388: }
1.150 raeburn 14389: }
14390: my $ishomedom;
1.171 raeburn 14391: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
14392: $ishomedom = 1;
1.150 raeburn 14393: }
14394: if (ref($alltypes) eq 'ARRAY') {
14395: foreach my $type (@{$alltypes}) {
14396: my $rule;
1.210 raeburn 14397: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 14398: (!$ishomedom)) {
1.171 raeburn 14399: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
14400: }
14401: if ($rule eq 'specific') {
1.255 raeburn 14402: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 14403: if (exists($servers{$specifiedhost})) {
1.255 raeburn 14404: $rule = $specifiedhost;
14405: }
1.150 raeburn 14406: }
1.171 raeburn 14407: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
14408: if (ref($currrules{$balancer}) eq 'HASH') {
14409: if ($rule ne $currrules{$balancer}{$type}) {
14410: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14411: }
14412: } elsif ($rule ne '') {
1.171 raeburn 14413: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14414: }
14415: }
14416: }
1.171 raeburn 14417: }
14418: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
14419: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
14420: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
14421: $defaultshash{'loadbalancing'} = {};
14422: }
14423: my $putresult = &Apache::lonnet::put_dom('configuration',
14424: \%defaultshash,$dom);
14425: if ($putresult eq 'ok') {
14426: if (keys(%changes) > 0) {
1.252 raeburn 14427: my %toupdate;
1.171 raeburn 14428: if (ref($changes{'delete'}) eq 'ARRAY') {
14429: foreach my $balancer (sort(@{$changes{'delete'}})) {
14430: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 14431: $toupdate{$balancer} = 1;
1.150 raeburn 14432: }
1.171 raeburn 14433: }
14434: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 14435: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 14436: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 14437: $toupdate{$balancer} = 1;
1.171 raeburn 14438: }
14439: }
14440: if (ref($changes{'curr'}) eq 'HASH') {
14441: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 14442: $toupdate{$balancer} = 1;
1.171 raeburn 14443: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
14444: if ($changes{'curr'}{$balancer}{'targets'}) {
14445: my %offloadstr;
14446: foreach my $sparetype (@sparestypes) {
14447: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14448: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14449: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14450: }
14451: }
1.150 raeburn 14452: }
1.171 raeburn 14453: if (keys(%offloadstr) == 0) {
14454: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 14455: } else {
1.171 raeburn 14456: my $showoffload;
14457: foreach my $sparetype (@sparestypes) {
14458: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
14459: if (defined($offloadstr{$sparetype})) {
14460: $showoffload .= $offloadstr{$sparetype};
14461: } else {
14462: $showoffload .= &mt('None');
14463: }
14464: $showoffload .= (' 'x3);
14465: }
14466: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 14467: }
14468: }
14469: }
1.171 raeburn 14470: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
14471: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
14472: foreach my $type (@{$alltypes}) {
14473: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
14474: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14475: my $balancetext;
14476: if ($rule eq '') {
14477: $balancetext = $ruletitles{'default'};
1.209 raeburn 14478: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 14479: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 14480: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 14481: foreach my $sparetype (@sparestypes) {
14482: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14483: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14484: }
14485: }
1.253 raeburn 14486: foreach my $item (@{$alltypes}) {
14487: next if ($item =~ /^_LC_ipchange/);
14488: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
14489: if ($hasrule eq 'homeserver') {
14490: map { $toupdate{$_} = 1; } (keys(%libraryservers));
14491: } else {
14492: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
14493: if ($servers{$hasrule}) {
14494: $toupdate{$hasrule} = 1;
14495: }
14496: }
14497: }
14498: }
1.254 raeburn 14499: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
14500: $balancetext = $ruletitles{$rule};
14501: } else {
14502: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14503: $balancetext = $ruletitles{'particular'}.' '.$receiver;
14504: if ($receiver) {
14505: $toupdate{$receiver};
14506: }
14507: }
14508: } else {
14509: $balancetext = $ruletitles{$rule};
1.252 raeburn 14510: }
1.171 raeburn 14511: } else {
14512: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
14513: }
1.210 raeburn 14514: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 14515: }
14516: }
14517: }
14518: }
1.252 raeburn 14519: if (keys(%toupdate)) {
14520: my %thismachine;
14521: my $updatedhere;
14522: my $cachetime = 60*60*24;
14523: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
14524: foreach my $lonhost (keys(%toupdate)) {
14525: if ($thismachine{$lonhost}) {
14526: unless ($updatedhere) {
14527: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
14528: $defaultshash{'loadbalancing'},
14529: $cachetime);
14530: $updatedhere = 1;
14531: }
14532: } else {
14533: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
14534: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
14535: }
14536: }
14537: }
1.150 raeburn 14538: }
1.171 raeburn 14539: }
14540: if ($resulttext ne '') {
14541: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 14542: } else {
14543: $resulttext = $nochgmsg;
14544: }
14545: } else {
1.171 raeburn 14546: $resulttext = $nochgmsg;
1.150 raeburn 14547: }
14548: } else {
1.171 raeburn 14549: $resulttext = '<span class="LC_error">'.
14550: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 14551: }
14552: } else {
1.171 raeburn 14553: $resulttext = $nochgmsg;
1.150 raeburn 14554: }
14555: return $resulttext;
14556: }
14557:
1.48 raeburn 14558: sub recurse_check {
14559: my ($chkcats,$categories,$depth,$name) = @_;
14560: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
14561: my $chg = 0;
14562: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
14563: my $category = $chkcats->[$depth]{$name}[$j];
14564: my $item;
14565: if ($category eq '') {
14566: $chg ++;
14567: } else {
14568: my $deeper = $depth + 1;
14569: $item = &escape($category).':'.&escape($name).':'.$depth;
14570: if ($chg) {
14571: $categories->{$item} -= $chg;
14572: }
14573: &recurse_check($chkcats,$categories,$deeper,$category);
14574: $deeper --;
14575: }
14576: }
14577: }
14578: return;
14579: }
14580:
14581: sub recurse_cat_deletes {
14582: my ($item,$coursecategories,$deletions) = @_;
14583: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14584: my $subdepth = $depth + 1;
14585: if (ref($coursecategories) eq 'HASH') {
14586: foreach my $subitem (keys(%{$coursecategories})) {
14587: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
14588: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
14589: delete($coursecategories->{$subitem});
14590: $deletions->{$subitem} = 1;
14591: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 14592: }
1.48 raeburn 14593: }
14594: }
14595: return;
14596: }
14597:
1.125 raeburn 14598: sub active_dc_picker {
1.191 raeburn 14599: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 14600: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 14601: my @domcoord = keys(%domcoords);
14602: if (keys(%currhash)) {
14603: foreach my $dc (keys(%currhash)) {
14604: unless (exists($domcoords{$dc})) {
14605: push(@domcoord,$dc);
14606: }
14607: }
14608: }
14609: @domcoord = sort(@domcoord);
1.210 raeburn 14610: my $numdcs = scalar(@domcoord);
1.191 raeburn 14611: my $rows = 0;
14612: my $table;
1.125 raeburn 14613: if ($numdcs > 1) {
1.191 raeburn 14614: $table = '<table>';
14615: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 14616: my $rem = $i%($numinrow);
14617: if ($rem == 0) {
14618: if ($i > 0) {
1.191 raeburn 14619: $table .= '</tr>';
1.125 raeburn 14620: }
1.191 raeburn 14621: $table .= '<tr>';
14622: $rows ++;
1.125 raeburn 14623: }
1.191 raeburn 14624: my $check = '';
14625: if ($inputtype eq 'radio') {
14626: if (keys(%currhash) == 0) {
14627: if (!$i) {
14628: $check = ' checked="checked"';
14629: }
14630: } elsif (exists($currhash{$domcoord[$i]})) {
14631: $check = ' checked="checked"';
14632: }
14633: } else {
14634: if (exists($currhash{$domcoord[$i]})) {
14635: $check = ' checked="checked"';
1.125 raeburn 14636: }
14637: }
1.191 raeburn 14638: if ($i == @domcoord - 1) {
1.125 raeburn 14639: my $colsleft = $numinrow - $rem;
14640: if ($colsleft > 1) {
1.191 raeburn 14641: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 14642: } else {
1.191 raeburn 14643: $table .= '<td class="LC_left_item">';
1.125 raeburn 14644: }
14645: } else {
1.191 raeburn 14646: $table .= '<td class="LC_left_item">';
14647: }
14648: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
14649: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
14650: $table .= '<span class="LC_nobreak"><label>'.
14651: '<input type="'.$inputtype.'" name="'.$name.'"'.
14652: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
14653: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 14654: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 14655: }
1.219 raeburn 14656: $table .= '</label></span></td>';
1.191 raeburn 14657: }
14658: $table .= '</tr></table>';
14659: } elsif ($numdcs == 1) {
1.219 raeburn 14660: my ($dcname,$dcdom) = split(':',$domcoord[0]);
14661: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 14662: if ($inputtype eq 'radio') {
1.247 raeburn 14663: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 14664: if ($user ne $dcname.':'.$dcdom) {
14665: $table .= ' ('.$dcname.':'.$dcdom.')';
14666: }
1.191 raeburn 14667: } else {
14668: my $check;
14669: if (exists($currhash{$domcoord[0]})) {
14670: $check = ' checked="checked"';
1.125 raeburn 14671: }
1.247 raeburn 14672: $table = '<span class="LC_nobreak"><label>'.
14673: '<input type="checkbox" name="'.$name.'" '.
14674: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 14675: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 14676: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 14677: }
1.220 raeburn 14678: $table .= '</label></span>';
1.191 raeburn 14679: $rows ++;
1.125 raeburn 14680: }
14681: }
1.191 raeburn 14682: return ($numdcs,$table,$rows);
1.125 raeburn 14683: }
14684:
1.137 raeburn 14685: sub usersession_titles {
14686: return &Apache::lonlocal::texthash(
14687: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
14688: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 14689: spares => 'Servers offloaded to, when busy',
1.137 raeburn 14690: version => 'LON-CAPA version requirement',
1.138 raeburn 14691: excludedomain => 'Allow all, but exclude specific domains',
14692: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 14693: primary => 'Primary (checked first)',
1.154 raeburn 14694: default => 'Default',
1.137 raeburn 14695: );
14696: }
14697:
1.152 raeburn 14698: sub id_for_thisdom {
14699: my (%servers) = @_;
14700: my %altids;
14701: foreach my $server (keys(%servers)) {
14702: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
14703: if ($serverhome ne $server) {
14704: $altids{$serverhome} = $server;
14705: }
14706: }
14707: return %altids;
14708: }
14709:
1.150 raeburn 14710: sub count_servers {
14711: my ($currbalancer,%servers) = @_;
14712: my (@spares,$numspares);
14713: foreach my $lonhost (sort(keys(%servers))) {
14714: next if ($currbalancer eq $lonhost);
14715: push(@spares,$lonhost);
14716: }
14717: if ($currbalancer) {
14718: $numspares = scalar(@spares);
14719: } else {
14720: $numspares = scalar(@spares) - 1;
14721: }
14722: return ($numspares,@spares);
14723: }
14724:
14725: sub lonbalance_targets_js {
1.171 raeburn 14726: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 14727: my $select = &mt('Select');
14728: my ($alltargets,$allishome,$allinsttypes,@alltypes);
14729: if (ref($servers) eq 'HASH') {
14730: $alltargets = join("','",sort(keys(%{$servers})));
14731: my @homedoms;
14732: foreach my $server (sort(keys(%{$servers}))) {
14733: if (&Apache::lonnet::host_domain($server) eq $dom) {
14734: push(@homedoms,'1');
14735: } else {
14736: push(@homedoms,'0');
14737: }
14738: }
14739: $allishome = join("','",@homedoms);
14740: }
14741: if (ref($types) eq 'ARRAY') {
14742: if (@{$types} > 0) {
14743: @alltypes = @{$types};
14744: }
14745: }
14746: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
14747: $allinsttypes = join("','",@alltypes);
1.171 raeburn 14748: my (%currbalancer,%currtargets,%currrules,%existing);
14749: if (ref($settings) eq 'HASH') {
14750: %existing = %{$settings};
14751: }
14752: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
14753: \%currtargets,\%currrules);
1.210 raeburn 14754: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 14755: return <<"END";
14756:
14757: <script type="text/javascript">
14758: // <![CDATA[
14759:
1.171 raeburn 14760: currBalancers = new Array('$balancers');
14761:
14762: function toggleTargets(balnum) {
14763: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14764: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
14765: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
14766: var prevbalancer = prevhostitem.value;
14767: var baltotal = document.getElementById('loadbalancing_total').value;
14768: prevhostitem.value = balancer;
14769: if (prevbalancer != '') {
14770: var prevIdx = currBalancers.indexOf(prevbalancer);
14771: if (prevIdx != -1) {
14772: currBalancers.splice(prevIdx,1);
14773: }
14774: }
1.150 raeburn 14775: if (balancer == '') {
1.171 raeburn 14776: hideSpares(balnum);
1.150 raeburn 14777: } else {
1.171 raeburn 14778: var currIdx = currBalancers.indexOf(balancer);
14779: if (currIdx == -1) {
14780: currBalancers.push(balancer);
14781: }
1.150 raeburn 14782: var homedoms = new Array('$allishome');
1.171 raeburn 14783: var ishomedom = homedoms[lonhostitem.selectedIndex];
14784: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 14785: }
1.171 raeburn 14786: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 14787: return;
14788: }
14789:
1.171 raeburn 14790: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 14791: var alltargets = new Array('$alltargets');
14792: var insttypes = new Array('$allinsttypes');
1.151 raeburn 14793: var offloadtypes = new Array('primary','default');
14794:
1.171 raeburn 14795: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
14796: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 14797:
1.151 raeburn 14798: for (var i=0; i<offloadtypes.length; i++) {
14799: var count = 0;
14800: for (var j=0; j<alltargets.length; j++) {
14801: if (alltargets[j] != balancer) {
1.171 raeburn 14802: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
14803: item.value = alltargets[j];
14804: item.style.textAlign='left';
14805: item.style.textFace='normal';
14806: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
14807: if (currBalancers.indexOf(alltargets[j]) == -1) {
14808: item.disabled = '';
14809: } else {
14810: item.disabled = 'disabled';
14811: item.checked = false;
14812: }
1.151 raeburn 14813: count ++;
14814: }
1.150 raeburn 14815: }
14816: }
1.151 raeburn 14817: for (var k=0; k<insttypes.length; k++) {
14818: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 14819: if (ishomedom == 1) {
1.171 raeburn 14820: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14821: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14822: } else {
1.171 raeburn 14823: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14824: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 14825: }
14826: } else {
1.171 raeburn 14827: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14828: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14829: }
1.151 raeburn 14830: if ((insttypes[k] != '_LC_external') &&
14831: ((insttypes[k] != '_LC_internetdom') ||
14832: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 14833: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
14834: item.options.length = 0;
14835: item.options[0] = new Option("","",true,true);
1.210 raeburn 14836: var idx = 0;
1.151 raeburn 14837: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 14838: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
14839: idx ++;
14840: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 14841: }
14842: }
14843: }
14844: }
14845: return;
14846: }
14847:
1.171 raeburn 14848: function hideSpares(balnum) {
1.150 raeburn 14849: var alltargets = new Array('$alltargets');
14850: var insttypes = new Array('$allinsttypes');
14851: var offloadtypes = new Array('primary','default');
14852:
1.171 raeburn 14853: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
14854: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 14855:
14856: var total = alltargets.length - 1;
14857: for (var i=0; i<offloadtypes; i++) {
14858: for (var j=0; j<total; j++) {
1.171 raeburn 14859: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
14860: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
14861: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 14862: }
1.150 raeburn 14863: }
14864: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 14865: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14866: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 14867: if (insttypes[k] != '_LC_external') {
1.171 raeburn 14868: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
14869: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 14870: }
14871: }
14872: return;
14873: }
14874:
1.171 raeburn 14875: function checkOffloads(item,balnum,type) {
1.150 raeburn 14876: var alltargets = new Array('$alltargets');
14877: var offloadtypes = new Array('primary','default');
14878: if (item.checked) {
14879: var total = alltargets.length - 1;
14880: var other;
14881: if (type == offloadtypes[0]) {
1.151 raeburn 14882: other = offloadtypes[1];
1.150 raeburn 14883: } else {
1.151 raeburn 14884: other = offloadtypes[0];
1.150 raeburn 14885: }
14886: for (var i=0; i<total; i++) {
1.171 raeburn 14887: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 14888: if (server == item.value) {
1.171 raeburn 14889: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
14890: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 14891: }
14892: }
14893: }
14894: }
14895: return;
14896: }
14897:
1.171 raeburn 14898: function singleServerToggle(balnum,type) {
14899: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 14900: if (offloadtoSelIdx == 0) {
1.171 raeburn 14901: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
14902: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14903:
14904: } else {
1.171 raeburn 14905: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
14906: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 14907: }
14908: return;
14909: }
14910:
1.171 raeburn 14911: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 14912: if (type == '_LC_external') {
1.171 raeburn 14913: return;
1.150 raeburn 14914: }
1.171 raeburn 14915: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 14916: for (var i=0; i<typesRules.length; i++) {
14917: if (formname.elements[typesRules[i]].checked) {
14918: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 14919: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
14920: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14921: } else {
1.171 raeburn 14922: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
14923: }
14924: }
14925: }
14926: return;
14927: }
14928:
14929: function balancerDeleteChange(balnum) {
14930: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14931: var baltotal = document.getElementById('loadbalancing_total').value;
14932: var addtarget;
14933: var removetarget;
14934: var action = 'delete';
14935: if (document.getElementById('loadbalancing_delete_'+balnum)) {
14936: var lonhost = hostitem.value;
14937: var currIdx = currBalancers.indexOf(lonhost);
14938: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
14939: if (currIdx != -1) {
14940: currBalancers.splice(currIdx,1);
14941: }
14942: addtarget = lonhost;
14943: } else {
14944: if (currIdx == -1) {
14945: currBalancers.push(lonhost);
14946: }
14947: removetarget = lonhost;
14948: action = 'undelete';
14949: }
14950: balancerChange(balnum,baltotal,action,addtarget,removetarget);
14951: }
14952: return;
14953: }
14954:
14955: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
14956: if (baltotal > 1) {
14957: var offloadtypes = new Array('primary','default');
14958: var alltargets = new Array('$alltargets');
14959: var insttypes = new Array('$allinsttypes');
14960: for (var i=0; i<baltotal; i++) {
14961: if (i != balnum) {
14962: for (var j=0; j<offloadtypes.length; j++) {
14963: var total = alltargets.length - 1;
14964: for (var k=0; k<total; k++) {
14965: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
14966: var server = serveritem.value;
14967: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14968: if (server == addtarget) {
14969: serveritem.disabled = '';
14970: }
14971: }
14972: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14973: if (server == removetarget) {
14974: serveritem.disabled = 'disabled';
14975: serveritem.checked = false;
14976: }
14977: }
14978: }
14979: }
14980: for (var j=0; j<insttypes.length; j++) {
14981: if (insttypes[j] != '_LC_external') {
14982: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
14983: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
14984: var currSel = singleserver.selectedIndex;
14985: var currVal = singleserver.options[currSel].value;
14986: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14987: var numoptions = singleserver.options.length;
14988: var needsnew = 1;
14989: for (var k=0; k<numoptions; k++) {
14990: if (singleserver.options[k] == addtarget) {
14991: needsnew = 0;
14992: break;
14993: }
14994: }
14995: if (needsnew == 1) {
14996: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
14997: }
14998: }
14999: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
15000: singleserver.options.length = 0;
15001: if ((currVal) && (currVal != removetarget)) {
15002: singleserver.options[0] = new Option("","",false,false);
15003: } else {
15004: singleserver.options[0] = new Option("","",true,true);
15005: }
15006: var idx = 0;
15007: for (var m=0; m<alltargets.length; m++) {
15008: if (currBalancers.indexOf(alltargets[m]) == -1) {
15009: idx ++;
15010: if (currVal == alltargets[m]) {
15011: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
15012: } else {
15013: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
15014: }
15015: }
15016: }
15017: }
15018: }
15019: }
15020: }
1.150 raeburn 15021: }
15022: }
15023: }
15024: return;
15025: }
15026:
1.152 raeburn 15027: // ]]>
15028: </script>
15029:
15030: END
15031: }
15032:
15033: sub new_spares_js {
15034: my @sparestypes = ('primary','default');
15035: my $types = join("','",@sparestypes);
15036: my $select = &mt('Select');
15037: return <<"END";
15038:
15039: <script type="text/javascript">
15040: // <![CDATA[
15041:
15042: function updateNewSpares(formname,lonhost) {
15043: var types = new Array('$types');
15044: var include = new Array();
15045: var exclude = new Array();
15046: for (var i=0; i<types.length; i++) {
15047: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
15048: for (var j=0; j<spareboxes.length; j++) {
15049: if (formname.elements[spareboxes[j]].checked) {
15050: exclude.push(formname.elements[spareboxes[j]].value);
15051: } else {
15052: include.push(formname.elements[spareboxes[j]].value);
15053: }
15054: }
15055: }
15056: for (var i=0; i<types.length; i++) {
15057: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
15058: var selIdx = newSpare.selectedIndex;
15059: var currnew = newSpare.options[selIdx].value;
15060: var okSpares = new Array();
15061: for (var j=0; j<newSpare.options.length; j++) {
15062: var possible = newSpare.options[j].value;
15063: if (possible != '') {
15064: if (exclude.indexOf(possible) == -1) {
15065: okSpares.push(possible);
15066: } else {
15067: if (currnew == possible) {
15068: selIdx = 0;
15069: }
15070: }
15071: }
15072: }
15073: for (var k=0; k<include.length; k++) {
15074: if (okSpares.indexOf(include[k]) == -1) {
15075: okSpares.push(include[k]);
15076: }
15077: }
15078: okSpares.sort();
15079: newSpare.options.length = 0;
15080: if (selIdx == 0) {
15081: newSpare.options[0] = new Option("$select","",true,true);
15082: } else {
15083: newSpare.options[0] = new Option("$select","",false,false);
15084: }
15085: for (var m=0; m<okSpares.length; m++) {
15086: var idx = m+1;
15087: var selThis = 0;
15088: if (selIdx != 0) {
15089: if (okSpares[m] == currnew) {
15090: selThis = 1;
15091: }
15092: }
15093: if (selThis == 1) {
15094: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
15095: } else {
15096: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
15097: }
15098: }
15099: }
15100: return;
15101: }
15102:
15103: function checkNewSpares(lonhost,type) {
15104: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
15105: var chosen = newSpare.options[newSpare.selectedIndex].value;
15106: if (chosen != '') {
15107: var othertype;
15108: var othernewSpare;
15109: if (type == 'primary') {
15110: othernewSpare = document.getElementById('newspare_default_'+lonhost);
15111: }
15112: if (type == 'default') {
15113: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
15114: }
15115: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
15116: othernewSpare.selectedIndex = 0;
15117: }
15118: }
15119: return;
15120: }
15121:
15122: // ]]>
15123: </script>
15124:
15125: END
15126:
15127: }
15128:
15129: sub common_domprefs_js {
15130: return <<"END";
15131:
15132: <script type="text/javascript">
15133: // <![CDATA[
15134:
1.150 raeburn 15135: function getIndicesByName(formname,item) {
1.152 raeburn 15136: var group = new Array();
1.150 raeburn 15137: for (var i=0;i<formname.elements.length;i++) {
15138: if (formname.elements[i].name == item) {
1.152 raeburn 15139: group.push(formname.elements[i].id);
1.150 raeburn 15140: }
15141: }
1.152 raeburn 15142: return group;
1.150 raeburn 15143: }
15144:
15145: // ]]>
15146: </script>
15147:
15148: END
1.152 raeburn 15149:
1.150 raeburn 15150: }
15151:
1.165 raeburn 15152: sub recaptcha_js {
15153: my %lt = &captcha_phrases();
15154: return <<"END";
15155:
15156: <script type="text/javascript">
15157: // <![CDATA[
15158:
15159: function updateCaptcha(caller,context) {
15160: var privitem;
15161: var pubitem;
15162: var privtext;
15163: var pubtext;
1.269 raeburn 15164: var versionitem;
15165: var versiontext;
1.165 raeburn 15166: if (document.getElementById(context+'_recaptchapub')) {
15167: pubitem = document.getElementById(context+'_recaptchapub');
15168: } else {
15169: return;
15170: }
15171: if (document.getElementById(context+'_recaptchapriv')) {
15172: privitem = document.getElementById(context+'_recaptchapriv');
15173: } else {
15174: return;
15175: }
15176: if (document.getElementById(context+'_recaptchapubtxt')) {
15177: pubtext = document.getElementById(context+'_recaptchapubtxt');
15178: } else {
15179: return;
15180: }
15181: if (document.getElementById(context+'_recaptchaprivtxt')) {
15182: privtext = document.getElementById(context+'_recaptchaprivtxt');
15183: } else {
15184: return;
15185: }
1.269 raeburn 15186: if (document.getElementById(context+'_recaptchaversion')) {
15187: versionitem = document.getElementById(context+'_recaptchaversion');
15188: } else {
15189: return;
15190: }
15191: if (document.getElementById(context+'_recaptchavertxt')) {
15192: versiontext = document.getElementById(context+'_recaptchavertxt');
15193: } else {
15194: return;
15195: }
1.165 raeburn 15196: if (caller.checked) {
15197: if (caller.value == 'recaptcha') {
15198: pubitem.type = 'text';
15199: privitem.type = 'text';
15200: pubitem.size = '40';
15201: privitem.size = '40';
15202: pubtext.innerHTML = "$lt{'pub'}";
15203: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 15204: versionitem.type = 'text';
15205: versionitem.size = '3';
1.289 raeburn 15206: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 15207: } else {
15208: pubitem.type = 'hidden';
15209: privitem.type = 'hidden';
1.269 raeburn 15210: versionitem.type = 'hidden';
1.165 raeburn 15211: pubtext.innerHTML = '';
15212: privtext.innerHTML = '';
1.269 raeburn 15213: versiontext.innerHTML = '';
1.165 raeburn 15214: }
15215: }
15216: return;
15217: }
15218:
15219: // ]]>
15220: </script>
15221:
15222: END
15223:
15224: }
15225:
1.236 raeburn 15226: sub toggle_display_js {
1.192 raeburn 15227: return <<"END";
15228:
15229: <script type="text/javascript">
15230: // <![CDATA[
15231:
1.236 raeburn 15232: function toggleDisplay(domForm,caller) {
15233: if (document.getElementById(caller)) {
15234: var divitem = document.getElementById(caller);
15235: var optionsElement = domForm.coursecredits;
1.264 raeburn 15236: var checkval = 1;
15237: var dispval = 'block';
1.236 raeburn 15238: if (caller == 'emailoptions') {
15239: optionsElement = domForm.cancreate_email;
15240: }
1.257 raeburn 15241: if (caller == 'studentsubmission') {
15242: optionsElement = domForm.postsubmit;
15243: }
1.264 raeburn 15244: if (caller == 'cloneinstcode') {
15245: optionsElement = domForm.canclone;
15246: checkval = 'instcode';
15247: }
1.236 raeburn 15248: if (optionsElement.length) {
1.192 raeburn 15249: var currval;
1.236 raeburn 15250: for (var i=0; i<optionsElement.length; i++) {
15251: if (optionsElement[i].checked) {
15252: currval = optionsElement[i].value;
1.192 raeburn 15253: }
15254: }
1.264 raeburn 15255: if (currval == checkval) {
15256: divitem.style.display = dispval;
1.192 raeburn 15257: } else {
1.236 raeburn 15258: divitem.style.display = 'none';
1.192 raeburn 15259: }
15260: }
15261: }
15262: return;
15263: }
15264:
15265: // ]]>
15266: </script>
15267:
15268: END
15269:
15270: }
15271:
1.165 raeburn 15272: sub captcha_phrases {
15273: return &Apache::lonlocal::texthash (
15274: priv => 'Private key',
15275: pub => 'Public key',
15276: original => 'original (CAPTCHA)',
15277: recaptcha => 'successor (ReCAPTCHA)',
15278: notused => 'unused',
1.289 raeburn 15279: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 15280: );
15281: }
15282:
1.205 raeburn 15283: sub devalidate_remote_domconfs {
1.212 raeburn 15284: my ($dom,$cachekeys) = @_;
15285: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 15286: my %servers = &Apache::lonnet::internet_dom_servers($dom);
15287: my %thismachine;
15288: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 15289: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 15290: if (keys(%servers)) {
1.205 raeburn 15291: foreach my $server (keys(%servers)) {
15292: next if ($thismachine{$server});
1.212 raeburn 15293: my @cached;
15294: foreach my $name (@posscached) {
15295: if ($cachekeys->{$name}) {
15296: push(@cached,&escape($name).':'.&escape($dom));
15297: }
15298: }
15299: if (@cached) {
15300: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
15301: }
1.205 raeburn 15302: }
15303: }
15304: return;
15305: }
15306:
1.3 raeburn 15307: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>