Annotation of loncom/interface/domainprefs.pm, revision 1.299
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.299 ! raeburn 4: # $Id: domainprefs.pm,v 1.298 2017/05/10 13:49:14 raeburn 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);
3264: if (ref($settings->{'adhoc'}) eq 'HASH') {
3265: %current = %{$settings->{'adhoc'}};
3266: }
3267: my $count = 0;
3268: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3269: if ($key=~/^rolesdef\_(\w+)$/) {
3270: my $rolename = $1;
1.285 raeburn 3271: my (%privs,$order);
1.282 raeburn 3272: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3273: $customroles{$rolename} = \%privs;
1.285 raeburn 3274: if (ref($current{$rolename}) eq 'HASH') {
3275: $order = $current{$rolename}{'order'};
3276: }
3277: if ($order eq '') {
3278: $order = $count;
3279: }
3280: $ordered{$order} = $rolename;
3281: $count++;
3282: }
3283: }
3284: my $maxnum = scalar(keys(%ordered));
3285: my @roles_by_num = ();
3286: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3287: push(@roles_by_num,$item);
3288: }
3289: my $context = 'domprefs';
3290: my $crstype = 'Course';
3291: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3292: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3293: my ($numstatustypes,@jsarray);
3294: if (ref($types) eq 'ARRAY') {
3295: if (@{$types} > 0) {
3296: $numstatustypes = scalar(@{$types});
3297: push(@accesstypes,'status');
3298: @jsarray = ('bystatus');
1.282 raeburn 3299: }
3300: }
1.290 raeburn 3301: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3302: if (keys(%domhelpdesk)) {
3303: push(@accesstypes,('inc','exc'));
3304: push(@jsarray,('notinc','notexc'));
3305: }
3306: my $hiddenstr = join("','",@jsarray);
3307: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.282 raeburn 3308: my $context = 'domprefs';
3309: my $crstype = 'Course';
1.285 raeburn 3310: my $prefix = 'helproles_';
3311: my $add_class = 'LC_hidden';
3312: foreach my $num (@roles_by_num) {
3313: my $role = $ordered{$num};
3314: my ($desc,$access,@statuses);
3315: if (ref($current{$role}) eq 'HASH') {
3316: $desc = $current{$role}{'desc'};
3317: $access = $current{$role}{'access'};
3318: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3319: @statuses = @{$current{$role}{'insttypes'}};
3320: }
3321: }
3322: if ($desc eq '') {
3323: $desc = $role;
3324: }
3325: my $identifier = 'custhelp'.$num;
1.282 raeburn 3326: my %full=();
3327: my %levels= (
3328: course => {},
3329: domain => {},
3330: system => {},
3331: );
3332: my %levelscurrent=(
3333: course => {},
3334: domain => {},
3335: system => {},
3336: );
3337: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3338: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3339: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 3340: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3341: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3342: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3343: for (my $k=0; $k<=$maxnum; $k++) {
3344: my $vpos = $k+1;
3345: my $selstr;
3346: if ($k == $num) {
3347: $selstr = ' selected="selected" ';
3348: }
3349: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3350: }
3351: $datatable .= '</select>'.(' 'x2).
3352: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3353: '</td>'.
3354: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3355: &mt('Name shown to users:').
3356: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3357: '</fieldset>'.
3358: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3359: $othertitle,$usertypes,$types,\%domhelpdesk).
3360: '<fieldset>'.
3361: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 3362: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 3363: \%levelscurrent,$identifier,
3364: 'LC_hidden',$prefix.$num.'_privs').
3365: '</fieldset></td>';
1.282 raeburn 3366: $itemcount ++;
3367: }
3368: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3369: my $newcust = 'custhelp'.$count;
3370: my (%privs,%levelscurrent);
3371: my %full=();
3372: my %levels= (
3373: course => {},
3374: domain => {},
3375: system => {},
3376: );
3377: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3378: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 3379: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3380: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3381: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3382: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3383: for (my $k=0; $k<$maxnum+1; $k++) {
3384: my $vpos = $k+1;
3385: my $selstr;
3386: if ($k == $maxnum) {
3387: $selstr = ' selected="selected" ';
3388: }
3389: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3390: }
3391: $datatable .= '</select> '."\n".
1.282 raeburn 3392: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3393: '</label></span></td>'.
1.285 raeburn 3394: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3395: '<span class="LC_nobreak">'.
3396: &mt('Internal name:').
3397: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3398: '</span>'.(' 'x4).
3399: '<span class="LC_nobreak">'.
3400: &mt('Name shown to users:').
3401: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3402: '</span></fieldset>'.
3403: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3404: $usertypes,$types,\%domhelpdesk).
3405: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 3406: &Apache::lonuserutils::custom_role_header($context,$crstype,
3407: \@templateroles,$newcust).
3408: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3409: \%levelscurrent,$newcust).
1.285 raeburn 3410: '</fieldset></td></tr>';
1.282 raeburn 3411: $count ++;
3412: $$rowtotal += $count;
3413: }
1.166 raeburn 3414: return $datatable;
1.121 raeburn 3415: }
3416:
1.285 raeburn 3417: sub adhocbutton {
3418: my ($prefix,$num,$field,$visibility) = @_;
3419: my %lt = &Apache::lonlocal::texthash(
3420: show => 'Show details',
3421: hide => 'Hide details',
3422: );
3423: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3424: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3425: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3426: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3427: }
3428:
3429: sub helpsettings_javascript {
3430: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3431: return unless(ref($roles_by_num) eq 'ARRAY');
3432: my %html_js_lt = &Apache::lonlocal::texthash(
3433: show => 'Show details',
3434: hide => 'Hide details',
3435: );
3436: &html_escape(\%html_js_lt);
3437: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3438: return <<"ENDSCRIPT";
3439: <script type="text/javascript">
3440: // <![CDATA[
3441:
3442: function reorderHelpRoles(form,item) {
3443: var changedVal;
3444: $jstext
3445: var newpos = 'helproles_${total}_pos';
3446: var maxh = 1 + $total;
3447: var current = new Array();
3448: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3449: if (item == newpos) {
3450: changedVal = newitemVal;
3451: } else {
3452: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3453: current[newitemVal] = newpos;
3454: }
3455: for (var i=0; i<helproles.length; i++) {
3456: var elementName = 'helproles_'+helproles[i]+'_pos';
3457: if (elementName != item) {
3458: if (form.elements[elementName]) {
3459: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3460: current[currVal] = elementName;
3461: }
3462: }
3463: }
3464: var oldVal;
3465: for (var j=0; j<maxh; j++) {
3466: if (current[j] == undefined) {
3467: oldVal = j;
3468: }
3469: }
3470: if (oldVal < changedVal) {
3471: for (var k=oldVal+1; k<=changedVal ; k++) {
3472: var elementName = current[k];
3473: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3474: }
3475: } else {
3476: for (var k=changedVal; k<oldVal; k++) {
3477: var elementName = current[k];
3478: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3479: }
3480: }
3481: return;
3482: }
3483:
3484: function helpdeskAccess(num) {
3485: var curraccess = null;
3486: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3487: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3488: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3489: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3490: }
3491: }
3492: }
3493: var shown = Array();
3494: var hidden = Array();
3495: if (curraccess == 'none') {
3496: hidden = Array('$hiddenstr');
3497: } else {
3498: if (curraccess == 'status') {
3499: shown = Array('bystatus');
3500: hidden = Array('notinc','notexc');
3501: } else {
3502: if (curraccess == 'exc') {
3503: shown = Array('notexc');
3504: hidden = Array('notinc','bystatus');
3505: }
3506: if (curraccess == 'inc') {
3507: shown = Array('notinc');
3508: hidden = Array('notexc','bystatus');
3509: }
1.293 raeburn 3510: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 3511: hidden = Array('notinc','notexc','bystatus');
3512: }
3513: }
3514: }
3515: if (hidden.length > 0) {
3516: for (var i=0; i<hidden.length; i++) {
3517: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3518: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3519: }
3520: }
3521: }
3522: if (shown.length > 0) {
3523: for (var i=0; i<shown.length; i++) {
3524: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3525: if (shown[i] == 'privs') {
3526: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3527: } else {
3528: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3529: }
3530: }
3531: }
3532: }
3533: return;
3534: }
3535:
3536: function toggleHelpdeskItem(num,field) {
3537: if (document.getElementById('helproles_'+num+'_'+field)) {
3538: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 3539: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 3540: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3541: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3542: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3543: }
3544: } else {
3545: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3546: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3547: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3548: }
3549: }
3550: }
3551: return;
3552: }
3553:
3554: // ]]>
3555: </script>
3556:
3557: ENDSCRIPT
3558: }
3559:
3560: sub helpdeskroles_access {
3561: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3562: $usertypes,$types,$domhelpdesk) = @_;
3563: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3564: my %lt = &Apache::lonlocal::texthash(
3565: 'rou' => 'Role usage',
3566: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 3567: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3568: 'dh' => 'All with domain helpdesk role',
3569: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 3570: 'none' => 'None',
3571: 'status' => 'Determined based on institutional status',
3572: 'inc' => 'Include all, but exclude specific personnel',
3573: 'exc' => 'Exclude all, but include specific personnel',
3574: );
3575: my %usecheck = (
3576: all => ' checked="checked"',
3577: );
3578: my %displaydiv = (
3579: status => 'none',
3580: inc => 'none',
3581: exc => 'none',
3582: priv => 'block',
3583: );
3584: my $output;
3585: if (ref($current) eq 'HASH') {
3586: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3587: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3588: $usecheck{$current->{access}} = $usecheck{'all'};
3589: delete($usecheck{'all'});
3590: if ($current->{access} =~ /^(status|inc|exc)$/) {
3591: my $access = $1;
3592: $displaydiv{$access} = 'inline';
3593: } elsif ($current->{access} eq 'none') {
3594: $displaydiv{'priv'} = 'none';
3595: }
3596: }
3597: }
3598: }
3599: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3600: '<p>'.$lt{'whi'}.'</p>';
3601: foreach my $access (@{$accesstypes}) {
3602: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3603: ' onclick="helpdeskAccess('."'$num'".');" />'.
3604: $lt{$access}.'</label>';
3605: if ($access eq 'status') {
3606: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3607: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3608: $othertitle,$usertypes,$types).
3609: '</div>';
3610: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3611: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3612: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3613: '</div>';
3614: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3615: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3616: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3617: '</div>';
3618: }
3619: $output .= '</p>';
3620: }
3621: $output .= '</fieldset>';
3622: return $output;
3623: }
3624:
1.121 raeburn 3625: sub radiobutton_prefs {
1.192 raeburn 3626: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 3627: $additional,$align) = @_;
1.121 raeburn 3628: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3629: (ref($choices) eq 'HASH'));
3630:
1.170 raeburn 3631: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 3632:
3633: foreach my $item (@{$toggles}) {
3634: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3635: $checkedon{$item} = ' checked="checked" ';
3636: $checkedoff{$item} = ' ';
1.121 raeburn 3637: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3638: $checkedoff{$item} = ' checked="checked" ';
3639: $checkedon{$item} = ' ';
3640: }
3641: }
3642: if (ref($settings) eq 'HASH') {
1.121 raeburn 3643: foreach my $item (@{$toggles}) {
1.118 jms 3644: if ($settings->{$item} eq '1') {
3645: $checkedon{$item} = ' checked="checked" ';
3646: $checkedoff{$item} = ' ';
3647: } elsif ($settings->{$item} eq '0') {
3648: $checkedoff{$item} = ' checked="checked" ';
3649: $checkedon{$item} = ' ';
3650: }
3651: }
1.121 raeburn 3652: }
1.192 raeburn 3653: if ($onclick) {
3654: $onclick = ' onclick="'.$onclick.'"';
3655: }
1.121 raeburn 3656: foreach my $item (@{$toggles}) {
1.118 jms 3657: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3658: $datatable .=
1.192 raeburn 3659: '<tr'.$css_class.'><td valign="top">'.
3660: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 3661: '</span></td>';
3662: if ($align eq 'left') {
3663: $datatable .= '<td class="LC_left_item">';
3664: } else {
3665: $datatable .= '<td class="LC_right_item">';
3666: }
1.289 raeburn 3667: $datatable .=
1.257 raeburn 3668: '<span class="LC_nobreak">'.
1.118 jms 3669: '<label><input type="radio" name="'.
1.192 raeburn 3670: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3671: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 3672: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3673: '</span>'.$additional.
3674: '</td>'.
1.118 jms 3675: '</tr>';
3676: $itemcount ++;
1.121 raeburn 3677: }
3678: return ($datatable,$itemcount);
3679: }
3680:
1.267 raeburn 3681: sub print_ltitools {
3682: my ($dom,$settings,$rowtotal) = @_;
3683: my $rownum = 0;
3684: my $css_class;
3685: my $itemcount = 1;
3686: my $maxnum = 0;
3687: my %ordered;
3688: if (ref($settings) eq 'HASH') {
3689: foreach my $item (keys(%{$settings})) {
3690: if (ref($settings->{$item}) eq 'HASH') {
3691: my $num = $settings->{$item}{'order'};
3692: $ordered{$num} = $item;
3693: }
3694: }
3695: }
3696: my $confname = $dom.'-domainconfig';
3697: my $switchserver = &check_switchserver($dom,$confname);
3698: my $maxnum = scalar(keys(%ordered));
3699: my $datatable = <itools_javascript($settings);
3700: my %lt = <itools_names();
3701: my @courseroles = ('cc','in','ta','ep','st');
3702: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3703: my @fields = ('fullname','firstname','lastname','email','user','roles');
3704: if (keys(%ordered)) {
3705: my @items = sort { $a <=> $b } keys(%ordered);
3706: for (my $i=0; $i<@items; $i++) {
3707: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3708: my $item = $ordered{$items[$i]};
3709: my ($title,$key,$secret,$url,$imgsrc,$version);
3710: if (ref($settings->{$item}) eq 'HASH') {
3711: $title = $settings->{$item}->{'title'};
3712: $url = $settings->{$item}->{'url'};
3713: $key = $settings->{$item}->{'key'};
3714: $secret = $settings->{$item}->{'secret'};
3715: my $image = $settings->{$item}->{'image'};
3716: if ($image ne '') {
3717: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3718: }
3719: }
3720: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3721: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3722: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3723: for (my $k=0; $k<=$maxnum; $k++) {
3724: my $vpos = $k+1;
3725: my $selstr;
3726: if ($k == $i) {
3727: $selstr = ' selected="selected" ';
3728: }
3729: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3730: }
3731: $datatable .= '</select>'.(' 'x2).
3732: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3733: &mt('Delete?').'</label></span></td>'.
3734: '<td colspan="2">'.
3735: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3736: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3737: (' 'x2).
3738: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3739: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3740: (' 'x2).
3741: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3742: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3743: '<br /><br />'.
3744: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3745: ' value="'.$url.'" /></span>'.
3746: (' 'x2).
3747: '<span class="LC_nobreak">'.$lt{'key'}.
3748: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3749: (' 'x2).
3750: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3751: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3752: '<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>'.
3753: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3754: '</fieldset>'.
3755: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3756: '<span class="LC_nobreak">'.&mt('Display target:');
3757: my %currdisp;
3758: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3759: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3760: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 3761: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
3762: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 3763: } else {
3764: $currdisp{'iframe'} = ' checked="checked"';
3765: }
3766: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3767: $currdisp{'width'} = $1;
3768: }
3769: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3770: $currdisp{'height'} = $1;
3771: }
1.296 raeburn 3772: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
3773: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 3774: } else {
3775: $currdisp{'iframe'} = ' checked="checked"';
3776: }
1.298 raeburn 3777: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 3778: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3779: $lt{$disp}.'</label>'.(' 'x2);
3780: }
3781: $datatable .= (' 'x4);
3782: foreach my $dimen ('width','height') {
3783: $datatable .= '<label>'.$lt{$dimen}.' '.
3784: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3785: (' 'x2);
3786: }
1.296 raeburn 3787: $datatable .= '<br />'.
3788: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
3789: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
3790: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
3791: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
3792: '</textarea></div><div style=""></div><br />';
1.267 raeburn 3793: $datatable .= '<br />';
3794: foreach my $extra ('passback','roster') {
3795: my $checkedon = '';
3796: my $checkedoff = ' checked="checked"';
3797: if ($settings->{$item}->{$extra}) {
3798: $checkedon = $checkedoff;
3799: $checkedoff = '';
3800: }
3801: $datatable .= $lt{$extra}.' '.
3802: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3803: &mt('Yes').'</label>'.(' 'x2).
3804: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3805: &mt('No').'</label>'.(' 'x4);
3806: }
3807: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3808: if ($imgsrc) {
3809: $datatable .= $imgsrc.
3810: '<label><input type="checkbox" name="ltitools_image_del"'.
3811: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3812: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3813: } else {
3814: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3815: }
3816: if ($switchserver) {
3817: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3818: } else {
3819: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3820: }
3821: $datatable .= '</span></fieldset>';
3822: my (%checkedfields,%rolemaps);
3823: if (ref($settings->{$item}) eq 'HASH') {
3824: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3825: %checkedfields = %{$settings->{$item}->{'fields'}};
3826: }
3827: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3828: %rolemaps = %{$settings->{$item}->{'roles'}};
3829: $checkedfields{'roles'} = 1;
3830: }
3831: }
3832: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3833: '<span class="LC_nobreak">';
3834: foreach my $field (@fields) {
3835: my $checked;
3836: if ($checkedfields{$field}) {
3837: $checked = ' checked="checked"';
3838: }
3839: $datatable .= '<label>'.
3840: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3841: $lt{$field}.'</label>'.(' ' x2);
3842: }
3843: $datatable .= '</span></fieldset>'.
3844: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3845: foreach my $role (@courseroles) {
3846: my ($selected,$selectnone);
3847: if (!$rolemaps{$role}) {
3848: $selectnone = ' selected="selected"';
3849: }
3850: $datatable .= '<td align="center">'.
3851: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3852: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3853: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3854: foreach my $ltirole (@ltiroles) {
3855: unless ($selectnone) {
3856: if ($rolemaps{$role} eq $ltirole) {
3857: $selected = ' selected="selected"';
3858: } else {
3859: $selected = '';
3860: }
3861: }
3862: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3863: }
3864: $datatable .= '</select></td>';
3865: }
1.273 raeburn 3866: $datatable .= '</tr></table></fieldset>';
3867: my %courseconfig;
3868: if (ref($settings->{$item}) eq 'HASH') {
3869: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3870: %courseconfig = %{$settings->{$item}->{'crsconf'}};
3871: }
3872: }
3873: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.296 raeburn 3874: foreach my $item ('label','title','target','linktext','explanation') {
1.273 raeburn 3875: my $checked;
3876: if ($courseconfig{$item}) {
3877: $checked = ' checked="checked"';
3878: }
3879: $datatable .= '<label>'.
3880: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3881: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3882: }
3883: $datatable .= '</span></fieldset>'.
1.267 raeburn 3884: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3885: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3886: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3887: my %custom = %{$settings->{$item}->{'custom'}};
3888: if (keys(%custom) > 0) {
3889: foreach my $key (sort(keys(%custom))) {
3890: $datatable .= '<tr><td><span class="LC_nobreak">'.
3891: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3892: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3893: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3894: ' value="'.$custom{$key}.'" /></td></tr>';
3895: }
3896: }
3897: }
3898: $datatable .= '<tr><td><span class="LC_nobreak">'.
3899: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3900: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3901: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3902: $datatable .= '</table></fieldset></td></tr>'."\n";
3903: $itemcount ++;
3904: }
3905: }
3906: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3907: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3908: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3909: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3910: '<select name="ltitools_add_pos"'.$chgstr.'>';
3911: for (my $k=0; $k<$maxnum+1; $k++) {
3912: my $vpos = $k+1;
3913: my $selstr;
3914: if ($k == $maxnum) {
3915: $selstr = ' selected="selected" ';
3916: }
3917: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3918: }
3919: $datatable .= '</select> '."\n".
3920: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3921: '<td colspan="2">'.
3922: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3923: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3924: (' 'x2).
3925: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3926: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3927: (' 'x2).
3928: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3929: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3930: '<br />'.
3931: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3932: (' 'x2).
3933: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3934: (' 'x2).
3935: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3936: '<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".
3937: '</fieldset>'.
3938: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3939: '<span class="LC_nobreak">'.&mt('Display target:');
3940: my %defaultdisp;
3941: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 3942: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 3943: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3944: $lt{$disp}.'</label>'.(' 'x2);
3945: }
3946: $datatable .= (' 'x4);
3947: foreach my $dimen ('width','height') {
3948: $datatable .= '<label>'.$lt{$dimen}.' '.
3949: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3950: (' 'x2);
3951: }
1.296 raeburn 3952: $datatable .= '<br />'.
3953: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
3954: '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
3955: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
3956: '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
3957: '</div><div style=""></div><br />';
1.267 raeburn 3958: foreach my $extra ('passback','roster') {
3959: $datatable .= $lt{$extra}.' '.
3960: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
3961: &mt('Yes').'</label>'.(' 'x2).
3962: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
3963: &mt('No').'</label>'.(' 'x4);
3964: }
3965: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
3966: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3967: if ($switchserver) {
3968: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3969: } else {
3970: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3971: }
3972: $datatable .= '</span></fieldset>'.
3973: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3974: '<span class="LC_nobreak">';
3975: foreach my $field (@fields) {
3976: $datatable .= '<label>'.
3977: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
3978: $lt{$field}.'</label>'.(' ' x2);
3979: }
3980: $datatable .= '</span></fieldset>'.
3981: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3982: foreach my $role (@courseroles) {
3983: my ($checked,$checkednone);
3984: $datatable .= '<td align="center">'.
3985: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3986: '<select name="ltitools_add_roles_'.$role.'">'.
3987: '<option value="" selected="selected">'.&mt('Select').'</option>';
3988: foreach my $ltirole (@ltiroles) {
3989: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
3990: }
3991: $datatable .= '</select></td>';
3992: }
3993: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 3994: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.296 raeburn 3995: foreach my $item ('label','title','target','linktext','explanation') {
3996: $datatable .= '<label>'.
3997: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
3998: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 3999: }
4000: $datatable .= '</span></fieldset>'.
1.267 raeburn 4001: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4002: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4003: '<tr><td><span class="LC_nobreak">'.
4004: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4005: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4006: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
4007: '</table></fieldset></td></tr>'."\n".
4008: '</td>'."\n".
4009: '</tr>'."\n";
4010: $itemcount ++;
4011: return $datatable;
4012: }
4013:
4014: sub ltitools_names {
4015: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4016: 'title' => 'Title',
4017: 'version' => 'Version',
4018: 'msgtype' => 'Message Type',
4019: 'url' => 'URL',
4020: 'key' => 'Key',
4021: 'secret' => 'Secret',
4022: 'icon' => 'Icon',
4023: 'user' => 'Username:domain',
4024: 'fullname' => 'Full Name',
4025: 'firstname' => 'First Name',
4026: 'lastname' => 'Last Name',
4027: 'email' => 'E-mail',
4028: 'roles' => 'Role',
1.298 raeburn 4029: 'window' => 'Window',
4030: 'tab' => 'Tab',
1.296 raeburn 4031: 'iframe' => 'iFrame',
4032: 'height' => 'Height',
4033: 'width' => 'Width',
4034: 'linktext' => 'Default Link Text',
4035: 'explanation' => 'Default Explanation',
4036: 'passback' => 'Tool can return grades:',
4037: 'roster' => 'Tool can retrieve roster:',
4038: 'crstarget' => 'Display target',
4039: 'crslabel' => 'Course label',
4040: 'crstitle' => 'Course title',
4041: 'crslinktext' => 'Link Text',
4042: 'crsexplanation' => 'Explanation',
1.267 raeburn 4043: );
4044: return %lt;
4045: }
4046:
1.121 raeburn 4047: sub print_coursedefaults {
1.139 raeburn 4048: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 4049: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4050: my $itemcount = 1;
1.192 raeburn 4051: my %choices = &Apache::lonlocal::texthash (
4052: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 4053: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 4054: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4055: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 4056: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4057: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
4058: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 4059: canclone => "People who may clone a course (besides course's owner and coordinators)",
4060: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 4061: );
1.198 raeburn 4062: my %staticdefaults = (
4063: anonsurvey_threshold => 10,
4064: uploadquota => 500,
1.257 raeburn 4065: postsubmit => 60,
1.276 raeburn 4066: mysqltables => 172800,
1.198 raeburn 4067: );
1.139 raeburn 4068: if ($position eq 'top') {
1.257 raeburn 4069: %defaultchecked = (
4070: 'canuse_pdfforms' => 'off',
4071: 'uselcmath' => 'on',
4072: 'usejsme' => 'on',
1.289 raeburn 4073: 'canclone' => 'none',
1.257 raeburn 4074: );
4075: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139 raeburn 4076: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 4077: \%choices,$itemcount);
1.264 raeburn 4078: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4079: $datatable .=
4080: '<tr'.$css_class.'><td valign="top">'.
4081: '<span class="LC_nobreak">'.$choices{'canclone'}.
4082: '</span></td><td class="LC_left_item">';
4083: my $currcanclone = 'none';
4084: my $onclick;
4085: my @cloneoptions = ('none','domain');
4086: my %clonetitles = (
4087: none => 'No additional course requesters',
4088: domain => "Any course requester in course's domain",
4089: instcode => 'Course requests for official courses ...',
4090: );
4091: my (%codedefaults,@code_order,@posscodes);
4092: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4093: \@code_order) eq 'ok') {
4094: if (@code_order > 0) {
4095: push(@cloneoptions,'instcode');
4096: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4097: }
4098: }
4099: if (ref($settings) eq 'HASH') {
4100: if ($settings->{'canclone'}) {
4101: if (ref($settings->{'canclone'}) eq 'HASH') {
4102: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4103: if (@code_order > 0) {
4104: $currcanclone = 'instcode';
4105: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4106: }
4107: }
4108: } elsif ($settings->{'canclone'} eq 'domain') {
4109: $currcanclone = $settings->{'canclone'};
4110: }
4111: }
1.289 raeburn 4112: }
1.264 raeburn 4113: foreach my $option (@cloneoptions) {
4114: my ($checked,$additional);
4115: if ($currcanclone eq $option) {
4116: $checked = ' checked="checked"';
4117: }
4118: if ($option eq 'instcode') {
4119: if (@code_order) {
4120: my $show = 'none';
4121: if ($checked) {
4122: $show = 'block';
4123: }
4124: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4125: &mt('Institutional codes for new and cloned course have identical:').
4126: '<br />';
4127: foreach my $item (@code_order) {
4128: my $codechk;
4129: if ($checked) {
4130: if (grep(/^\Q$item\E$/,@posscodes)) {
4131: $codechk = ' checked="checked"';
4132: }
4133: }
4134: $additional .= '<label>'.
4135: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4136: $item.'</label>';
4137: }
4138: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4139: }
4140: }
4141: $datatable .=
4142: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4143: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4144: '</label> '.$additional.'</span><br />';
4145: }
4146: $datatable .= '</td>'.
4147: '</tr>';
4148: $itemcount ++;
1.139 raeburn 4149: } else {
4150: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 4151: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 4152: my $currusecredits = 0;
1.257 raeburn 4153: my $postsubmitclient = 1;
1.271 raeburn 4154: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 4155: if (ref($settings) eq 'HASH') {
4156: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 4157: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4158: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4159: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4160: }
4161: }
1.192 raeburn 4162: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 4163: foreach my $type (@types) {
4164: next if ($type eq 'community');
4165: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4166: if ($defcredits{$type} ne '') {
4167: $currusecredits = 1;
4168: }
4169: }
4170: }
4171: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4172: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4173: $postsubmitclient = 0;
4174: foreach my $type (@types) {
4175: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4176: }
4177: } else {
4178: foreach my $type (@types) {
4179: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4180: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 4181: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 4182: } else {
4183: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4184: }
4185: } else {
4186: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4187: }
4188: }
4189: }
4190: } else {
4191: foreach my $type (@types) {
4192: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 4193: }
4194: }
1.276 raeburn 4195: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4196: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4197: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4198: }
4199: } else {
4200: foreach my $type (@types) {
4201: $currmysql{$type} = $staticdefaults{'mysqltables'};
4202: }
4203: }
1.258 raeburn 4204: } else {
4205: foreach my $type (@types) {
4206: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4207: }
1.139 raeburn 4208: }
4209: if (!$currdefresponder) {
1.198 raeburn 4210: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4211: } elsif ($currdefresponder < 1) {
4212: $currdefresponder = 1;
4213: }
1.198 raeburn 4214: foreach my $type (@types) {
4215: if ($curruploadquota{$type} eq '') {
4216: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4217: }
4218: }
1.139 raeburn 4219: $datatable .=
1.192 raeburn 4220: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4221: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4222: '</span></td>'.
4223: '<td class="LC_right_item"><span class="LC_nobreak">'.
4224: '<input type="text" name="anonsurvey_threshold"'.
4225: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 4226: '</td></tr>'."\n";
4227: $itemcount ++;
4228: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4229: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4230: $choices{'uploadquota'}.
4231: '</span></td>'.
4232: '<td align="right" class="LC_right_item">'.
4233: '<table><tr>';
1.198 raeburn 4234: foreach my $type (@types) {
4235: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4236: '<input type="text" name="uploadquota_'.$type.'"'.
4237: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4238: }
4239: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 4240: $itemcount ++;
1.236 raeburn 4241: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 4242: my $display = 'none';
1.192 raeburn 4243: if ($currusecredits) {
4244: $display = 'block';
4245: }
4246: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 4247: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4248: foreach my $type (@types) {
4249: next if ($type eq 'community');
4250: $additional .= '<td align="center">'.&mt($type).'<br />'.
4251: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 4252: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 4253: }
4254: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 4255: %defaultchecked = ('coursecredits' => 'off');
4256: @toggles = ('coursecredits');
4257: my $current = {
4258: 'coursecredits' => $currusecredits,
4259: };
4260: (my $table,$itemcount) =
4261: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 4262: \%choices,$itemcount,$onclick,$additional,'left');
4263: $datatable .= $table;
4264: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4265: my $display = 'none';
4266: if ($postsubmitclient) {
4267: $display = 'block';
4268: }
4269: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 4270: &mt('Number of seconds submit is disabled').'<br />'.
4271: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4272: '<table><tr>';
1.257 raeburn 4273: foreach my $type (@types) {
4274: $additional .= '<td align="center">'.&mt($type).'<br />'.
4275: '<input type="text" name="'.$type.'_timeout" value="'.
4276: $deftimeout{$type}.'" size="5" /></td>';
4277: }
4278: $additional .= '</tr></table></div>'."\n";
4279: %defaultchecked = ('postsubmit' => 'on');
4280: @toggles = ('postsubmit');
1.280 raeburn 4281: $current = {
4282: 'postsubmit' => $postsubmitclient,
4283: };
1.257 raeburn 4284: ($table,$itemcount) =
4285: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4286: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 4287: $datatable .= $table;
1.276 raeburn 4288: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4289: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4290: $choices{'mysqltables'}.
4291: '</span></td>'.
4292: '<td align="right" class="LC_right_item">'.
4293: '<table><tr>';
4294: foreach my $type (@types) {
4295: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4296: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 4297: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 4298: }
4299: $datatable .= '</tr></table></td></tr>'."\n";
4300: $itemcount ++;
4301:
1.139 raeburn 4302: }
1.192 raeburn 4303: $$rowtotal += $itemcount;
1.121 raeburn 4304: return $datatable;
1.118 jms 4305: }
4306:
1.231 raeburn 4307: sub print_selfenrollment {
4308: my ($position,$dom,$settings,$rowtotal) = @_;
4309: my ($css_class,$datatable);
4310: my $itemcount = 1;
1.271 raeburn 4311: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 4312: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 4313: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4314: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 4315: my @rows;
4316: my $key;
4317: if ($position eq 'top') {
4318: $key = 'admin';
4319: if (ref($rowsref) eq 'ARRAY') {
4320: @rows = @{$rowsref};
4321: }
4322: } elsif ($position eq 'middle') {
4323: $key = 'default';
4324: @rows = ('types','registered','approval','limit');
4325: }
4326: foreach my $row (@rows) {
4327: if (defined($titlesref->{$row})) {
4328: $itemcount ++;
4329: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4330: $datatable .= '<tr'.$css_class.'>'.
4331: '<td>'.$titlesref->{$row}.'</td>'.
4332: '<td class="LC_left_item">'.
4333: '<table><tr>';
4334: my (%current,%currentcap);
4335: if (ref($settings) eq 'HASH') {
4336: if (ref($settings->{$key}) eq 'HASH') {
4337: foreach my $type (@types) {
4338: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4339: $current{$type} = $settings->{$key}->{$type}->{$row};
4340: }
4341: if (($row eq 'limit') && ($key eq 'default')) {
4342: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4343: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4344: }
4345: }
4346: }
4347: }
4348: }
4349: my %roles = (
4350: '0' => &Apache::lonnet::plaintext('dc'),
4351: );
4352:
4353: foreach my $type (@types) {
4354: unless (($row eq 'registered') && ($key eq 'default')) {
4355: $datatable .= '<th>'.&mt($type).'</th>';
4356: }
4357: }
4358: unless (($row eq 'registered') && ($key eq 'default')) {
4359: $datatable .= '</tr><tr>';
4360: }
4361: foreach my $type (@types) {
4362: if ($type eq 'community') {
4363: $roles{'1'} = &mt('Community personnel');
4364: } else {
4365: $roles{'1'} = &mt('Course personnel');
4366: }
4367: $datatable .= '<td style="vertical-align: top">';
4368: if ($position eq 'top') {
4369: my %checked;
4370: if ($current{$type} eq '0') {
4371: $checked{'0'} = ' checked="checked"';
4372: } else {
4373: $checked{'1'} = ' checked="checked"';
4374: }
4375: foreach my $role ('1','0') {
4376: $datatable .= '<span class="LC_nobreak"><label>'.
4377: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4378: 'value="'.$role.'"'.$checked{$role}.' />'.
4379: $roles{$role}.'</label></span> ';
4380: }
4381: } else {
4382: if ($row eq 'types') {
4383: my %checked;
4384: if ($current{$type} =~ /^(all|dom)$/) {
4385: $checked{$1} = ' checked="checked"';
4386: } else {
4387: $checked{''} = ' checked="checked"';
4388: }
4389: foreach my $val ('','dom','all') {
4390: $datatable .= '<span class="LC_nobreak"><label>'.
4391: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4392: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4393: }
4394: } elsif ($row eq 'registered') {
4395: my %checked;
4396: if ($current{$type} eq '1') {
4397: $checked{'1'} = ' checked="checked"';
4398: } else {
4399: $checked{'0'} = ' checked="checked"';
4400: }
4401: foreach my $val ('0','1') {
4402: $datatable .= '<span class="LC_nobreak"><label>'.
4403: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4404: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4405: }
4406: } elsif ($row eq 'approval') {
4407: my %checked;
4408: if ($current{$type} =~ /^([12])$/) {
4409: $checked{$1} = ' checked="checked"';
4410: } else {
4411: $checked{'0'} = ' checked="checked"';
4412: }
4413: for my $val (0..2) {
4414: $datatable .= '<span class="LC_nobreak"><label>'.
4415: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4416: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4417: }
4418: } elsif ($row eq 'limit') {
4419: my %checked;
4420: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4421: $checked{$1} = ' checked="checked"';
4422: } else {
4423: $checked{'none'} = ' checked="checked"';
4424: }
4425: my $cap;
4426: if ($currentcap{$type} =~ /^\d+$/) {
4427: $cap = $currentcap{$type};
4428: }
4429: foreach my $val ('none','allstudents','selfenrolled') {
4430: $datatable .= '<span class="LC_nobreak"><label>'.
4431: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4432: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4433: }
4434: $datatable .= '<br />'.
4435: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4436: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4437: '</span>';
4438: }
4439: }
4440: $datatable .= '</td>';
4441: }
4442: $datatable .= '</tr>';
4443: }
4444: $datatable .= '</table></td></tr>';
4445: }
4446: } elsif ($position eq 'bottom') {
1.235 raeburn 4447: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4448: }
4449: $$rowtotal += $itemcount;
4450: return $datatable;
4451: }
4452:
4453: sub print_validation_rows {
4454: my ($caller,$dom,$settings,$rowtotal) = @_;
4455: my ($itemsref,$namesref,$fieldsref);
4456: if ($caller eq 'selfenroll') {
4457: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4458: } elsif ($caller eq 'requestcourses') {
4459: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4460: }
4461: my %currvalidation;
4462: if (ref($settings) eq 'HASH') {
4463: if (ref($settings->{'validation'}) eq 'HASH') {
4464: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 4465: }
1.235 raeburn 4466: }
4467: my $datatable;
4468: my $itemcount = 0;
4469: foreach my $item (@{$itemsref}) {
4470: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4471: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4472: $namesref->{$item}.
4473: '</span></td>'.
4474: '<td class="LC_left_item">';
4475: if (($item eq 'url') || ($item eq 'button')) {
4476: $datatable .= '<span class="LC_nobreak">'.
4477: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4478: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4479: } elsif ($item eq 'fields') {
4480: my @currfields;
4481: if (ref($currvalidation{$item}) eq 'ARRAY') {
4482: @currfields = @{$currvalidation{$item}};
4483: }
4484: foreach my $field (@{$fieldsref}) {
4485: my $check = '';
4486: if (grep(/^\Q$field\E$/,@currfields)) {
4487: $check = ' checked="checked"';
4488: }
4489: $datatable .= '<span class="LC_nobreak"><label>'.
4490: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4491: ' value="'.$field.'"'.$check.' />'.$field.
4492: '</label></span> ';
4493: }
4494: } elsif ($item eq 'markup') {
4495: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
4496: $currvalidation{$item}.
1.231 raeburn 4497: '</textarea>';
1.235 raeburn 4498: }
4499: $datatable .= '</td></tr>'."\n";
4500: if (ref($rowtotal)) {
1.231 raeburn 4501: $itemcount ++;
4502: }
4503: }
1.235 raeburn 4504: if ($caller eq 'requestcourses') {
4505: my %currhash;
1.248 raeburn 4506: if (ref($settings) eq 'HASH') {
4507: if (ref($settings->{'validation'}) eq 'HASH') {
4508: if ($settings->{'validation'}{'dc'} ne '') {
4509: $currhash{$settings->{'validation'}{'dc'}} = 1;
4510: }
1.235 raeburn 4511: }
4512: }
4513: my $numinrow = 2;
4514: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4515: 'validationdc',%currhash);
1.247 raeburn 4516: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4517: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 4518: if ($numdc > 1) {
1.247 raeburn 4519: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 4520: } else {
1.247 raeburn 4521: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 4522: }
1.247 raeburn 4523: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 4524: $itemcount ++;
4525: }
4526: if (ref($rowtotal)) {
4527: $$rowtotal += $itemcount;
4528: }
1.231 raeburn 4529: return $datatable;
4530: }
4531:
1.137 raeburn 4532: sub print_usersessions {
4533: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 4534: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 4535: my (%by_ip,%by_location,@intdoms,@instdoms);
4536: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 4537:
4538: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4539: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4540: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4541: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4542: if ($position eq 'top') {
1.152 raeburn 4543: if (keys(%serverhomes) > 1) {
1.145 raeburn 4544: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 4545: my $curroffloadnow;
4546: if (ref($settings) eq 'HASH') {
4547: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4548: $curroffloadnow = $settings->{'offloadnow'};
4549: }
4550: }
4551: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4552: } else {
1.140 raeburn 4553: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 4554: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
4555: '</td></tr>';
1.140 raeburn 4556: }
1.137 raeburn 4557: } else {
1.279 raeburn 4558: my %titles = &usersession_titles();
4559: my ($prefix,@types);
4560: if ($position eq 'bottom') {
4561: $prefix = 'remote';
4562: @types = ('version','excludedomain','includedomain');
1.145 raeburn 4563: } else {
1.279 raeburn 4564: $prefix = 'hosted';
4565: @types = ('excludedomain','includedomain');
4566: }
4567: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4568: }
4569: $$rowtotal += $itemcount;
4570: return $datatable;
4571: }
4572:
4573: sub rules_by_location {
4574: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
4575: my ($datatable,$itemcount,$css_class);
4576: if (keys(%{$by_location}) == 0) {
4577: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4578: $datatable = '<tr'.$css_class.'><td colspan="2">'.
4579: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
4580: '</td></tr>';
4581: $itemcount = 1;
4582: } else {
4583: $itemcount = 0;
4584: my $numinrow = 5;
4585: my (%current,%checkedon,%checkedoff);
4586: my @locations = sort(keys(%{$by_location}));
4587: foreach my $type (@{$types}) {
4588: $checkedon{$type} = '';
4589: $checkedoff{$type} = ' checked="checked"';
4590: }
4591: if (ref($settings) eq 'HASH') {
4592: if (ref($settings->{$prefix}) eq 'HASH') {
4593: foreach my $key (keys(%{$settings->{$prefix}})) {
4594: $current{$key} = $settings->{$prefix}{$key};
4595: if ($key eq 'version') {
4596: if ($current{$key} ne '') {
1.145 raeburn 4597: $checkedon{$key} = ' checked="checked"';
4598: $checkedoff{$key} = '';
4599: }
1.279 raeburn 4600: } elsif (ref($current{$key}) eq 'ARRAY') {
4601: $checkedon{$key} = ' checked="checked"';
4602: $checkedoff{$key} = '';
1.137 raeburn 4603: }
4604: }
4605: }
1.279 raeburn 4606: }
4607: foreach my $type (@{$types}) {
4608: next if ($type ne 'version' && !@locations);
4609: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4610: $datatable .= '<tr'.$css_class.'>
4611: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
4612: <span class="LC_nobreak">
4613: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4614: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4615: if ($type eq 'version') {
4616: my @lcversions = &Apache::lonnet::all_loncaparevs();
4617: my $selector = '<select name="'.$prefix.'_version">';
4618: foreach my $version (@lcversions) {
4619: my $selected = '';
4620: if ($current{'version'} eq $version) {
4621: $selected = ' selected="selected"';
1.145 raeburn 4622: }
1.279 raeburn 4623: $selector .= ' <option value="'.$version.'"'.
4624: $selected.'>'.$version.'</option>';
4625: }
4626: $selector .= '</select> ';
4627: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4628: } else {
4629: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4630: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4631: ' />'.(' 'x2).
4632: '<input type="button" value="'.&mt('uncheck all').'" '.
4633: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4634: "\n".
4635: '</div><div><table>';
4636: my $rem;
4637: for (my $i=0; $i<@locations; $i++) {
4638: my ($showloc,$value,$checkedtype);
4639: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
4640: my $ip = $by_location->{$locations[$i]}->[0];
4641: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4642: $value = join(':',@{$by_ip->{$ip}});
4643: $showloc = join(', ',@{$by_ip->{$ip}});
4644: if (ref($current{$type}) eq 'ARRAY') {
4645: foreach my $loc (@{$by_ip->{$ip}}) {
4646: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4647: $checkedtype = ' checked="checked"';
4648: last;
1.145 raeburn 4649: }
1.138 raeburn 4650: }
4651: }
4652: }
1.137 raeburn 4653: }
1.279 raeburn 4654: $rem = $i%($numinrow);
4655: if ($rem == 0) {
4656: if ($i > 0) {
4657: $datatable .= '</tr>';
4658: }
4659: $datatable .= '<tr>';
4660: }
4661: $datatable .= '<td class="LC_left_item">'.
4662: '<span class="LC_nobreak"><label>'.
4663: '<input type="checkbox" name="'.$prefix.'_'.$type.
4664: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4665: '</label></span></td>';
4666: }
4667: $rem = @locations%($numinrow);
4668: my $colsleft = $numinrow - $rem;
4669: if ($colsleft > 1 ) {
4670: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4671: ' </td>';
4672: } elsif ($colsleft == 1) {
4673: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4674: }
1.279 raeburn 4675: $datatable .= '</tr></table>';
1.137 raeburn 4676: }
1.279 raeburn 4677: $datatable .= '</td></tr>';
4678: $itemcount ++;
1.137 raeburn 4679: }
4680: }
1.279 raeburn 4681: return ($datatable,$itemcount);
1.137 raeburn 4682: }
4683:
1.275 raeburn 4684: sub print_ssl {
4685: my ($position,$dom,$settings,$rowtotal) = @_;
4686: my ($css_class,$datatable);
4687: my $itemcount = 1;
4688: if ($position eq 'top') {
1.281 raeburn 4689: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4690: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4691: my $same_institution;
4692: if ($intdom ne '') {
4693: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
4694: if (ref($internet_names) eq 'ARRAY') {
4695: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4696: $same_institution = 1;
4697: }
4698: }
4699: }
1.275 raeburn 4700: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 4701: $datatable = '<tr'.$css_class.'><td colspan="2">';
4702: if ($same_institution) {
4703: my %domservers = &Apache::lonnet::get_servers($dom);
4704: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
4705: } else {
4706: $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.");
4707: }
4708: $datatable .= '</td></tr>';
1.275 raeburn 4709: $itemcount ++;
4710: } else {
4711: my %titles = &ssl_titles();
4712: my (%by_ip,%by_location,@intdoms,@instdoms);
4713: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4714: my @alldoms = &Apache::lonnet::all_domains();
4715: my %serverhomes = %Apache::lonnet::serverhomeIDs;
4716: my @domservers = &Apache::lonnet::get_servers($dom);
4717: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4718: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 4719: if (($position eq 'connto') || ($position eq 'connfrom')) {
4720: my $legacy;
4721: unless (ref($settings) eq 'HASH') {
4722: my $name;
4723: if ($position eq 'connto') {
4724: $name = 'loncAllowInsecure';
4725: } else {
4726: $name = 'londAllowInsecure';
4727: }
4728: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
4729: my @ids=&Apache::lonnet::current_machine_ids();
4730: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
4731: my %what = (
4732: $name => 1,
4733: );
4734: my ($result,$returnhash) =
4735: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
4736: if ($result eq 'ok') {
4737: if (ref($returnhash) eq 'HASH') {
4738: $legacy = $returnhash->{$name};
4739: }
4740: }
4741: } else {
4742: $legacy = $Apache::lonnet::perlvar{$name};
4743: }
4744: }
1.275 raeburn 4745: foreach my $type ('dom','intdom','other') {
4746: my %checked;
4747: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4748: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
4749: '<td class="LC_right_item">';
4750: my $skip;
4751: if ($type eq 'dom') {
4752: unless (keys(%servers) > 1) {
4753: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
4754: $skip = 1;
4755: }
4756: }
4757: if ($type eq 'intdom') {
4758: unless (@instdoms > 1) {
4759: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
4760: $skip = 1;
4761: }
4762: } elsif ($type eq 'other') {
4763: if (keys(%by_location) == 0) {
4764: $datatable .= &mt('Nothing to set here, as there are no other institutions');
4765: $skip = 1;
4766: }
4767: }
4768: unless ($skip) {
4769: $checked{'yes'} = ' checked="checked"';
4770: if (ref($settings) eq 'HASH') {
1.293 raeburn 4771: if (ref($settings->{$position}) eq 'HASH') {
4772: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 4773: $checked{$1} = $checked{'yes'};
4774: delete($checked{'yes'});
4775: }
4776: }
1.293 raeburn 4777: } else {
4778: if ($legacy == 0) {
4779: $checked{'req'} = $checked{'yes'};
4780: delete($checked{'yes'});
4781: }
1.275 raeburn 4782: }
4783: foreach my $option ('no','yes','req') {
4784: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 4785: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 4786: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
4787: '</label></span>'.(' 'x2);
4788: }
4789: }
4790: $datatable .= '</td></tr>';
4791: $itemcount ++;
4792: }
4793: } else {
4794: my $prefix = 'replication';
4795: my @types = ('certreq','nocertreq');
1.279 raeburn 4796: if (keys(%by_location) == 0) {
4797: $datatable .= '<tr'.$css_class.'><td>'.
4798: &mt('Nothing to set here, as there are no other institutions').
4799: '</td></tr>';
4800: $itemcount ++;
1.275 raeburn 4801: } else {
1.279 raeburn 4802: ($datatable,$itemcount) =
4803: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 4804: }
4805: }
4806: }
4807: $$rowtotal += $itemcount;
4808: return $datatable;
4809: }
4810:
4811: sub ssl_titles {
4812: return &Apache::lonlocal::texthash (
4813: dom => 'LON-CAPA servers/VMs from same domain',
4814: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
4815: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 4816: connto => 'Connections to other servers',
4817: connfrom => 'Connections from other servers',
1.275 raeburn 4818: replication => 'Replicating content to other institutions',
4819: certreq => 'Client certificate required, but specific domains exempt',
4820: nocertreq => 'No client certificate required, except for specific domains',
4821: no => 'SSL not used',
4822: yes => 'SSL Optional (used if available)',
4823: req => 'SSL Required',
4824: );
1.279 raeburn 4825: }
4826:
4827: sub print_trust {
4828: my ($prefix,$dom,$settings,$rowtotal) = @_;
4829: my ($css_class,$datatable,%checked,%choices);
4830: my (%by_ip,%by_location,@intdoms,@instdoms);
4831: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4832: my $itemcount = 1;
4833: my %titles = &trust_titles();
4834: my @types = ('exc','inc');
4835: if ($prefix eq 'top') {
4836: $prefix = 'content';
4837: } elsif ($prefix eq 'bottom') {
4838: $prefix = 'msg';
4839: }
4840: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4841: $$rowtotal += $itemcount;
4842: return $datatable;
4843: }
4844:
4845: sub trust_titles {
4846: return &Apache::lonlocal::texthash(
4847: content => "Access to this domain's content by others",
4848: shared => "Access to other domain's content by this domain",
4849: enroll => "Enrollment in this domain's courses by others",
4850: othcoau => "Co-author roles in this domain for others",
4851: coaurem => "Co-author roles for this domain's users elsewhere",
4852: domroles => "Domain roles in this domain assignable to others",
4853: catalog => "Course Catalog for this domain displayed elsewhere",
4854: reqcrs => "Requests for creation of courses in this domain by others",
4855: msg => "Users in other domains can send messages to this domain",
4856: exc => "Allow all, but exclude specific domains",
4857: inc => "Deny all, but include specific domains",
4858: );
1.275 raeburn 4859: }
4860:
1.138 raeburn 4861: sub build_location_hashes {
1.275 raeburn 4862: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 4863: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 4864: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 4865: my %iphost = &Apache::lonnet::get_iphost();
4866: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4867: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4868: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4869: foreach my $id (@{$iphost{$primary_ip}}) {
4870: my $intdom = &Apache::lonnet::internet_dom($id);
4871: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4872: push(@{$intdoms},$intdom);
4873: }
4874: }
4875: }
4876: foreach my $ip (keys(%iphost)) {
4877: if (ref($iphost{$ip}) eq 'ARRAY') {
4878: foreach my $id (@{$iphost{$ip}}) {
4879: my $location = &Apache::lonnet::internet_dom($id);
4880: if ($location) {
1.275 raeburn 4881: if (grep(/^\Q$location\E$/,@{$intdoms})) {
4882: my $dom = &Apache::lonnet::host_domain($id);
4883: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
4884: push(@{$instdoms},$dom);
4885: }
4886: next;
4887: }
1.138 raeburn 4888: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4889: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4890: push(@{$by_ip->{$ip}},$location);
4891: }
4892: } else {
4893: $by_ip->{$ip} = [$location];
4894: }
4895: }
4896: }
4897: }
4898: }
4899: foreach my $ip (sort(keys(%{$by_ip}))) {
4900: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4901: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4902: my $first = $by_ip->{$ip}->[0];
4903: if (ref($by_location->{$first}) eq 'ARRAY') {
4904: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4905: push(@{$by_location->{$first}},$ip);
4906: }
4907: } else {
4908: $by_location->{$first} = [$ip];
4909: }
4910: }
4911: }
4912: return;
4913: }
4914:
1.145 raeburn 4915: sub current_offloads_to {
4916: my ($dom,$settings,$servers) = @_;
4917: my (%spareid,%otherdomconfigs);
1.152 raeburn 4918: if (ref($servers) eq 'HASH') {
1.145 raeburn 4919: foreach my $lonhost (sort(keys(%{$servers}))) {
4920: my $gotspares;
1.152 raeburn 4921: if (ref($settings) eq 'HASH') {
4922: if (ref($settings->{'spares'}) eq 'HASH') {
4923: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4924: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4925: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4926: $gotspares = 1;
4927: }
1.145 raeburn 4928: }
4929: }
4930: unless ($gotspares) {
4931: my $gotspares;
4932: my $serverhomeID =
4933: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4934: my $serverhomedom =
4935: &Apache::lonnet::host_domain($serverhomeID);
4936: if ($serverhomedom ne $dom) {
4937: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4938: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4939: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4940: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4941: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4942: $gotspares = 1;
4943: }
4944: }
4945: } else {
4946: $otherdomconfigs{$serverhomedom} =
4947: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4948: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4949: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4950: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4951: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4952: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4953: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4954: $gotspares = 1;
4955: }
4956: }
4957: }
4958: }
4959: }
4960: }
4961: }
4962: unless ($gotspares) {
4963: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4964: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4965: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4966: } else {
4967: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4968: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4969: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4970: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4971: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4972: } else {
1.150 raeburn 4973: my %what = (
4974: spareid => 1,
4975: );
4976: my ($result,$returnhash) =
4977: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4978: if ($result eq 'ok') {
4979: if (ref($returnhash) eq 'HASH') {
4980: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4981: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4982: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4983: }
4984: }
1.145 raeburn 4985: }
4986: }
4987: }
4988: }
4989: }
4990: }
4991: return %spareid;
4992: }
4993:
4994: sub spares_row {
1.261 raeburn 4995: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4996: my $css_class;
4997: my $numinrow = 4;
4998: my $itemcount = 1;
4999: my $datatable;
1.152 raeburn 5000: my %typetitles = &sparestype_titles();
5001: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 5002: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 5003: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5004: my ($othercontrol,$serverdom);
5005: if ($serverhome ne $server) {
5006: $serverdom = &Apache::lonnet::host_domain($serverhome);
5007: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5008: } else {
5009: $serverdom = &Apache::lonnet::host_domain($server);
5010: if ($serverdom ne $dom) {
5011: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5012: }
5013: }
5014: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 5015: my $checkednow;
5016: if (ref($curroffloadnow) eq 'HASH') {
5017: if ($curroffloadnow->{$server}) {
5018: $checkednow = ' checked="checked"';
5019: }
5020: }
1.145 raeburn 5021: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5022: $datatable .= '<tr'.$css_class.'>
5023: <td rowspan="2">
1.183 bisitz 5024: <span class="LC_nobreak">'.
5025: &mt('[_1] when busy, offloads to:'
1.261 raeburn 5026: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 5027: '<span class="LC_nobreak">'."\n".
1.261 raeburn 5028: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
5029: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 5030: "\n";
1.145 raeburn 5031: my (%current,%canselect);
1.152 raeburn 5032: my @choices =
5033: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5034: foreach my $type ('primary','default') {
5035: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 5036: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5037: my @spares = @{$spareid->{$server}{$type}};
5038: if (@spares > 0) {
1.152 raeburn 5039: if ($othercontrol) {
5040: $current{$type} = join(', ',@spares);
5041: } else {
5042: $current{$type} .= '<table>';
5043: my $numspares = scalar(@spares);
5044: for (my $i=0; $i<@spares; $i++) {
5045: my $rem = $i%($numinrow);
5046: if ($rem == 0) {
5047: if ($i > 0) {
5048: $current{$type} .= '</tr>';
5049: }
5050: $current{$type} .= '<tr>';
1.145 raeburn 5051: }
1.152 raeburn 5052: $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'".');" /> '.
5053: $spareid->{$server}{$type}[$i].
5054: '</label></td>'."\n";
5055: }
5056: my $rem = @spares%($numinrow);
5057: my $colsleft = $numinrow - $rem;
5058: if ($colsleft > 1 ) {
5059: $current{$type} .= '<td colspan="'.$colsleft.
5060: '" class="LC_left_item">'.
5061: ' </td>';
5062: } elsif ($colsleft == 1) {
5063: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 5064: }
1.152 raeburn 5065: $current{$type} .= '</tr></table>';
1.150 raeburn 5066: }
1.145 raeburn 5067: }
5068: }
5069: if ($current{$type} eq '') {
5070: $current{$type} = &mt('None specified');
5071: }
1.152 raeburn 5072: if ($othercontrol) {
5073: if ($type eq 'primary') {
5074: $canselect{$type} = $othercontrol;
5075: }
5076: } else {
5077: $canselect{$type} =
5078: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
5079: '<select name="newspare_'.$type.'_'.$server.'" '.
5080: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
5081: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
5082: if (@choices > 0) {
5083: foreach my $lonhost (@choices) {
5084: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
5085: }
5086: }
5087: $canselect{$type} .= '</select>'."\n";
5088: }
5089: } else {
5090: $current{$type} = &mt('Could not be determined');
5091: if ($type eq 'primary') {
5092: $canselect{$type} = $othercontrol;
5093: }
1.145 raeburn 5094: }
1.152 raeburn 5095: if ($type eq 'default') {
5096: $datatable .= '<tr'.$css_class.'>';
5097: }
5098: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5099: '<td>'.$current{$type}.'</td>'."\n".
5100: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 5101: }
5102: $itemcount ++;
5103: }
5104: }
5105: $$rowtotal += $itemcount;
5106: return $datatable;
5107: }
5108:
1.152 raeburn 5109: sub possible_newspares {
5110: my ($server,$currspares,$serverhomes,$altids) = @_;
5111: my $serverhostname = &Apache::lonnet::hostname($server);
5112: my %excluded;
5113: if ($serverhostname ne '') {
5114: %excluded = (
5115: $serverhostname => 1,
5116: );
5117: }
5118: if (ref($currspares) eq 'HASH') {
5119: foreach my $type (keys(%{$currspares})) {
5120: if (ref($currspares->{$type}) eq 'ARRAY') {
5121: if (@{$currspares->{$type}} > 0) {
5122: foreach my $curr (@{$currspares->{$type}}) {
5123: my $hostname = &Apache::lonnet::hostname($curr);
5124: $excluded{$hostname} = 1;
5125: }
5126: }
5127: }
5128: }
5129: }
5130: my @choices;
5131: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5132: if (keys(%{$serverhomes}) > 1) {
5133: foreach my $name (sort(keys(%{$serverhomes}))) {
5134: unless ($excluded{$name}) {
5135: if (exists($altids->{$serverhomes->{$name}})) {
5136: push(@choices,$altids->{$serverhomes->{$name}});
5137: } else {
5138: push(@choices,$serverhomes->{$name});
1.145 raeburn 5139: }
5140: }
5141: }
5142: }
5143: }
1.152 raeburn 5144: return sort(@choices);
1.145 raeburn 5145: }
5146:
1.150 raeburn 5147: sub print_loadbalancing {
5148: my ($dom,$settings,$rowtotal) = @_;
5149: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5150: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5151: my $numinrow = 1;
5152: my $datatable;
5153: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 5154: my (%currbalancer,%currtargets,%currrules,%existing);
5155: if (ref($settings) eq 'HASH') {
5156: %existing = %{$settings};
5157: }
5158: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5159: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
5160: \%currtargets,\%currrules);
1.150 raeburn 5161: } else {
5162: return;
5163: }
5164: my ($othertitle,$usertypes,$types) =
5165: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 5166: my $rownum = 8;
1.150 raeburn 5167: if (ref($types) eq 'ARRAY') {
5168: $rownum += scalar(@{$types});
5169: }
1.171 raeburn 5170: my @css_class = ('LC_odd_row','LC_even_row');
5171: my $balnum = 0;
5172: my $islast;
5173: my (@toshow,$disabledtext);
5174: if (keys(%currbalancer) > 0) {
5175: @toshow = sort(keys(%currbalancer));
5176: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5177: push(@toshow,'');
5178: }
5179: } else {
5180: @toshow = ('');
5181: $disabledtext = &mt('No existing load balancer');
5182: }
5183: foreach my $lonhost (@toshow) {
5184: if ($balnum == scalar(@toshow)-1) {
5185: $islast = 1;
5186: } else {
5187: $islast = 0;
5188: }
5189: my $cssidx = $balnum%2;
5190: my $targets_div_style = 'display: none';
5191: my $disabled_div_style = 'display: block';
5192: my $homedom_div_style = 'display: none';
5193: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
5194: '<td rowspan="'.$rownum.'" valign="top">'.
5195: '<p>';
5196: if ($lonhost eq '') {
1.210 raeburn 5197: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 5198: if (keys(%currbalancer) > 0) {
5199: $datatable .= &mt('Add balancer:');
5200: } else {
5201: $datatable .= &mt('Enable balancer:');
5202: }
5203: $datatable .= ' '.
5204: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5205: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5206: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5207: '<option value="" selected="selected">'.&mt('None').
5208: '</option>'."\n";
5209: foreach my $server (sort(keys(%servers))) {
5210: next if ($currbalancer{$server});
5211: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5212: }
1.210 raeburn 5213: $datatable .=
1.171 raeburn 5214: '</select>'."\n".
5215: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5216: } else {
5217: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5218: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5219: &mt('Stop balancing').'</label>'.
5220: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5221: $targets_div_style = 'display: block';
5222: $disabled_div_style = 'display: none';
5223: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5224: $homedom_div_style = 'display: block';
5225: }
5226: }
5227: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
5228: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5229: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5230: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5231: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5232: my @sparestypes = ('primary','default');
5233: my %typetitles = &sparestype_titles();
1.284 raeburn 5234: my %hostherechecked = (
5235: no => ' checked="checked"',
5236: );
1.171 raeburn 5237: foreach my $sparetype (@sparestypes) {
5238: my $targettable;
5239: for (my $i=0; $i<$numspares; $i++) {
5240: my $checked;
5241: if (ref($currtargets{$lonhost}) eq 'HASH') {
5242: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5243: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5244: $checked = ' checked="checked"';
5245: }
5246: }
5247: }
5248: my ($chkboxval,$disabled);
5249: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5250: $chkboxval = $spares[$i];
5251: }
5252: if (exists($currbalancer{$spares[$i]})) {
5253: $disabled = ' disabled="disabled"';
5254: }
1.210 raeburn 5255: $targettable .=
1.253 raeburn 5256: '<td><span class="LC_nobreak"><label>'.
5257: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 5258: $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 5259: '</span></label></span></td>';
1.171 raeburn 5260: my $rem = $i%($numinrow);
5261: if ($rem == 0) {
5262: if (($i > 0) && ($i < $numspares-1)) {
5263: $targettable .= '</tr>';
5264: }
5265: if ($i < $numspares-1) {
5266: $targettable .= '<tr>';
1.150 raeburn 5267: }
5268: }
5269: }
1.171 raeburn 5270: if ($targettable ne '') {
5271: my $rem = $numspares%($numinrow);
5272: my $colsleft = $numinrow - $rem;
5273: if ($colsleft > 1 ) {
5274: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5275: ' </td>';
5276: } elsif ($colsleft == 1) {
5277: $targettable .= '<td class="LC_left_item"> </td>';
5278: }
5279: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5280: '<table><tr>'.$targettable.'</tr></table><br />';
5281: }
1.284 raeburn 5282: $hostherechecked{$sparetype} = '';
5283: if (ref($currtargets{$lonhost}) eq 'HASH') {
5284: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5285: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5286: $hostherechecked{$sparetype} = ' checked="checked"';
5287: $hostherechecked{'no'} = '';
5288: }
5289: }
5290: }
5291: }
5292: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5293: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5294: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5295: foreach my $sparetype (@sparestypes) {
5296: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5297: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5298: '</i></label><br />';
1.171 raeburn 5299: }
5300: $datatable .= '</div></td></tr>'.
5301: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5302: $othertitle,$usertypes,$types,\%servers,
5303: \%currbalancer,$lonhost,
5304: $targets_div_style,$homedom_div_style,
5305: $css_class[$cssidx],$balnum,$islast);
5306: $$rowtotal += $rownum;
5307: $balnum ++;
5308: }
5309: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5310: return $datatable;
5311: }
5312:
5313: sub get_loadbalancers_config {
5314: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
5315: return unless ((ref($servers) eq 'HASH') &&
5316: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
5317: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
5318: if (keys(%{$existing}) > 0) {
5319: my $oldlonhost;
5320: foreach my $key (sort(keys(%{$existing}))) {
5321: if ($key eq 'lonhost') {
5322: $oldlonhost = $existing->{'lonhost'};
5323: $currbalancer->{$oldlonhost} = 1;
5324: } elsif ($key eq 'targets') {
5325: if ($oldlonhost) {
5326: $currtargets->{$oldlonhost} = $existing->{'targets'};
5327: }
5328: } elsif ($key eq 'rules') {
5329: if ($oldlonhost) {
5330: $currrules->{$oldlonhost} = $existing->{'rules'};
5331: }
5332: } elsif (ref($existing->{$key}) eq 'HASH') {
5333: $currbalancer->{$key} = 1;
5334: $currtargets->{$key} = $existing->{$key}{'targets'};
5335: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 5336: }
5337: }
1.171 raeburn 5338: } else {
5339: my ($balancerref,$targetsref) =
5340: &Apache::lonnet::get_lonbalancer_config($servers);
5341: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5342: foreach my $server (sort(keys(%{$balancerref}))) {
5343: $currbalancer->{$server} = 1;
5344: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5345: }
5346: }
5347: }
1.171 raeburn 5348: return;
1.150 raeburn 5349: }
5350:
5351: sub loadbalancing_rules {
5352: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 5353: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5354: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5355: my $output;
1.171 raeburn 5356: my $num = 0;
1.210 raeburn 5357: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5358: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5359: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5360: foreach my $type (@{$alltypes}) {
1.171 raeburn 5361: $num ++;
1.150 raeburn 5362: my $current;
5363: if (ref($currrules) eq 'HASH') {
5364: $current = $currrules->{$type};
5365: }
1.253 raeburn 5366: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 5367: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5368: $current = '';
5369: }
5370: }
5371: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 5372: $servers,$currbalancer,$lonhost,$dom,
5373: $targets_div_style,$homedom_div_style,
5374: $css_class,$balnum,$num,$islast);
1.150 raeburn 5375: }
5376: }
5377: return $output;
5378: }
5379:
5380: sub loadbalancing_titles {
5381: my ($dom,$intdom,$usertypes,$types) = @_;
5382: my %othertypes = (
5383: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5384: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5385: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5386: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 5387: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5388: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5389: );
1.209 raeburn 5390: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 5391: if (ref($types) eq 'ARRAY') {
5392: unshift(@alltypes,@{$types},'default');
5393: }
5394: my %titles;
5395: foreach my $type (@alltypes) {
5396: if ($type =~ /^_LC_/) {
5397: $titles{$type} = $othertypes{$type};
5398: } elsif ($type eq 'default') {
5399: $titles{$type} = &mt('All users from [_1]',$dom);
5400: if (ref($types) eq 'ARRAY') {
5401: if (@{$types} > 0) {
5402: $titles{$type} = &mt('Other users from [_1]',$dom);
5403: }
5404: }
5405: } elsif (ref($usertypes) eq 'HASH') {
5406: $titles{$type} = $usertypes->{$type};
5407: }
5408: }
5409: return (\@alltypes,\%othertypes,\%titles);
5410: }
5411:
5412: sub loadbalance_rule_row {
1.171 raeburn 5413: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5414: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 5415: my @rulenames;
1.150 raeburn 5416: my %ruletitles = &offloadtype_text();
1.209 raeburn 5417: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 5418: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 5419: } else {
1.209 raeburn 5420: @rulenames = ('default','homeserver');
5421: if ($type eq '_LC_external') {
5422: push(@rulenames,'externalbalancer');
5423: } else {
5424: push(@rulenames,'specific');
5425: }
5426: push(@rulenames,'none');
1.150 raeburn 5427: }
5428: my $style = $targets_div_style;
1.253 raeburn 5429: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 5430: $style = $homedom_div_style;
5431: }
1.171 raeburn 5432: my $space;
5433: if ($islast && $num == 1) {
5434: $space = '<div display="inline-block"> </div>';
5435: }
1.210 raeburn 5436: my $output =
1.171 raeburn 5437: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
5438: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5439: '<td valaign="top">'.$space.
5440: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 5441: for (my $i=0; $i<@rulenames; $i++) {
5442: my $rule = $rulenames[$i];
5443: my ($checked,$extra);
5444: if ($rulenames[$i] eq 'default') {
5445: $rule = '';
5446: }
5447: if ($rulenames[$i] eq 'specific') {
5448: if (ref($servers) eq 'HASH') {
5449: my $default;
5450: if (($current ne '') && (exists($servers->{$current}))) {
5451: $checked = ' checked="checked"';
5452: }
5453: unless ($checked) {
5454: $default = ' selected="selected"';
5455: }
1.210 raeburn 5456: $extra =
1.171 raeburn 5457: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5458: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5459: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5460: '<option value=""'.$default.'></option>'."\n";
5461: foreach my $server (sort(keys(%{$servers}))) {
5462: if (ref($currbalancer) eq 'HASH') {
5463: next if (exists($currbalancer->{$server}));
5464: }
1.150 raeburn 5465: my $selected;
1.171 raeburn 5466: if ($server eq $current) {
1.150 raeburn 5467: $selected = ' selected="selected"';
5468: }
1.171 raeburn 5469: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 5470: }
5471: $extra .= '</select>';
5472: }
5473: } elsif ($rule eq $current) {
5474: $checked = ' checked="checked"';
5475: }
5476: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 5477: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5478: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5479: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 5480: ')"'.$checked.' /> ';
5481: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
5482: $output .= $ruletitles{'particular'};
5483: } else {
5484: $output .= $ruletitles{$rulenames[$i]};
5485: }
5486: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 5487: }
5488: $output .= '</div></td></tr>'."\n";
5489: return $output;
5490: }
5491:
5492: sub offloadtype_text {
5493: my %ruletitles = &Apache::lonlocal::texthash (
5494: 'default' => 'Offloads to default destinations',
5495: 'homeserver' => "Offloads to user's home server",
5496: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5497: 'specific' => 'Offloads to specific server',
1.161 raeburn 5498: 'none' => 'No offload',
1.209 raeburn 5499: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5500: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 5501: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 5502: );
5503: return %ruletitles;
5504: }
5505:
5506: sub sparestype_titles {
5507: my %typestitles = &Apache::lonlocal::texthash (
5508: 'primary' => 'primary',
5509: 'default' => 'default',
5510: );
5511: return %typestitles;
5512: }
5513:
1.28 raeburn 5514: sub contact_titles {
5515: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 5516: 'supportemail' => 'Support E-mail address',
5517: 'adminemail' => 'Default Server Admin E-mail address',
5518: 'errormail' => 'Error reports to be e-mailed to',
5519: 'packagesmail' => 'Package update alerts to be e-mailed to',
5520: 'helpdeskmail' => "Helpdesk requests for this domain's users",
1.289 raeburn 5521: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
1.286 raeburn 5522: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5523: 'requestsmail' => 'E-mail from course requests requiring approval',
5524: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 5525: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 5526: );
5527: my %short_titles = &Apache::lonlocal::texthash (
5528: adminemail => 'Admin E-mail address',
5529: supportemail => 'Support E-mail',
5530: );
5531: return (\%titles,\%short_titles);
5532: }
5533:
1.286 raeburn 5534: sub helpform_fields {
5535: my %titles = &Apache::lonlocal::texthash (
5536: 'username' => 'Name',
5537: 'user' => 'Username/domain',
5538: 'phone' => 'Phone',
5539: 'cc' => 'Cc e-mail',
5540: 'course' => 'Course Details',
5541: 'section' => 'Sections',
1.289 raeburn 5542: 'screenshot' => 'File upload',
1.286 raeburn 5543: );
5544: my @fields = ('username','phone','user','course','section','cc','screenshot');
5545: my %possoptions = (
5546: username => ['yes','no','req'],
1.289 raeburn 5547: phone => ['yes','no','req'],
1.286 raeburn 5548: user => ['yes','no'],
1.289 raeburn 5549: cc => ['yes','no'],
1.286 raeburn 5550: course => ['yes','no'],
5551: section => ['yes','no'],
5552: screenshot => ['yes','no'],
5553: );
5554: my %fieldoptions = &Apache::lonlocal::texthash (
5555: 'yes' => 'Optional',
5556: 'req' => 'Required',
5557: 'no' => "Not shown",
5558: );
5559: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5560: }
5561:
1.72 raeburn 5562: sub tool_titles {
5563: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 5564: aboutme => 'Personal web page',
1.86 raeburn 5565: blog => 'Blog',
1.162 raeburn 5566: webdav => 'WebDAV',
1.86 raeburn 5567: portfolio => 'Portfolio',
1.88 bisitz 5568: official => 'Official courses (with institutional codes)',
5569: unofficial => 'Unofficial courses',
1.98 raeburn 5570: community => 'Communities',
1.216 raeburn 5571: textbook => 'Textbook courses',
1.271 raeburn 5572: placement => 'Placement tests',
1.86 raeburn 5573: );
1.72 raeburn 5574: return %titles;
5575: }
5576:
1.101 raeburn 5577: sub courserequest_titles {
5578: my %titles = &Apache::lonlocal::texthash (
5579: official => 'Official',
5580: unofficial => 'Unofficial',
5581: community => 'Communities',
1.216 raeburn 5582: textbook => 'Textbook',
1.271 raeburn 5583: placement => 'Placement tests',
1.101 raeburn 5584: norequest => 'Not allowed',
1.104 raeburn 5585: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5586: validate => 'With validation',
5587: autolimit => 'Numerical limit',
1.103 raeburn 5588: unlimited => '(blank for unlimited)',
1.101 raeburn 5589: );
5590: return %titles;
5591: }
5592:
1.163 raeburn 5593: sub authorrequest_titles {
5594: my %titles = &Apache::lonlocal::texthash (
5595: norequest => 'Not allowed',
5596: approval => 'Approval by Dom. Coord.',
5597: automatic => 'Automatic approval',
5598: );
5599: return %titles;
1.210 raeburn 5600: }
1.163 raeburn 5601:
1.101 raeburn 5602: sub courserequest_conditions {
5603: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5604: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 5605: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 5606: );
5607: return %conditions;
5608: }
5609:
5610:
1.27 raeburn 5611: sub print_usercreation {
1.30 raeburn 5612: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 5613: my $numinrow = 4;
1.28 raeburn 5614: my $datatable;
5615: if ($position eq 'top') {
1.30 raeburn 5616: $$rowtotal ++;
1.34 raeburn 5617: my $rowcount = 0;
1.32 raeburn 5618: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 5619: if (ref($rules) eq 'HASH') {
5620: if (keys(%{$rules}) > 0) {
1.32 raeburn 5621: $datatable .= &user_formats_row('username',$settings,$rules,
5622: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 5623: $$rowtotal ++;
1.32 raeburn 5624: $rowcount ++;
5625: }
5626: }
5627: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5628: if (ref($idrules) eq 'HASH') {
5629: if (keys(%{$idrules}) > 0) {
5630: $datatable .= &user_formats_row('id',$settings,$idrules,
5631: $idruleorder,$numinrow,$rowcount);
5632: $$rowtotal ++;
5633: $rowcount ++;
1.28 raeburn 5634: }
5635: }
1.39 raeburn 5636: if ($rowcount == 0) {
5637: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5638: $$rowtotal ++;
5639: $rowcount ++;
5640: }
1.34 raeburn 5641: } elsif ($position eq 'middle') {
1.224 raeburn 5642: my @creators = ('author','course','requestcrs');
1.37 raeburn 5643: my ($rules,$ruleorder) =
5644: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 5645: my %lt = &usercreation_types();
5646: my %checked;
5647: if (ref($settings) eq 'HASH') {
5648: if (ref($settings->{'cancreate'}) eq 'HASH') {
5649: foreach my $item (@creators) {
5650: $checked{$item} = $settings->{'cancreate'}{$item};
5651: }
5652: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5653: foreach my $item (@creators) {
5654: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5655: $checked{$item} = 'none';
5656: }
5657: }
5658: }
5659: }
5660: my $rownum = 0;
5661: foreach my $item (@creators) {
5662: $rownum ++;
1.224 raeburn 5663: if ($checked{$item} eq '') {
5664: $checked{$item} = 'any';
1.34 raeburn 5665: }
5666: my $css_class;
5667: if ($rownum%2) {
5668: $css_class = '';
5669: } else {
5670: $css_class = ' class="LC_odd_row" ';
5671: }
5672: $datatable .= '<tr'.$css_class.'>'.
5673: '<td><span class="LC_nobreak">'.$lt{$item}.
5674: '</span></td><td align="right">';
1.224 raeburn 5675: my @options = ('any');
5676: if (ref($rules) eq 'HASH') {
5677: if (keys(%{$rules}) > 0) {
5678: push(@options,('official','unofficial'));
1.37 raeburn 5679: }
5680: }
1.224 raeburn 5681: push(@options,'none');
1.37 raeburn 5682: foreach my $option (@options) {
1.50 raeburn 5683: my $type = 'radio';
1.34 raeburn 5684: my $check = ' ';
1.224 raeburn 5685: if ($checked{$item} eq $option) {
5686: $check = ' checked="checked" ';
1.34 raeburn 5687: }
5688: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5689: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5690: $item.'" value="'.$option.'"'.$check.'/> '.
5691: $lt{$option}.'</label> </span>';
5692: }
5693: $datatable .= '</td></tr>';
5694: }
1.28 raeburn 5695: } else {
5696: my @contexts = ('author','course','domain');
5697: my @authtypes = ('int','krb4','krb5','loc');
5698: my %checked;
5699: if (ref($settings) eq 'HASH') {
5700: if (ref($settings->{'authtypes'}) eq 'HASH') {
5701: foreach my $item (@contexts) {
5702: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5703: foreach my $auth (@authtypes) {
5704: if ($settings->{'authtypes'}{$item}{$auth}) {
5705: $checked{$item}{$auth} = ' checked="checked" ';
5706: }
5707: }
5708: }
5709: }
1.27 raeburn 5710: }
1.35 raeburn 5711: } else {
5712: foreach my $item (@contexts) {
1.36 raeburn 5713: foreach my $auth (@authtypes) {
1.35 raeburn 5714: $checked{$item}{$auth} = ' checked="checked" ';
5715: }
5716: }
1.27 raeburn 5717: }
1.28 raeburn 5718: my %title = &context_names();
5719: my %authname = &authtype_names();
5720: my $rownum = 0;
5721: my $css_class;
5722: foreach my $item (@contexts) {
5723: if ($rownum%2) {
5724: $css_class = '';
5725: } else {
5726: $css_class = ' class="LC_odd_row" ';
5727: }
1.30 raeburn 5728: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5729: '<td>'.$title{$item}.
5730: '</td><td class="LC_left_item">'.
5731: '<span class="LC_nobreak">';
5732: foreach my $auth (@authtypes) {
5733: $datatable .= '<label>'.
5734: '<input type="checkbox" name="'.$item.'_auth" '.
5735: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5736: $authname{$auth}.'</label> ';
5737: }
5738: $datatable .= '</span></td></tr>';
5739: $rownum ++;
1.27 raeburn 5740: }
1.30 raeburn 5741: $$rowtotal += $rownum;
1.27 raeburn 5742: }
5743: return $datatable;
5744: }
5745:
1.224 raeburn 5746: sub print_selfcreation {
5747: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 5748: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 5749: if (ref($settings) eq 'HASH') {
5750: if (ref($settings->{'cancreate'}) eq 'HASH') {
5751: $createsettings = $settings->{'cancreate'};
1.236 raeburn 5752: if (ref($createsettings) eq 'HASH') {
5753: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5754: @selfcreate = @{$createsettings->{'selfcreate'}};
5755: } elsif ($createsettings->{'selfcreate'} ne '') {
5756: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5757: @selfcreate = ('email','login','sso');
5758: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5759: @selfcreate = ($createsettings->{'selfcreate'});
5760: }
5761: }
5762: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5763: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 5764: }
5765: }
5766: }
5767: }
5768: my %radiohash;
5769: my $numinrow = 4;
5770: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5771: if ($position eq 'top') {
5772: my %choices = &Apache::lonlocal::texthash (
5773: cancreate_login => 'Institutional Login',
5774: cancreate_sso => 'Institutional Single Sign On',
5775: );
5776: my @toggles = sort(keys(%choices));
5777: my %defaultchecked = (
5778: 'cancreate_login' => 'off',
5779: 'cancreate_sso' => 'off',
5780: );
1.228 raeburn 5781: my ($onclick,$itemcount);
1.224 raeburn 5782: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5783: \%choices,$itemcount,$onclick);
1.228 raeburn 5784: $$rowtotal += $itemcount;
5785:
1.224 raeburn 5786: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5787:
5788: if (ref($usertypes) eq 'HASH') {
5789: if (keys(%{$usertypes}) > 0) {
5790: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5791: $dom,$numinrow,$othertitle,
1.228 raeburn 5792: 'statustocreate',$$rowtotal);
1.224 raeburn 5793: $$rowtotal ++;
5794: }
5795: }
1.240 raeburn 5796: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5797: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5798: $fieldtitles{'inststatus'} = &mt('Institutional status');
5799: my $rem;
5800: my $numperrow = 2;
5801: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5802: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 5803: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 5804: '<td class="LC_left_item">'."\n".
5805: '<table><tr><td>'."\n";
5806: for (my $i=0; $i<@fields; $i++) {
5807: $rem = $i%($numperrow);
5808: if ($rem == 0) {
5809: if ($i > 0) {
5810: $datatable .= '</tr>';
5811: }
5812: $datatable .= '<tr>';
5813: }
5814: my $currval;
1.248 raeburn 5815: if (ref($createsettings) eq 'HASH') {
5816: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5817: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5818: }
1.240 raeburn 5819: }
5820: $datatable .= '<td class="LC_left_item">'.
5821: '<span class="LC_nobreak">'.
5822: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5823: 'value="'.$currval.'" size="10" /> '.
5824: $fieldtitles{$fields[$i]}.'</span></td>';
5825: }
5826: my $colsleft = $numperrow - $rem;
5827: if ($colsleft > 1 ) {
5828: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5829: ' </td>';
5830: } elsif ($colsleft == 1) {
5831: $datatable .= '<td class="LC_left_item"> </td>';
5832: }
5833: $datatable .= '</tr></table></td></tr>';
5834: $$rowtotal ++;
1.224 raeburn 5835: } elsif ($position eq 'middle') {
5836: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5837: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5838: $usertypes->{'default'} = $othertitle;
5839: if (ref($types) eq 'ARRAY') {
5840: push(@{$types},'default');
5841: $usertypes->{'default'} = $othertitle;
5842: foreach my $status (@{$types}) {
5843: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 5844: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 5845: $$rowtotal ++;
1.224 raeburn 5846: }
5847: }
5848: } else {
1.236 raeburn 5849: my %choices = &Apache::lonlocal::texthash (
5850: cancreate_email => 'E-mail address as username',
5851: );
5852: my @toggles = sort(keys(%choices));
5853: my %defaultchecked = (
5854: 'cancreate_email' => 'off',
5855: );
5856: my $itemcount = 0;
5857: my $display = 'none';
5858: if (grep(/^\Qemail\E$/,@selfcreate)) {
5859: $display = 'block';
5860: }
5861: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5862: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5863: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5864: my $usertypes = {};
5865: my $order = [];
5866: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
5867: $usertypes = $domdefaults{'inststatustypes'};
5868: $order = $domdefaults{'inststatusguest'};
5869: }
5870: if (ref($order) eq 'ARRAY') {
5871: push(@{$order},'default');
5872: if (@{$order} > 1) {
5873: $usertypes->{'default'} = &mt('Other users');
5874: $additional .= '<table><tr>';
5875: foreach my $status (@{$order}) {
5876: $additional .= '<th>'.$usertypes->{$status}.'</th>';
5877: }
5878: $additional .= '</tr><tr>';
5879: foreach my $status (@{$order}) {
5880: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 5881: }
1.236 raeburn 5882: $additional .= '</tr></table>';
1.224 raeburn 5883: } else {
1.236 raeburn 5884: $usertypes->{'default'} = &mt('All users');
5885: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 5886: }
5887: }
1.236 raeburn 5888: $additional .= '</div>'."\n";
5889:
5890: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 5891: \%choices,$$rowtotal,$onclick,$additional);
5892: $$rowtotal ++;
1.236 raeburn 5893: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 5894: $$rowtotal ++;
1.224 raeburn 5895: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 5896: $numinrow = 1;
1.236 raeburn 5897: if (ref($order) eq 'ARRAY') {
5898: foreach my $status (@{$order}) {
1.228 raeburn 5899: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5900: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
5901: $$rowtotal ++;
5902: }
5903: }
1.224 raeburn 5904: my ($emailrules,$emailruleorder) =
5905: &Apache::lonnet::inst_userrules($dom,'email');
5906: if (ref($emailrules) eq 'HASH') {
5907: if (keys(%{$emailrules}) > 0) {
5908: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 5909: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 5910: $$rowtotal ++;
5911: }
5912: }
1.228 raeburn 5913: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 5914: }
5915: return $datatable;
5916: }
5917:
1.236 raeburn 5918: sub email_as_username {
5919: my ($rowtotal,$processing,$type) = @_;
5920: my %choices =
5921: &Apache::lonlocal::texthash (
5922: automatic => 'Automatic approval',
5923: approval => 'Queued for approval',
5924: );
5925: my $output;
5926: foreach my $option ('automatic','approval') {
5927: my $checked;
5928: if (ref($processing) eq 'HASH') {
5929: if ($type eq '') {
5930: if (!exists($processing->{'default'})) {
5931: if ($option eq 'automatic') {
5932: $checked = ' checked="checked"';
5933: }
5934: } else {
5935: if ($processing->{'default'} eq $option) {
5936: $checked = ' checked="checked"';
5937: }
5938: }
5939: } else {
5940: if (!exists($processing->{$type})) {
5941: if ($option eq 'automatic') {
5942: $checked = ' checked="checked"';
5943: }
5944: } else {
5945: if ($processing->{$type} eq $option) {
5946: $checked = ' checked="checked"';
5947: }
5948: }
5949: }
5950: } elsif ($option eq 'automatic') {
5951: $checked = ' checked="checked"';
5952: }
5953: my $name = 'cancreate_emailprocess';
5954: if (($type ne '') && ($type ne 'default')) {
5955: $name .= '_'.$type;
5956: }
5957: $output .= '<span class="LC_nobreak"><label>'.
5958: '<input type="radio" name="'.$name.'"'.
5959: $checked.' value="'.$option.'" />'.
5960: $choices{$option}.'</label></span>';
5961: if ($type eq '') {
5962: $output .= ' ';
5963: } else {
5964: $output .= '<br />';
5965: }
5966: }
5967: $$rowtotal ++;
5968: return $output;
5969: }
5970:
1.165 raeburn 5971: sub captcha_choice {
1.169 raeburn 5972: my ($context,$settings,$itemcount) = @_;
1.269 raeburn 5973: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5974: $vertext,$currver);
1.165 raeburn 5975: my %lt = &captcha_phrases();
5976: $keyentry = 'hidden';
5977: if ($context eq 'cancreate') {
1.224 raeburn 5978: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 5979: } elsif ($context eq 'login') {
5980: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 5981: }
5982: if (ref($settings) eq 'HASH') {
5983: if ($settings->{'captcha'}) {
5984: $checked{$settings->{'captcha'}} = ' checked="checked"';
5985: } else {
5986: $checked{'original'} = ' checked="checked"';
5987: }
5988: if ($settings->{'captcha'} eq 'recaptcha') {
5989: $pubtext = $lt{'pub'};
5990: $privtext = $lt{'priv'};
5991: $keyentry = 'text';
1.269 raeburn 5992: $vertext = $lt{'ver'};
5993: $currver = $settings->{'recaptchaversion'};
5994: if ($currver ne '2') {
5995: $currver = 1;
5996: }
1.165 raeburn 5997: }
5998: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5999: $currpub = $settings->{'recaptchakeys'}{'public'};
6000: $currpriv = $settings->{'recaptchakeys'}{'private'};
6001: }
6002: } else {
6003: $checked{'original'} = ' checked="checked"';
6004: }
1.169 raeburn 6005: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
6006: my $output = '<tr'.$css_class.'>'.
6007: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 6008: '<table><tr><td>'."\n";
6009: foreach my $option ('original','recaptcha','notused') {
6010: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
6011: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
6012: $lt{$option}.'</label></span>';
6013: unless ($option eq 'notused') {
6014: $output .= (' 'x2)."\n";
6015: }
6016: }
6017: #
6018: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
6019: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 6020: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 6021: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 6022: #
1.165 raeburn 6023: $output .= '</td></tr>'."\n".
6024: '<tr><td>'."\n".
6025: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
6026: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
6027: $currpub.'" size="40" /></span><br />'."\n".
6028: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
6029: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 6030: $currpriv.'" size="40" /></span><br />'.
6031: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
6032: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
6033: $currver.'" size="3" /></span><br />'.
6034: '</td></tr></table>'."\n".
1.165 raeburn 6035: '</td></tr>';
6036: return $output;
6037: }
6038:
1.32 raeburn 6039: sub user_formats_row {
6040: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
6041: my $output;
6042: my %text = (
6043: 'username' => 'new usernames',
6044: 'id' => 'IDs',
1.45 raeburn 6045: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 6046: );
6047: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6048: $output = '<tr '.$css_class.'>'.
1.63 raeburn 6049: '<td><span class="LC_nobreak">';
6050: if ($type eq 'email') {
6051: $output .= &mt("Formats disallowed for $text{$type}: ");
6052: } else {
6053: $output .= &mt("Format rules to check for $text{$type}: ");
6054: }
6055: $output .= '</span></td>'.
6056: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 6057: my $rem;
6058: if (ref($ruleorder) eq 'ARRAY') {
6059: for (my $i=0; $i<@{$ruleorder}; $i++) {
6060: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
6061: my $rem = $i%($numinrow);
6062: if ($rem == 0) {
6063: if ($i > 0) {
6064: $output .= '</tr>';
6065: }
6066: $output .= '<tr>';
6067: }
6068: my $check = ' ';
1.39 raeburn 6069: if (ref($settings) eq 'HASH') {
6070: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
6071: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
6072: $check = ' checked="checked" ';
6073: }
1.27 raeburn 6074: }
6075: }
6076: $output .= '<td class="LC_left_item">'.
6077: '<span class="LC_nobreak"><label>'.
1.32 raeburn 6078: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 6079: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
6080: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
6081: }
6082: }
6083: $rem = @{$ruleorder}%($numinrow);
6084: }
6085: my $colsleft = $numinrow - $rem;
6086: if ($colsleft > 1 ) {
6087: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6088: ' </td>';
6089: } elsif ($colsleft == 1) {
6090: $output .= '<td class="LC_left_item"> </td>';
6091: }
6092: $output .= '</tr></table></td></tr>';
6093: return $output;
6094: }
6095:
1.34 raeburn 6096: sub usercreation_types {
6097: my %lt = &Apache::lonlocal::texthash (
6098: author => 'When adding a co-author',
6099: course => 'When adding a user to a course',
1.100 raeburn 6100: requestcrs => 'When requesting a course',
1.34 raeburn 6101: any => 'Any',
6102: official => 'Institutional only ',
6103: unofficial => 'Non-institutional only',
6104: none => 'None',
6105: );
6106: return %lt;
1.48 raeburn 6107: }
1.34 raeburn 6108:
1.224 raeburn 6109: sub selfcreation_types {
6110: my %lt = &Apache::lonlocal::texthash (
6111: selfcreate => 'User creates own account',
6112: any => 'Any',
6113: official => 'Institutional only ',
6114: unofficial => 'Non-institutional only',
6115: email => 'E-mail address',
6116: login => 'Institutional Login',
6117: sso => 'SSO',
6118: );
6119: }
6120:
1.28 raeburn 6121: sub authtype_names {
6122: my %lt = &Apache::lonlocal::texthash(
6123: int => 'Internal',
6124: krb4 => 'Kerberos 4',
6125: krb5 => 'Kerberos 5',
6126: loc => 'Local',
6127: );
6128: return %lt;
6129: }
6130:
6131: sub context_names {
6132: my %context_title = &Apache::lonlocal::texthash(
6133: author => 'Creating users when an Author',
6134: course => 'Creating users when in a course',
6135: domain => 'Creating users when a Domain Coordinator',
6136: );
6137: return %context_title;
6138: }
6139:
1.33 raeburn 6140: sub print_usermodification {
6141: my ($position,$dom,$settings,$rowtotal) = @_;
6142: my $numinrow = 4;
6143: my ($context,$datatable,$rowcount);
6144: if ($position eq 'top') {
6145: $rowcount = 0;
6146: $context = 'author';
6147: foreach my $role ('ca','aa') {
6148: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6149: $numinrow,$rowcount);
6150: $$rowtotal ++;
6151: $rowcount ++;
6152: }
1.230 raeburn 6153: } elsif ($position eq 'bottom') {
1.33 raeburn 6154: $context = 'course';
6155: $rowcount = 0;
6156: foreach my $role ('st','ep','ta','in','cr') {
6157: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6158: $numinrow,$rowcount);
6159: $$rowtotal ++;
6160: $rowcount ++;
6161: }
6162: }
6163: return $datatable;
6164: }
6165:
1.43 raeburn 6166: sub print_defaults {
1.236 raeburn 6167: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 6168: my $rownum = 0;
1.294 raeburn 6169: my ($datatable,$css_class,$titles);
6170: unless ($position eq 'bottom') {
6171: $titles = &defaults_titles($dom);
6172: }
1.236 raeburn 6173: if ($position eq 'top') {
6174: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6175: 'datelocale_def','portal_def');
6176: my %defaults;
6177: if (ref($settings) eq 'HASH') {
6178: %defaults = %{$settings};
1.43 raeburn 6179: } else {
1.236 raeburn 6180: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6181: foreach my $item (@items) {
6182: $defaults{$item} = $domdefaults{$item};
6183: }
1.43 raeburn 6184: }
1.236 raeburn 6185: foreach my $item (@items) {
6186: if ($rownum%2) {
6187: $css_class = '';
6188: } else {
6189: $css_class = ' class="LC_odd_row" ';
6190: }
6191: $datatable .= '<tr'.$css_class.'>'.
6192: '<td><span class="LC_nobreak">'.$titles->{$item}.
6193: '</span></td><td class="LC_right_item" colspan="3">';
6194: if ($item eq 'auth_def') {
6195: my @authtypes = ('internal','krb4','krb5','localauth');
6196: my %shortauth = (
6197: internal => 'int',
6198: krb4 => 'krb4',
6199: krb5 => 'krb5',
6200: localauth => 'loc'
6201: );
6202: my %authnames = &authtype_names();
6203: foreach my $auth (@authtypes) {
6204: my $checked = ' ';
6205: if ($defaults{$item} eq $auth) {
6206: $checked = ' checked="checked" ';
6207: }
6208: $datatable .= '<label><input type="radio" name="'.$item.
6209: '" value="'.$auth.'"'.$checked.'/>'.
6210: $authnames{$shortauth{$auth}}.'</label> ';
6211: }
6212: } elsif ($item eq 'timezone_def') {
6213: my $includeempty = 1;
6214: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6215: } elsif ($item eq 'datelocale_def') {
6216: my $includeempty = 1;
6217: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
6218: } elsif ($item eq 'lang_def') {
1.263 raeburn 6219: my $includeempty = 1;
6220: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 6221: } else {
6222: my $size;
6223: if ($item eq 'portal_def') {
6224: $size = ' size="25"';
6225: }
6226: $datatable .= '<input type="text" name="'.$item.'" value="'.
6227: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 6228: }
1.236 raeburn 6229: $datatable .= '</td></tr>';
6230: $rownum ++;
6231: }
1.294 raeburn 6232: } elsif ($position eq 'middle') {
6233: my @items = ('intauth_cost','intauth_check','intauth_switch');
6234: my %defaults;
6235: if (ref($settings) eq 'HASH') {
6236: %defaults = %{$settings};
6237: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6238: $defaults{'intauth_cost'} = 10;
6239: }
6240: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6241: $defaults{'intauth_check'} = 0;
6242: }
6243: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6244: $defaults{'intauth_switch'} = 0;
6245: }
6246: } else {
6247: %defaults = (
6248: 'intauth_cost' => 10,
6249: 'intauth_check' => 0,
6250: 'intauth_switch' => 0,
6251: );
6252: }
6253: foreach my $item (@items) {
6254: if ($rownum%2) {
6255: $css_class = '';
6256: } else {
6257: $css_class = ' class="LC_odd_row" ';
6258: }
6259: $datatable .= '<tr'.$css_class.'>'.
6260: '<td><span class="LC_nobreak">'.$titles->{$item}.
6261: '</span></td><td class="LC_left_item" colspan="3">';
6262: if ($item eq 'intauth_switch') {
6263: my @options = (0,1,2);
6264: my %optiondesc = &Apache::lonlocal::texthash (
6265: 0 => 'No',
6266: 1 => 'Yes',
6267: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6268: );
6269: $datatable .= '<table width="100%">';
6270: foreach my $option (@options) {
6271: my $checked = ' ';
6272: if ($defaults{$item} eq $option) {
6273: $checked = ' checked="checked"';
6274: }
6275: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6276: '<label><input type="radio" name="'.$item.
6277: '" value="'.$option.'"'.$checked.' />'.
6278: $optiondesc{$option}.'</label></span></td></tr>';
6279: }
6280: $datatable .= '</table>';
6281: } elsif ($item eq 'intauth_check') {
6282: my @options = (0,1,2);
6283: my %optiondesc = &Apache::lonlocal::texthash (
6284: 0 => 'No',
6285: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6286: 2 => 'Yes, disallow login if stored cost is less than domain default',
6287: );
6288: $datatable .= '<table wisth="100%">';
6289: foreach my $option (@options) {
6290: my $checked = ' ';
6291: my $onclick;
6292: if ($defaults{$item} eq $option) {
6293: $checked = ' checked="checked"';
6294: }
6295: if ($option == 2) {
6296: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6297: }
6298: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6299: '<label><input type="radio" name="'.$item.
6300: '" value="'.$option.'"'.$checked.$onclick.' />'.
6301: $optiondesc{$option}.'</label></span></td></tr>';
6302: }
6303: $datatable .= '</table>';
6304: } else {
6305: $datatable .= '<input type="text" name="'.$item.'" value="'.
6306: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6307: }
6308: $datatable .= '</td></tr>';
6309: $rownum ++;
6310: }
1.236 raeburn 6311: } else {
1.294 raeburn 6312: my %defaults;
1.236 raeburn 6313: if (ref($settings) eq 'HASH') {
6314: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
6315: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
6316: my $maxnum = @{$settings->{'inststatusorder'}};
6317: for (my $i=0; $i<$maxnum; $i++) {
6318: $css_class = $rownum%2?' class="LC_odd_row"':'';
6319: my $item = $settings->{'inststatusorder'}->[$i];
6320: my $title = $settings->{'inststatustypes'}->{$item};
6321: my $guestok;
6322: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
6323: $guestok = 1;
6324: }
6325: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6326: $datatable .= '<tr'.$css_class.'>'.
6327: '<td><span class="LC_nobreak">'.
6328: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6329: for (my $k=0; $k<=$maxnum; $k++) {
6330: my $vpos = $k+1;
6331: my $selstr;
6332: if ($k == $i) {
6333: $selstr = ' selected="selected" ';
6334: }
6335: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6336: }
6337: my ($checkedon,$checkedoff);
6338: $checkedoff = ' checked="checked"';
6339: if ($guestok) {
6340: $checkedon = $checkedoff;
6341: $checkedoff = '';
6342: }
6343: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6344: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6345: &mt('delete').'</span></td>'.
6346: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
6347: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
6348: '</span></td>'.
6349: '<td class="LC_right_item"><span class="LC_nobreak">'.
6350: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
6351: &mt('Yes').'</label>'.(' 'x2).
6352: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
6353: &mt('No').'</label></span></td></tr>';
6354: }
6355: $css_class = $rownum%2?' class="LC_odd_row"':'';
6356: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6357: $datatable .= '<tr '.$css_class.'>'.
6358: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6359: for (my $k=0; $k<=$maxnum; $k++) {
6360: my $vpos = $k+1;
6361: my $selstr;
6362: if ($k == $maxnum) {
6363: $selstr = ' selected="selected" ';
6364: }
6365: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6366: }
6367: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 6368: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 6369: ' '.&mt('(new)').
6370: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
6371: &mt('Name displayed:').
6372: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6373: '<td class="LC_right_item"><span class="LC_nobreak">'.
6374: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
6375: &mt('Yes').'</label>'.(' 'x2).
6376: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
6377: &mt('No').'</label></span></td></tr>';
6378: '</tr>'."\n";
6379: $rownum ++;
1.141 raeburn 6380: }
1.43 raeburn 6381: }
6382: }
6383: $$rowtotal += $rownum;
6384: return $datatable;
6385: }
6386:
1.168 raeburn 6387: sub get_languages_hash {
6388: my %langchoices;
6389: foreach my $id (&Apache::loncommon::languageids()) {
6390: my $code = &Apache::loncommon::supportedlanguagecode($id);
6391: if ($code ne '') {
6392: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6393: }
6394: }
6395: return %langchoices;
6396: }
6397:
1.43 raeburn 6398: sub defaults_titles {
1.141 raeburn 6399: my ($dom) = @_;
1.43 raeburn 6400: my %titles = &Apache::lonlocal::texthash (
6401: 'auth_def' => 'Default authentication type',
6402: 'auth_arg_def' => 'Default authentication argument',
6403: 'lang_def' => 'Default language',
1.54 raeburn 6404: 'timezone_def' => 'Default timezone',
1.68 raeburn 6405: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6406: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 6407: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
6408: 'intauth_check' => 'Check bcrypt cost if authenticated',
6409: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 6410: );
1.141 raeburn 6411: if ($dom) {
6412: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6413: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6414: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6415: $protocol = 'http' if ($protocol ne 'https');
6416: if ($uint_dom) {
6417: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6418: $uint_dom);
6419: }
6420: }
1.43 raeburn 6421: return (\%titles);
6422: }
6423:
1.46 raeburn 6424: sub print_scantronformat {
6425: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6426: my $itemcount = 1;
1.60 raeburn 6427: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6428: %confhash);
1.46 raeburn 6429: my $switchserver = &check_switchserver($dom,$confname);
6430: my %lt = &Apache::lonlocal::texthash (
1.95 www 6431: default => 'Default bubblesheet format file error',
6432: custom => 'Custom bubblesheet format file error',
1.46 raeburn 6433: );
6434: my %scantronfiles = (
6435: default => 'default.tab',
6436: custom => 'custom.tab',
6437: );
6438: foreach my $key (keys(%scantronfiles)) {
6439: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6440: .$scantronfiles{$key};
6441: }
6442: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6443: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6444: if (!$switchserver) {
6445: my $servadm = $r->dir_config('lonAdmEMail');
6446: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6447: if ($configuserok eq 'ok') {
6448: if ($author_ok eq 'ok') {
6449: my %legacyfile = (
6450: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6451: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
6452: );
6453: my %md5chk;
6454: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6455: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6456: chomp($md5chk{$type});
1.46 raeburn 6457: }
6458: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6459: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6460: ($scantronurls{$type},my $error) =
1.46 raeburn 6461: &legacy_scantronformat($r,$dom,$confname,
6462: $type,$legacyfile{$type},
6463: $scantronurls{$type},
6464: $scantronfiles{$type});
1.60 raeburn 6465: if ($error ne '') {
6466: $error{$type} = $error;
6467: }
6468: }
6469: if (keys(%error) == 0) {
6470: $is_custom = 1;
6471: $confhash{'scantron'}{'scantronformat'} =
6472: $scantronurls{'custom'};
6473: my $putresult =
6474: &Apache::lonnet::put_dom('configuration',
6475: \%confhash,$dom);
6476: if ($putresult ne 'ok') {
6477: $error{'custom'} =
6478: '<span class="LC_error">'.
6479: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6480: }
1.46 raeburn 6481: }
6482: } else {
1.60 raeburn 6483: ($scantronurls{'default'},my $error) =
1.46 raeburn 6484: &legacy_scantronformat($r,$dom,$confname,
6485: 'default',$legacyfile{'default'},
6486: $scantronurls{'default'},
6487: $scantronfiles{'default'});
1.60 raeburn 6488: if ($error eq '') {
6489: $confhash{'scantron'}{'scantronformat'} = '';
6490: my $putresult =
6491: &Apache::lonnet::put_dom('configuration',
6492: \%confhash,$dom);
6493: if ($putresult ne 'ok') {
6494: $error{'default'} =
6495: '<span class="LC_error">'.
6496: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6497: }
6498: } else {
6499: $error{'default'} = $error;
6500: }
1.46 raeburn 6501: }
6502: }
6503: }
6504: } else {
1.95 www 6505: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 6506: }
6507: }
6508: if (ref($settings) eq 'HASH') {
6509: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6510: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
6511: if ((!@info) || ($info[0] eq 'no_such_dir')) {
6512: $scantronurl = '';
6513: } else {
6514: $scantronurl = $settings->{'scantronformat'};
6515: }
6516: $is_custom = 1;
6517: } else {
6518: $scantronurl = $scantronurls{'default'};
6519: }
6520: } else {
1.60 raeburn 6521: if ($is_custom) {
6522: $scantronurl = $scantronurls{'custom'};
6523: } else {
6524: $scantronurl = $scantronurls{'default'};
6525: }
1.46 raeburn 6526: }
6527: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6528: $datatable .= '<tr'.$css_class.'>';
6529: if (!$is_custom) {
1.65 raeburn 6530: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6531: '<span class="LC_nobreak">';
1.46 raeburn 6532: if ($scantronurl) {
1.199 raeburn 6533: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6534: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 6535: } else {
6536: $datatable = &mt('File unavailable for display');
6537: }
1.65 raeburn 6538: $datatable .= '</span></td>';
1.60 raeburn 6539: if (keys(%error) == 0) {
6540: $datatable .= '<td valign="bottom">';
6541: if (!$switchserver) {
6542: $datatable .= &mt('Upload:').'<br />';
6543: }
6544: } else {
6545: my $errorstr;
6546: foreach my $key (sort(keys(%error))) {
6547: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6548: }
6549: $datatable .= '<td>'.$errorstr;
6550: }
1.46 raeburn 6551: } else {
6552: if (keys(%error) > 0) {
6553: my $errorstr;
6554: foreach my $key (sort(keys(%error))) {
6555: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6556: }
1.60 raeburn 6557: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 6558: } elsif ($scantronurl) {
1.199 raeburn 6559: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
6560: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 6561: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 6562: $link.
6563: '<label><input type="checkbox" name="scantronformat_del"'.
6564: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 6565: '<td><span class="LC_nobreak"> '.
6566: &mt('Replace:').'</span><br />';
1.46 raeburn 6567: }
6568: }
6569: if (keys(%error) == 0) {
6570: if ($switchserver) {
6571: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6572: } else {
1.65 raeburn 6573: $datatable .='<span class="LC_nobreak"> '.
6574: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 6575: }
6576: }
6577: $datatable .= '</td></tr>';
6578: $$rowtotal ++;
6579: return $datatable;
6580: }
6581:
6582: sub legacy_scantronformat {
6583: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6584: my ($url,$error);
6585: my @statinfo = &Apache::lonnet::stat_file($newurl);
6586: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6587: (my $result,$url) =
6588: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6589: '','',$newfile);
6590: if ($result ne 'ok') {
1.130 raeburn 6591: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 6592: }
6593: }
6594: return ($url,$error);
6595: }
1.43 raeburn 6596:
1.49 raeburn 6597: sub print_coursecategories {
1.57 raeburn 6598: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6599: my $datatable;
6600: if ($position eq 'top') {
1.238 raeburn 6601: my (%checked);
6602: my @catitems = ('unauth','auth');
6603: my @cattypes = ('std','domonly','codesrch','none');
6604: $checked{'unauth'} = 'std';
6605: $checked{'auth'} = 'std';
6606: if (ref($settings) eq 'HASH') {
6607: foreach my $type (@cattypes) {
6608: if ($type eq $settings->{'unauth'}) {
6609: $checked{'unauth'} = $type;
6610: }
6611: if ($type eq $settings->{'auth'}) {
6612: $checked{'auth'} = $type;
6613: }
6614: }
6615: }
6616: my %lt = &Apache::lonlocal::texthash (
6617: unauth => 'Catalog type for unauthenticated users',
6618: auth => 'Catalog type for authenticated users',
6619: none => 'No catalog',
6620: std => 'Standard catalog',
6621: domonly => 'Domain-only catalog',
6622: codesrch => "Code search form",
6623: );
6624: my $itemcount = 0;
6625: foreach my $item (@catitems) {
6626: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6627: $datatable .= '<tr '.$css_class.'>'.
6628: '<td>'.$lt{$item}.'</td>'.
6629: '<td class="LC_right_item"><span class="LC_nobreak">';
6630: foreach my $type (@cattypes) {
6631: my $ischecked;
6632: if ($checked{$item} eq $type) {
6633: $ischecked=' checked="checked"';
6634: }
6635: $datatable .= '<label>'.
6636: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6637: ' />'.$lt{$type}.'</label> ';
6638: }
6639: $datatable .= '</td></tr>';
6640: $itemcount ++;
6641: }
6642: $$rowtotal += $itemcount;
6643: } elsif ($position eq 'middle') {
1.57 raeburn 6644: my $toggle_cats_crs = ' ';
6645: my $toggle_cats_dom = ' checked="checked" ';
6646: my $can_cat_crs = ' ';
6647: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 6648: my $toggle_catscomm_comm = ' ';
6649: my $toggle_catscomm_dom = ' checked="checked" ';
6650: my $can_catcomm_comm = ' ';
6651: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 6652: my $toggle_catsplace_place = ' ';
6653: my $toggle_catsplace_dom = ' checked="checked" ';
6654: my $can_catplace_place = ' ';
6655: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 6656:
1.57 raeburn 6657: if (ref($settings) eq 'HASH') {
6658: if ($settings->{'togglecats'} eq 'crs') {
6659: $toggle_cats_crs = $toggle_cats_dom;
6660: $toggle_cats_dom = ' ';
6661: }
6662: if ($settings->{'categorize'} eq 'crs') {
6663: $can_cat_crs = $can_cat_dom;
6664: $can_cat_dom = ' ';
6665: }
1.120 raeburn 6666: if ($settings->{'togglecatscomm'} eq 'comm') {
6667: $toggle_catscomm_comm = $toggle_catscomm_dom;
6668: $toggle_catscomm_dom = ' ';
6669: }
6670: if ($settings->{'categorizecomm'} eq 'comm') {
6671: $can_catcomm_comm = $can_catcomm_dom;
6672: $can_catcomm_dom = ' ';
6673: }
1.272 raeburn 6674: if ($settings->{'togglecatsplace'} eq 'place') {
6675: $toggle_catsplace_place = $toggle_catsplace_dom;
6676: $toggle_catsplace_dom = ' ';
6677: }
6678: if ($settings->{'categorizeplace'} eq 'place') {
6679: $can_catplace_place = $can_catplace_dom;
6680: $can_catplace_dom = ' ';
6681: }
1.57 raeburn 6682: }
6683: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 6684: togglecats => 'Show/Hide a course in catalog',
6685: togglecatscomm => 'Show/Hide a community in catalog',
6686: togglecatsplace => 'Show/Hide a placement test in catalog',
6687: categorize => 'Assign a category to a course',
6688: categorizecomm => 'Assign a category to a community',
6689: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 6690: );
6691: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 6692: dom => 'Set in Domain',
6693: crs => 'Set in Course',
6694: comm => 'Set in Community',
6695: place => 'Set in Placement Test',
1.57 raeburn 6696: );
6697: $datatable = '<tr class="LC_odd_row">'.
6698: '<td>'.$title{'togglecats'}.'</td>'.
6699: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6700: '<input type="radio" name="togglecats"'.
6701: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6702: '<label><input type="radio" name="togglecats"'.
6703: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
6704: '</tr><tr>'.
6705: '<td>'.$title{'categorize'}.'</td>'.
6706: '<td class="LC_right_item"><span class="LC_nobreak">'.
6707: '<label><input type="radio" name="categorize"'.
6708: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6709: '<label><input type="radio" name="categorize"'.
6710: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 6711: '</tr><tr class="LC_odd_row">'.
6712: '<td>'.$title{'togglecatscomm'}.'</td>'.
6713: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6714: '<input type="radio" name="togglecatscomm"'.
6715: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6716: '<label><input type="radio" name="togglecatscomm"'.
6717: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
6718: '</tr><tr>'.
6719: '<td>'.$title{'categorizecomm'}.'</td>'.
6720: '<td class="LC_right_item"><span class="LC_nobreak">'.
6721: '<label><input type="radio" name="categorizecomm"'.
6722: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6723: '<label><input type="radio" name="categorizecomm"'.
6724: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 6725: '</tr><tr>'.
6726: '<td>'.$title{'togglecatsplace'}.'</td>'.
6727: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6728: '<input type="radio" name="togglecatsplace"'.
6729: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6730: '<label><input type="radio" name="togglecatscomm"'.
6731: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
6732: '</tr><tr>'.
6733: '<td>'.$title{'categorizeplace'}.'</td>'.
6734: '<td class="LC_right_item"><span class="LC_nobreak">'.
6735: '<label><input type="radio" name="categorizeplace"'.
6736: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6737: '<label><input type="radio" name="categorizeplace"'.
6738: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 6739: '</tr>';
1.272 raeburn 6740: $$rowtotal += 6;
1.57 raeburn 6741: } else {
6742: my $css_class;
6743: my $itemcount = 1;
6744: my $cathash;
6745: if (ref($settings) eq 'HASH') {
6746: $cathash = $settings->{'cats'};
6747: }
6748: if (ref($cathash) eq 'HASH') {
6749: my (@cats,@trails,%allitems,%idx,@jsarray);
6750: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
6751: \%allitems,\%idx,\@jsarray);
6752: my $maxdepth = scalar(@cats);
6753: my $colattrib = '';
6754: if ($maxdepth > 2) {
6755: $colattrib = ' colspan="2" ';
6756: }
6757: my @path;
6758: if (@cats > 0) {
6759: if (ref($cats[0]) eq 'ARRAY') {
6760: my $numtop = @{$cats[0]};
6761: my $maxnum = $numtop;
1.120 raeburn 6762: my %default_names = (
6763: instcode => &mt('Official courses'),
6764: communities => &mt('Communities'),
1.272 raeburn 6765: placement => &mt('Placement Tests'),
1.120 raeburn 6766: );
6767:
6768: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6769: ($cathash->{'instcode::0'} eq '') ||
6770: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 6771: ($cathash->{'communities::0'} eq '') ||
6772: (!grep(/^placement$/,@{$cats[0]})) ||
6773: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 6774: $maxnum ++;
6775: }
6776: my $lastidx;
6777: for (my $i=0; $i<$numtop; $i++) {
6778: my $parent = $cats[0][$i];
6779: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6780: my $item = &escape($parent).'::0';
6781: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6782: $lastidx = $idx{$item};
6783: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6784: .'<select name="'.$item.'"'.$chgstr.'>';
6785: for (my $k=0; $k<=$maxnum; $k++) {
6786: my $vpos = $k+1;
6787: my $selstr;
6788: if ($k == $i) {
6789: $selstr = ' selected="selected" ';
6790: }
6791: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6792: }
1.214 raeburn 6793: $datatable .= '</select></span></td><td>';
1.272 raeburn 6794: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 6795: $datatable .= '<span class="LC_nobreak">'
6796: .$default_names{$parent}.'</span>';
6797: if ($parent eq 'instcode') {
6798: $datatable .= '<br /><span class="LC_nobreak">('
6799: .&mt('with institutional codes')
6800: .')</span></td><td'.$colattrib.'>';
6801: } else {
6802: $datatable .= '<table><tr><td>';
6803: }
6804: $datatable .= '<span class="LC_nobreak">'
6805: .'<label><input type="radio" name="'
6806: .$parent.'" value="1" checked="checked" />'
6807: .&mt('Display').'</label>';
6808: if ($parent eq 'instcode') {
6809: $datatable .= ' ';
6810: } else {
6811: $datatable .= '</span></td></tr><tr><td>'
6812: .'<span class="LC_nobreak">';
6813: }
6814: $datatable .= '<label><input type="radio" name="'
6815: .$parent.'" value="0" />'
6816: .&mt('Do not display').'</label></span>';
1.272 raeburn 6817: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 6818: $datatable .= '</td></tr></table>';
6819: }
6820: $datatable .= '</td>';
1.57 raeburn 6821: } else {
6822: $datatable .= $parent
1.214 raeburn 6823: .' <span class="LC_nobreak"><label>'
6824: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6825: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6826: }
6827: my $depth = 1;
6828: push(@path,$parent);
6829: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6830: pop(@path);
6831: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6832: $itemcount ++;
6833: }
1.48 raeburn 6834: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6835: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6836: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6837: for (my $k=0; $k<=$maxnum; $k++) {
6838: my $vpos = $k+1;
6839: my $selstr;
1.57 raeburn 6840: if ($k == $numtop) {
1.48 raeburn 6841: $selstr = ' selected="selected" ';
6842: }
6843: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6844: }
1.59 bisitz 6845: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6846: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6847: .'</tr>'."\n";
1.48 raeburn 6848: $itemcount ++;
1.272 raeburn 6849: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6850: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6851: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6852: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6853: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6854: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6855: for (my $k=0; $k<=$maxnum; $k++) {
6856: my $vpos = $k+1;
6857: my $selstr;
6858: if ($k == $maxnum) {
6859: $selstr = ' selected="selected" ';
6860: }
6861: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6862: }
1.120 raeburn 6863: $datatable .= '</select></span></td>'.
6864: '<td><span class="LC_nobreak">'.
6865: $default_names{$default}.'</span>';
6866: if ($default eq 'instcode') {
6867: $datatable .= '<br /><span class="LC_nobreak">('
6868: .&mt('with institutional codes').')</span>';
6869: }
6870: $datatable .= '</td>'
6871: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6872: .&mt('Display').'</label> '
6873: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6874: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6875: }
6876: }
6877: }
1.57 raeburn 6878: } else {
6879: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6880: }
6881: } else {
1.238 raeburn 6882: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6883: .&initialize_categories($itemcount);
1.48 raeburn 6884: }
1.57 raeburn 6885: $$rowtotal += $itemcount;
1.48 raeburn 6886: }
6887: return $datatable;
6888: }
6889:
1.69 raeburn 6890: sub print_serverstatuses {
6891: my ($dom,$settings,$rowtotal) = @_;
6892: my $datatable;
6893: my @pages = &serverstatus_pages();
6894: my (%namedaccess,%machineaccess);
6895: foreach my $type (@pages) {
6896: $namedaccess{$type} = '';
6897: $machineaccess{$type}= '';
6898: }
6899: if (ref($settings) eq 'HASH') {
6900: foreach my $type (@pages) {
6901: if (exists($settings->{$type})) {
6902: if (ref($settings->{$type}) eq 'HASH') {
6903: foreach my $key (keys(%{$settings->{$type}})) {
6904: if ($key eq 'namedusers') {
6905: $namedaccess{$type} = $settings->{$type}->{$key};
6906: } elsif ($key eq 'machines') {
6907: $machineaccess{$type} = $settings->{$type}->{$key};
6908: }
6909: }
6910: }
6911: }
6912: }
6913: }
1.81 raeburn 6914: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6915: my $rownum = 0;
6916: my $css_class;
6917: foreach my $type (@pages) {
6918: $rownum ++;
6919: $css_class = $rownum%2?' class="LC_odd_row"':'';
6920: $datatable .= '<tr'.$css_class.'>'.
6921: '<td><span class="LC_nobreak">'.
6922: $titles->{$type}.'</span></td>'.
6923: '<td class="LC_left_item">'.
6924: '<input type="text" name="'.$type.'_namedusers" '.
6925: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6926: '<td class="LC_right_item">'.
6927: '<span class="LC_nobreak">'.
6928: '<input type="text" name="'.$type.'_machines" '.
6929: 'value="'.$machineaccess{$type}.'" size="10" />'.
6930: '</td></tr>'."\n";
6931: }
6932: $$rowtotal += $rownum;
6933: return $datatable;
6934: }
6935:
6936: sub serverstatus_pages {
6937: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 6938: 'checksums','clusterstatus','certstatus','metadata_keywords',
6939: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
6940: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6941: }
6942:
1.236 raeburn 6943: sub defaults_javascript {
6944: my ($settings) = @_;
1.294 raeburn 6945: 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.');
6946: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
6947: &js_escape(\$intauthcheck);
6948: &js_escape(\$intauthcost);
6949: my $intauthjs = <<"ENDSCRIPT";
6950:
6951: function warnIntAuth(field) {
6952: if (field.name == 'intauth_check') {
6953: if (field.value == '2') {
6954: alert('$intauthcheck');
6955: }
6956: }
6957: if (field.name == 'intauth_cost') {
6958: field.value.replace(/\s/g,'');
6959: if (field.value != '') {
6960: var regexdigit=/^\\d+\$/;
6961: if (!regexdigit.test(field.value)) {
6962: alert('$intauthcost');
6963: }
6964: }
6965: }
6966: return;
6967: }
6968:
6969: ENDSCRIPT
6970:
6971: if (ref($settings) ne 'HASH') {
6972: return &Apache::lonhtmlcommon::scripttag($intauthjs);
6973: }
1.236 raeburn 6974: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6975: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6976: if ($maxnum eq '') {
6977: $maxnum = 0;
6978: }
6979: $maxnum ++;
1.249 raeburn 6980: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 6981: return <<"ENDSCRIPT";
6982: <script type="text/javascript">
6983: // <![CDATA[
6984: function reorderTypes(form,caller) {
6985: var changedVal;
6986: $jstext
6987: var newpos = 'addinststatus_pos';
6988: var current = new Array;
6989: var maxh = $maxnum;
6990: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6991: var oldVal;
6992: if (caller == newpos) {
6993: changedVal = newitemVal;
6994: } else {
6995: var curritem = 'inststatus_pos_'+caller;
6996: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6997: current[newitemVal] = newpos;
6998: }
6999: for (var i=0; i<inststatuses.length; i++) {
7000: if (inststatuses[i] != caller) {
7001: var elementName = 'inststatus_pos_'+inststatuses[i];
7002: if (form.elements[elementName]) {
7003: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7004: current[currVal] = elementName;
7005: }
7006: }
7007: }
7008: for (var j=0; j<maxh; j++) {
7009: if (current[j] == undefined) {
7010: oldVal = j;
7011: }
7012: }
7013: if (oldVal < changedVal) {
7014: for (var k=oldVal+1; k<=changedVal ; k++) {
7015: var elementName = current[k];
7016: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7017: }
7018: } else {
7019: for (var k=changedVal; k<oldVal; k++) {
7020: var elementName = current[k];
7021: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7022: }
7023: }
7024: return;
7025: }
7026:
1.294 raeburn 7027: $intauthjs
7028:
1.236 raeburn 7029: // ]]>
7030: </script>
7031:
7032: ENDSCRIPT
1.294 raeburn 7033: } else {
7034: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 7035: }
7036: }
7037:
1.49 raeburn 7038: sub coursecategories_javascript {
7039: my ($settings) = @_;
1.57 raeburn 7040: my ($output,$jstext,$cathash);
1.49 raeburn 7041: if (ref($settings) eq 'HASH') {
1.57 raeburn 7042: $cathash = $settings->{'cats'};
7043: }
7044: if (ref($cathash) eq 'HASH') {
1.49 raeburn 7045: my (@cats,@jsarray,%idx);
1.57 raeburn 7046: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 7047: if (@jsarray > 0) {
7048: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
7049: for (my $i=0; $i<@jsarray; $i++) {
7050: if (ref($jsarray[$i]) eq 'ARRAY') {
7051: my $catstr = join('","',@{$jsarray[$i]});
7052: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
7053: }
7054: }
7055: }
7056: } else {
7057: $jstext = ' var categories = Array(1);'."\n".
7058: ' categories[0] = Array("instcode_pos");'."\n";
7059: }
1.237 bisitz 7060: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
7061: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 7062: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 7063: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
7064: &js_escape(\$instcode_reserved);
7065: &js_escape(\$communities_reserved);
1.272 raeburn 7066: &js_escape(\$placement_reserved);
1.265 damieng 7067: &js_escape(\$choose_again);
1.49 raeburn 7068: $output = <<"ENDSCRIPT";
7069: <script type="text/javascript">
1.109 raeburn 7070: // <![CDATA[
1.49 raeburn 7071: function reorderCats(form,parent,item,idx) {
7072: var changedVal;
7073: $jstext
7074: var newpos = 'addcategory_pos';
7075: if (parent == '') {
7076: var has_instcode = 0;
7077: var maxtop = categories[idx].length;
7078: for (var j=0; j<maxtop; j++) {
7079: if (categories[idx][j] == 'instcode::0') {
7080: has_instcode == 1;
7081: }
7082: }
7083: if (has_instcode == 0) {
7084: categories[idx][maxtop] = 'instcode_pos';
7085: }
7086: } else {
7087: newpos += '_'+parent;
7088: }
7089: var maxh = 1 + categories[idx].length;
7090: var current = new Array;
7091: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7092: if (item == newpos) {
7093: changedVal = newitemVal;
7094: } else {
7095: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
7096: current[newitemVal] = newpos;
7097: }
7098: for (var i=0; i<categories[idx].length; i++) {
7099: var elementName = categories[idx][i];
7100: if (elementName != item) {
7101: if (form.elements[elementName]) {
7102: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7103: current[currVal] = elementName;
7104: }
7105: }
7106: }
7107: var oldVal;
7108: for (var j=0; j<maxh; j++) {
7109: if (current[j] == undefined) {
7110: oldVal = j;
7111: }
7112: }
7113: if (oldVal < changedVal) {
7114: for (var k=oldVal+1; k<=changedVal ; k++) {
7115: var elementName = current[k];
7116: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7117: }
7118: } else {
7119: for (var k=changedVal; k<oldVal; k++) {
7120: var elementName = current[k];
7121: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7122: }
7123: }
7124: return;
7125: }
1.120 raeburn 7126:
7127: function categoryCheck(form) {
7128: if (form.elements['addcategory_name'].value == 'instcode') {
7129: alert('$instcode_reserved\\n$choose_again');
7130: return false;
7131: }
7132: if (form.elements['addcategory_name'].value == 'communities') {
7133: alert('$communities_reserved\\n$choose_again');
7134: return false;
7135: }
1.272 raeburn 7136: if (form.elements['addcategory_name'].value == 'placement') {
7137: alert('$placement_reserved\\n$choose_again');
7138: return false;
7139: }
1.120 raeburn 7140: return true;
7141: }
7142:
1.109 raeburn 7143: // ]]>
1.49 raeburn 7144: </script>
7145:
7146: ENDSCRIPT
7147: return $output;
7148: }
7149:
1.48 raeburn 7150: sub initialize_categories {
7151: my ($itemcount) = @_;
1.120 raeburn 7152: my ($datatable,$css_class,$chgstr);
7153: my %default_names = (
7154: instcode => 'Official courses (with institutional codes)',
7155: communities => 'Communities',
1.272 raeburn 7156: placement => 'Placement Tests',
1.120 raeburn 7157: );
7158: my $select0 = ' selected="selected"';
7159: my $select1 = '';
1.272 raeburn 7160: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 7161: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7162: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 7163: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 7164: $select1 = $select0;
7165: $select0 = '';
7166: }
7167: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7168: .'<select name="'.$default.'_pos">'
7169: .'<option value="0"'.$select0.'>1</option>'
7170: .'<option value="1"'.$select1.'>2</option>'
7171: .'<option value="2">3</option></select> '
7172: .$default_names{$default}
7173: .'</span></td><td><span class="LC_nobreak">'
7174: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
7175: .&mt('Display').'</label> <label>'
7176: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 7177: .'</label></span></td></tr>';
1.120 raeburn 7178: $itemcount ++;
7179: }
1.48 raeburn 7180: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 7181: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 7182: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 7183: .'<select name="addcategory_pos"'.$chgstr.'>'
7184: .'<option value="0">1</option>'
7185: .'<option value="1">2</option>'
7186: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 7187: .&mt('Add category').'</td><td>'.&mt('Name:')
7188: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
7189: return $datatable;
7190: }
7191:
7192: sub build_category_rows {
1.49 raeburn 7193: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
7194: my ($text,$name,$item,$chgstr);
1.48 raeburn 7195: if (ref($cats) eq 'ARRAY') {
7196: my $maxdepth = scalar(@{$cats});
7197: if (ref($cats->[$depth]) eq 'HASH') {
7198: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
7199: my $numchildren = @{$cats->[$depth]{$parent}};
7200: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 7201: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 7202: my ($idxnum,$parent_name,$parent_item);
7203: my $higher = $depth - 1;
7204: if ($higher == 0) {
7205: $parent_name = &escape($parent).'::'.$higher;
7206: } else {
7207: if (ref($path) eq 'ARRAY') {
7208: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7209: }
7210: }
7211: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 7212: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 7213: if ($j < $numchildren) {
1.48 raeburn 7214: $name = $cats->[$depth]{$parent}[$j];
7215: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 7216: $idxnum = $idx->{$item};
7217: } else {
7218: $name = $parent_name;
7219: $item = $parent_item;
1.48 raeburn 7220: }
1.49 raeburn 7221: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
7222: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 7223: for (my $i=0; $i<=$numchildren; $i++) {
7224: my $vpos = $i+1;
7225: my $selstr;
7226: if ($j == $i) {
7227: $selstr = ' selected="selected" ';
7228: }
7229: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
7230: }
7231: $text .= '</select> ';
7232: if ($j < $numchildren) {
7233: my $deeper = $depth+1;
7234: $text .= $name.' '
7235: .'<label><input type="checkbox" name="deletecategory" value="'
7236: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
7237: if(ref($path) eq 'ARRAY') {
7238: push(@{$path},$name);
1.49 raeburn 7239: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 7240: pop(@{$path});
7241: }
7242: } else {
1.59 bisitz 7243: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 7244: if ($j == $numchildren) {
7245: $text .= $name;
7246: } else {
7247: $text .= $item;
7248: }
7249: $text .= '" value="" />';
7250: }
7251: $text .= '</td></tr>';
7252: }
7253: $text .= '</table></td>';
7254: } else {
7255: my $higher = $depth-1;
7256: if ($higher == 0) {
7257: $name = &escape($parent).'::'.$higher;
7258: } else {
7259: if (ref($path) eq 'ARRAY') {
7260: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7261: }
7262: }
7263: my $colspan;
7264: if ($parent ne 'instcode') {
7265: $colspan = $maxdepth - $depth - 1;
7266: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
7267: }
7268: }
7269: }
7270: }
7271: return $text;
7272: }
7273:
1.33 raeburn 7274: sub modifiable_userdata_row {
1.228 raeburn 7275: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
7276: my ($role,$rolename,$statustype);
7277: $role = $item;
1.224 raeburn 7278: if ($context eq 'cancreate') {
1.228 raeburn 7279: if ($item =~ /^emailusername_(.+)$/) {
7280: $statustype = $1;
7281: $role = 'emailusername';
7282: if (ref($usertypes) eq 'HASH') {
7283: if ($usertypes->{$statustype}) {
7284: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7285: } else {
7286: $rolename = &mt('Data provided by user');
7287: }
7288: }
1.224 raeburn 7289: }
7290: } elsif ($context eq 'selfcreate') {
1.63 raeburn 7291: if (ref($usertypes) eq 'HASH') {
7292: $rolename = $usertypes->{$role};
7293: } else {
7294: $rolename = $role;
7295: }
1.33 raeburn 7296: } else {
1.63 raeburn 7297: if ($role eq 'cr') {
7298: $rolename = &mt('Custom role');
7299: } else {
7300: $rolename = &Apache::lonnet::plaintext($role);
7301: }
1.33 raeburn 7302: }
1.224 raeburn 7303: my (@fields,%fieldtitles);
7304: if (ref($fieldsref) eq 'ARRAY') {
7305: @fields = @{$fieldsref};
7306: } else {
7307: @fields = ('lastname','firstname','middlename','generation',
7308: 'permanentemail','id');
7309: }
7310: if ((ref($titlesref) eq 'HASH')) {
7311: %fieldtitles = %{$titlesref};
7312: } else {
7313: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7314: }
1.33 raeburn 7315: my $output;
7316: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7317: $output = '<tr '.$css_class.'>'.
7318: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7319: '<td class="LC_left_item" colspan="2"><table>';
7320: my $rem;
7321: my %checks;
7322: if (ref($settings) eq 'HASH') {
7323: if (ref($settings->{$context}) eq 'HASH') {
7324: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 7325: my $hashref = $settings->{$context}->{$role};
7326: if ($role eq 'emailusername') {
7327: if ($statustype) {
7328: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7329: $hashref = $settings->{$context}->{$role}->{$statustype};
7330: if (ref($hashref) eq 'HASH') {
7331: foreach my $field (@fields) {
7332: if ($hashref->{$field}) {
7333: $checks{$field} = $hashref->{$field};
7334: }
7335: }
7336: }
7337: }
7338: }
7339: } else {
7340: if (ref($hashref) eq 'HASH') {
7341: foreach my $field (@fields) {
7342: if ($hashref->{$field}) {
7343: $checks{$field} = ' checked="checked" ';
7344: }
7345: }
1.33 raeburn 7346: }
7347: }
7348: }
7349: }
7350: }
1.228 raeburn 7351:
1.33 raeburn 7352: for (my $i=0; $i<@fields; $i++) {
7353: my $rem = $i%($numinrow);
7354: if ($rem == 0) {
7355: if ($i > 0) {
7356: $output .= '</tr>';
7357: }
7358: $output .= '<tr>';
7359: }
7360: my $check = ' ';
1.228 raeburn 7361: unless ($role eq 'emailusername') {
7362: if (exists($checks{$fields[$i]})) {
7363: $check = $checks{$fields[$i]}
7364: } else {
7365: if ($role eq 'st') {
7366: if (ref($settings) ne 'HASH') {
7367: $check = ' checked="checked" ';
7368: }
1.33 raeburn 7369: }
7370: }
7371: }
7372: $output .= '<td class="LC_left_item">'.
1.228 raeburn 7373: '<span class="LC_nobreak">';
7374: if ($role eq 'emailusername') {
7375: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7376: $checks{$fields[$i]} = 'omit';
7377: }
7378: foreach my $option ('required','optional','omit') {
7379: my $checked='';
7380: if ($checks{$fields[$i]} eq $option) {
7381: $checked='checked="checked" ';
7382: }
7383: $output .= '<label>'.
7384: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7385: &mt($option).'</label>'.(' ' x2);
7386: }
7387: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7388: } else {
7389: $output .= '<label>'.
7390: '<input type="checkbox" name="canmodify_'.$role.'" '.
7391: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7392: '</label>';
7393: }
7394: $output .= '</span></td>';
1.33 raeburn 7395: $rem = @fields%($numinrow);
7396: }
7397: my $colsleft = $numinrow - $rem;
7398: if ($colsleft > 1 ) {
7399: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7400: ' </td>';
7401: } elsif ($colsleft == 1) {
7402: $output .= '<td class="LC_left_item"> </td>';
7403: }
7404: $output .= '</tr></table></td></tr>';
7405: return $output;
7406: }
1.28 raeburn 7407:
1.93 raeburn 7408: sub insttypes_row {
1.224 raeburn 7409: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 7410: my %lt = &Apache::lonlocal::texthash (
7411: cansearch => 'Users allowed to search',
7412: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 7413: lockablenames => 'User preference to lock name',
1.93 raeburn 7414: );
7415: my $showdom;
7416: if ($context eq 'cansearch') {
7417: $showdom = ' ('.$dom.')';
7418: }
1.165 raeburn 7419: my $class = 'LC_left_item';
7420: if ($context eq 'statustocreate') {
7421: $class = 'LC_right_item';
7422: }
1.224 raeburn 7423: my $css_class = ' class="LC_odd_row"';
7424: if ($rownum ne '') {
7425: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
7426: }
7427: my $output = '<tr'.$css_class.'>'.
7428: '<td>'.$lt{$context}.$showdom.
7429: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7430: my $rem;
7431: if (ref($types) eq 'ARRAY') {
7432: for (my $i=0; $i<@{$types}; $i++) {
7433: if (defined($usertypes->{$types->[$i]})) {
7434: my $rem = $i%($numinrow);
7435: if ($rem == 0) {
7436: if ($i > 0) {
7437: $output .= '</tr>';
7438: }
7439: $output .= '<tr>';
1.23 raeburn 7440: }
1.26 raeburn 7441: my $check = ' ';
1.99 raeburn 7442: if (ref($settings) eq 'HASH') {
7443: if (ref($settings->{$context}) eq 'ARRAY') {
7444: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7445: $check = ' checked="checked" ';
7446: }
7447: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7448: $check = ' checked="checked" ';
7449: }
1.23 raeburn 7450: }
1.26 raeburn 7451: $output .= '<td class="LC_left_item">'.
7452: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7453: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 7454: 'value="'.$types->[$i].'"'.$check.'/>'.
7455: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7456: }
7457: }
1.26 raeburn 7458: $rem = @{$types}%($numinrow);
1.23 raeburn 7459: }
7460: my $colsleft = $numinrow - $rem;
1.131 raeburn 7461: if (($rem == 0) && (@{$types} > 0)) {
7462: $output .= '<tr>';
7463: }
1.23 raeburn 7464: if ($colsleft > 1) {
1.25 raeburn 7465: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 7466: } else {
1.25 raeburn 7467: $output .= '<td class="LC_left_item">';
1.23 raeburn 7468: }
7469: my $defcheck = ' ';
1.99 raeburn 7470: if (ref($settings) eq 'HASH') {
7471: if (ref($settings->{$context}) eq 'ARRAY') {
7472: if (grep(/^default$/,@{$settings->{$context}})) {
7473: $defcheck = ' checked="checked" ';
7474: }
7475: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7476: $defcheck = ' checked="checked" ';
7477: }
1.23 raeburn 7478: }
1.25 raeburn 7479: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 7480: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 7481: 'value="default"'.$defcheck.'/>'.
7482: $othertitle.'</label></span></td>'.
7483: '</tr></table></td></tr>';
7484: return $output;
1.23 raeburn 7485: }
7486:
7487: sub sorted_searchtitles {
7488: my %searchtitles = &Apache::lonlocal::texthash(
7489: 'uname' => 'username',
7490: 'lastname' => 'last name',
7491: 'lastfirst' => 'last name, first name',
7492: );
7493: my @titleorder = ('uname','lastname','lastfirst');
7494: return (\%searchtitles,\@titleorder);
7495: }
7496:
1.25 raeburn 7497: sub sorted_searchtypes {
7498: my %srchtypes_desc = (
7499: exact => 'is exact match',
7500: contains => 'contains ..',
7501: begins => 'begins with ..',
7502: );
7503: my @srchtypeorder = ('exact','begins','contains');
7504: return (\%srchtypes_desc,\@srchtypeorder);
7505: }
7506:
1.3 raeburn 7507: sub usertype_update_row {
7508: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7509: my $datatable;
7510: my $numinrow = 4;
7511: foreach my $type (@{$types}) {
7512: if (defined($usertypes->{$type})) {
7513: $$rownums ++;
7514: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7515: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7516: '</td><td class="LC_left_item"><table>';
7517: for (my $i=0; $i<@{$fields}; $i++) {
7518: my $rem = $i%($numinrow);
7519: if ($rem == 0) {
7520: if ($i > 0) {
7521: $datatable .= '</tr>';
7522: }
7523: $datatable .= '<tr>';
7524: }
7525: my $check = ' ';
1.39 raeburn 7526: if (ref($settings) eq 'HASH') {
7527: if (ref($settings->{'fields'}) eq 'HASH') {
7528: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7529: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7530: $check = ' checked="checked" ';
7531: }
1.3 raeburn 7532: }
7533: }
7534: }
7535:
7536: if ($i == @{$fields}-1) {
7537: my $colsleft = $numinrow - $rem;
7538: if ($colsleft > 1) {
7539: $datatable .= '<td colspan="'.$colsleft.'">';
7540: } else {
7541: $datatable .= '<td>';
7542: }
7543: } else {
7544: $datatable .= '<td>';
7545: }
1.8 raeburn 7546: $datatable .= '<span class="LC_nobreak"><label>'.
7547: '<input type="checkbox" name="updateable_'.$type.
7548: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7549: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 7550: }
7551: $datatable .= '</tr></table></td></tr>';
7552: }
7553: }
7554: return $datatable;
1.1 raeburn 7555: }
7556:
7557: sub modify_login {
1.205 raeburn 7558: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 7559: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7560: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7561: %title = ( coursecatalog => 'Display course catalog',
7562: adminmail => 'Display administrator E-mail address',
1.188 raeburn 7563: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 7564: newuser => 'Link for visitors to create a user account',
7565: loginheader => 'Log-in box header');
7566: @offon = ('off','on');
1.112 raeburn 7567: if (ref($domconfig{login}) eq 'HASH') {
7568: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7569: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7570: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7571: }
7572: }
7573: }
1.9 raeburn 7574: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7575: \%domconfig,\%loginhash);
1.188 raeburn 7576: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7577: foreach my $item (@toggles) {
7578: $loginhash{login}{$item} = $env{'form.'.$item};
7579: }
1.41 raeburn 7580: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 7581: if (ref($colchanges{'login'}) eq 'HASH') {
7582: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7583: \%loginhash);
7584: }
1.110 raeburn 7585:
1.149 raeburn 7586: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 7587: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 7588: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 7589: if (keys(%servers) > 1) {
7590: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 7591: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7592: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7593: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7594: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7595: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7596: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7597: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7598: $changes{'loginvia'}{$lonhost} = 1;
7599: } else {
7600: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7601: $changes{'loginvia'}{$lonhost} = 1;
7602: }
7603: } else {
7604: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7605: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7606: $changes{'loginvia'}{$lonhost} = 1;
7607: }
7608: }
7609: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7610: foreach my $item (@loginvia_attribs) {
7611: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7612: }
7613: } else {
7614: foreach my $item (@loginvia_attribs) {
7615: my $new = $env{'form.'.$lonhost.'_'.$item};
7616: if (($item eq 'serverpath') && ($new eq 'custom')) {
7617: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7618: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7619: $new = '/';
7620: }
7621: }
7622: if (($item eq 'custompath') &&
7623: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7624: $new = '';
7625: }
7626: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7627: $changes{'loginvia'}{$lonhost} = 1;
7628: }
7629: if ($item eq 'exempt') {
1.256 raeburn 7630: $new = &check_exempt_addresses($new);
1.128 raeburn 7631: }
7632: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7633: }
7634: }
1.112 raeburn 7635: } else {
1.128 raeburn 7636: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7637: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 7638: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 7639: foreach my $item (@loginvia_attribs) {
7640: my $new = $env{'form.'.$lonhost.'_'.$item};
7641: if (($item eq 'serverpath') && ($new eq 'custom')) {
7642: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7643: $new = '/';
7644: }
7645: }
7646: if (($item eq 'custompath') &&
7647: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7648: $new = '';
7649: }
7650: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7651: }
1.110 raeburn 7652: }
7653: }
7654: }
7655: }
1.119 raeburn 7656:
1.168 raeburn 7657: my $servadm = $r->dir_config('lonAdmEMail');
7658: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
7659: if (ref($domconfig{'login'}) eq 'HASH') {
7660: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
7661: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
7662: if ($lang eq 'nolang') {
7663: push(@currlangs,$lang);
7664: } elsif (defined($langchoices{$lang})) {
7665: push(@currlangs,$lang);
7666: } else {
7667: next;
7668: }
7669: }
7670: }
7671: }
7672: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
7673: if (@currlangs > 0) {
7674: foreach my $lang (@currlangs) {
7675: if (grep(/^\Q$lang\E$/,@delurls)) {
7676: $changes{'helpurl'}{$lang} = 1;
7677: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
7678: $changes{'helpurl'}{$lang} = 1;
7679: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
7680: push(@newlangs,$lang);
7681: } else {
7682: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7683: }
7684: }
7685: }
7686: unless (grep(/^nolang$/,@currlangs)) {
7687: if ($env{'form.loginhelpurl_nolang.filename'}) {
7688: $changes{'helpurl'}{'nolang'} = 1;
7689: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
7690: push(@newlangs,'nolang');
7691: }
7692: }
7693: if ($env{'form.loginhelpurl_add_lang'}) {
7694: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
7695: ($env{'form.loginhelpurl_add_file.filename'})) {
7696: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
7697: $addedfile = $env{'form.loginhelpurl_add_lang'};
7698: }
7699: }
7700: if ((@newlangs > 0) || ($addedfile)) {
7701: my $error;
7702: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7703: if ($configuserok eq 'ok') {
7704: if ($switchserver) {
7705: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7706: } elsif ($author_ok eq 'ok') {
7707: my @allnew = @newlangs;
7708: if ($addedfile ne '') {
7709: push(@allnew,$addedfile);
7710: }
7711: foreach my $lang (@allnew) {
7712: my $formelem = 'loginhelpurl_'.$lang;
7713: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
7714: $formelem = 'loginhelpurl_add_file';
7715: }
7716: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7717: "help/$lang",'','',$newfile{$lang});
7718: if ($result eq 'ok') {
7719: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
7720: $changes{'helpurl'}{$lang} = 1;
7721: } else {
7722: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
7723: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 7724: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 7725: (!grep(/^\Q$lang\E$/,@delurls))) {
7726: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7727: }
7728: }
7729: }
7730: } else {
7731: $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);
7732: }
7733: } else {
7734: $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);
7735: }
7736: if ($error) {
7737: &Apache::lonnet::logthis($error);
7738: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7739: }
7740: }
1.256 raeburn 7741:
7742: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
7743: if (ref($domconfig{'login'}) eq 'HASH') {
7744: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
7745: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
7746: if ($domservers{$lonhost}) {
7747: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7748: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 7749: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 7750: }
7751: }
7752: }
7753: }
7754: }
7755: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
7756: foreach my $lonhost (sort(keys(%domservers))) {
7757: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7758: $changes{'headtag'}{$lonhost} = 1;
7759: } else {
7760: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
7761: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
7762: }
7763: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
7764: push(@newhosts,$lonhost);
7765: } elsif ($currheadtagurls{$lonhost}) {
7766: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
7767: if ($currexempt{$lonhost}) {
1.289 raeburn 7768: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 7769: $changes{'headtag'}{$lonhost} = 1;
7770: }
7771: } elsif ($possexempt{$lonhost}) {
7772: $changes{'headtag'}{$lonhost} = 1;
7773: }
7774: if ($possexempt{$lonhost}) {
7775: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7776: }
7777: }
7778: }
7779: }
7780: if (@newhosts) {
7781: my $error;
7782: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7783: if ($configuserok eq 'ok') {
7784: if ($switchserver) {
7785: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
7786: } elsif ($author_ok eq 'ok') {
7787: foreach my $lonhost (@newhosts) {
7788: my $formelem = 'loginheadtag_'.$lonhost;
7789: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7790: "login/headtag/$lonhost",'','',
7791: $env{'form.loginheadtag_'.$lonhost.'.filename'});
7792: if ($result eq 'ok') {
7793: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
7794: $changes{'headtag'}{$lonhost} = 1;
7795: if ($possexempt{$lonhost}) {
7796: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7797: }
7798: } else {
7799: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7800: $newheadtagurls{$lonhost},$result);
7801: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7802: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7803: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7804: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7805: }
7806: }
7807: }
7808: } else {
7809: $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);
7810: }
7811: } else {
7812: $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);
7813: }
7814: if ($error) {
7815: &Apache::lonnet::logthis($error);
7816: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7817: }
7818: }
1.169 raeburn 7819: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 7820:
7821: my $defaulthelpfile = '/adm/loginproblems.html';
7822: my $defaulttext = &mt('Default in use');
7823:
1.1 raeburn 7824: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7825: $dom);
7826: if ($putresult eq 'ok') {
1.188 raeburn 7827: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7828: my %defaultchecked = (
7829: 'coursecatalog' => 'on',
1.188 raeburn 7830: 'helpdesk' => 'on',
1.42 raeburn 7831: 'adminmail' => 'off',
1.43 raeburn 7832: 'newuser' => 'off',
1.42 raeburn 7833: );
1.55 raeburn 7834: if (ref($domconfig{'login'}) eq 'HASH') {
7835: foreach my $item (@toggles) {
7836: if ($defaultchecked{$item} eq 'on') {
7837: if (($domconfig{'login'}{$item} eq '0') &&
7838: ($env{'form.'.$item} eq '1')) {
7839: $changes{$item} = 1;
7840: } elsif (($domconfig{'login'}{$item} eq '' ||
7841: $domconfig{'login'}{$item} eq '1') &&
7842: ($env{'form.'.$item} eq '0')) {
7843: $changes{$item} = 1;
7844: }
7845: } elsif ($defaultchecked{$item} eq 'off') {
7846: if (($domconfig{'login'}{$item} eq '1') &&
7847: ($env{'form.'.$item} eq '0')) {
7848: $changes{$item} = 1;
7849: } elsif (($domconfig{'login'}{$item} eq '' ||
7850: $domconfig{'login'}{$item} eq '0') &&
7851: ($env{'form.'.$item} eq '1')) {
7852: $changes{$item} = 1;
7853: }
1.42 raeburn 7854: }
7855: }
1.41 raeburn 7856: }
1.6 raeburn 7857: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7858: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7859: if (ref($lastactref) eq 'HASH') {
7860: $lastactref->{'domainconfig'} = 1;
7861: }
1.1 raeburn 7862: $resulttext = &mt('Changes made:').'<ul>';
7863: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7864: if ($item eq 'loginvia') {
1.112 raeburn 7865: if (ref($changes{$item}) eq 'HASH') {
7866: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7867: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7868: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7869: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7870: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7871: $protocol = 'http' if ($protocol ne 'https');
7872: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7873:
7874: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7875: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7876: } else {
7877: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7878: }
7879: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7880: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7881: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7882: }
7883: $resulttext .= '</li>';
7884: } else {
7885: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7886: }
1.112 raeburn 7887: } else {
1.128 raeburn 7888: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7889: }
7890: }
1.128 raeburn 7891: $resulttext .= '</ul></li>';
1.112 raeburn 7892: }
1.168 raeburn 7893: } elsif ($item eq 'helpurl') {
7894: if (ref($changes{$item}) eq 'HASH') {
7895: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7896: if (grep(/^\Q$lang\E$/,@delurls)) {
7897: my ($chg,$link);
7898: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7899: if ($lang eq 'nolang') {
7900: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7901: } else {
7902: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7903: }
7904: $resulttext .= '<li>'.$chg.'</li>';
7905: } else {
7906: my $chg;
7907: if ($lang eq 'nolang') {
7908: $chg = &mt('custom log-in help file for no preferred language');
7909: } else {
7910: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7911: }
7912: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7913: $loginhash{'login'}{'helpurl'}{$lang}.
7914: '?inhibitmenu=yes',$chg,600,500).
7915: '</li>';
7916: }
7917: }
7918: }
1.256 raeburn 7919: } elsif ($item eq 'headtag') {
7920: if (ref($changes{$item}) eq 'HASH') {
7921: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7922: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7923: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7924: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7925: $resulttext .= '<li><a href="'.
7926: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7927: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7928: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7929: if ($possexempt{$lonhost}) {
7930: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7931: } else {
7932: $resulttext .= &mt('included for any client IP');
7933: }
7934: $resulttext .= '</li>';
7935: }
7936: }
7937: }
1.169 raeburn 7938: } elsif ($item eq 'captcha') {
7939: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 7940: my $chgtxt;
1.169 raeburn 7941: if ($loginhash{'login'}{$item} eq 'notused') {
7942: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7943: } else {
7944: my %captchas = &captcha_phrases();
7945: if ($captchas{$loginhash{'login'}{$item}}) {
7946: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7947: } else {
7948: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7949: }
7950: }
7951: $resulttext .= '<li>'.$chgtxt.'</li>';
7952: }
7953: } elsif ($item eq 'recaptchakeys') {
7954: if (ref($loginhash{'login'}) eq 'HASH') {
7955: my ($privkey,$pubkey);
7956: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7957: $pubkey = $loginhash{'login'}{$item}{'public'};
7958: $privkey = $loginhash{'login'}{$item}{'private'};
7959: }
7960: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7961: if (!$pubkey) {
7962: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7963: } else {
7964: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7965: }
7966: if (!$privkey) {
7967: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7968: } else {
1.251 raeburn 7969: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 7970: }
7971: $chgtxt .= '</ul>';
7972: $resulttext .= '<li>'.$chgtxt.'</li>';
7973: }
1.269 raeburn 7974: } elsif ($item eq 'recaptchaversion') {
7975: if (ref($loginhash{'login'}) eq 'HASH') {
7976: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 7977: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 7978: '</li>';
7979: }
7980: }
1.41 raeburn 7981: } else {
7982: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7983: }
1.1 raeburn 7984: }
1.6 raeburn 7985: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7986: } else {
7987: $resulttext = &mt('No changes made to log-in page settings');
7988: }
7989: } else {
1.11 albertel 7990: $resulttext = '<span class="LC_error">'.
7991: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7992: }
1.6 raeburn 7993: if ($errors) {
1.9 raeburn 7994: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7995: $errors.'</ul>';
7996: }
7997: return $resulttext;
7998: }
7999:
1.256 raeburn 8000: sub check_exempt_addresses {
8001: my ($iplist) = @_;
8002: $iplist =~ s/^\s+//;
8003: $iplist =~ s/\s+$//;
8004: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
8005: my (@okips,$new);
8006: foreach my $ip (@poss_ips) {
8007: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
8008: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
8009: push(@okips,$ip);
8010: }
8011: }
8012: }
8013: if (@okips > 0) {
8014: $new = join(',',@okips);
8015: } else {
8016: $new = '';
8017: }
8018: return $new;
8019: }
8020:
1.6 raeburn 8021: sub color_font_choices {
8022: my %choices =
8023: &Apache::lonlocal::texthash (
8024: img => "Header",
8025: bgs => "Background colors",
8026: links => "Link colors",
1.55 raeburn 8027: images => "Images",
1.6 raeburn 8028: font => "Font color",
1.201 raeburn 8029: fontmenu => "Font menu",
1.76 raeburn 8030: pgbg => "Page",
1.6 raeburn 8031: tabbg => "Header",
8032: sidebg => "Border",
8033: link => "Link",
8034: alink => "Active link",
8035: vlink => "Visited link",
8036: );
8037: return %choices;
8038: }
8039:
8040: sub modify_rolecolors {
1.205 raeburn 8041: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 8042: my ($resulttext,%rolehash);
8043: $rolehash{'rolecolors'} = {};
1.55 raeburn 8044: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
8045: if ($domconfig{'rolecolors'} eq '') {
8046: $domconfig{'rolecolors'} = {};
8047: }
8048: }
1.9 raeburn 8049: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 8050: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
8051: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
8052: $dom);
8053: if ($putresult eq 'ok') {
8054: if (keys(%changes) > 0) {
1.41 raeburn 8055: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8056: if (ref($lastactref) eq 'HASH') {
8057: $lastactref->{'domainconfig'} = 1;
8058: }
1.6 raeburn 8059: $resulttext = &display_colorchgs($dom,\%changes,$roles,
8060: $rolehash{'rolecolors'});
8061: } else {
8062: $resulttext = &mt('No changes made to default color schemes');
8063: }
8064: } else {
1.11 albertel 8065: $resulttext = '<span class="LC_error">'.
8066: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 8067: }
8068: if ($errors) {
8069: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8070: $errors.'</ul>';
8071: }
8072: return $resulttext;
8073: }
8074:
8075: sub modify_colors {
1.9 raeburn 8076: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 8077: my (%changes,%choices);
1.51 raeburn 8078: my @bgs;
1.6 raeburn 8079: my @links = ('link','alink','vlink');
1.41 raeburn 8080: my @logintext;
1.6 raeburn 8081: my @images;
8082: my $servadm = $r->dir_config('lonAdmEMail');
8083: my $errors;
1.200 raeburn 8084: my %defaults;
1.6 raeburn 8085: foreach my $role (@{$roles}) {
8086: if ($role eq 'login') {
1.12 raeburn 8087: %choices = &login_choices();
1.41 raeburn 8088: @logintext = ('textcol','bgcol');
1.12 raeburn 8089: } else {
8090: %choices = &color_font_choices();
8091: }
8092: if ($role eq 'login') {
1.41 raeburn 8093: @images = ('img','logo','domlogo','login');
1.51 raeburn 8094: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 8095: } else {
8096: @images = ('img');
1.200 raeburn 8097: @bgs = ('pgbg','tabbg','sidebg');
8098: }
8099: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
8100: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
8101: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
8102: }
8103: if ($role eq 'login') {
8104: foreach my $item (@logintext) {
1.234 raeburn 8105: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8106: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8107: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8108: }
8109: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 8110: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8111: }
8112: }
8113: } else {
1.234 raeburn 8114: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
8115: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
8116: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
8117: }
8118: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 8119: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
8120: }
1.6 raeburn 8121: }
1.200 raeburn 8122: foreach my $item (@bgs) {
1.234 raeburn 8123: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8124: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8125: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8126: }
8127: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 8128: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8129: }
8130: }
8131: foreach my $item (@links) {
1.234 raeburn 8132: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8133: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8134: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8135: }
8136: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 8137: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8138: }
1.6 raeburn 8139: }
1.46 raeburn 8140: my ($configuserok,$author_ok,$switchserver) =
8141: &config_check($dom,$confname,$servadm);
1.9 raeburn 8142: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 8143: if (ref($domconfig->{$role}) ne 'HASH') {
8144: $domconfig->{$role} = {};
8145: }
1.8 raeburn 8146: foreach my $img (@images) {
1.70 raeburn 8147: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
8148: if (defined($env{'form.login_showlogo_'.$img})) {
8149: $confhash->{$role}{'showlogo'}{$img} = 1;
8150: } else {
8151: $confhash->{$role}{'showlogo'}{$img} = 0;
8152: }
8153: }
1.18 albertel 8154: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
8155: && !defined($domconfig->{$role}{$img})
8156: && !$env{'form.'.$role.'_del_'.$img}
8157: && $env{'form.'.$role.'_import_'.$img}) {
8158: # import the old configured image from the .tab setting
8159: # if they haven't provided a new one
8160: $domconfig->{$role}{$img} =
8161: $env{'form.'.$role.'_import_'.$img};
8162: }
1.6 raeburn 8163: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 8164: my $error;
1.6 raeburn 8165: if ($configuserok eq 'ok') {
1.9 raeburn 8166: if ($switchserver) {
1.12 raeburn 8167: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 8168: } else {
8169: if ($author_ok eq 'ok') {
8170: my ($result,$logourl) =
8171: &publishlogo($r,'upload',$role.'_'.$img,
8172: $dom,$confname,$img,$width,$height);
8173: if ($result eq 'ok') {
8174: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 8175: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8176: } else {
1.12 raeburn 8177: $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 8178: }
8179: } else {
1.46 raeburn 8180: $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 8181: }
8182: }
8183: } else {
1.46 raeburn 8184: $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 8185: }
8186: if ($error) {
1.8 raeburn 8187: &Apache::lonnet::logthis($error);
1.11 albertel 8188: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 8189: }
8190: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 8191: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
8192: my $error;
8193: if ($configuserok eq 'ok') {
8194: # is confname an author?
8195: if ($switchserver eq '') {
8196: if ($author_ok eq 'ok') {
8197: my ($result,$logourl) =
8198: &publishlogo($r,'copy',$domconfig->{$role}{$img},
8199: $dom,$confname,$img,$width,$height);
8200: if ($result eq 'ok') {
8201: $confhash->{$role}{$img} = $logourl;
1.18 albertel 8202: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8203: }
8204: }
8205: }
8206: }
1.6 raeburn 8207: }
8208: }
8209: }
8210: if (ref($domconfig) eq 'HASH') {
8211: if (ref($domconfig->{$role}) eq 'HASH') {
8212: foreach my $img (@images) {
8213: if ($domconfig->{$role}{$img} ne '') {
8214: if ($env{'form.'.$role.'_del_'.$img}) {
8215: $confhash->{$role}{$img} = '';
1.12 raeburn 8216: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8217: } else {
1.9 raeburn 8218: if ($confhash->{$role}{$img} eq '') {
8219: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8220: }
1.6 raeburn 8221: }
8222: } else {
8223: if ($env{'form.'.$role.'_del_'.$img}) {
8224: $confhash->{$role}{$img} = '';
1.12 raeburn 8225: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8226: }
8227: }
1.70 raeburn 8228: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8229: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8230: if ($confhash->{$role}{'showlogo'}{$img} ne
8231: $domconfig->{$role}{'showlogo'}{$img}) {
8232: $changes{$role}{'showlogo'}{$img} = 1;
8233: }
8234: } else {
8235: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8236: $changes{$role}{'showlogo'}{$img} = 1;
8237: }
8238: }
8239: }
8240: }
1.6 raeburn 8241: if ($domconfig->{$role}{'font'} ne '') {
8242: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8243: $changes{$role}{'font'} = 1;
8244: }
8245: } else {
8246: if ($confhash->{$role}{'font'}) {
8247: $changes{$role}{'font'} = 1;
8248: }
8249: }
1.107 raeburn 8250: if ($role ne 'login') {
8251: if ($domconfig->{$role}{'fontmenu'} ne '') {
8252: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8253: $changes{$role}{'fontmenu'} = 1;
8254: }
8255: } else {
8256: if ($confhash->{$role}{'fontmenu'}) {
8257: $changes{$role}{'fontmenu'} = 1;
8258: }
1.97 tempelho 8259: }
8260: }
1.6 raeburn 8261: foreach my $item (@bgs) {
8262: if ($domconfig->{$role}{$item} ne '') {
8263: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8264: $changes{$role}{'bgs'}{$item} = 1;
8265: }
8266: } else {
8267: if ($confhash->{$role}{$item}) {
8268: $changes{$role}{'bgs'}{$item} = 1;
8269: }
8270: }
8271: }
8272: foreach my $item (@links) {
8273: if ($domconfig->{$role}{$item} ne '') {
8274: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8275: $changes{$role}{'links'}{$item} = 1;
8276: }
8277: } else {
8278: if ($confhash->{$role}{$item}) {
8279: $changes{$role}{'links'}{$item} = 1;
8280: }
8281: }
8282: }
1.41 raeburn 8283: foreach my $item (@logintext) {
8284: if ($domconfig->{$role}{$item} ne '') {
8285: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8286: $changes{$role}{'logintext'}{$item} = 1;
8287: }
8288: } else {
8289: if ($confhash->{$role}{$item}) {
8290: $changes{$role}{'logintext'}{$item} = 1;
8291: }
8292: }
8293: }
1.6 raeburn 8294: } else {
8295: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8296: \@logintext,$confhash,\%changes);
1.6 raeburn 8297: }
8298: } else {
8299: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8300: \@logintext,$confhash,\%changes);
1.6 raeburn 8301: }
8302: }
8303: return ($errors,%changes);
8304: }
8305:
1.46 raeburn 8306: sub config_check {
8307: my ($dom,$confname,$servadm) = @_;
8308: my ($configuserok,$author_ok,$switchserver,%currroles);
8309: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8310: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8311: $confname,$servadm);
8312: if ($configuserok eq 'ok') {
8313: $switchserver = &check_switchserver($dom,$confname);
8314: if ($switchserver eq '') {
8315: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8316: }
8317: }
8318: return ($configuserok,$author_ok,$switchserver);
8319: }
8320:
1.6 raeburn 8321: sub default_change_checker {
1.41 raeburn 8322: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8323: foreach my $item (@{$links}) {
8324: if ($confhash->{$role}{$item}) {
8325: $changes->{$role}{'links'}{$item} = 1;
8326: }
8327: }
8328: foreach my $item (@{$bgs}) {
8329: if ($confhash->{$role}{$item}) {
8330: $changes->{$role}{'bgs'}{$item} = 1;
8331: }
8332: }
1.41 raeburn 8333: foreach my $item (@{$logintext}) {
8334: if ($confhash->{$role}{$item}) {
8335: $changes->{$role}{'logintext'}{$item} = 1;
8336: }
8337: }
1.6 raeburn 8338: foreach my $img (@{$images}) {
8339: if ($env{'form.'.$role.'_del_'.$img}) {
8340: $confhash->{$role}{$img} = '';
1.12 raeburn 8341: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8342: }
1.70 raeburn 8343: if ($role eq 'login') {
8344: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8345: $changes->{$role}{'showlogo'}{$img} = 1;
8346: }
8347: }
1.6 raeburn 8348: }
8349: if ($confhash->{$role}{'font'}) {
8350: $changes->{$role}{'font'} = 1;
8351: }
1.48 raeburn 8352: }
1.6 raeburn 8353:
8354: sub display_colorchgs {
8355: my ($dom,$changes,$roles,$confhash) = @_;
8356: my (%choices,$resulttext);
8357: if (!grep(/^login$/,@{$roles})) {
8358: $resulttext = &mt('Changes made:').'<br />';
8359: }
8360: foreach my $role (@{$roles}) {
8361: if ($role eq 'login') {
8362: %choices = &login_choices();
8363: } else {
8364: %choices = &color_font_choices();
8365: }
8366: if (ref($changes->{$role}) eq 'HASH') {
8367: if ($role ne 'login') {
8368: $resulttext .= '<h4>'.&mt($role).'</h4>';
8369: }
8370: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8371: if ($role ne 'login') {
8372: $resulttext .= '<ul>';
8373: }
8374: if (ref($changes->{$role}{$key}) eq 'HASH') {
8375: if ($role ne 'login') {
8376: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8377: }
8378: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8379: if (($role eq 'login') && ($key eq 'showlogo')) {
8380: if ($confhash->{$role}{$key}{$item}) {
8381: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8382: } else {
8383: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8384: }
8385: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8386: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8387: } else {
1.12 raeburn 8388: my $newitem = $confhash->{$role}{$item};
8389: if ($key eq 'images') {
8390: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
8391: }
8392: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8393: }
8394: }
8395: if ($role ne 'login') {
8396: $resulttext .= '</ul></li>';
8397: }
8398: } else {
8399: if ($confhash->{$role}{$key} eq '') {
8400: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8401: } else {
8402: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8403: }
8404: }
8405: if ($role ne 'login') {
8406: $resulttext .= '</ul>';
8407: }
8408: }
8409: }
8410: }
1.3 raeburn 8411: return $resulttext;
1.1 raeburn 8412: }
8413:
1.9 raeburn 8414: sub thumb_dimensions {
8415: return ('200','50');
8416: }
8417:
1.16 raeburn 8418: sub check_dimensions {
8419: my ($inputfile) = @_;
8420: my ($fullwidth,$fullheight);
8421: if ($inputfile =~ m|^[/\w.\-]+$|) {
8422: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8423: my $imageinfo = <PIPE>;
8424: if (!close(PIPE)) {
8425: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8426: }
8427: chomp($imageinfo);
8428: my ($fullsize) =
1.21 raeburn 8429: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8430: if ($fullsize) {
8431: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8432: }
8433: }
8434: }
8435: return ($fullwidth,$fullheight);
8436: }
8437:
1.9 raeburn 8438: sub check_configuser {
8439: my ($uhome,$dom,$confname,$servadm) = @_;
8440: my ($configuserok,%currroles);
8441: if ($uhome eq 'no_host') {
8442: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
8443: my $configpass = &LONCAPA::Enrollment::create_password();
8444: $configuserok =
8445: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8446: $configpass,'','','','','',undef,$servadm);
8447: } else {
8448: $configuserok = 'ok';
8449: %currroles =
8450: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8451: }
8452: return ($configuserok,%currroles);
8453: }
8454:
8455: sub check_authorstatus {
8456: my ($dom,$confname,%currroles) = @_;
8457: my $author_ok;
1.40 raeburn 8458: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8459: my $start = time;
8460: my $end = 0;
8461: $author_ok =
8462: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8463: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8464: } else {
8465: $author_ok = 'ok';
8466: }
8467: return $author_ok;
8468: }
8469:
8470: sub publishlogo {
1.46 raeburn 8471: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 8472: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 8473: if ($action eq 'upload') {
8474: $fname=$env{'form.'.$formname.'.filename'};
8475: chop($env{'form.'.$formname});
8476: } else {
8477: ($fname) = ($formname =~ /([^\/]+)$/);
8478: }
1.46 raeburn 8479: if ($savefileas ne '') {
8480: $fname = $savefileas;
8481: }
1.9 raeburn 8482: $fname=&Apache::lonnet::clean_filename($fname);
8483: # See if there is anything left
8484: unless ($fname) { return ('error: no uploaded file'); }
8485: $fname="$subdir/$fname";
1.210 raeburn 8486: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 8487: my $filepath="$docroot/priv";
8488: my $relpath = "$dom/$confname";
1.9 raeburn 8489: my ($fnamepath,$file,$fetchthumb);
8490: $file=$fname;
8491: if ($fname=~m|/|) {
8492: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8493: }
1.164 raeburn 8494: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8495: my $count;
1.164 raeburn 8496: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8497: $filepath.="/$parts[$count]";
8498: if ((-e $filepath)!=1) {
8499: mkdir($filepath,02770);
8500: }
8501: }
8502: # Check for bad extension and disallow upload
8503: if ($file=~/\.(\w+)$/ &&
8504: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8505: $output =
1.207 bisitz 8506: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8507: } elsif ($file=~/\.(\w+)$/ &&
8508: !defined(&Apache::loncommon::fileembstyle($1))) {
8509: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8510: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 8511: $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 8512: } elsif (-d "$filepath/$file") {
1.195 bisitz 8513: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8514: } else {
8515: my $source = $filepath.'/'.$file;
8516: my $logfile;
8517: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 8518: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8519: }
8520: print $logfile
8521: "\n================= Publish ".localtime()." ================\n".
8522: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8523: # Save the file
8524: if (!open(FH,'>'.$source)) {
8525: &Apache::lonnet::logthis('Failed to create '.$source);
8526: return (&mt('Failed to create file'));
8527: }
8528: if ($action eq 'upload') {
8529: if (!print FH ($env{'form.'.$formname})) {
8530: &Apache::lonnet::logthis('Failed to write to '.$source);
8531: return (&mt('Failed to write file'));
8532: }
8533: } else {
8534: my $original = &Apache::lonnet::filelocation('',$formname);
8535: if(!copy($original,$source)) {
8536: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8537: return (&mt('Failed to write file'));
8538: }
8539: }
8540: close(FH);
8541: chmod(0660, $source); # Permissions to rw-rw---.
8542:
8543: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8544: my $copyfile=$targetdir.'/'.$file;
8545:
8546: my @parts=split(/\//,$targetdir);
8547: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8548: for (my $count=5;$count<=$#parts;$count++) {
8549: $path.="/$parts[$count]";
8550: if (!-e $path) {
8551: print $logfile "\nCreating directory ".$path;
8552: mkdir($path,02770);
8553: }
8554: }
8555: my $versionresult;
8556: if (-e $copyfile) {
8557: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8558: } else {
8559: $versionresult = 'ok';
8560: }
8561: if ($versionresult eq 'ok') {
8562: if (copy($source,$copyfile)) {
8563: print $logfile "\nCopied original source to ".$copyfile."\n";
8564: $output = 'ok';
8565: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8566: push(@{$modified_urls},[$copyfile,$source]);
8567: my $metaoutput =
8568: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8569: unless ($registered_cleanup) {
8570: my $handlers = $r->get_handlers('PerlCleanupHandler');
8571: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8572: $registered_cleanup=1;
8573: }
1.9 raeburn 8574: } else {
8575: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8576: $output = &mt('Failed to copy file to RES space').", $!";
8577: }
8578: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8579: my $inputfile = $filepath.'/'.$file;
8580: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8581: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8582: if ($fullwidth ne '' && $fullheight ne '') {
8583: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8584: my $thumbsize = $thumbwidth.'x'.$thumbheight;
8585: system("convert -sample $thumbsize $inputfile $outfile");
8586: chmod(0660, $filepath.'/tn-'.$file);
8587: if (-e $outfile) {
8588: my $copyfile=$targetdir.'/tn-'.$file;
8589: if (copy($outfile,$copyfile)) {
8590: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8591: my $thumb_metaoutput =
8592: &write_metadata($dom,$confname,$formname,
8593: $targetdir,'tn-'.$file,$logfile);
8594: push(@{$modified_urls},[$copyfile,$outfile]);
8595: unless ($registered_cleanup) {
8596: my $handlers = $r->get_handlers('PerlCleanupHandler');
8597: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8598: $registered_cleanup=1;
8599: }
1.267 raeburn 8600: $madethumb = 1;
1.16 raeburn 8601: } else {
8602: print $logfile "\nUnable to write ".$copyfile.
8603: ':'.$!."\n";
8604: }
8605: }
1.9 raeburn 8606: }
8607: }
8608: }
8609: } else {
8610: $output = $versionresult;
8611: }
8612: }
1.267 raeburn 8613: return ($output,$logourl,$madethumb);
1.9 raeburn 8614: }
8615:
8616: sub logo_versioning {
8617: my ($targetdir,$file,$logfile) = @_;
8618: my $target = $targetdir.'/'.$file;
8619: my ($maxversion,$fn,$extn,$output);
8620: $maxversion = 0;
8621: if ($file =~ /^(.+)\.(\w+)$/) {
8622: $fn=$1;
8623: $extn=$2;
8624: }
8625: opendir(DIR,$targetdir);
8626: while (my $filename=readdir(DIR)) {
8627: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8628: $maxversion=($1>$maxversion)?$1:$maxversion;
8629: }
8630: }
8631: $maxversion++;
8632: print $logfile "\nCreating old version ".$maxversion."\n";
8633: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8634: if (copy($target,$copyfile)) {
8635: print $logfile "Copied old target to ".$copyfile."\n";
8636: $copyfile=$copyfile.'.meta';
8637: if (copy($target.'.meta',$copyfile)) {
8638: print $logfile "Copied old target metadata to ".$copyfile."\n";
8639: $output = 'ok';
8640: } else {
8641: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8642: $output = &mt('Failed to copy old meta').", $!, ";
8643: }
8644: } else {
8645: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8646: $output = &mt('Failed to copy old target').", $!, ";
8647: }
8648: return $output;
8649: }
8650:
8651: sub write_metadata {
8652: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
8653: my (%metadatafields,%metadatakeys,$output);
8654: $metadatafields{'title'}=$formname;
8655: $metadatafields{'creationdate'}=time;
8656: $metadatafields{'lastrevisiondate'}=time;
8657: $metadatafields{'copyright'}='public';
8658: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
8659: $env{'user.domain'};
8660: $metadatafields{'authorspace'}=$confname.':'.$dom;
8661: $metadatafields{'domain'}=$dom;
8662: {
8663: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
8664: my $mfh;
1.155 raeburn 8665: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 8666: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 8667: unless ($_=~/\./) {
8668: my $unikey=$_;
8669: $unikey=~/^([A-Za-z]+)/;
8670: my $tag=$1;
8671: $tag=~tr/A-Z/a-z/;
8672: print $mfh "\n\<$tag";
8673: foreach (split(/\,/,$metadatakeys{$unikey})) {
8674: my $value=$metadatafields{$unikey.'.'.$_};
8675: $value=~s/\"/\'\'/g;
8676: print $mfh ' '.$_.'="'.$value.'"';
8677: }
8678: print $mfh '>'.
8679: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
8680: .'</'.$tag.'>';
8681: }
8682: }
8683: $output = 'ok';
8684: print $logfile "\nWrote metadata";
8685: close($mfh);
8686: } else {
8687: print $logfile "\nFailed to open metadata file";
1.9 raeburn 8688: $output = &mt('Could not write metadata');
8689: }
8690: }
1.155 raeburn 8691: return $output;
8692: }
8693:
8694: sub notifysubscribed {
8695: foreach my $targetsource (@{$modified_urls}){
8696: next unless (ref($targetsource) eq 'ARRAY');
8697: my ($target,$source)=@{$targetsource};
8698: if ($source ne '') {
8699: if (open(my $logfh,'>>'.$source.'.log')) {
8700: print $logfh "\nCleanup phase: Notifications\n";
8701: my @subscribed=&subscribed_hosts($target);
8702: foreach my $subhost (@subscribed) {
8703: print $logfh "\nNotifying host ".$subhost.':';
8704: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
8705: print $logfh $reply;
8706: }
8707: my @subscribedmeta=&subscribed_hosts("$target.meta");
8708: foreach my $subhost (@subscribedmeta) {
8709: print $logfh "\nNotifying host for metadata only ".$subhost.':';
8710: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
8711: $subhost);
8712: print $logfh $reply;
8713: }
8714: print $logfh "\n============ Done ============\n";
1.160 raeburn 8715: close($logfh);
1.155 raeburn 8716: }
8717: }
8718: }
8719: return OK;
8720: }
8721:
8722: sub subscribed_hosts {
8723: my ($target) = @_;
8724: my @subscribed;
8725: if (open(my $fh,"<$target.subscription")) {
8726: while (my $subline=<$fh>) {
8727: if ($subline =~ /^($match_lonid):/) {
8728: my $host = $1;
8729: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
8730: unless (grep(/^\Q$host\E$/,@subscribed)) {
8731: push(@subscribed,$host);
8732: }
8733: }
8734: }
8735: }
8736: }
8737: return @subscribed;
1.9 raeburn 8738: }
8739:
8740: sub check_switchserver {
8741: my ($dom,$confname) = @_;
8742: my ($allowed,$switchserver);
8743: my $home = &Apache::lonnet::homeserver($confname,$dom);
8744: if ($home eq 'no_host') {
8745: $home = &Apache::lonnet::domain($dom,'primary');
8746: }
8747: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 8748: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
8749: if (!$allowed) {
1.180 raeburn 8750: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 8751: }
8752: return $switchserver;
8753: }
8754:
1.1 raeburn 8755: sub modify_quotas {
1.216 raeburn 8756: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 8757: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 8758: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 8759: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8760: $validationfieldsref);
1.86 raeburn 8761: if ($action eq 'quotas') {
8762: $context = 'tools';
1.163 raeburn 8763: } else {
1.86 raeburn 8764: $context = $action;
8765: }
8766: if ($context eq 'requestcourses') {
1.271 raeburn 8767: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 8768: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 8769: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8770: %titles = &courserequest_titles();
8771: $toolregexp = join('|',@usertools);
8772: %conditions = &courserequest_conditions();
1.216 raeburn 8773: $confname = $dom.'-domainconfig';
8774: my $servadm = $r->dir_config('lonAdmEMail');
8775: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 8776: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8777: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 8778: } elsif ($context eq 'requestauthor') {
8779: @usertools = ('author');
8780: %titles = &authorrequest_titles();
1.86 raeburn 8781: } else {
1.162 raeburn 8782: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 8783: %titles = &tool_titles();
1.86 raeburn 8784: }
1.212 raeburn 8785: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 8786: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8787: foreach my $key (keys(%env)) {
1.101 raeburn 8788: if ($context eq 'requestcourses') {
8789: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8790: my $item = $1;
8791: my $type = $2;
8792: if ($type =~ /^limit_(.+)/) {
8793: $limithash{$item}{$1} = $env{$key};
8794: } else {
8795: $confhash{$item}{$type} = $env{$key};
8796: }
8797: }
1.163 raeburn 8798: } elsif ($context eq 'requestauthor') {
8799: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8800: $confhash{$1} = $env{$key};
8801: }
1.101 raeburn 8802: } else {
1.86 raeburn 8803: if ($key =~ /^form\.quota_(.+)$/) {
8804: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 8805: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8806: $confhash{'authorquota'}{$1} = $env{$key};
8807: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8808: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8809: }
1.72 raeburn 8810: }
8811: }
1.163 raeburn 8812: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 8813: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8814: @approvalnotify = sort(@approvalnotify);
8815: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 8816: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 8817: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8818: foreach my $type (@hasuniquecode) {
8819: if (grep(/^\Q$type\E$/,@crstypes)) {
8820: $confhash{'uniquecode'}{$type} = 1;
8821: }
1.216 raeburn 8822: }
1.242 raeburn 8823: my (%newbook,%allpos);
1.216 raeburn 8824: if ($context eq 'requestcourses') {
1.242 raeburn 8825: foreach my $type ('textbooks','templates') {
8826: @{$allpos{$type}} = ();
8827: my $invalid;
8828: if ($type eq 'textbooks') {
8829: $invalid = &mt('Invalid LON-CAPA course for textbook');
8830: } else {
8831: $invalid = &mt('Invalid LON-CAPA course for template');
8832: }
8833: if ($env{'form.'.$type.'_addbook'}) {
8834: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8835: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8836: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8837: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8838: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8839: } else {
8840: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8841: my $position = $env{'form.'.$type.'_addbook_pos'};
8842: $position =~ s/\D+//g;
8843: if ($position ne '') {
8844: $allpos{$type}[$position] = $newbook{$type};
8845: }
1.216 raeburn 8846: }
1.242 raeburn 8847: } else {
8848: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 8849: }
8850: }
1.242 raeburn 8851: }
1.216 raeburn 8852: }
1.102 raeburn 8853: if (ref($domconfig{$action}) eq 'HASH') {
8854: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8855: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8856: $changes{'notify'}{'approval'} = 1;
8857: }
8858: } else {
1.144 raeburn 8859: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8860: $changes{'notify'}{'approval'} = 1;
8861: }
8862: }
1.218 raeburn 8863: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8864: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8865: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8866: unless ($confhash{'uniquecode'}{$crstype}) {
8867: $changes{'uniquecode'} = 1;
8868: }
8869: }
8870: unless ($changes{'uniquecode'}) {
8871: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8872: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8873: $changes{'uniquecode'} = 1;
8874: }
8875: }
8876: }
8877: } else {
8878: $changes{'uniquecode'} = 1;
8879: }
8880: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8881: $changes{'uniquecode'} = 1;
1.216 raeburn 8882: }
8883: if ($context eq 'requestcourses') {
1.242 raeburn 8884: foreach my $type ('textbooks','templates') {
8885: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8886: my %deletions;
8887: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8888: if (@todelete) {
8889: map { $deletions{$_} = 1; } @todelete;
8890: }
8891: my %imgdeletions;
8892: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8893: if (@todeleteimages) {
8894: map { $imgdeletions{$_} = 1; } @todeleteimages;
8895: }
8896: my $maxnum = $env{'form.'.$type.'_maxnum'};
8897: for (my $i=0; $i<=$maxnum; $i++) {
8898: my $itemid = $env{'form.'.$type.'_id_'.$i};
8899: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8900: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8901: if ($deletions{$key}) {
8902: if ($domconfig{$action}{$type}{$key}{'image'}) {
8903: #FIXME need to obsolete item in RES space
8904: }
8905: next;
8906: } else {
8907: my $newpos = $env{'form.'.$itemid};
8908: $newpos =~ s/\D+//g;
1.243 raeburn 8909: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 8910: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 8911: ($type eq 'templates'));
1.242 raeburn 8912: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8913: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8914: $changes{$type}{$key} = 1;
8915: }
8916: }
8917: $allpos{$type}[$newpos] = $key;
8918: }
8919: if ($imgdeletions{$key}) {
8920: $changes{$type}{$key} = 1;
1.216 raeburn 8921: #FIXME need to obsolete item in RES space
1.242 raeburn 8922: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8923: my ($cdom,$cnum) = split(/_/,$key);
8924: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8925: $cdom,$cnum,$type,$configuserok,
8926: $switchserver,$author_ok);
8927: if ($imgurl) {
8928: $confhash{$type}{$key}{'image'} = $imgurl;
8929: $changes{$type}{$key} = 1;
1.216 raeburn 8930: }
1.242 raeburn 8931: if ($error) {
8932: &Apache::lonnet::logthis($error);
8933: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8934: }
8935: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8936: $confhash{$type}{$key}{'image'} =
8937: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 8938: }
8939: }
8940: }
8941: }
8942: }
8943: }
1.102 raeburn 8944: } else {
1.144 raeburn 8945: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8946: $changes{'notify'}{'approval'} = 1;
8947: }
1.218 raeburn 8948: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 8949: $changes{'uniquecode'} = 1;
8950: }
8951: }
8952: if ($context eq 'requestcourses') {
1.242 raeburn 8953: foreach my $type ('textbooks','templates') {
8954: if ($newbook{$type}) {
8955: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 8956: foreach my $item ('subject','title','publisher','author') {
8957: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8958: ($type eq 'template'));
1.242 raeburn 8959: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8960: if ($env{'form.'.$type.'_addbook_'.$item}) {
8961: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8962: }
8963: }
8964: if ($type eq 'textbooks') {
8965: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8966: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8967: my ($imageurl,$error) =
8968: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8969: $configuserok,$switchserver,$author_ok);
8970: if ($imageurl) {
8971: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8972: }
8973: if ($error) {
8974: &Apache::lonnet::logthis($error);
8975: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8976: }
8977: }
1.216 raeburn 8978: }
8979: }
1.242 raeburn 8980: if (@{$allpos{$type}} > 0) {
8981: my $idx = 0;
8982: foreach my $item (@{$allpos{$type}}) {
8983: if ($item ne '') {
8984: $confhash{$type}{$item}{'order'} = $idx;
8985: if (ref($domconfig{$action}) eq 'HASH') {
8986: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8987: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8988: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8989: $changes{$type}{$item} = 1;
8990: }
1.216 raeburn 8991: }
8992: }
8993: }
1.242 raeburn 8994: $idx ++;
1.216 raeburn 8995: }
8996: }
8997: }
8998: }
1.235 raeburn 8999: if (ref($validationitemsref) eq 'ARRAY') {
9000: foreach my $item (@{$validationitemsref}) {
9001: if ($item eq 'fields') {
9002: my @changed;
9003: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
9004: if (@{$confhash{'validation'}{$item}} > 0) {
9005: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
9006: }
1.266 raeburn 9007: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9008: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9009: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
9010: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
9011: $domconfig{'requestcourses'}{'validation'}{$item});
9012: } else {
9013: @changed = @{$confhash{'validation'}{$item}};
9014: }
1.235 raeburn 9015: } else {
9016: @changed = @{$confhash{'validation'}{$item}};
9017: }
9018: } else {
9019: @changed = @{$confhash{'validation'}{$item}};
9020: }
9021: if (@changed) {
9022: if ($confhash{'validation'}{$item}) {
9023: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
9024: } else {
9025: $changes{'validation'}{$item} = &mt('None');
9026: }
9027: }
9028: } else {
9029: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
9030: if ($item eq 'markup') {
9031: if ($env{'form.requestcourses_validation_'.$item}) {
9032: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
9033: }
9034: }
1.266 raeburn 9035: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9036: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9037: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
9038: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9039: }
9040: } else {
9041: if ($confhash{'validation'}{$item} ne '') {
9042: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9043: }
1.235 raeburn 9044: }
9045: } else {
9046: if ($confhash{'validation'}{$item} ne '') {
9047: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9048: }
9049: }
9050: }
9051: }
9052: }
9053: if ($env{'form.validationdc'}) {
9054: my $newval = $env{'form.validationdc'};
1.285 raeburn 9055: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 9056: if (exists($domcoords{$newval})) {
9057: $confhash{'validation'}{'dc'} = $newval;
9058: }
9059: }
9060: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 9061: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9062: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9063: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9064: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
9065: if ($confhash{'validation'}{'dc'} eq '') {
9066: $changes{'validation'}{'dc'} = &mt('None');
9067: } else {
9068: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9069: }
1.235 raeburn 9070: }
1.266 raeburn 9071: } elsif ($confhash{'validation'}{'dc'} ne '') {
9072: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 9073: }
9074: } elsif ($confhash{'validation'}{'dc'} ne '') {
9075: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9076: }
9077: } elsif ($confhash{'validation'}{'dc'} ne '') {
9078: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 9079: }
1.266 raeburn 9080: } else {
9081: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9082: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9083: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9084: $changes{'validation'}{'dc'} = &mt('None');
9085: }
9086: }
1.235 raeburn 9087: }
9088: }
1.102 raeburn 9089: }
9090: } else {
1.86 raeburn 9091: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 9092: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 9093: }
1.72 raeburn 9094: foreach my $item (@usertools) {
9095: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 9096: my $unset;
1.101 raeburn 9097: if ($context eq 'requestcourses') {
1.104 raeburn 9098: $unset = '0';
9099: if ($type eq '_LC_adv') {
9100: $unset = '';
9101: }
1.101 raeburn 9102: if ($confhash{$item}{$type} eq 'autolimit') {
9103: $confhash{$item}{$type} .= '=';
9104: unless ($limithash{$item}{$type} =~ /\D/) {
9105: $confhash{$item}{$type} .= $limithash{$item}{$type};
9106: }
9107: }
1.163 raeburn 9108: } elsif ($context eq 'requestauthor') {
9109: $unset = '0';
9110: if ($type eq '_LC_adv') {
9111: $unset = '';
9112: }
1.72 raeburn 9113: } else {
1.101 raeburn 9114: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
9115: $confhash{$item}{$type} = 1;
9116: } else {
9117: $confhash{$item}{$type} = 0;
9118: }
1.72 raeburn 9119: }
1.86 raeburn 9120: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 9121: if ($action eq 'requestauthor') {
9122: if ($domconfig{$action}{$type} ne $confhash{$type}) {
9123: $changes{$type} = 1;
9124: }
9125: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 9126: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
9127: $changes{$item}{$type} = 1;
9128: }
9129: } else {
9130: if ($context eq 'requestcourses') {
1.104 raeburn 9131: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 9132: $changes{$item}{$type} = 1;
9133: }
9134: } else {
9135: if (!$confhash{$item}{$type}) {
9136: $changes{$item}{$type} = 1;
9137: }
9138: }
9139: }
9140: } else {
9141: if ($context eq 'requestcourses') {
1.104 raeburn 9142: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 9143: $changes{$item}{$type} = 1;
9144: }
1.163 raeburn 9145: } elsif ($context eq 'requestauthor') {
9146: if ($confhash{$type} ne $unset) {
9147: $changes{$type} = 1;
9148: }
1.72 raeburn 9149: } else {
9150: if (!$confhash{$item}{$type}) {
9151: $changes{$item}{$type} = 1;
9152: }
9153: }
9154: }
1.1 raeburn 9155: }
9156: }
1.163 raeburn 9157: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 9158: if (ref($domconfig{'quotas'}) eq 'HASH') {
9159: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9160: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
9161: if (exists($confhash{'defaultquota'}{$key})) {
9162: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
9163: $changes{'defaultquota'}{$key} = 1;
9164: }
9165: } else {
9166: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 9167: }
9168: }
1.86 raeburn 9169: } else {
9170: foreach my $key (keys(%{$domconfig{'quotas'}})) {
9171: if (exists($confhash{'defaultquota'}{$key})) {
9172: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
9173: $changes{'defaultquota'}{$key} = 1;
9174: }
9175: } else {
9176: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 9177: }
1.1 raeburn 9178: }
9179: }
1.197 raeburn 9180: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9181: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
9182: if (exists($confhash{'authorquota'}{$key})) {
9183: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
9184: $changes{'authorquota'}{$key} = 1;
9185: }
9186: } else {
9187: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
9188: }
9189: }
9190: }
1.1 raeburn 9191: }
1.86 raeburn 9192: if (ref($confhash{'defaultquota'}) eq 'HASH') {
9193: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
9194: if (ref($domconfig{'quotas'}) eq 'HASH') {
9195: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9196: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
9197: $changes{'defaultquota'}{$key} = 1;
9198: }
9199: } else {
9200: if (!exists($domconfig{'quotas'}{$key})) {
9201: $changes{'defaultquota'}{$key} = 1;
9202: }
1.72 raeburn 9203: }
9204: } else {
1.86 raeburn 9205: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 9206: }
1.1 raeburn 9207: }
9208: }
1.197 raeburn 9209: if (ref($confhash{'authorquota'}) eq 'HASH') {
9210: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9211: if (ref($domconfig{'quotas'}) eq 'HASH') {
9212: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9213: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9214: $changes{'authorquota'}{$key} = 1;
9215: }
9216: } else {
9217: $changes{'authorquota'}{$key} = 1;
9218: }
9219: } else {
9220: $changes{'authorquota'}{$key} = 1;
9221: }
9222: }
9223: }
1.1 raeburn 9224: }
1.72 raeburn 9225:
1.163 raeburn 9226: if ($context eq 'requestauthor') {
9227: $domdefaults{'requestauthor'} = \%confhash;
9228: } else {
9229: foreach my $key (keys(%confhash)) {
1.242 raeburn 9230: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 9231: $domdefaults{$key} = $confhash{$key};
9232: }
1.163 raeburn 9233: }
1.72 raeburn 9234: }
1.163 raeburn 9235:
1.1 raeburn 9236: my %quotahash = (
1.86 raeburn 9237: $action => { %confhash }
1.1 raeburn 9238: );
9239: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9240: $dom);
9241: if ($putresult eq 'ok') {
9242: if (keys(%changes) > 0) {
1.72 raeburn 9243: my $cachetime = 24*60*60;
9244: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9245: if (ref($lastactref) eq 'HASH') {
9246: $lastactref->{'domdefaults'} = 1;
9247: }
1.1 raeburn 9248: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 9249: unless (($context eq 'requestcourses') ||
1.163 raeburn 9250: ($context eq 'requestauthor')) {
1.86 raeburn 9251: if (ref($changes{'defaultquota'}) eq 'HASH') {
9252: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9253: foreach my $type (@{$types},'default') {
9254: if (defined($changes{'defaultquota'}{$type})) {
9255: my $typetitle = $usertypes->{$type};
9256: if ($type eq 'default') {
9257: $typetitle = $othertitle;
9258: }
1.213 raeburn 9259: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9260: }
9261: }
1.86 raeburn 9262: $resulttext .= '</ul></li>';
1.72 raeburn 9263: }
1.197 raeburn 9264: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 9265: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 9266: foreach my $type (@{$types},'default') {
9267: if (defined($changes{'authorquota'}{$type})) {
9268: my $typetitle = $usertypes->{$type};
9269: if ($type eq 'default') {
9270: $typetitle = $othertitle;
9271: }
1.213 raeburn 9272: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 9273: }
9274: }
9275: $resulttext .= '</ul></li>';
9276: }
1.72 raeburn 9277: }
1.80 raeburn 9278: my %newenv;
1.72 raeburn 9279: foreach my $item (@usertools) {
1.163 raeburn 9280: my (%haschgs,%inconf);
9281: if ($context eq 'requestauthor') {
9282: %haschgs = %changes;
1.210 raeburn 9283: %inconf = %confhash;
1.163 raeburn 9284: } else {
9285: if (ref($changes{$item}) eq 'HASH') {
9286: %haschgs = %{$changes{$item}};
9287: }
9288: if (ref($confhash{$item}) eq 'HASH') {
9289: %inconf = %{$confhash{$item}};
9290: }
9291: }
9292: if (keys(%haschgs) > 0) {
1.80 raeburn 9293: my $newacc =
9294: &Apache::lonnet::usertools_access($env{'user.name'},
9295: $env{'user.domain'},
1.86 raeburn 9296: $item,'reload',$context);
1.210 raeburn 9297: if (($context eq 'requestcourses') ||
1.163 raeburn 9298: ($context eq 'requestauthor')) {
1.108 raeburn 9299: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9300: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9301: }
9302: } else {
9303: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9304: $newenv{'environment.availabletools.'.$item} = $newacc;
9305: }
1.80 raeburn 9306: }
1.163 raeburn 9307: unless ($context eq 'requestauthor') {
9308: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9309: }
1.72 raeburn 9310: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 9311: if ($haschgs{$type}) {
1.72 raeburn 9312: my $typetitle = $usertypes->{$type};
9313: if ($type eq 'default') {
9314: $typetitle = $othertitle;
9315: } elsif ($type eq '_LC_adv') {
9316: $typetitle = 'LON-CAPA Advanced Users';
9317: }
1.163 raeburn 9318: if ($inconf{$type}) {
1.101 raeburn 9319: if ($context eq 'requestcourses') {
9320: my $cond;
1.163 raeburn 9321: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9322: if ($1 eq '') {
9323: $cond = &mt('(Automatic processing of any request).');
9324: } else {
9325: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9326: }
9327: } else {
1.163 raeburn 9328: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9329: }
9330: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 9331: } elsif ($context eq 'requestauthor') {
9332: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9333: $titles{$inconf{$type}},$typetitle);
9334:
1.101 raeburn 9335: } else {
9336: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9337: }
1.72 raeburn 9338: } else {
1.104 raeburn 9339: if ($type eq '_LC_adv') {
1.163 raeburn 9340: if ($inconf{$type} eq '0') {
1.104 raeburn 9341: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9342: } else {
9343: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9344: }
9345: } else {
9346: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9347: }
1.72 raeburn 9348: }
9349: }
1.26 raeburn 9350: }
1.163 raeburn 9351: unless ($context eq 'requestauthor') {
9352: $resulttext .= '</ul></li>';
9353: }
1.26 raeburn 9354: }
1.1 raeburn 9355: }
1.163 raeburn 9356: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9357: if (ref($changes{'notify'}) eq 'HASH') {
9358: if ($changes{'notify'}{'approval'}) {
9359: if (ref($confhash{'notify'}) eq 'HASH') {
9360: if ($confhash{'notify'}{'approval'}) {
9361: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9362: } else {
1.163 raeburn 9363: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9364: }
9365: }
9366: }
9367: }
9368: }
1.216 raeburn 9369: if ($action eq 'requestcourses') {
9370: my @offon = ('off','on');
9371: if ($changes{'uniquecode'}) {
1.218 raeburn 9372: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9373: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9374: $resulttext .= '<li>'.
9375: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9376: '</li>';
9377: } else {
9378: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9379: '</li>';
9380: }
1.216 raeburn 9381: }
1.242 raeburn 9382: foreach my $type ('textbooks','templates') {
9383: if (ref($changes{$type}) eq 'HASH') {
9384: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9385: foreach my $key (sort(keys(%{$changes{$type}}))) {
9386: my %coursehash = &Apache::lonnet::coursedescription($key);
9387: my $coursetitle = $coursehash{'description'};
9388: my $position = $confhash{$type}{$key}{'order'} + 1;
9389: $resulttext .= '<li>';
1.243 raeburn 9390: foreach my $item ('subject','title','publisher','author') {
9391: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9392: ($type eq 'templates'));
1.242 raeburn 9393: my $name = $item.':';
9394: $name =~ s/^(\w)/\U$1/;
9395: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9396: }
9397: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9398: if ($type eq 'textbooks') {
9399: if ($confhash{$type}{$key}{'image'}) {
9400: $resulttext .= ' '.&mt('Image: [_1]',
9401: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9402: ' alt="Textbook cover" />').'<br />';
9403: }
9404: }
9405: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 9406: }
1.242 raeburn 9407: $resulttext .= '</ul></li>';
1.216 raeburn 9408: }
9409: }
1.235 raeburn 9410: if (ref($changes{'validation'}) eq 'HASH') {
9411: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9412: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9413: foreach my $item (@{$validationitemsref}) {
9414: if (exists($changes{'validation'}{$item})) {
9415: if ($item eq 'markup') {
9416: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9417: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9418: } else {
9419: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9420: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9421: }
9422: }
9423: }
9424: if (exists($changes{'validation'}{'dc'})) {
9425: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9426: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9427: }
9428: }
9429: }
1.216 raeburn 9430: }
1.1 raeburn 9431: $resulttext .= '</ul>';
1.80 raeburn 9432: if (keys(%newenv)) {
9433: &Apache::lonnet::appenv(\%newenv);
9434: }
1.1 raeburn 9435: } else {
1.86 raeburn 9436: if ($context eq 'requestcourses') {
9437: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 9438: } elsif ($context eq 'requestauthor') {
9439: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9440: } else {
1.90 weissno 9441: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9442: }
1.1 raeburn 9443: }
9444: } else {
1.11 albertel 9445: $resulttext = '<span class="LC_error">'.
9446: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9447: }
1.216 raeburn 9448: if ($errors) {
9449: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9450: '<ul>'.$errors.'</ul></p>';
9451: }
1.3 raeburn 9452: return $resulttext;
1.1 raeburn 9453: }
9454:
1.216 raeburn 9455: sub process_textbook_image {
1.242 raeburn 9456: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 9457: my $filename = $env{'form.'.$caller.'.filename'};
9458: my ($error,$url);
9459: my ($width,$height) = (50,50);
9460: if ($configuserok eq 'ok') {
9461: if ($switchserver) {
9462: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9463: $switchserver);
9464: } elsif ($author_ok eq 'ok') {
9465: my ($result,$imageurl) =
9466: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 9467: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 9468: if ($result eq 'ok') {
9469: $url = $imageurl;
9470: } else {
9471: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9472: }
9473: } else {
9474: $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);
9475: }
9476: } else {
9477: $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);
9478: }
9479: return ($url,$error);
9480: }
9481:
1.267 raeburn 9482: sub modify_ltitools {
9483: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
9484: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 9485: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 9486: my $confname = $dom.'-domainconfig';
9487: my $servadm = $r->dir_config('lonAdmEMail');
9488: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9489: my (%posslti,%possfield);
9490: my @courseroles = ('cc','in','ta','ep','st');
9491: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
9492: map { $posslti{$_} = 1; } @ltiroles;
9493: my @allfields = ('fullname','firstname','lastname','email','user','roles');
9494: map { $possfield{$_} = 1; } @allfields;
9495: my %lt = <itools_names();
9496: if ($env{'form.ltitools_add'}) {
9497: my $title = $env{'form.ltitools_add_title'};
9498: $title =~ s/(`)/'/g;
9499: ($newid,my $error) = &get_ltitools_id($dom,$title);
9500: if ($newid) {
9501: my $position = $env{'form.ltitools_add_pos'};
9502: $position =~ s/\D+//g;
9503: if ($position ne '') {
9504: $allpos[$position] = $newid;
9505: }
9506: $changes{$newid} = 1;
9507: foreach my $item ('title','url','key','secret') {
9508: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
9509: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 9510: if (($item eq 'key') || ($item eq 'secret')) {
9511: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9512: } else {
9513: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9514: }
1.267 raeburn 9515: }
9516: }
9517: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
9518: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
9519: }
9520: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
9521: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
9522: }
1.296 raeburn 9523: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 9524: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
9525: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 9526: if (($item eq 'width') || ($item eq 'height')) {
9527: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
9528: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9529: }
9530: } else {
9531: if ($env{'form.ltitools_add_'.$item} ne '') {
9532: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9533: }
1.267 raeburn 9534: }
9535: }
9536: if ($env{'form.ltitools_add_target'} eq 'window') {
9537: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 9538: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
9539: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 9540: } else {
9541: $confhash{$newid}{'display'}{'target'} = 'iframe';
9542: }
9543: foreach my $item ('passback','roster') {
9544: if ($env{'form.ltitools_add_'.$item}) {
9545: $confhash{$newid}{$item} = 1;
9546: }
9547: }
9548: if ($env{'form.ltitools_add_image.filename'} ne '') {
9549: my ($imageurl,$error) =
9550: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
9551: $configuserok,$switchserver,$author_ok);
9552: if ($imageurl) {
9553: $confhash{$newid}{'image'} = $imageurl;
9554: }
9555: if ($error) {
9556: &Apache::lonnet::logthis($error);
9557: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9558: }
9559: }
9560: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
9561: foreach my $field (@fields) {
9562: if ($possfield{$field}) {
9563: if ($field eq 'roles') {
9564: foreach my $role (@courseroles) {
9565: my $choice = $env{'form.ltitools_add_roles_'.$role};
9566: if (($choice ne '') && ($posslti{$choice})) {
9567: $confhash{$newid}{'roles'}{$role} = $choice;
9568: if ($role eq 'cc') {
9569: $confhash{$newid}{'roles'}{'co'} = $choice;
9570: }
9571: }
9572: }
9573: } else {
9574: $confhash{$newid}{'fields'}{$field} = 1;
9575: }
9576: }
9577: }
1.273 raeburn 9578: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
9579: foreach my $item (@courseconfig) {
9580: $confhash{$newid}{'crsconf'}{$item} = 1;
9581: }
1.267 raeburn 9582: if ($env{'form.ltitools_add_custom'}) {
9583: my $name = $env{'form.ltitools_add_custom_name'};
9584: my $value = $env{'form.ltitools_add_custom_value'};
9585: $value =~ s/(`)/'/g;
9586: $name =~ s/(`)/'/g;
9587: $confhash{$newid}{'custom'}{$name} = $value;
9588: }
9589: } else {
9590: my $error = &mt('Failed to acquire unique ID for new external tool');
9591: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9592: }
9593: }
9594: if (ref($domconfig{$action}) eq 'HASH') {
9595: my %deletions;
9596: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
9597: if (@todelete) {
9598: map { $deletions{$_} = 1; } @todelete;
9599: }
9600: my %customadds;
9601: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
9602: if (@newcustom) {
9603: map { $customadds{$_} = 1; } @newcustom;
9604: }
9605: my %imgdeletions;
9606: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
9607: if (@todeleteimages) {
9608: map { $imgdeletions{$_} = 1; } @todeleteimages;
9609: }
9610: my $maxnum = $env{'form.ltitools_maxnum'};
9611: for (my $i=0; $i<=$maxnum; $i++) {
9612: my $itemid = $env{'form.ltitools_id_'.$i};
9613: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9614: if ($deletions{$itemid}) {
9615: if ($domconfig{$action}{$itemid}{'image'}) {
9616: #FIXME need to obsolete item in RES space
9617: }
9618: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
9619: next;
9620: } else {
9621: my $newpos = $env{'form.ltitools_'.$itemid};
9622: $newpos =~ s/\D+//g;
1.297 raeburn 9623: foreach my $item ('title','url') {
1.267 raeburn 9624: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9625: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
9626: $changes{$itemid} = 1;
9627: }
9628: }
1.297 raeburn 9629: foreach my $item ('key','secret') {
9630: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9631: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
9632: $changes{$itemid} = 1;
9633: }
9634: }
1.267 raeburn 9635: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
9636: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
9637: }
9638: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
9639: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
9640: }
9641: foreach my $size ('width','height') {
9642: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
9643: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
9644: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
9645: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
9646: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9647: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
9648: $changes{$itemid} = 1;
9649: }
9650: } else {
9651: $changes{$itemid} = 1;
9652: }
1.296 raeburn 9653: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9654: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
9655: $changes{$itemid} = 1;
9656: }
9657: }
9658: }
9659: foreach my $item ('linktext','explanation') {
9660: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
9661: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
9662: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
9663: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9664: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9665: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
9666: $changes{$itemid} = 1;
9667: }
9668: } else {
9669: $changes{$itemid} = 1;
9670: }
9671: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9672: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
9673: $changes{$itemid} = 1;
9674: }
1.267 raeburn 9675: }
9676: }
9677: if ($env{'form.ltitools_target_'.$i} eq 'window') {
9678: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 9679: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
9680: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 9681: } else {
9682: $confhash{$itemid}{'display'}{'target'} = 'iframe';
9683: }
9684: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9685: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
9686: $changes{$itemid} = 1;
9687: }
9688: } else {
9689: $changes{$itemid} = 1;
9690: }
9691: foreach my $extra ('passback','roster') {
9692: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
9693: $confhash{$itemid}{$extra} = 1;
9694: }
9695: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
9696: $changes{$itemid} = 1;
9697: }
9698: }
1.273 raeburn 9699: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.296 raeburn 9700: foreach my $item ('label','title','target','linktext','explanation') {
1.273 raeburn 9701: if (grep(/^\Q$item\E$/,@courseconfig)) {
9702: $confhash{$itemid}{'crsconf'}{$item} = 1;
9703: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
9704: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
9705: $changes{$itemid} = 1;
9706: }
9707: } else {
9708: $changes{$itemid} = 1;
9709: }
9710: }
9711: }
1.267 raeburn 9712: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
9713: foreach my $field (@fields) {
9714: if ($possfield{$field}) {
9715: if ($field eq 'roles') {
9716: foreach my $role (@courseroles) {
9717: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
9718: if (($choice ne '') && ($posslti{$choice})) {
9719: $confhash{$itemid}{'roles'}{$role} = $choice;
9720: if ($role eq 'cc') {
9721: $confhash{$itemid}{'roles'}{'co'} = $choice;
9722: }
9723: }
9724: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
9725: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
9726: $changes{$itemid} = 1;
9727: }
9728: } elsif ($confhash{$itemid}{'roles'}{$role}) {
9729: $changes{$itemid} = 1;
9730: }
9731: }
9732: } else {
9733: $confhash{$itemid}{'fields'}{$field} = 1;
9734: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
9735: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
9736: $changes{$itemid} = 1;
9737: }
9738: } else {
9739: $changes{$itemid} = 1;
9740: }
9741: }
9742: }
9743: }
9744: $allpos[$newpos] = $itemid;
9745: }
9746: if ($imgdeletions{$itemid}) {
9747: $changes{$itemid} = 1;
9748: #FIXME need to obsolete item in RES space
9749: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
9750: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
9751: $itemid,$configuserok,$switchserver,
9752: $author_ok);
9753: if ($imgurl) {
9754: $confhash{$itemid}{'image'} = $imgurl;
9755: $changes{$itemid} = 1;
9756: }
9757: if ($error) {
9758: &Apache::lonnet::logthis($error);
9759: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9760: }
9761: } elsif ($domconfig{$action}{$itemid}{'image'}) {
9762: $confhash{$itemid}{'image'} =
9763: $domconfig{$action}{$itemid}{'image'};
9764: }
9765: if ($customadds{$i}) {
9766: my $name = $env{'form.ltitools_custom_name_'.$i};
9767: $name =~ s/(`)/'/g;
9768: $name =~ s/^\s+//;
9769: $name =~ s/\s+$//;
9770: my $value = $env{'form.ltitools_custom_value_'.$i};
9771: $value =~ s/(`)/'/g;
9772: $value =~ s/^\s+//;
9773: $value =~ s/\s+$//;
9774: if ($name ne '') {
9775: $confhash{$itemid}{'custom'}{$name} = $value;
9776: $changes{$itemid} = 1;
9777: }
9778: }
9779: my %customdels;
9780: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
9781: if (@customdeletions) {
9782: $changes{$itemid} = 1;
9783: }
9784: map { $customdels{$_} = 1; } @customdeletions;
9785: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
9786: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
9787: unless ($customdels{$key}) {
9788: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
9789: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
9790: }
9791: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
9792: $changes{$itemid} = 1;
9793: }
9794: }
9795: }
9796: }
9797: unless ($changes{$itemid}) {
9798: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
9799: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
9800: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
9801: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
9802: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
9803: $changes{$itemid} = 1;
9804: last;
9805: }
9806: }
9807: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
9808: $changes{$itemid} = 1;
9809: }
9810: }
9811: last if ($changes{$itemid});
9812: }
9813: }
9814: }
9815: }
9816: }
9817: if (@allpos > 0) {
9818: my $idx = 0;
9819: foreach my $itemid (@allpos) {
9820: if ($itemid ne '') {
9821: $confhash{$itemid}{'order'} = $idx;
9822: if (ref($domconfig{$action}) eq 'HASH') {
9823: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9824: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
9825: $changes{$itemid} = 1;
9826: }
9827: }
9828: }
9829: $idx ++;
9830: }
9831: }
9832: }
9833: my %ltitoolshash = (
9834: $action => { %confhash }
9835: );
9836: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
9837: $dom);
9838: if ($putresult eq 'ok') {
1.297 raeburn 9839: my %ltienchash = (
9840: $action => { %encconfig }
9841: );
9842: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 9843: if (keys(%changes) > 0) {
9844: my $cachetime = 24*60*60;
1.297 raeburn 9845: my %ltiall = %confhash;
9846: foreach my $id (keys(%ltiall)) {
9847: if (ref($encconfig{$id}) eq 'HASH') {
9848: foreach my $item ('key','secret') {
9849: $ltiall{$id}{$item} = $encconfig{$id}{$item};
9850: }
9851: }
9852: }
9853: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 9854: if (ref($lastactref) eq 'HASH') {
9855: $lastactref->{'ltitools'} = 1;
9856: }
9857: $resulttext = &mt('Changes made:').'<ul>';
9858: my %bynum;
9859: foreach my $itemid (sort(keys(%changes))) {
9860: my $position = $confhash{$itemid}{'order'};
9861: $bynum{$position} = $itemid;
9862: }
9863: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9864: my $itemid = $bynum{$pos};
9865: if (ref($confhash{$itemid}) ne 'HASH') {
9866: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9867: } else {
9868: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
9869: if ($confhash{$itemid}{'image'}) {
9870: $resulttext .= ' '.
9871: '<img src="'.$confhash{$itemid}{'image'}.'"'.
9872: ' alt="'.&mt('Tool Provider icon').'" />';
9873: }
9874: $resulttext .= '</li><ul>';
9875: my $position = $pos + 1;
9876: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.297 raeburn 9877: foreach my $item ('version','msgtype','url') {
1.267 raeburn 9878: if ($confhash{$itemid}{$item} ne '') {
9879: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
9880: }
9881: }
1.297 raeburn 9882: if ($encconfig{$itemid}{'key'} ne '') {
9883: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
9884: }
9885: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 9886: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 9887: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 9888: $resulttext .= ('*'x$num).'</li>';
9889: }
1.273 raeburn 9890: $resulttext .= '<li>'.&mt('Configurable in course:');
1.296 raeburn 9891: my @possconfig = ('label','title','target','linktext','explanation');
1.273 raeburn 9892: my $numconfig = 0;
9893: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
9894: foreach my $item (@possconfig) {
9895: if ($confhash{$itemid}{'crsconf'}{$item}) {
9896: $numconfig ++;
1.296 raeburn 9897: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 9898: }
9899: }
9900: }
9901: if (!$numconfig) {
9902: $resulttext .= &mt('None');
9903: }
9904: $resulttext .= '</li>';
1.267 raeburn 9905: foreach my $item ('passback','roster') {
9906: $resulttext .= '<li>'.$lt{$item}.' ';
9907: if ($confhash{$itemid}{$item}) {
9908: $resulttext .= &mt('Yes');
9909: } else {
9910: $resulttext .= &mt('No');
9911: }
9912: $resulttext .= '</li>';
9913: }
9914: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
9915: my $displaylist;
9916: if ($confhash{$itemid}{'display'}{'target'}) {
9917: $displaylist = &mt('Display target').': '.
9918: $confhash{$itemid}{'display'}{'target'}.',';
9919: }
9920: foreach my $size ('width','height') {
9921: if ($confhash{$itemid}{'display'}{$size}) {
9922: $displaylist .= (' 'x2).$lt{$size}.': '.
9923: $confhash{$itemid}{'display'}{$size}.',';
9924: }
9925: }
9926: if ($displaylist) {
9927: $displaylist =~ s/,$//;
9928: $resulttext .= '<li>'.$displaylist.'</li>';
9929: }
1.296 raeburn 9930: foreach my $item ('linktext','explanation') {
9931: if ($confhash{$itemid}{'display'}{$item}) {
9932: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
9933: }
9934: }
9935: }
1.267 raeburn 9936: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
9937: my $fieldlist;
9938: foreach my $field (@allfields) {
9939: if ($confhash{$itemid}{'fields'}{$field}) {
9940: $fieldlist .= (' 'x2).$lt{$field}.',';
9941: }
9942: }
9943: if ($fieldlist) {
9944: $fieldlist =~ s/,$//;
9945: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
9946: }
9947: }
9948: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
9949: my $rolemaps;
9950: foreach my $role (@courseroles) {
9951: if ($confhash{$itemid}{'roles'}{$role}) {
9952: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
9953: $confhash{$itemid}{'roles'}{$role}.',';
9954: }
9955: }
9956: if ($rolemaps) {
9957: $rolemaps =~ s/,$//;
9958: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
9959: }
9960: }
9961: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
9962: my $customlist;
9963: if (keys(%{$confhash{$itemid}{'custom'}})) {
9964: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
9965: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
9966: }
9967: }
9968: if ($customlist) {
9969: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
9970: }
9971: }
9972: $resulttext .= '</ul></li>';
9973: }
9974: }
9975: $resulttext .= '</ul>';
9976: } else {
9977: $resulttext = &mt('No changes made.');
9978: }
9979: } else {
9980: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9981: }
9982: if ($errors) {
9983: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9984: $errors.'</ul>';
9985: }
9986: return $resulttext;
9987: }
9988:
9989: sub process_ltitools_image {
9990: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
9991: my $filename = $env{'form.'.$caller.'.filename'};
9992: my ($error,$url);
9993: my ($width,$height) = (21,21);
9994: if ($configuserok eq 'ok') {
9995: if ($switchserver) {
9996: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
9997: $switchserver);
9998: } elsif ($author_ok eq 'ok') {
9999: my ($result,$imageurl,$madethumb) =
10000: &publishlogo($r,'upload',$caller,$dom,$confname,
10001: "ltitools/$itemid/icon",$width,$height);
10002: if ($result eq 'ok') {
10003: if ($madethumb) {
10004: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
10005: my $imagethumb = "$path/tn-".$imagefile;
10006: $url = $imagethumb;
10007: } else {
10008: $url = $imageurl;
10009: }
10010: } else {
10011: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10012: }
10013: } else {
10014: $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);
10015: }
10016: } else {
10017: $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);
10018: }
10019: return ($url,$error);
10020: }
10021:
10022: sub get_ltitools_id {
10023: my ($cdom,$title) = @_;
10024: # get lock on ltitools db
10025: my $lockhash = {
10026: lock => $env{'user.name'}.
10027: ':'.$env{'user.domain'},
10028: };
10029: my $tries = 0;
10030: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10031: my ($id,$error);
10032:
10033: while (($gotlock ne 'ok') && ($tries<10)) {
10034: $tries ++;
10035: sleep (0.1);
10036: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10037: }
10038: if ($gotlock eq 'ok') {
10039: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
10040: if ($currids{'lock'}) {
10041: delete($currids{'lock'});
10042: if (keys(%currids)) {
10043: my @curr = sort { $a <=> $b } keys(%currids);
10044: if ($curr[-1] =~ /^\d+$/) {
10045: $id = 1 + $curr[-1];
10046: }
10047: } else {
10048: $id = 1;
10049: }
10050: if ($id) {
10051: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
10052: $error = 'nostore';
10053: }
10054: } else {
10055: $error = 'nonumber';
10056: }
10057: }
10058: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
10059: } else {
10060: $error = 'nolock';
10061: }
10062: return ($id,$error);
10063: }
10064:
1.3 raeburn 10065: sub modify_autoenroll {
1.205 raeburn 10066: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 10067: my ($resulttext,%changes);
10068: my %currautoenroll;
10069: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
10070: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
10071: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
10072: }
10073: }
10074: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
10075: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 10076: sender => 'Sender for notification messages',
1.274 raeburn 10077: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
10078: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 10079: my @offon = ('off','on');
1.17 raeburn 10080: my $sender_uname = $env{'form.sender_uname'};
10081: my $sender_domain = $env{'form.sender_domain'};
10082: if ($sender_domain eq '') {
10083: $sender_uname = '';
10084: } elsif ($sender_uname eq '') {
10085: $sender_domain = '';
10086: }
1.129 raeburn 10087: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 10088: my $failsafe = $env{'form.autoenroll_failsafe'};
10089: $failsafe =~ s{^\s+|\s+$}{}g;
10090: if ($failsafe =~ /\D/) {
10091: undef($failsafe);
10092: }
1.1 raeburn 10093: my %autoenrollhash = (
1.129 raeburn 10094: autoenroll => { 'run' => $env{'form.autoenroll_run'},
10095: 'sender_uname' => $sender_uname,
10096: 'sender_domain' => $sender_domain,
10097: 'co-owners' => $coowners,
1.274 raeburn 10098: 'autofailsafe' => $failsafe,
1.1 raeburn 10099: }
10100: );
1.4 raeburn 10101: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
10102: $dom);
1.1 raeburn 10103: if ($putresult eq 'ok') {
10104: if (exists($currautoenroll{'run'})) {
10105: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
10106: $changes{'run'} = 1;
10107: }
10108: } elsif ($autorun) {
10109: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 10110: $changes{'run'} = 1;
1.1 raeburn 10111: }
10112: }
1.17 raeburn 10113: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 10114: $changes{'sender'} = 1;
10115: }
1.17 raeburn 10116: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 10117: $changes{'sender'} = 1;
10118: }
1.129 raeburn 10119: if ($currautoenroll{'co-owners'} ne '') {
10120: if ($currautoenroll{'co-owners'} ne $coowners) {
10121: $changes{'coowners'} = 1;
10122: }
10123: } elsif ($coowners) {
10124: $changes{'coowners'} = 1;
1.274 raeburn 10125: }
10126: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
10127: $changes{'autofailsafe'} = 1;
10128: }
1.1 raeburn 10129: if (keys(%changes) > 0) {
10130: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 10131: if ($changes{'run'}) {
1.1 raeburn 10132: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
10133: }
10134: if ($changes{'sender'}) {
1.17 raeburn 10135: if ($sender_uname eq '' || $sender_domain eq '') {
10136: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
10137: } else {
10138: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
10139: }
1.1 raeburn 10140: }
1.129 raeburn 10141: if ($changes{'coowners'}) {
10142: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
10143: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10144: if (ref($lastactref) eq 'HASH') {
10145: $lastactref->{'domainconfig'} = 1;
10146: }
1.129 raeburn 10147: }
1.274 raeburn 10148: if ($changes{'autofailsafe'}) {
10149: if ($failsafe ne '') {
1.299 ! raeburn 10150: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 10151: } else {
1.299 ! raeburn 10152: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 10153: }
10154: &Apache::lonnet::get_domain_defaults($dom,1);
10155: if (ref($lastactref) eq 'HASH') {
10156: $lastactref->{'domdefaults'} = 1;
10157: }
10158: }
1.1 raeburn 10159: $resulttext .= '</ul>';
10160: } else {
10161: $resulttext = &mt('No changes made to auto-enrollment settings');
10162: }
10163: } else {
1.11 albertel 10164: $resulttext = '<span class="LC_error">'.
10165: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10166: }
1.3 raeburn 10167: return $resulttext;
1.1 raeburn 10168: }
10169:
10170: sub modify_autoupdate {
1.3 raeburn 10171: my ($dom,%domconfig) = @_;
1.1 raeburn 10172: my ($resulttext,%currautoupdate,%fields,%changes);
10173: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
10174: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
10175: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
10176: }
10177: }
10178: my @offon = ('off','on');
10179: my %title = &Apache::lonlocal::texthash (
10180: run => 'Auto-update:',
10181: classlists => 'Updates to user information in classlists?'
10182: );
1.44 raeburn 10183: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10184: my %fieldtitles = &Apache::lonlocal::texthash (
10185: id => 'Student/Employee ID',
1.20 raeburn 10186: permanentemail => 'E-mail address',
1.1 raeburn 10187: lastname => 'Last Name',
10188: firstname => 'First Name',
10189: middlename => 'Middle Name',
1.132 raeburn 10190: generation => 'Generation',
1.1 raeburn 10191: );
1.142 raeburn 10192: $othertitle = &mt('All users');
1.1 raeburn 10193: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 10194: $othertitle = &mt('Other users');
1.1 raeburn 10195: }
10196: foreach my $key (keys(%env)) {
10197: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 10198: my ($usertype,$item) = ($1,$2);
10199: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
10200: if ($usertype eq 'default') {
10201: push(@{$fields{$1}},$2);
10202: } elsif (ref($types) eq 'ARRAY') {
10203: if (grep(/^\Q$usertype\E$/,@{$types})) {
10204: push(@{$fields{$1}},$2);
10205: }
10206: }
10207: }
1.1 raeburn 10208: }
10209: }
1.131 raeburn 10210: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
10211: @lockablenames = sort(@lockablenames);
10212: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
10213: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10214: if (@changed) {
10215: $changes{'lockablenames'} = 1;
10216: }
10217: } else {
10218: if (@lockablenames) {
10219: $changes{'lockablenames'} = 1;
10220: }
10221: }
1.1 raeburn 10222: my %updatehash = (
10223: autoupdate => { run => $env{'form.autoupdate_run'},
10224: classlists => $env{'form.classlists'},
10225: fields => {%fields},
1.131 raeburn 10226: lockablenames => \@lockablenames,
1.1 raeburn 10227: }
10228: );
10229: foreach my $key (keys(%currautoupdate)) {
10230: if (($key eq 'run') || ($key eq 'classlists')) {
10231: if (exists($updatehash{autoupdate}{$key})) {
10232: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
10233: $changes{$key} = 1;
10234: }
10235: }
10236: } elsif ($key eq 'fields') {
10237: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 10238: foreach my $item (@{$types},'default') {
1.1 raeburn 10239: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
10240: my $change = 0;
10241: foreach my $type (@{$currautoupdate{$key}{$item}}) {
10242: if (!exists($fields{$item})) {
10243: $change = 1;
1.132 raeburn 10244: last;
1.1 raeburn 10245: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 10246: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 10247: $change = 1;
1.132 raeburn 10248: last;
1.1 raeburn 10249: }
10250: }
10251: }
10252: if ($change) {
10253: push(@{$changes{$key}},$item);
10254: }
1.26 raeburn 10255: }
1.1 raeburn 10256: }
10257: }
1.131 raeburn 10258: } elsif ($key eq 'lockablenames') {
10259: if (ref($currautoupdate{$key}) eq 'ARRAY') {
10260: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10261: if (@changed) {
10262: $changes{'lockablenames'} = 1;
10263: }
10264: } else {
10265: if (@lockablenames) {
10266: $changes{'lockablenames'} = 1;
10267: }
10268: }
10269: }
10270: }
10271: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10272: if (@lockablenames) {
10273: $changes{'lockablenames'} = 1;
1.1 raeburn 10274: }
10275: }
1.26 raeburn 10276: foreach my $item (@{$types},'default') {
10277: if (defined($fields{$item})) {
10278: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 10279: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10280: my $change = 0;
10281: if (ref($fields{$item}) eq 'ARRAY') {
10282: foreach my $type (@{$fields{$item}}) {
10283: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10284: $change = 1;
10285: last;
10286: }
10287: }
10288: }
10289: if ($change) {
10290: push(@{$changes{'fields'}},$item);
10291: }
10292: } else {
1.26 raeburn 10293: push(@{$changes{'fields'}},$item);
10294: }
10295: } else {
10296: push(@{$changes{'fields'}},$item);
1.1 raeburn 10297: }
10298: }
10299: }
10300: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10301: $dom);
10302: if ($putresult eq 'ok') {
10303: if (keys(%changes) > 0) {
10304: $resulttext = &mt('Changes made:').'<ul>';
10305: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 10306: if ($key eq 'lockablenames') {
10307: $resulttext .= '<li>';
10308: if (@lockablenames) {
10309: $usertypes->{'default'} = $othertitle;
10310: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10311: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10312: } else {
10313: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10314: }
10315: $resulttext .= '</li>';
10316: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 10317: foreach my $item (@{$changes{$key}}) {
10318: my @newvalues;
10319: foreach my $type (@{$fields{$item}}) {
10320: push(@newvalues,$fieldtitles{$type});
10321: }
1.3 raeburn 10322: my $newvaluestr;
10323: if (@newvalues > 0) {
10324: $newvaluestr = join(', ',@newvalues);
10325: } else {
10326: $newvaluestr = &mt('none');
1.6 raeburn 10327: }
1.1 raeburn 10328: if ($item eq 'default') {
1.26 raeburn 10329: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 10330: } else {
1.26 raeburn 10331: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 10332: }
10333: }
10334: } else {
10335: my $newvalue;
10336: if ($key eq 'run') {
10337: $newvalue = $offon[$env{'form.autoupdate_run'}];
10338: } else {
10339: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 10340: }
1.1 raeburn 10341: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
10342: }
10343: }
10344: $resulttext .= '</ul>';
10345: } else {
1.3 raeburn 10346: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 10347: }
10348: } else {
1.11 albertel 10349: $resulttext = '<span class="LC_error">'.
10350: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10351: }
1.3 raeburn 10352: return $resulttext;
1.1 raeburn 10353: }
10354:
1.125 raeburn 10355: sub modify_autocreate {
10356: my ($dom,%domconfig) = @_;
10357: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10358: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10359: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10360: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10361: }
10362: }
10363: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10364: req => 'Auto-creation of validated requests for official courses',
10365: xmldc => 'Identity of course creator of courses from XML files',
10366: );
10367: my @types = ('xml','req');
10368: foreach my $item (@types) {
10369: $newvals{$item} = $env{'form.autocreate_'.$item};
10370: $newvals{$item} =~ s/\D//g;
10371: $newvals{$item} = 0 if ($newvals{$item} eq '');
10372: }
10373: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 10374: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 10375: unless (exists($domcoords{$newvals{'xmldc'}})) {
10376: $newvals{'xmldc'} = '';
10377: }
10378: %autocreatehash = (
10379: autocreate => { xml => $newvals{'xml'},
10380: req => $newvals{'req'},
10381: }
10382: );
10383: if ($newvals{'xmldc'} ne '') {
10384: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10385: }
10386: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10387: $dom);
10388: if ($putresult eq 'ok') {
10389: my @items = @types;
10390: if ($newvals{'xml'}) {
10391: push(@items,'xmldc');
10392: }
10393: foreach my $item (@items) {
10394: if (exists($currautocreate{$item})) {
10395: if ($currautocreate{$item} ne $newvals{$item}) {
10396: $changes{$item} = 1;
10397: }
10398: } elsif ($newvals{$item}) {
10399: $changes{$item} = 1;
10400: }
10401: }
10402: if (keys(%changes) > 0) {
10403: my @offon = ('off','on');
10404: $resulttext = &mt('Changes made:').'<ul>';
10405: foreach my $item (@types) {
10406: if ($changes{$item}) {
10407: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 10408: $resulttext .= '<li>'.
10409: &mt("$title{$item} set to [_1]$newtxt [_2]",
10410: '<b>','</b>').
10411: '</li>';
1.125 raeburn 10412: }
10413: }
10414: if ($changes{'xmldc'}) {
10415: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10416: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 10417: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 10418: }
10419: $resulttext .= '</ul>';
10420: } else {
10421: $resulttext = &mt('No changes made to auto-creation settings');
10422: }
10423: } else {
10424: $resulttext = '<span class="LC_error">'.
10425: &mt('An error occurred: [_1]',$putresult).'</span>';
10426: }
10427: return $resulttext;
10428: }
10429:
1.23 raeburn 10430: sub modify_directorysrch {
1.295 raeburn 10431: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 10432: my ($resulttext,%changes);
10433: my %currdirsrch;
10434: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10435: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10436: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10437: }
10438: }
1.277 raeburn 10439: my %title = ( available => 'Institutional directory search available',
10440: localonly => 'Other domains can search institution',
10441: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 10442: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 10443: searchby => 'Search types',
10444: searchtypes => 'Search latitude');
10445: my @offon = ('off','on');
1.24 raeburn 10446: my @otherdoms = ('Yes','No');
1.23 raeburn 10447:
1.25 raeburn 10448: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 10449: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10450: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10451:
1.44 raeburn 10452: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 10453: if (keys(%{$usertypes}) == 0) {
10454: @cansearch = ('default');
10455: } else {
10456: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10457: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10458: if (!grep(/^\Q$type\E$/,@cansearch)) {
10459: push(@{$changes{'cansearch'}},$type);
10460: }
1.23 raeburn 10461: }
1.26 raeburn 10462: foreach my $type (@cansearch) {
10463: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10464: push(@{$changes{'cansearch'}},$type);
10465: }
1.23 raeburn 10466: }
1.26 raeburn 10467: } else {
10468: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 10469: }
10470: }
10471:
10472: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10473: foreach my $by (@{$currdirsrch{'searchby'}}) {
10474: if (!grep(/^\Q$by\E$/,@searchby)) {
10475: push(@{$changes{'searchby'}},$by);
10476: }
10477: }
10478: foreach my $by (@searchby) {
10479: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10480: push(@{$changes{'searchby'}},$by);
10481: }
10482: }
10483: } else {
10484: push(@{$changes{'searchby'}},@searchby);
10485: }
1.25 raeburn 10486:
10487: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10488: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10489: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10490: push(@{$changes{'searchtypes'}},$type);
10491: }
10492: }
10493: foreach my $type (@searchtypes) {
10494: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10495: push(@{$changes{'searchtypes'}},$type);
10496: }
10497: }
10498: } else {
10499: if (exists($currdirsrch{'searchtypes'})) {
10500: foreach my $type (@searchtypes) {
10501: if ($type ne $currdirsrch{'searchtypes'}) {
10502: push(@{$changes{'searchtypes'}},$type);
10503: }
10504: }
10505: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10506: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10507: }
10508: } else {
10509: push(@{$changes{'searchtypes'}},@searchtypes);
10510: }
10511: }
10512:
1.23 raeburn 10513: my %dirsrch_hash = (
10514: directorysrch => { available => $env{'form.dirsrch_available'},
10515: cansearch => \@cansearch,
1.277 raeburn 10516: localonly => $env{'form.dirsrch_instlocalonly'},
10517: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10518: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 10519: searchby => \@searchby,
1.25 raeburn 10520: searchtypes => \@searchtypes,
1.23 raeburn 10521: }
10522: );
10523: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10524: $dom);
10525: if ($putresult eq 'ok') {
10526: if (exists($currdirsrch{'available'})) {
10527: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10528: $changes{'available'} = 1;
10529: }
10530: } else {
10531: if ($env{'form.dirsrch_available'} eq '1') {
10532: $changes{'available'} = 1;
10533: }
10534: }
1.277 raeburn 10535: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 10536: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
10537: $changes{'lcavailable'} = 1;
10538: }
1.277 raeburn 10539: } else {
10540: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10541: $changes{'lcavailable'} = 1;
10542: }
10543: }
1.24 raeburn 10544: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 10545: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
10546: $changes{'localonly'} = 1;
10547: }
1.24 raeburn 10548: } else {
1.277 raeburn 10549: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 10550: $changes{'localonly'} = 1;
10551: }
10552: }
1.277 raeburn 10553: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 10554: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
10555: $changes{'lclocalonly'} = 1;
10556: }
1.277 raeburn 10557: } else {
10558: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10559: $changes{'lclocalonly'} = 1;
10560: }
10561: }
1.23 raeburn 10562: if (keys(%changes) > 0) {
10563: $resulttext = &mt('Changes made:').'<ul>';
10564: if ($changes{'available'}) {
10565: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10566: }
1.277 raeburn 10567: if ($changes{'lcavailable'}) {
10568: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10569: }
1.24 raeburn 10570: if ($changes{'localonly'}) {
1.277 raeburn 10571: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 10572: }
1.277 raeburn 10573: if ($changes{'lclocalonly'}) {
10574: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 10575: }
1.23 raeburn 10576: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10577: my $chgtext;
1.26 raeburn 10578: if (ref($usertypes) eq 'HASH') {
10579: if (keys(%{$usertypes}) > 0) {
10580: foreach my $type (@{$types}) {
10581: if (grep(/^\Q$type\E$/,@cansearch)) {
10582: $chgtext .= $usertypes->{$type}.'; ';
10583: }
10584: }
10585: if (grep(/^default$/,@cansearch)) {
10586: $chgtext .= $othertitle;
10587: } else {
10588: $chgtext =~ s/\; $//;
10589: }
1.210 raeburn 10590: $resulttext .=
1.178 raeburn 10591: '<li>'.
10592: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10593: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10594: '</li>';
1.23 raeburn 10595: }
10596: }
10597: }
10598: if (ref($changes{'searchby'}) eq 'ARRAY') {
10599: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10600: my $chgtext;
10601: foreach my $type (@{$titleorder}) {
10602: if (grep(/^\Q$type\E$/,@searchby)) {
10603: if (defined($searchtitles->{$type})) {
10604: $chgtext .= $searchtitles->{$type}.'; ';
10605: }
10606: }
10607: }
10608: $chgtext =~ s/\; $//;
10609: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10610: }
1.25 raeburn 10611: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10612: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10613: my $chgtext;
10614: foreach my $type (@{$srchtypeorder}) {
10615: if (grep(/^\Q$type\E$/,@searchtypes)) {
10616: if (defined($srchtypes_desc->{$type})) {
10617: $chgtext .= $srchtypes_desc->{$type}.'; ';
10618: }
10619: }
10620: }
10621: $chgtext =~ s/\; $//;
1.178 raeburn 10622: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 10623: }
10624: $resulttext .= '</ul>';
1.295 raeburn 10625: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
10626: if (ref($lastactref) eq 'HASH') {
10627: $lastactref->{'directorysrch'} = 1;
10628: }
1.23 raeburn 10629: } else {
1.277 raeburn 10630: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 10631: }
10632: } else {
10633: $resulttext = '<span class="LC_error">'.
1.27 raeburn 10634: &mt('An error occurred: [_1]',$putresult).'</span>';
10635: }
10636: return $resulttext;
10637: }
10638:
1.28 raeburn 10639: sub modify_contacts {
1.205 raeburn 10640: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 10641: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10642: if (ref($domconfig{'contacts'}) eq 'HASH') {
10643: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10644: $currsetting{$key} = $domconfig{'contacts'}{$key};
10645: }
10646: }
1.286 raeburn 10647: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 10648: my @contacts = ('supportemail','adminemail');
1.286 raeburn 10649: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
10650: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 10651: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 10652: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 10653: foreach my $type (@mailings) {
10654: @{$newsetting{$type}} =
10655: &Apache::loncommon::get_env_multiple('form.'.$type);
10656: foreach my $item (@contacts) {
10657: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
10658: $contacts_hash{contacts}{$type}{$item} = 1;
10659: } else {
10660: $contacts_hash{contacts}{$type}{$item} = 0;
10661: }
1.289 raeburn 10662: }
1.28 raeburn 10663: $others{$type} = $env{'form.'.$type.'_others'};
10664: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 10665: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10666: $bcc{$type} = $env{'form.'.$type.'_bcc'};
10667: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 10668: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
10669: $includestr{$type} = $env{'form.'.$type.'_includestr'};
10670: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
10671: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10672: }
1.134 raeburn 10673: }
1.28 raeburn 10674: }
10675: foreach my $item (@contacts) {
10676: $to{$item} = $env{'form.'.$item};
10677: $contacts_hash{'contacts'}{$item} = $to{$item};
10678: }
1.203 raeburn 10679: foreach my $item (@toggles) {
10680: if ($env{'form.'.$item} =~ /^(0|1)$/) {
10681: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
10682: }
10683: }
1.286 raeburn 10684: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
10685: foreach my $field (@{$fields}) {
10686: if (ref($possoptions->{$field}) eq 'ARRAY') {
10687: my $value = $env{'form.helpform_'.$field};
10688: $value =~ s/^\s+|\s+$//g;
10689: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
10690: $contacts_hash{contacts}{'helpform'}{$field} = $value;
10691: if ($field eq 'screenshot') {
10692: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
10693: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
10694: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
10695: }
10696: }
10697: }
10698: }
10699: }
10700: }
1.28 raeburn 10701: if (keys(%currsetting) > 0) {
10702: foreach my $item (@contacts) {
10703: if ($to{$item} ne $currsetting{$item}) {
10704: $changes{$item} = 1;
10705: }
10706: }
10707: foreach my $type (@mailings) {
10708: foreach my $item (@contacts) {
10709: if (ref($currsetting{$type}) eq 'HASH') {
10710: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
10711: push(@{$changes{$type}},$item);
10712: }
10713: } else {
10714: push(@{$changes{$type}},@{$newsetting{$type}});
10715: }
10716: }
10717: if ($others{$type} ne $currsetting{$type}{'others'}) {
10718: push(@{$changes{$type}},'others');
10719: }
1.289 raeburn 10720: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10721: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
10722: push(@{$changes{$type}},'bcc');
10723: }
1.286 raeburn 10724: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
10725: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
10726: push(@{$changes{$type}},'include');
10727: }
10728: }
10729: }
10730: if (ref($fields) eq 'ARRAY') {
10731: if (ref($currsetting{'helpform'}) eq 'HASH') {
10732: foreach my $field (@{$fields}) {
10733: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
10734: push(@{$changes{'helpform'}},$field);
10735: }
10736: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10737: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
10738: push(@{$changes{'helpform'}},'maxsize');
10739: }
10740: }
10741: }
10742: } else {
10743: foreach my $field (@{$fields}) {
10744: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10745: push(@{$changes{'helpform'}},$field);
10746: }
10747: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10748: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10749: push(@{$changes{'helpform'}},'maxsize');
10750: }
10751: }
10752: }
1.134 raeburn 10753: }
1.28 raeburn 10754: }
10755: } else {
10756: my %default;
10757: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
10758: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
10759: $default{'errormail'} = 'adminemail';
10760: $default{'packagesmail'} = 'adminemail';
10761: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 10762: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 10763: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 10764: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 10765: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 10766: foreach my $item (@contacts) {
10767: if ($to{$item} ne $default{$item}) {
1.286 raeburn 10768: $changes{$item} = 1;
1.203 raeburn 10769: }
1.28 raeburn 10770: }
10771: foreach my $type (@mailings) {
10772: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
10773: push(@{$changes{$type}},@{$newsetting{$type}});
10774: }
10775: if ($others{$type} ne '') {
10776: push(@{$changes{$type}},'others');
1.134 raeburn 10777: }
1.286 raeburn 10778: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10779: if ($bcc{$type} ne '') {
10780: push(@{$changes{$type}},'bcc');
10781: }
1.286 raeburn 10782: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
10783: push(@{$changes{$type}},'include');
10784: }
1.134 raeburn 10785: }
1.28 raeburn 10786: }
1.286 raeburn 10787: if (ref($fields) eq 'ARRAY') {
10788: foreach my $field (@{$fields}) {
10789: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10790: push(@{$changes{'helpform'}},$field);
10791: }
10792: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10793: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10794: push(@{$changes{'helpform'}},'maxsize');
10795: }
10796: }
10797: }
1.289 raeburn 10798: }
1.28 raeburn 10799: }
1.203 raeburn 10800: foreach my $item (@toggles) {
10801: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
10802: $changes{$item} = 1;
10803: } elsif ((!$env{'form.'.$item}) &&
10804: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
10805: $changes{$item} = 1;
10806: }
10807: }
1.28 raeburn 10808: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
10809: $dom);
10810: if ($putresult eq 'ok') {
10811: if (keys(%changes) > 0) {
1.205 raeburn 10812: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10813: if (ref($lastactref) eq 'HASH') {
10814: $lastactref->{'domainconfig'} = 1;
10815: }
1.28 raeburn 10816: my ($titles,$short_titles) = &contact_titles();
10817: $resulttext = &mt('Changes made:').'<ul>';
10818: foreach my $item (@contacts) {
10819: if ($changes{$item}) {
10820: $resulttext .= '<li>'.$titles->{$item}.
10821: &mt(' set to: ').
10822: '<span class="LC_cusr_emph">'.
10823: $to{$item}.'</span></li>';
10824: }
10825: }
10826: foreach my $type (@mailings) {
10827: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 10828: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 10829: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 10830: } else {
10831: $resulttext .= '<li>'.$titles->{$type}.': ';
10832: }
1.28 raeburn 10833: my @text;
10834: foreach my $item (@{$newsetting{$type}}) {
10835: push(@text,$short_titles->{$item});
10836: }
10837: if ($others{$type} ne '') {
10838: push(@text,$others{$type});
10839: }
1.286 raeburn 10840: if (@text) {
10841: $resulttext .= '<span class="LC_cusr_emph">'.
10842: join(', ',@text).'</span>';
10843: }
10844: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10845: if ($bcc{$type} ne '') {
1.286 raeburn 10846: my $bcctext;
10847: if (@text) {
1.289 raeburn 10848: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 10849: } else {
10850: $bcctext = '(Bcc)';
10851: }
10852: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10853: } elsif (!@text) {
10854: $resulttext .= &mt('No one');
10855: }
1.289 raeburn 10856: if ($includestr{$type} ne '') {
1.286 raeburn 10857: if ($includeloc{$type} eq 'b') {
10858: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
10859: } elsif ($includeloc{$type} eq 's') {
10860: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
10861: }
1.134 raeburn 10862: }
1.286 raeburn 10863: } elsif (!@text) {
10864: $resulttext .= &mt('No recipients');
1.134 raeburn 10865: }
10866: $resulttext .= '</li>';
1.28 raeburn 10867: }
10868: }
1.203 raeburn 10869: my @offon = ('off','on');
10870: if ($changes{'reporterrors'}) {
10871: $resulttext .= '<li>'.
10872: &mt('E-mail error reports to [_1] set to "'.
10873: $offon[$env{'form.reporterrors'}].'".',
10874: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10875: &mt('LON-CAPA core group - MSU'),600,500)).
10876: '</li>';
10877: }
10878: if ($changes{'reportupdates'}) {
10879: $resulttext .= '<li>'.
10880: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
10881: $offon[$env{'form.reportupdates'}].'".',
10882: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10883: &mt('LON-CAPA core group - MSU'),600,500)).
10884: '</li>';
10885: }
1.286 raeburn 10886: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
10887: my (@optional,@required,@unused,$maxsizechg);
10888: foreach my $field (@{$changes{'helpform'}}) {
10889: if ($field eq 'maxsize') {
10890: $maxsizechg = 1;
10891: next;
10892: }
10893: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 10894: push(@optional,$field);
1.286 raeburn 10895: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
10896: push(@unused,$field);
10897: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 10898: push(@required,$field);
1.286 raeburn 10899: }
10900: }
10901: if (@optional) {
10902: $resulttext .= '<li>'.
10903: &mt('Help form fields changed to "Optional": [_1].',
10904: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
10905: '</li>';
10906: }
10907: if (@required) {
10908: $resulttext .= '<li>'.
10909: &mt('Help form fields changed to "Required": [_1].',
10910: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
10911: '</li>';
10912: }
10913: if (@unused) {
10914: $resulttext .= '<li>'.
10915: &mt('Help form fields changed to "Not shown": [_1].',
10916: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
10917: '</li>';
10918: }
10919: if ($maxsizechg) {
10920: $resulttext .= '<li>'.
10921: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
10922: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
10923: '</li>';
10924:
10925: }
10926: }
1.28 raeburn 10927: $resulttext .= '</ul>';
10928: } else {
1.288 raeburn 10929: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 10930: }
10931: } else {
10932: $resulttext = '<span class="LC_error">'.
10933: &mt('An error occurred: [_1].',$putresult).'</span>';
10934: }
10935: return $resulttext;
10936: }
10937:
10938: sub modify_usercreation {
1.27 raeburn 10939: my ($dom,%domconfig) = @_;
1.224 raeburn 10940: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 10941: my $warningmsg;
1.27 raeburn 10942: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10943: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 10944: if ($key eq 'cancreate') {
10945: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10946: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10947: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269 raeburn 10948: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
10949: ($item eq 'recaptchaversion')) {
1.224 raeburn 10950: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10951: } else {
10952: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10953: }
10954: }
10955: }
10956: } elsif ($key eq 'email_rule') {
10957: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10958: } else {
10959: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10960: }
1.27 raeburn 10961: }
10962: }
10963: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 10964: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 10965: my @contexts = ('author','course','requestcrs');
1.34 raeburn 10966: foreach my $item(@contexts) {
1.224 raeburn 10967: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 10968: }
1.34 raeburn 10969: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10970: foreach my $item (@contexts) {
1.224 raeburn 10971: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
10972: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 10973: }
1.27 raeburn 10974: }
1.34 raeburn 10975: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
10976: foreach my $item (@contexts) {
1.43 raeburn 10977: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 10978: if ($cancreate{$item} ne 'any') {
10979: push(@{$changes{'cancreate'}},$item);
10980: }
10981: } else {
10982: if ($cancreate{$item} ne 'none') {
10983: push(@{$changes{'cancreate'}},$item);
10984: }
1.27 raeburn 10985: }
10986: }
10987: } else {
1.43 raeburn 10988: foreach my $item (@contexts) {
1.34 raeburn 10989: push(@{$changes{'cancreate'}},$item);
10990: }
1.27 raeburn 10991: }
1.34 raeburn 10992:
1.27 raeburn 10993: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
10994: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
10995: if (!grep(/^\Q$type\E$/,@username_rule)) {
10996: push(@{$changes{'username_rule'}},$type);
10997: }
10998: }
10999: foreach my $type (@username_rule) {
11000: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
11001: push(@{$changes{'username_rule'}},$type);
11002: }
11003: }
11004: } else {
11005: push(@{$changes{'username_rule'}},@username_rule);
11006: }
11007:
1.32 raeburn 11008: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
11009: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
11010: if (!grep(/^\Q$type\E$/,@id_rule)) {
11011: push(@{$changes{'id_rule'}},$type);
11012: }
11013: }
11014: foreach my $type (@id_rule) {
11015: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
11016: push(@{$changes{'id_rule'}},$type);
11017: }
11018: }
11019: } else {
11020: push(@{$changes{'id_rule'}},@id_rule);
11021: }
11022:
1.43 raeburn 11023: my @authen_contexts = ('author','course','domain');
1.28 raeburn 11024: my @authtypes = ('int','krb4','krb5','loc');
11025: my %authhash;
1.43 raeburn 11026: foreach my $item (@authen_contexts) {
1.28 raeburn 11027: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
11028: foreach my $auth (@authtypes) {
11029: if (grep(/^\Q$auth\E$/,@authallowed)) {
11030: $authhash{$item}{$auth} = 1;
11031: } else {
11032: $authhash{$item}{$auth} = 0;
11033: }
11034: }
11035: }
11036: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 11037: foreach my $item (@authen_contexts) {
1.28 raeburn 11038: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
11039: foreach my $auth (@authtypes) {
11040: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
11041: push(@{$changes{'authtypes'}},$item);
11042: last;
11043: }
11044: }
11045: }
11046: }
11047: } else {
1.43 raeburn 11048: foreach my $item (@authen_contexts) {
1.28 raeburn 11049: push(@{$changes{'authtypes'}},$item);
11050: }
11051: }
11052:
1.224 raeburn 11053: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
11054: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
11055: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
11056: $save_usercreate{'id_rule'} = \@id_rule;
11057: $save_usercreate{'username_rule'} = \@username_rule,
11058: $save_usercreate{'authtypes'} = \%authhash;
11059:
1.27 raeburn 11060: my %usercreation_hash = (
1.224 raeburn 11061: usercreation => \%save_usercreate,
11062: );
1.27 raeburn 11063:
11064: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
11065: $dom);
1.50 raeburn 11066:
1.224 raeburn 11067: if ($putresult eq 'ok') {
11068: if (keys(%changes) > 0) {
11069: $resulttext = &mt('Changes made:').'<ul>';
11070: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11071: my %lt = &usercreation_types();
11072: foreach my $type (@{$changes{'cancreate'}}) {
11073: my $chgtext = $lt{$type}.', ';
11074: if ($cancreate{$type} eq 'none') {
11075: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
11076: } elsif ($cancreate{$type} eq 'any') {
11077: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
11078: } elsif ($cancreate{$type} eq 'official') {
11079: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
11080: } elsif ($cancreate{$type} eq 'unofficial') {
11081: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
11082: }
11083: $resulttext .= '<li>'.$chgtext.'</li>';
11084: }
11085: }
11086: if (ref($changes{'username_rule'}) eq 'ARRAY') {
11087: my ($rules,$ruleorder) =
11088: &Apache::lonnet::inst_userrules($dom,'username');
11089: my $chgtext = '<ul>';
11090: foreach my $type (@username_rule) {
11091: if (ref($rules->{$type}) eq 'HASH') {
11092: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
11093: }
11094: }
11095: $chgtext .= '</ul>';
11096: if (@username_rule > 0) {
11097: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11098: } else {
11099: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
11100: }
11101: }
11102: if (ref($changes{'id_rule'}) eq 'ARRAY') {
11103: my ($idrules,$idruleorder) =
11104: &Apache::lonnet::inst_userrules($dom,'id');
11105: my $chgtext = '<ul>';
11106: foreach my $type (@id_rule) {
11107: if (ref($idrules->{$type}) eq 'HASH') {
11108: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
11109: }
11110: }
11111: $chgtext .= '</ul>';
11112: if (@id_rule > 0) {
11113: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11114: } else {
11115: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
11116: }
11117: }
11118: my %authname = &authtype_names();
11119: my %context_title = &context_names();
11120: if (ref($changes{'authtypes'}) eq 'ARRAY') {
11121: my $chgtext = '<ul>';
11122: foreach my $type (@{$changes{'authtypes'}}) {
11123: my @allowed;
11124: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
11125: foreach my $auth (@authtypes) {
11126: if ($authhash{$type}{$auth}) {
11127: push(@allowed,$authname{$auth});
11128: }
11129: }
11130: if (@allowed > 0) {
11131: $chgtext .= join(', ',@allowed).'</li>';
11132: } else {
11133: $chgtext .= &mt('none').'</li>';
11134: }
11135: }
11136: $chgtext .= '</ul>';
11137: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
11138: $resulttext .= '</li>';
11139: }
11140: $resulttext .= '</ul>';
11141: } else {
11142: $resulttext = &mt('No changes made to user creation settings');
11143: }
11144: } else {
11145: $resulttext = '<span class="LC_error">'.
11146: &mt('An error occurred: [_1]',$putresult).'</span>';
11147: }
11148: if ($warningmsg ne '') {
11149: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11150: }
11151: return $resulttext;
11152: }
11153:
11154: sub modify_selfcreation {
11155: my ($dom,%domconfig) = @_;
11156: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
11157: my (%save_usercreate,%save_usermodify);
1.228 raeburn 11158: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11159: if (ref($types) eq 'ARRAY') {
11160: $usertypes->{'default'} = $othertitle;
11161: push(@{$types},'default');
11162: }
1.224 raeburn 11163: #
11164: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
11165: #
11166: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11167: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11168: if ($key eq 'cancreate') {
11169: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11170: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11171: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
11172: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.269 raeburn 11173: ($item eq 'recaptchaversion') ||
1.236 raeburn 11174: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 11175: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 11176: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11177: } else {
11178: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11179: }
11180: }
11181: }
11182: } elsif ($key eq 'email_rule') {
11183: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11184: } else {
11185: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11186: }
11187: }
11188: }
11189: #
11190: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
11191: #
11192: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11193: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11194: if ($key eq 'selfcreate') {
11195: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
11196: } else {
11197: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
11198: }
11199: }
11200: }
11201:
11202: my @contexts = ('selfcreate');
11203: @{$cancreate{'selfcreate'}} = ();
11204: %{$cancreate{'emailusername'}} = ();
11205: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 11206: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 11207: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 11208: my %selfcreatetypes = (
11209: sso => 'users authenticated by institutional single sign on',
11210: login => 'users authenticated by institutional log-in',
1.236 raeburn 11211: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 11212: );
1.224 raeburn 11213: #
11214: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
11215: # is permitted.
11216: #
1.236 raeburn 11217:
11218: my @statuses;
11219: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11220: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
11221: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
11222: }
11223: }
11224: push(@statuses,'default');
11225:
1.228 raeburn 11226: foreach my $item ('login','sso','email') {
1.224 raeburn 11227: if ($item eq 'email') {
1.236 raeburn 11228: if ($env{'form.cancreate_email'}) {
1.224 raeburn 11229: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 11230: push(@contexts,'selfcreateprocessing');
11231: foreach my $type (@statuses) {
11232: if ($type eq 'default') {
11233: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
11234: } else {
11235: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
11236: }
11237: }
1.224 raeburn 11238: }
11239: } else {
11240: if ($env{'form.cancreate_'.$item}) {
11241: push(@{$cancreate{'selfcreate'}},$item);
11242: }
11243: }
11244: }
11245: my (@email_rule,%userinfo,%savecaptcha);
11246: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
11247: #
1.228 raeburn 11248: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
11249: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 11250: #
1.236 raeburn 11251:
1.244 raeburn 11252: if ($env{'form.cancreate_email'}) {
1.228 raeburn 11253: push(@contexts,'emailusername');
11254: if (ref($types) eq 'ARRAY') {
11255: foreach my $type (@{$types}) {
11256: if (ref($infofields) eq 'ARRAY') {
11257: foreach my $field (@{$infofields}) {
11258: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
11259: $cancreate{'emailusername'}{$type}{$field} = $1;
11260: }
11261: }
1.224 raeburn 11262: }
11263: }
11264: }
11265: #
11266: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
11267: # queued requests for self-creation of account using e-mail address as username
11268: #
11269:
11270: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
11271: @approvalnotify = sort(@approvalnotify);
11272: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
11273: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11274: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11275: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11276: push(@{$changes{'cancreate'}},'notify');
11277: }
11278: } else {
11279: if ($cancreate{'notify'}{'approval'}) {
11280: push(@{$changes{'cancreate'}},'notify');
11281: }
11282: }
11283: } elsif ($cancreate{'notify'}{'approval'}) {
11284: push(@{$changes{'cancreate'}},'notify');
11285: }
11286:
11287: #
11288: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
11289: #
11290: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
11291: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11292: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11293: if (@{$curr_usercreation{'email_rule'}} > 0) {
11294: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
11295: if (!grep(/^\Q$type\E$/,@email_rule)) {
11296: push(@{$changes{'email_rule'}},$type);
11297: }
11298: }
11299: }
11300: if (@email_rule > 0) {
11301: foreach my $type (@email_rule) {
11302: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
11303: push(@{$changes{'email_rule'}},$type);
11304: }
11305: }
11306: }
11307: } elsif (@email_rule > 0) {
11308: push(@{$changes{'email_rule'}},@email_rule);
11309: }
11310: }
11311: #
1.236 raeburn 11312: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 11313: # institutional log-in.
11314: #
11315: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11316: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11317: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11318: ($domdefaults{'auth_def'} eq 'localauth'))) {
11319: $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.').' '.
11320: &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.');
11321: }
11322: }
11323: my @fields = ('lastname','firstname','middlename','generation',
11324: 'permanentemail','id');
1.240 raeburn 11325: my @shibfields = (@fields,'inststatus');
1.224 raeburn 11326: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11327: #
11328: # Where usernames may created for institutional log-in and/or institutional single sign on:
11329: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11330: # may self-create accounts
11331: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11332: # which the user may supply, if institutional data is unavailable.
11333: #
11334: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
11335: if (ref($types) eq 'ARRAY') {
1.228 raeburn 11336: if (@{$types} > 1) {
1.224 raeburn 11337: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11338: push(@contexts,'statustocreate');
11339: } else {
11340: undef($cancreate{'statustocreate'});
11341: }
11342: foreach my $type (@{$types}) {
11343: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11344: foreach my $field (@fields) {
11345: if (grep(/^\Q$field\E$/,@modifiable)) {
11346: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11347: } else {
11348: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11349: }
11350: }
11351: }
11352: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
11353: foreach my $type (@{$types}) {
11354: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11355: foreach my $field (@fields) {
11356: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11357: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11358: push(@{$changes{'selfcreate'}},$type);
11359: last;
11360: }
11361: }
11362: }
11363: }
11364: } else {
11365: foreach my $type (@{$types}) {
11366: push(@{$changes{'selfcreate'}},$type);
11367: }
11368: }
11369: }
1.240 raeburn 11370: foreach my $field (@shibfields) {
11371: if ($env{'form.shibenv_'.$field} ne '') {
11372: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11373: }
11374: }
11375: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11376: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11377: foreach my $field (@shibfields) {
11378: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11379: push(@{$changes{'cancreate'}},'shibenv');
11380: }
11381: }
11382: } else {
11383: foreach my $field (@shibfields) {
11384: if ($env{'form.shibenv_'.$field}) {
11385: push(@{$changes{'cancreate'}},'shibenv');
11386: last;
11387: }
11388: }
11389: }
11390: }
1.224 raeburn 11391: }
11392: foreach my $item (@contexts) {
11393: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11394: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11395: if (ref($cancreate{$item}) eq 'ARRAY') {
11396: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11397: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11398: push(@{$changes{'cancreate'}},$item);
11399: }
11400: }
11401: }
11402: }
11403: if (ref($cancreate{$item}) eq 'ARRAY') {
11404: foreach my $type (@{$cancreate{$item}}) {
11405: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11406: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11407: push(@{$changes{'cancreate'}},$item);
11408: }
11409: }
11410: }
11411: }
11412: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11413: if (ref($cancreate{$item}) eq 'HASH') {
11414: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 11415: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
11416: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
11417: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
11418: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11419: push(@{$changes{'cancreate'}},$item);
11420: }
11421: }
11422: }
1.236 raeburn 11423: } elsif ($item eq 'selfcreateprocessing') {
11424: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
11425: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11426: push(@{$changes{'cancreate'}},$item);
11427: }
11428: }
1.228 raeburn 11429: } else {
11430: if (!$cancreate{$item}{$curr}) {
11431: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11432: push(@{$changes{'cancreate'}},$item);
11433: }
1.224 raeburn 11434: }
11435: }
11436: }
11437: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 11438: if (ref($cancreate{$item}{$field}) eq 'HASH') {
11439: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
11440: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
11441: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
11442: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11443: push(@{$changes{'cancreate'}},$item);
11444: }
11445: }
11446: } else {
11447: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11448: push(@{$changes{'cancreate'}},$item);
11449: }
11450: }
11451: }
1.236 raeburn 11452: } elsif ($item eq 'selfcreateprocessing') {
11453: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
11454: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11455: push(@{$changes{'cancreate'}},$item);
11456: }
11457: }
1.228 raeburn 11458: } else {
11459: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
11460: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11461: push(@{$changes{'cancreate'}},$item);
11462: }
1.224 raeburn 11463: }
11464: }
11465: }
11466: }
11467: } elsif ($curr_usercreation{'cancreate'}{$item}) {
11468: if (ref($cancreate{$item}) eq 'ARRAY') {
11469: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
11470: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11471: push(@{$changes{'cancreate'}},$item);
11472: }
11473: }
11474: } elsif (ref($cancreate{$item}) eq 'HASH') {
11475: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
11476: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11477: push(@{$changes{'cancreate'}},$item);
11478: }
11479: }
11480: }
11481: } elsif ($item eq 'emailusername') {
1.228 raeburn 11482: if (ref($cancreate{$item}) eq 'HASH') {
11483: foreach my $type (keys(%{$cancreate{$item}})) {
11484: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11485: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11486: if ($cancreate{$item}{$type}{$field}) {
11487: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11488: push(@{$changes{'cancreate'}},$item);
11489: }
11490: last;
11491: }
11492: }
11493: }
11494: }
1.224 raeburn 11495: }
11496: }
11497: }
11498: #
11499: # Populate %save_usercreate hash with updates to self-creation configuration.
11500: #
11501: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
11502: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 11503: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 11504: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
11505: if (ref($cancreate{'notify'}) eq 'HASH') {
11506: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
11507: }
1.236 raeburn 11508: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
11509: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
11510: }
1.224 raeburn 11511: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11512: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
11513: }
1.240 raeburn 11514: if (ref($cancreate{'shibenv'}) eq 'HASH') {
11515: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
11516: }
1.224 raeburn 11517: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
11518: $save_usercreate{'emailrule'} = \@email_rule;
11519:
11520: my %userconfig_hash = (
11521: usercreation => \%save_usercreate,
11522: usermodification => \%save_usermodify,
11523: );
11524: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
11525: $dom);
11526: #
11527: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
11528: #
1.27 raeburn 11529: if ($putresult eq 'ok') {
11530: if (keys(%changes) > 0) {
11531: $resulttext = &mt('Changes made:').'<ul>';
11532: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 11533: my %lt = &selfcreation_types();
1.34 raeburn 11534: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 11535: my $chgtext;
1.45 raeburn 11536: if ($type eq 'selfcreate') {
1.50 raeburn 11537: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 11538: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 11539: } else {
1.224 raeburn 11540: $chgtext .= &mt('Self-creation of a new account is permitted for:').
11541: '<ul>';
1.50 raeburn 11542: foreach my $case (@{$cancreate{$type}}) {
11543: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
11544: }
11545: $chgtext .= '</ul>';
1.100 raeburn 11546: if (ref($cancreate{$type}) eq 'ARRAY') {
11547: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
11548: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11549: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 11550: $chgtext .= '<br />'.
11551: '<span class="LC_warning">'.
11552: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11553: '</span>';
1.100 raeburn 11554: }
11555: }
11556: }
11557: }
1.43 raeburn 11558: }
1.240 raeburn 11559: } elsif ($type eq 'shibenv') {
11560: if (keys(%{$cancreate{$type}}) == 0) {
11561: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
11562: } else {
11563: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
11564: '<ul>';
11565: foreach my $field (@shibfields) {
11566: next if ($cancreate{$type}{$field} eq '');
11567: if ($field eq 'inststatus') {
11568: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
11569: } else {
11570: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
11571: }
11572: }
11573: $chgtext .= '</ul>';
11574: }
1.93 raeburn 11575: } elsif ($type eq 'statustocreate') {
1.96 raeburn 11576: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
11577: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
11578: if (@{$cancreate{'selfcreate'}} > 0) {
11579: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 11580: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 11581: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 11582: $chgtext .= '<br />'.
11583: '<span class="LC_warning">'.
11584: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11585: '</span>';
11586: }
1.96 raeburn 11587: } elsif (ref($usertypes) eq 'HASH') {
11588: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 11589: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
11590: } else {
11591: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
11592: }
11593: $chgtext .= '<ul>';
11594: foreach my $case (@{$cancreate{$type}}) {
11595: if ($case eq 'default') {
11596: $chgtext .= '<li>'.$othertitle.'</li>';
11597: } else {
11598: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 11599: }
11600: }
1.100 raeburn 11601: $chgtext .= '</ul>';
11602: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 11603: $chgtext .= '<br /><span class="LC_warning">'.
11604: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
11605: '</span>';
1.100 raeburn 11606: }
11607: }
11608: } else {
11609: if (@{$cancreate{$type}} == 0) {
11610: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
11611: } else {
11612: $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 11613: }
11614: }
11615: }
1.236 raeburn 11616: } elsif ($type eq 'selfcreateprocessing') {
11617: my %choices = &Apache::lonlocal::texthash (
11618: automatic => 'Automatic approval',
11619: approval => 'Queued for approval',
11620: );
11621: if (@statuses > 1) {
11622: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
11623: '<ul>';
11624: foreach my $type (@statuses) {
11625: if ($type eq 'default') {
11626: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11627: } else {
11628: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11629: }
11630: }
11631: $chgtext .= '</ul>';
11632: } else {
11633: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
11634: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
11635: }
1.165 raeburn 11636: } elsif ($type eq 'captcha') {
1.224 raeburn 11637: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 11638: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
11639: } else {
11640: my %captchas = &captcha_phrases();
1.224 raeburn 11641: if ($captchas{$savecaptcha{$type}}) {
11642: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 11643: } else {
1.210 raeburn 11644: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 11645: }
11646: }
11647: } elsif ($type eq 'recaptchakeys') {
11648: my ($privkey,$pubkey);
1.224 raeburn 11649: if (ref($savecaptcha{$type}) eq 'HASH') {
11650: $pubkey = $savecaptcha{$type}{'public'};
11651: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 11652: }
11653: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
11654: if (!$pubkey) {
11655: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
11656: } else {
11657: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11658: }
11659: if (!$privkey) {
11660: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
11661: } else {
11662: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
11663: }
11664: $chgtext .= '</ul>';
1.269 raeburn 11665: } elsif ($type eq 'recaptchaversion') {
11666: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 11667: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 11668: }
1.224 raeburn 11669: } elsif ($type eq 'emailusername') {
11670: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 11671: if (ref($types) eq 'ARRAY') {
11672: foreach my $type (@{$types}) {
11673: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
11674: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 11675: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 11676: '<ul>';
11677: foreach my $field (@{$infofields}) {
11678: if ($cancreate{'emailusername'}{$type}{$field}) {
11679: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
11680: }
11681: }
1.245 raeburn 11682: $chgtext .= '</ul>';
11683: } else {
11684: $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 11685: }
11686: } else {
1.245 raeburn 11687: $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 11688: }
11689: }
11690: }
11691: }
11692: } elsif ($type eq 'notify') {
11693: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
11694: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11695: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
11696: if ($cancreate{'notify'}{'approval'}) {
11697: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
11698: }
11699: }
1.43 raeburn 11700: }
1.34 raeburn 11701: }
1.224 raeburn 11702: if ($chgtext) {
11703: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 11704: }
11705: }
11706: }
1.43 raeburn 11707: if (ref($changes{'email_rule'}) eq 'ARRAY') {
11708: my ($emailrules,$emailruleorder) =
11709: &Apache::lonnet::inst_userrules($dom,'email');
11710: my $chgtext = '<ul>';
11711: foreach my $type (@email_rule) {
11712: if (ref($emailrules->{$type}) eq 'HASH') {
11713: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
11714: }
11715: }
11716: $chgtext .= '</ul>';
11717: if (@email_rule > 0) {
1.224 raeburn 11718: $resulttext .= '<li>'.
11719: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
11720: $chgtext.
11721: '</li>';
1.43 raeburn 11722: } else {
1.224 raeburn 11723: $resulttext .= '<li>'.
11724: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
11725: '</li>';
1.43 raeburn 11726: }
11727: }
1.224 raeburn 11728: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
11729: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
11730: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11731: foreach my $type (@{$changes{'selfcreate'}}) {
11732: my $typename = $type;
11733: if (ref($usertypes) eq 'HASH') {
11734: if ($usertypes->{$type} ne '') {
11735: $typename = $usertypes->{$type};
11736: }
11737: }
11738: my @modifiable;
11739: $resulttext .= '<li>'.
11740: &mt('Self-creation of account by users with status: [_1]',
11741: '<span class="LC_cusr_emph">'.$typename.'</span>').
11742: ' - '.&mt('modifiable fields (if institutional data blank): ');
11743: foreach my $field (@fields) {
11744: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
11745: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 11746: }
11747: }
1.224 raeburn 11748: if (@modifiable > 0) {
11749: $resulttext .= join(', ',@modifiable);
1.43 raeburn 11750: } else {
1.224 raeburn 11751: $resulttext .= &mt('none');
1.43 raeburn 11752: }
1.224 raeburn 11753: $resulttext .= '</li>';
1.28 raeburn 11754: }
1.224 raeburn 11755: $resulttext .= '</ul></li>';
1.28 raeburn 11756: }
1.27 raeburn 11757: $resulttext .= '</ul>';
11758: } else {
1.224 raeburn 11759: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 11760: }
11761: } else {
11762: $resulttext = '<span class="LC_error">'.
1.23 raeburn 11763: &mt('An error occurred: [_1]',$putresult).'</span>';
11764: }
1.43 raeburn 11765: if ($warningmsg ne '') {
11766: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11767: }
1.23 raeburn 11768: return $resulttext;
11769: }
11770:
1.165 raeburn 11771: sub process_captcha {
11772: my ($container,$changes,$newsettings,$current) = @_;
11773: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
11774: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
11775: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
11776: $newsettings->{'captcha'} = 'original';
11777: }
11778: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 11779: if ($container eq 'cancreate') {
1.169 raeburn 11780: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11781: push(@{$changes->{'cancreate'}},'captcha');
11782: } elsif (!defined($changes->{'cancreate'})) {
11783: $changes->{'cancreate'} = ['captcha'];
11784: }
11785: } else {
11786: $changes->{'captcha'} = 1;
1.165 raeburn 11787: }
11788: }
1.269 raeburn 11789: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 11790: if ($newsettings->{'captcha'} eq 'recaptcha') {
11791: $newpub = $env{'form.'.$container.'_recaptchapub'};
11792: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 11793: $newpub =~ s/[^\w\-]//g;
11794: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 11795: $newsettings->{'recaptchakeys'} = {
11796: public => $newpub,
11797: private => $newpriv,
11798: };
1.269 raeburn 11799: $newversion = $env{'form.'.$container.'_recaptchaversion'};
11800: $newversion =~ s/\D//g;
11801: if ($newversion ne '2') {
11802: $newversion = 1;
11803: }
11804: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 11805: }
11806: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
11807: $currpub = $current->{'recaptchakeys'}{'public'};
11808: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 11809: unless ($newsettings->{'captcha'} eq 'recaptcha') {
11810: $newsettings->{'recaptchakeys'} = {
11811: public => '',
11812: private => '',
11813: }
11814: }
1.165 raeburn 11815: }
1.269 raeburn 11816: if ($current->{'captcha'} eq 'recaptcha') {
11817: $currversion = $current->{'recaptchaversion'};
11818: if ($currversion ne '2') {
11819: $currversion = 1;
11820: }
11821: }
11822: if ($currversion ne $newversion) {
11823: if ($container eq 'cancreate') {
11824: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11825: push(@{$changes->{'cancreate'}},'recaptchaversion');
11826: } elsif (!defined($changes->{'cancreate'})) {
11827: $changes->{'cancreate'} = ['recaptchaversion'];
11828: }
11829: } else {
11830: $changes->{'recaptchaversion'} = 1;
11831: }
11832: }
1.165 raeburn 11833: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 11834: if ($container eq 'cancreate') {
11835: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11836: push(@{$changes->{'cancreate'}},'recaptchakeys');
11837: } elsif (!defined($changes->{'cancreate'})) {
11838: $changes->{'cancreate'} = ['recaptchakeys'];
11839: }
11840: } else {
1.210 raeburn 11841: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 11842: }
11843: }
11844: return;
11845: }
11846:
1.33 raeburn 11847: sub modify_usermodification {
11848: my ($dom,%domconfig) = @_;
1.224 raeburn 11849: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 11850: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11851: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 11852: if ($key eq 'selfcreate') {
11853: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
11854: } else {
11855: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
11856: }
1.33 raeburn 11857: }
11858: }
1.224 raeburn 11859: my @contexts = ('author','course');
1.33 raeburn 11860: my %context_title = (
11861: author => 'In author context',
11862: course => 'In course context',
11863: );
11864: my @fields = ('lastname','firstname','middlename','generation',
11865: 'permanentemail','id');
11866: my %roles = (
11867: author => ['ca','aa'],
11868: course => ['st','ep','ta','in','cr'],
11869: );
11870: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11871: foreach my $context (@contexts) {
11872: foreach my $role (@{$roles{$context}}) {
11873: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
11874: foreach my $item (@fields) {
11875: if (grep(/^\Q$item\E$/,@modifiable)) {
11876: $modifyhash{$context}{$role}{$item} = 1;
11877: } else {
11878: $modifyhash{$context}{$role}{$item} = 0;
11879: }
11880: }
11881: }
11882: if (ref($curr_usermodification{$context}) eq 'HASH') {
11883: foreach my $role (@{$roles{$context}}) {
11884: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
11885: foreach my $field (@fields) {
11886: if ($modifyhash{$context}{$role}{$field} ne
11887: $curr_usermodification{$context}{$role}{$field}) {
11888: push(@{$changes{$context}},$role);
11889: last;
11890: }
11891: }
11892: }
11893: }
11894: } else {
11895: foreach my $context (@contexts) {
11896: foreach my $role (@{$roles{$context}}) {
11897: push(@{$changes{$context}},$role);
11898: }
11899: }
11900: }
11901: }
11902: my %usermodification_hash = (
11903: usermodification => \%modifyhash,
11904: );
11905: my $putresult = &Apache::lonnet::put_dom('configuration',
11906: \%usermodification_hash,$dom);
11907: if ($putresult eq 'ok') {
11908: if (keys(%changes) > 0) {
11909: $resulttext = &mt('Changes made: ').'<ul>';
11910: foreach my $context (@contexts) {
11911: if (ref($changes{$context}) eq 'ARRAY') {
11912: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
11913: if (ref($changes{$context}) eq 'ARRAY') {
11914: foreach my $role (@{$changes{$context}}) {
11915: my $rolename;
1.224 raeburn 11916: if ($role eq 'cr') {
11917: $rolename = &mt('Custom');
1.33 raeburn 11918: } else {
1.224 raeburn 11919: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 11920: }
11921: my @modifiable;
1.224 raeburn 11922: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 11923: foreach my $field (@fields) {
11924: if ($modifyhash{$context}{$role}{$field}) {
11925: push(@modifiable,$fieldtitles{$field});
11926: }
11927: }
11928: if (@modifiable > 0) {
11929: $resulttext .= join(', ',@modifiable);
11930: } else {
11931: $resulttext .= &mt('none');
11932: }
11933: $resulttext .= '</li>';
11934: }
11935: $resulttext .= '</ul></li>';
11936: }
11937: }
11938: }
11939: $resulttext .= '</ul>';
11940: } else {
11941: $resulttext = &mt('No changes made to user modification settings');
11942: }
11943: } else {
11944: $resulttext = '<span class="LC_error">'.
11945: &mt('An error occurred: [_1]',$putresult).'</span>';
11946: }
11947: return $resulttext;
11948: }
11949:
1.43 raeburn 11950: sub modify_defaults {
1.212 raeburn 11951: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 11952: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 11953: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 11954: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
11955: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 11956: my @authtypes = ('internal','krb4','krb5','localauth');
11957: foreach my $item (@items) {
11958: $newvalues{$item} = $env{'form.'.$item};
11959: if ($item eq 'auth_def') {
11960: if ($newvalues{$item} ne '') {
11961: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
11962: push(@errors,$item);
11963: }
11964: }
11965: } elsif ($item eq 'lang_def') {
11966: if ($newvalues{$item} ne '') {
11967: if ($newvalues{$item} =~ /^(\w+)/) {
11968: my $langcode = $1;
1.103 raeburn 11969: if ($langcode ne 'x_chef') {
11970: if (code2language($langcode) eq '') {
11971: push(@errors,$item);
11972: }
1.43 raeburn 11973: }
11974: } else {
11975: push(@errors,$item);
11976: }
11977: }
1.54 raeburn 11978: } elsif ($item eq 'timezone_def') {
11979: if ($newvalues{$item} ne '') {
1.62 raeburn 11980: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 11981: push(@errors,$item);
11982: }
11983: }
1.68 raeburn 11984: } elsif ($item eq 'datelocale_def') {
11985: if ($newvalues{$item} ne '') {
11986: my @datelocale_ids = DateTime::Locale->ids();
11987: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
11988: push(@errors,$item);
11989: }
11990: }
1.141 raeburn 11991: } elsif ($item eq 'portal_def') {
11992: if ($newvalues{$item} ne '') {
11993: 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])\/?$/) {
11994: push(@errors,$item);
11995: }
11996: }
1.294 raeburn 11997: } elsif ($item eq 'intauth_cost') {
11998: if ($newvalues{$item} ne '') {
11999: if ($newvalues{$item} =~ /\D/) {
12000: push(@errors,$item);
12001: }
12002: }
12003: } elsif ($item eq 'intauth_check') {
12004: if ($newvalues{$item} ne '') {
12005: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
12006: push(@errors,$item);
12007: }
12008: }
12009: } elsif ($item eq 'intauth_switch') {
12010: if ($newvalues{$item} ne '') {
12011: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
12012: push(@errors,$item);
12013: }
12014: }
1.43 raeburn 12015: }
12016: if (grep(/^\Q$item\E$/,@errors)) {
12017: $newvalues{$item} = $domdefaults{$item};
12018: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
12019: $changes{$item} = 1;
12020: }
1.72 raeburn 12021: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 12022: }
12023: my %defaults_hash = (
1.72 raeburn 12024: defaults => \%newvalues,
12025: );
1.43 raeburn 12026: my $title = &defaults_titles();
1.236 raeburn 12027:
12028: my $currinststatus;
12029: if (ref($domconfig{'inststatus'}) eq 'HASH') {
12030: $currinststatus = $domconfig{'inststatus'};
12031: } else {
12032: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12033: $currinststatus = {
12034: inststatustypes => $usertypes,
12035: inststatusorder => $types,
12036: inststatusguest => [],
12037: };
12038: }
12039: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
12040: my @allpos;
12041: my %guests;
12042: my %alltypes;
12043: my ($currtitles,$currguests,$currorder);
12044: if (ref($currinststatus) eq 'HASH') {
12045: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
12046: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
12047: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
12048: if ($currinststatus->{inststatustypes}->{$type} ne '') {
12049: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
12050: }
12051: }
12052: unless (grep(/^\Q$type\E$/,@todelete)) {
12053: my $position = $env{'form.inststatus_pos_'.$type};
12054: $position =~ s/\D+//g;
12055: $allpos[$position] = $type;
12056: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
12057: $alltypes{$type} =~ s/`//g;
12058: if ($env{'form.inststatus_guest_'.$type}) {
12059: $guests{$type} = 1;
12060: }
12061: }
12062: }
12063: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
12064: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
12065: }
12066: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
12067: $currtitles =~ s/,$//;
12068: }
12069: }
12070: if ($env{'form.addinststatus'}) {
12071: my $newtype = $env{'form.addinststatus'};
12072: $newtype =~ s/\W//g;
12073: unless (exists($alltypes{$newtype})) {
12074: if ($env{'form.addinststatus_guest'}) {
12075: $guests{$newtype} = 1;
12076: }
12077: $alltypes{$newtype} = $env{'form.addinststatus_title'};
12078: $alltypes{$newtype} =~ s/`//g;
12079: my $position = $env{'form.addinststatus_pos'};
12080: $position =~ s/\D+//g;
12081: if ($position ne '') {
12082: $allpos[$position] = $newtype;
12083: }
12084: }
12085: }
12086: my (@orderedstatus,@orderedguests);
12087: foreach my $type (@allpos) {
12088: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
12089: push(@orderedstatus,$type);
12090: if ($guests{$type}) {
12091: push(@orderedguests,$type);
12092: }
12093: }
12094: }
12095: foreach my $type (keys(%alltypes)) {
12096: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
12097: delete($alltypes{$type});
12098: }
12099: }
12100: $defaults_hash{'inststatus'} = {
12101: inststatustypes => \%alltypes,
12102: inststatusorder => \@orderedstatus,
12103: inststatusguest => \@orderedguests,
12104: };
12105: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
12106: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
12107: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
12108: }
12109: }
12110: if ($currorder ne join(',',@orderedstatus)) {
12111: $changes{'inststatus'}{'inststatusorder'} = 1;
12112: }
12113: if ($currguests ne join(',',@orderedguests)) {
12114: $changes{'inststatus'}{'inststatusguest'} = 1;
12115: }
12116: my $newtitles;
12117: foreach my $item (@orderedstatus) {
12118: $newtitles .= $alltypes{$item}.',';
12119: }
12120: $newtitles =~ s/,$//;
12121: if ($currtitles ne $newtitles) {
12122: $changes{'inststatus'}{'inststatustypes'} = 1;
12123: }
1.43 raeburn 12124: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
12125: $dom);
12126: if ($putresult eq 'ok') {
12127: if (keys(%changes) > 0) {
12128: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 12129: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 12130: 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";
12131: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 12132: if ($item eq 'inststatus') {
12133: if (ref($changes{'inststatus'}) eq 'HASH') {
12134: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
12135: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
12136: foreach my $type (@orderedstatus) {
12137: $resulttext .= $alltypes{$type}.', ';
12138: }
12139: $resulttext =~ s/, $//;
12140: $resulttext .= '</li>';
12141: }
12142: if ($changes{'inststatus'}{'inststatusguest'}) {
12143: $resulttext .= '<li>';
12144: if (@orderedguests) {
12145: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
12146: foreach my $type (@orderedguests) {
12147: $resulttext .= $alltypes{$type}.', ';
12148: }
12149: $resulttext =~ s/, $//;
12150: } else {
12151: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
12152: }
12153: $resulttext .= '</li>';
12154: }
12155: }
12156: } else {
12157: my $value = $env{'form.'.$item};
12158: if ($value eq '') {
12159: $value = &mt('none');
12160: } elsif ($item eq 'auth_def') {
12161: my %authnames = &authtype_names();
12162: my %shortauth = (
12163: internal => 'int',
12164: krb4 => 'krb4',
12165: krb5 => 'krb5',
12166: localauth => 'loc',
12167: );
12168: $value = $authnames{$shortauth{$value}};
1.294 raeburn 12169: } elsif ($item eq 'intauth_switch') {
12170: my %optiondesc = &Apache::lonlocal::texthash (
12171: 0 => 'No',
12172: 1 => 'Yes',
12173: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
12174: );
12175: if ($value =~ /^(0|1|2)$/) {
12176: $value = $optiondesc{$value};
12177: } else {
12178: $value = &mt('none -- defaults to No');
12179: }
12180: } elsif ($item eq 'intauth_check') {
12181: my %optiondesc = &Apache::lonlocal::texthash (
12182: 0 => 'No',
12183: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
12184: 2 => 'Yes, disallow login if stored cost is less than domain default',
12185: );
12186: if ($value =~ /^(0|1|2)$/) {
12187: $value = $optiondesc{$value};
12188: } else {
12189: $value = &mt('none -- defaults to No');
12190: }
1.236 raeburn 12191: }
12192: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
12193: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 12194: }
12195: }
12196: $resulttext .= '</ul>';
12197: $mailmsgtext .= "\n";
12198: my $cachetime = 24*60*60;
1.72 raeburn 12199: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12200: if (ref($lastactref) eq 'HASH') {
12201: $lastactref->{'domdefaults'} = 1;
12202: }
1.68 raeburn 12203: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 12204: my $notify = 1;
12205: if (ref($domconfig{'contacts'}) eq 'HASH') {
12206: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
12207: $notify = 0;
12208: }
12209: }
12210: if ($notify) {
12211: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
12212: "LON-CAPA Domain Settings Change - $dom",
12213: $mailmsgtext);
12214: }
1.54 raeburn 12215: }
1.43 raeburn 12216: } else {
1.54 raeburn 12217: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 12218: }
12219: } else {
12220: $resulttext = '<span class="LC_error">'.
12221: &mt('An error occurred: [_1]',$putresult).'</span>';
12222: }
12223: if (@errors > 0) {
12224: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
12225: foreach my $item (@errors) {
12226: $resulttext .= ' "'.$title->{$item}.'",';
12227: }
12228: $resulttext =~ s/,$//;
12229: }
12230: return $resulttext;
12231: }
12232:
1.46 raeburn 12233: sub modify_scantron {
1.205 raeburn 12234: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 12235: my ($resulttext,%confhash,%changes,$errors);
12236: my $custom = 'custom.tab';
12237: my $default = 'default.tab';
12238: my $servadm = $r->dir_config('lonAdmEMail');
12239: my ($configuserok,$author_ok,$switchserver) =
12240: &config_check($dom,$confname,$servadm);
12241: if ($env{'form.scantronformat.filename'} ne '') {
12242: my $error;
12243: if ($configuserok eq 'ok') {
12244: if ($switchserver) {
1.130 raeburn 12245: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 12246: } else {
12247: if ($author_ok eq 'ok') {
12248: my ($result,$scantronurl) =
12249: &publishlogo($r,'upload','scantronformat',$dom,
12250: $confname,'scantron','','',$custom);
12251: if ($result eq 'ok') {
12252: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 12253: $changes{'scantronformat'} = 1;
1.46 raeburn 12254: } else {
12255: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
12256: }
12257: } else {
12258: $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);
12259: }
12260: }
12261: } else {
12262: $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);
12263: }
12264: if ($error) {
12265: &Apache::lonnet::logthis($error);
12266: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12267: }
12268: }
1.48 raeburn 12269: if (ref($domconfig{'scantron'}) eq 'HASH') {
12270: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
12271: if ($env{'form.scantronformat_del'}) {
12272: $confhash{'scantron'}{'scantronformat'} = '';
12273: $changes{'scantronformat'} = 1;
1.46 raeburn 12274: }
12275: }
12276: }
12277: if (keys(%confhash) > 0) {
12278: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
12279: $dom);
12280: if ($putresult eq 'ok') {
12281: if (keys(%changes) > 0) {
1.48 raeburn 12282: if (ref($confhash{'scantron'}) eq 'HASH') {
12283: $resulttext = &mt('Changes made:').'<ul>';
12284: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 12285: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 12286: } else {
1.130 raeburn 12287: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 12288: }
1.48 raeburn 12289: $resulttext .= '</ul>';
12290: } else {
1.130 raeburn 12291: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 12292: }
12293: $resulttext .= '</ul>';
12294: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12295: if (ref($lastactref) eq 'HASH') {
12296: $lastactref->{'domainconfig'} = 1;
12297: }
1.46 raeburn 12298: } else {
1.130 raeburn 12299: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12300: }
12301: } else {
12302: $resulttext = '<span class="LC_error">'.
12303: &mt('An error occurred: [_1]',$putresult).'</span>';
12304: }
12305: } else {
1.130 raeburn 12306: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12307: }
12308: if ($errors) {
12309: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12310: $errors.'</ul>';
12311: }
12312: return $resulttext;
12313: }
12314:
1.48 raeburn 12315: sub modify_coursecategories {
1.239 raeburn 12316: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 12317: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
12318: $cathash);
1.48 raeburn 12319: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 12320: my @catitems = ('unauth','auth');
12321: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 12322: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 12323: $cathash = $domconfig{'coursecategories'}{'cats'};
12324: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
12325: $changes{'togglecats'} = 1;
12326: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
12327: }
12328: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
12329: $changes{'categorize'} = 1;
12330: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
12331: }
1.120 raeburn 12332: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
12333: $changes{'togglecatscomm'} = 1;
12334: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
12335: }
12336: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
12337: $changes{'categorizecomm'} = 1;
12338: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 12339:
12340: }
12341: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
12342: $changes{'togglecatsplace'} = 1;
12343: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
12344: }
12345: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
12346: $changes{'categorizeplace'} = 1;
12347: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 12348: }
1.238 raeburn 12349: foreach my $item (@catitems) {
12350: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12351: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
12352: $changes{$item} = 1;
12353: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12354: }
12355: }
12356: }
1.57 raeburn 12357: } else {
12358: $changes{'togglecats'} = 1;
12359: $changes{'categorize'} = 1;
1.124 raeburn 12360: $changes{'togglecatscomm'} = 1;
12361: $changes{'categorizecomm'} = 1;
1.272 raeburn 12362: $changes{'togglecatsplace'} = 1;
12363: $changes{'categorizeplace'} = 1;
1.87 raeburn 12364: $domconfig{'coursecategories'} = {
12365: togglecats => $env{'form.togglecats'},
12366: categorize => $env{'form.categorize'},
1.124 raeburn 12367: togglecatscomm => $env{'form.togglecatscomm'},
12368: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 12369: togglecatsplace => $env{'form.togglecatsplace'},
12370: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 12371: };
1.238 raeburn 12372: foreach my $item (@catitems) {
12373: if ($env{'form.coursecat_'.$item} ne 'std') {
12374: $changes{$item} = 1;
12375: }
12376: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12377: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12378: }
12379: }
1.57 raeburn 12380: }
12381: if (ref($cathash) eq 'HASH') {
12382: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 12383: push (@deletecategory,'instcode::0');
12384: }
1.120 raeburn 12385: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
12386: push(@deletecategory,'communities::0');
12387: }
1.272 raeburn 12388: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
12389: push(@deletecategory,'placement::0');
12390: }
1.48 raeburn 12391: }
1.57 raeburn 12392: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
12393: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12394: if (@deletecategory > 0) {
12395: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 12396: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 12397: foreach my $item (@deletecategory) {
1.57 raeburn 12398: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
12399: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 12400: $deletions{$item} = 1;
1.57 raeburn 12401: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 12402: }
12403: }
12404: }
1.57 raeburn 12405: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 12406: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 12407: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 12408: $reorderings{$item} = 1;
1.57 raeburn 12409: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 12410: }
12411: if ($env{'form.addcategory_name_'.$item} ne '') {
12412: my $newcat = $env{'form.addcategory_name_'.$item};
12413: my $newdepth = $depth+1;
12414: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12415: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 12416: $adds{$newitem} = 1;
12417: }
12418: if ($env{'form.subcat_'.$item} ne '') {
12419: my $newcat = $env{'form.subcat_'.$item};
12420: my $newdepth = $depth+1;
12421: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12422: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 12423: $adds{$newitem} = 1;
12424: }
12425: }
12426: }
12427: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 12428: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12429: my $newitem = 'instcode::0';
1.57 raeburn 12430: if ($cathash->{$newitem} eq '') {
12431: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12432: $adds{$newitem} = 1;
12433: }
12434: } else {
12435: my $newitem = 'instcode::0';
1.57 raeburn 12436: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12437: $adds{$newitem} = 1;
12438: }
12439: }
1.120 raeburn 12440: if ($env{'form.communities'} eq '1') {
12441: if (ref($cathash) eq 'HASH') {
12442: my $newitem = 'communities::0';
12443: if ($cathash->{$newitem} eq '') {
12444: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12445: $adds{$newitem} = 1;
12446: }
12447: } else {
12448: my $newitem = 'communities::0';
12449: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12450: $adds{$newitem} = 1;
12451: }
12452: }
1.272 raeburn 12453: if ($env{'form.placement'} eq '1') {
12454: if (ref($cathash) eq 'HASH') {
12455: my $newitem = 'placement::0';
12456: if ($cathash->{$newitem} eq '') {
12457: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12458: $adds{$newitem} = 1;
12459: }
12460: } else {
12461: my $newitem = 'placement::0';
12462: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12463: $adds{$newitem} = 1;
12464: }
12465: }
1.48 raeburn 12466: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 12467: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 12468: ($env{'form.addcategory_name'} ne 'communities') &&
12469: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 12470: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
12471: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
12472: $adds{$newitem} = 1;
12473: }
1.48 raeburn 12474: }
1.57 raeburn 12475: my $putresult;
1.48 raeburn 12476: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12477: if (keys(%deletions) > 0) {
12478: foreach my $key (keys(%deletions)) {
12479: if ($predelallitems{$key} ne '') {
12480: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
12481: }
12482: }
12483: }
12484: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 12485: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 12486: if (ref($chkcats[0]) eq 'ARRAY') {
12487: my $depth = 0;
12488: my $chg = 0;
12489: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
12490: my $name = $chkcats[0][$i];
12491: my $item;
12492: if ($name eq '') {
12493: $chg ++;
12494: } else {
12495: $item = &escape($name).'::0';
12496: if ($chg) {
1.57 raeburn 12497: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 12498: }
12499: $depth ++;
1.57 raeburn 12500: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 12501: $depth --;
12502: }
12503: }
12504: }
1.57 raeburn 12505: }
12506: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12507: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 12508: if ($putresult eq 'ok') {
1.57 raeburn 12509: my %title = (
1.120 raeburn 12510: togglecats => 'Show/Hide a course in catalog',
12511: categorize => 'Assign a category to a course',
12512: togglecatscomm => 'Show/Hide a community in catalog',
12513: categorizecomm => 'Assign a category to a community',
1.57 raeburn 12514: );
12515: my %level = (
1.120 raeburn 12516: dom => 'set in Domain ("Modify Course/Community")',
12517: crs => 'set in Course ("Course Configuration")',
12518: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 12519: none => 'No catalog',
12520: std => 'Standard catalog',
12521: domonly => 'Domain-only catalog',
12522: codesrch => 'Code search form',
1.57 raeburn 12523: );
1.48 raeburn 12524: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 12525: if ($changes{'togglecats'}) {
12526: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
12527: }
12528: if ($changes{'categorize'}) {
12529: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 12530: }
1.120 raeburn 12531: if ($changes{'togglecatscomm'}) {
12532: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
12533: }
12534: if ($changes{'categorizecomm'}) {
12535: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
12536: }
1.238 raeburn 12537: if ($changes{'unauth'}) {
12538: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
12539: }
12540: if ($changes{'auth'}) {
12541: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
12542: }
1.57 raeburn 12543: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12544: my $cathash;
12545: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
12546: $cathash = $domconfig{'coursecategories'}{'cats'};
12547: } else {
12548: $cathash = {};
12549: }
12550: my (@cats,@trails,%allitems);
12551: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
12552: if (keys(%deletions) > 0) {
12553: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
12554: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
12555: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
12556: }
12557: $resulttext .= '</ul></li>';
12558: }
12559: if (keys(%reorderings) > 0) {
12560: my %sort_by_trail;
12561: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
12562: foreach my $key (keys(%reorderings)) {
12563: if ($allitems{$key} ne '') {
12564: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12565: }
1.48 raeburn 12566: }
1.57 raeburn 12567: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12568: $resulttext .= '<li>'.$trails[$trail].'</li>';
12569: }
12570: $resulttext .= '</ul></li>';
1.48 raeburn 12571: }
1.57 raeburn 12572: if (keys(%adds) > 0) {
12573: my %sort_by_trail;
12574: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
12575: foreach my $key (keys(%adds)) {
12576: if ($allitems{$key} ne '') {
12577: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12578: }
12579: }
12580: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12581: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 12582: }
1.57 raeburn 12583: $resulttext .= '</ul></li>';
1.48 raeburn 12584: }
12585: }
12586: $resulttext .= '</ul>';
1.239 raeburn 12587: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 12588: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12589: if ($changes{'auth'}) {
12590: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
12591: }
12592: if ($changes{'unauth'}) {
12593: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
12594: }
12595: my $cachetime = 24*60*60;
12596: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 12597: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 12598: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 12599: }
12600: }
1.48 raeburn 12601: } else {
12602: $resulttext = '<span class="LC_error">'.
1.57 raeburn 12603: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 12604: }
12605: } else {
1.120 raeburn 12606: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 12607: }
12608: return $resulttext;
12609: }
12610:
1.69 raeburn 12611: sub modify_serverstatuses {
12612: my ($dom,%domconfig) = @_;
12613: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
12614: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
12615: %currserverstatus = %{$domconfig{'serverstatuses'}};
12616: }
12617: my @pages = &serverstatus_pages();
12618: foreach my $type (@pages) {
12619: $newserverstatus{$type}{'namedusers'} = '';
12620: $newserverstatus{$type}{'machines'} = '';
12621: if (defined($env{'form.'.$type.'_namedusers'})) {
12622: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
12623: my @okusers;
12624: foreach my $user (@users) {
12625: my ($uname,$udom) = split(/:/,$user);
12626: if (($udom =~ /^$match_domain$/) &&
12627: (&Apache::lonnet::domain($udom)) &&
12628: ($uname =~ /^$match_username$/)) {
12629: if (!grep(/^\Q$user\E/,@okusers)) {
12630: push(@okusers,$user);
12631: }
12632: }
12633: }
12634: if (@okusers > 0) {
12635: @okusers = sort(@okusers);
12636: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
12637: }
12638: }
12639: if (defined($env{'form.'.$type.'_machines'})) {
12640: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
12641: my @okmachines;
12642: foreach my $ip (@machines) {
12643: my @parts = split(/\./,$ip);
12644: next if (@parts < 4);
12645: my $badip = 0;
12646: for (my $i=0; $i<4; $i++) {
12647: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
12648: $badip = 1;
12649: last;
12650: }
12651: }
12652: if (!$badip) {
12653: push(@okmachines,$ip);
12654: }
12655: }
12656: @okmachines = sort(@okmachines);
12657: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
12658: }
12659: }
12660: my %serverstatushash = (
12661: serverstatuses => \%newserverstatus,
12662: );
12663: foreach my $type (@pages) {
1.83 raeburn 12664: foreach my $setting ('namedusers','machines') {
1.84 raeburn 12665: my (@current,@new);
1.83 raeburn 12666: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 12667: if ($currserverstatus{$type}{$setting} ne '') {
12668: @current = split(/,/,$currserverstatus{$type}{$setting});
12669: }
12670: }
12671: if ($newserverstatus{$type}{$setting} ne '') {
12672: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 12673: }
12674: if (@current > 0) {
12675: if (@new > 0) {
12676: foreach my $item (@current) {
12677: if (!grep(/^\Q$item\E$/,@new)) {
12678: $changes{$type}{$setting} = 1;
1.82 raeburn 12679: last;
12680: }
12681: }
1.84 raeburn 12682: foreach my $item (@new) {
12683: if (!grep(/^\Q$item\E$/,@current)) {
12684: $changes{$type}{$setting} = 1;
12685: last;
1.82 raeburn 12686: }
12687: }
12688: } else {
1.83 raeburn 12689: $changes{$type}{$setting} = 1;
1.69 raeburn 12690: }
1.83 raeburn 12691: } elsif (@new > 0) {
12692: $changes{$type}{$setting} = 1;
1.69 raeburn 12693: }
12694: }
12695: }
12696: if (keys(%changes) > 0) {
1.81 raeburn 12697: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 12698: my $putresult = &Apache::lonnet::put_dom('configuration',
12699: \%serverstatushash,$dom);
12700: if ($putresult eq 'ok') {
12701: $resulttext .= &mt('Changes made:').'<ul>';
12702: foreach my $type (@pages) {
1.84 raeburn 12703: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 12704: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 12705: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 12706: if ($newserverstatus{$type}{'namedusers'} eq '') {
12707: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
12708: } else {
12709: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
12710: }
1.84 raeburn 12711: }
12712: if ($changes{$type}{'machines'}) {
1.69 raeburn 12713: if ($newserverstatus{$type}{'machines'} eq '') {
12714: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
12715: } else {
12716: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
12717: }
12718:
12719: }
12720: $resulttext .= '</ul></li>';
12721: }
12722: }
12723: $resulttext .= '</ul>';
12724: } else {
12725: $resulttext = '<span class="LC_error">'.
12726: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
12727:
12728: }
12729: } else {
12730: $resulttext = &mt('No changes made to access to server status pages');
12731: }
12732: return $resulttext;
12733: }
12734:
1.118 jms 12735: sub modify_helpsettings {
1.285 raeburn 12736: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 12737: my ($resulttext,$errors,%changes,%helphash);
12738: my %defaultchecked = ('submitbugs' => 'on');
12739: my @offon = ('off','on');
1.118 jms 12740: my @toggles = ('submitbugs');
1.285 raeburn 12741: my %current = ('submitbugs' => '',
12742: 'adhoc' => {},
12743: );
1.118 jms 12744: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 12745: %current = %{$domconfig{'helpsettings'}};
12746: }
1.285 raeburn 12747: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 12748: foreach my $item (@toggles) {
12749: if ($defaultchecked{$item} eq 'on') {
12750: if ($current{$item} eq '') {
12751: if ($env{'form.'.$item} eq '0') {
12752: $changes{$item} = 1;
12753: }
12754: } elsif ($current{$item} ne $env{'form.'.$item}) {
12755: $changes{$item} = 1;
12756: }
12757: } elsif ($defaultchecked{$item} eq 'off') {
12758: if ($current{$item} eq '') {
12759: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 12760: $changes{$item} = 1;
12761: }
1.282 raeburn 12762: } elsif ($current{$item} ne $env{'form.'.$item}) {
12763: $changes{$item} = 1;
12764: }
12765: }
12766: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
12767: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
12768: }
12769: }
1.285 raeburn 12770: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 12771: my $confname = $dom.'-domainconfig';
12772: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 12773: my (@allpos,%newsettings,%changedprivs,$newrole);
12774: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 12775: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 12776: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 12777: my %lt = &Apache::lonlocal::texthash(
12778: s => 'system',
12779: d => 'domain',
12780: order => 'Display order',
12781: access => 'Role usage',
1.291 raeburn 12782: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 12783: dh => 'All with domain helpdesk role',
12784: da => 'All with domain helpdesk assistant role',
1.285 raeburn 12785: none => 'None',
12786: status => 'Determined based on institutional status',
12787: inc => 'Include all, but exclude specific personnel',
12788: exc => 'Exclude all, but include specific personnel',
12789: );
12790: for (my $num=0; $num<=$maxnum; $num++) {
12791: my ($prefix,$identifier,$rolename,%curr);
12792: if ($num == $maxnum) {
12793: next unless ($env{'form.newcusthelp'} == $maxnum);
12794: $identifier = 'custhelp'.$num;
12795: $prefix = 'helproles_'.$num;
12796: $rolename = $env{'form.custhelpname'.$num};
12797: $rolename=~s/[^A-Za-z0-9]//gs;
12798: next if ($rolename eq '');
12799: next if (exists($existing{'rolesdef_'.$rolename}));
12800: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12801: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12802: $newprivs{'c'},$confname,$dom);
12803: if ($result ne 'ok') {
12804: $errors .= '<li><span class="LC_error">'.
12805: &mt('An error occurred storing the new custom role: [_1]',
12806: $result).'</span></li>';
12807: next;
12808: } else {
12809: $changedprivs{$rolename} = \%newprivs;
12810: $newrole = $rolename;
12811: }
12812: } else {
12813: $prefix = 'helproles_'.$num;
12814: $rolename = $env{'form.'.$prefix};
12815: next if ($rolename eq '');
12816: next unless (exists($existing{'rolesdef_'.$rolename}));
12817: $identifier = 'custhelp'.$num;
12818: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12819: my %currprivs;
1.289 raeburn 12820: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 12821: split(/\_/,$existing{'rolesdef_'.$rolename});
12822: foreach my $level ('c','d','s') {
12823: if ($newprivs{$level} ne $currprivs{$level}) {
12824: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12825: $newprivs{'c'},$confname,$dom);
12826: if ($result ne 'ok') {
12827: $errors .= '<li><span class="LC_error">'.
12828: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
12829: $rolename,$result).'</span></li>';
12830: } else {
12831: $changedprivs{$rolename} = \%newprivs;
12832: }
12833: last;
12834: }
12835: }
12836: if (ref($current{'adhoc'}) eq 'HASH') {
12837: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12838: %curr = %{$current{'adhoc'}{$rolename}};
12839: }
12840: }
12841: }
12842: my $newpos = $env{'form.'.$prefix.'_pos'};
12843: $newpos =~ s/\D+//g;
12844: $allpos[$newpos] = $rolename;
12845: my $newdesc = $env{'form.'.$prefix.'_desc'};
12846: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
12847: if ($curr{'desc'}) {
12848: if ($curr{'desc'} ne $newdesc) {
12849: $changes{'customrole'}{$rolename}{'desc'} = 1;
12850: $newsettings{$rolename}{'desc'} = $newdesc;
12851: }
12852: } elsif ($newdesc ne '') {
12853: $changes{'customrole'}{$rolename}{'desc'} = 1;
12854: $newsettings{$rolename}{'desc'} = $newdesc;
12855: }
12856: my $access = $env{'form.'.$prefix.'_access'};
12857: if (grep(/^\Q$access\E$/,@accesstypes)) {
12858: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
12859: if ($access eq 'status') {
12860: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
12861: if (scalar(@statuses) == 0) {
1.289 raeburn 12862: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 12863: } else {
12864: my (@shownstatus,$numtypes);
12865: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12866: if (ref($types) eq 'ARRAY') {
12867: $numtypes = scalar(@{$types});
12868: foreach my $type (sort(@statuses)) {
12869: if ($type eq 'default') {
12870: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12871: } elsif (grep(/^\Q$type\E$/,@{$types})) {
12872: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12873: push(@shownstatus,$usertypes->{$type});
12874: }
12875: }
12876: }
12877: if (grep(/^default$/,@statuses)) {
12878: push(@shownstatus,$othertitle);
12879: }
12880: if (scalar(@shownstatus) == 1+$numtypes) {
12881: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
12882: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
12883: } else {
12884: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
12885: if (ref($curr{'status'}) eq 'ARRAY') {
12886: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12887: if (@diffs) {
12888: $changes{'customrole'}{$rolename}{$access} = 1;
12889: }
12890: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12891: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 12892: }
1.166 raeburn 12893: }
12894: }
1.285 raeburn 12895: } elsif (($access eq 'inc') || ($access eq 'exc')) {
12896: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
12897: my @newspecstaff;
12898: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12899: foreach my $person (sort(@personnel)) {
12900: if ($domhelpdesk{$person}) {
12901: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
12902: }
12903: }
12904: if (ref($curr{$access}) eq 'ARRAY') {
12905: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12906: if (@diffs) {
12907: $changes{'customrole'}{$rolename}{$access} = 1;
12908: }
12909: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12910: $changes{'customrole'}{$rolename}{$access} = 1;
12911: }
12912: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12913: my ($uname,$udom) = split(/:/,$person);
12914: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
12915: }
12916: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 12917: }
1.285 raeburn 12918: } else {
12919: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
12920: }
12921: unless ($curr{'access'} eq $access) {
12922: $changes{'customrole'}{$rolename}{'access'} = 1;
12923: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 12924: }
12925: }
1.285 raeburn 12926: if (@allpos > 0) {
12927: my $idx = 0;
12928: foreach my $rolename (@allpos) {
12929: if ($rolename ne '') {
12930: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
12931: if (ref($current{'adhoc'}) eq 'HASH') {
12932: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12933: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
12934: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 12935: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 12936: }
12937: }
1.282 raeburn 12938: }
1.285 raeburn 12939: $idx ++;
1.166 raeburn 12940: }
12941: }
1.118 jms 12942: }
1.123 jms 12943: my $putresult;
12944: if (keys(%changes) > 0) {
1.166 raeburn 12945: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 12946: if ($putresult eq 'ok') {
1.285 raeburn 12947: if (ref($helphash{'helpsettings'}) eq 'HASH') {
12948: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
12949: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
12950: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
12951: }
12952: }
12953: my $cachetime = 24*60*60;
12954: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12955: if (ref($lastactref) eq 'HASH') {
12956: $lastactref->{'domdefaults'} = 1;
12957: }
12958: } else {
12959: $errors .= '<li><span class="LC_error">'.
12960: &mt('An error occurred storing the settings: [_1]',
12961: $putresult).'</span></li>';
12962: }
12963: }
12964: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
12965: $resulttext = &mt('Changes made:').'<ul>';
12966: my (%shownprivs,@levelorder);
12967: @levelorder = ('c','d','s');
12968: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 12969: foreach my $item (sort(keys(%changes))) {
12970: if ($item eq 'submitbugs') {
12971: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
12972: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
12973: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 12974: } elsif ($item eq 'customrole') {
12975: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 12976: my @keyorder = ('order','desc','access','status','exc','inc');
12977: my %keytext = &Apache::lonlocal::texthash(
12978: order => 'Order',
12979: desc => 'Role description',
12980: access => 'Role usage',
12981: status => 'Allowed instituional types',
12982: exc => 'Allowed personnel',
12983: inc => 'Disallowed personnel',
12984: );
1.282 raeburn 12985: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 12986: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
12987: if ($role eq $newrole) {
12988: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
12989: $role).'<ul>';
12990: } else {
12991: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12992: $role).'<ul>';
12993: }
12994: foreach my $key (@keyorder) {
12995: if ($changes{'customrole'}{$role}{$key}) {
12996: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
12997: $keytext{$key},$newsettings{$role}{$key}).
12998: '</li>';
12999: }
13000: }
13001: if (ref($changedprivs{$role}) eq 'HASH') {
13002: $shownprivs{$role} = 1;
13003: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
13004: foreach my $level (@levelorder) {
13005: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13006: next if ($item eq '');
13007: my ($priv) = split(/\&/,$item,2);
13008: if (&Apache::lonnet::plaintext($priv)) {
13009: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13010: unless ($level eq 'c') {
13011: $resulttext .= ' ('.$lt{$level}.')';
13012: }
13013: $resulttext .= '</li>';
13014: }
13015: }
13016: }
13017: $resulttext .= '</ul>';
13018: }
13019: $resulttext .= '</ul></li>';
13020: }
13021: }
13022: }
13023: }
13024: }
13025: }
13026: if (keys(%changedprivs)) {
13027: foreach my $role (sort(keys(%changedprivs))) {
13028: unless ($shownprivs{$role}) {
13029: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13030: $role).'<ul>'.
13031: '<li>'.&mt('Privileges set to :').'<ul>';
13032: foreach my $level (@levelorder) {
13033: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13034: next if ($item eq '');
13035: my ($priv) = split(/\&/,$item,2);
13036: if (&Apache::lonnet::plaintext($priv)) {
13037: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13038: unless ($level eq 'c') {
13039: $resulttext .= ' ('.$lt{$level}.')';
13040: }
13041: $resulttext .= '</li>';
13042: }
1.282 raeburn 13043: }
13044: }
1.285 raeburn 13045: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 13046: }
13047: }
13048: }
1.285 raeburn 13049: $resulttext .= '</ul>';
13050: } else {
13051: $resulttext = &mt('No changes made to help settings');
1.118 jms 13052: }
13053: if ($errors) {
1.168 raeburn 13054: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 13055: $errors.'</ul>';
1.118 jms 13056: }
13057: return $resulttext;
13058: }
13059:
1.121 raeburn 13060: sub modify_coursedefaults {
1.212 raeburn 13061: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 13062: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 13063: my %defaultchecked = (
13064: 'canuse_pdfforms' => 'off',
13065: 'uselcmath' => 'on',
13066: 'usejsme' => 'on'
13067: );
13068: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 13069: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 13070: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
13071: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
13072: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 13073: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 13074: my %staticdefaults = (
13075: anonsurvey_threshold => 10,
13076: uploadquota => 500,
1.257 raeburn 13077: postsubmit => 60,
1.276 raeburn 13078: mysqltables => 172800,
1.198 raeburn 13079: );
1.121 raeburn 13080:
13081: $defaultshash{'coursedefaults'} = {};
13082:
13083: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
13084: if ($domconfig{'coursedefaults'} eq '') {
13085: $domconfig{'coursedefaults'} = {};
13086: }
13087: }
13088:
13089: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
13090: foreach my $item (@toggles) {
13091: if ($defaultchecked{$item} eq 'on') {
13092: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13093: ($env{'form.'.$item} eq '0')) {
13094: $changes{$item} = 1;
1.192 raeburn 13095: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 13096: $changes{$item} = 1;
13097: }
13098: } elsif ($defaultchecked{$item} eq 'off') {
13099: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13100: ($env{'form.'.$item} eq '1')) {
13101: $changes{$item} = 1;
13102: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
13103: $changes{$item} = 1;
13104: }
13105: }
13106: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
13107: }
1.198 raeburn 13108: foreach my $item (@numbers) {
13109: my ($currdef,$newdef);
1.208 raeburn 13110: $newdef = $env{'form.'.$item};
1.198 raeburn 13111: if ($item eq 'anonsurvey_threshold') {
13112: $currdef = $domconfig{'coursedefaults'}{$item};
13113: $newdef =~ s/\D//g;
13114: if ($newdef eq '' || $newdef < 1) {
13115: $newdef = 1;
13116: }
13117: $defaultshash{'coursedefaults'}{$item} = $newdef;
13118: } else {
1.276 raeburn 13119: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
13120: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
13121: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 13122: }
13123: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 13124: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 13125: }
13126: if ($currdef ne $newdef) {
13127: my $staticdef;
13128: if ($item eq 'anonsurvey_threshold') {
13129: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
13130: $changes{$item} = 1;
13131: }
1.276 raeburn 13132: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 13133: my $setting = $1;
1.276 raeburn 13134: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
13135: $changes{$setting} = 1;
1.198 raeburn 13136: }
13137: }
1.139 raeburn 13138: }
13139: }
1.264 raeburn 13140: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
13141: my @currclonecode;
13142: if (ref($currclone) eq 'HASH') {
13143: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
13144: @currclonecode = @{$currclone->{'instcode'}};
13145: }
13146: }
13147: my $newclone;
1.289 raeburn 13148: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 13149: $newclone = $env{'form.canclone'};
13150: }
13151: if ($newclone eq 'instcode') {
13152: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
13153: my (%codedefaults,@code_order,@clonecode);
13154: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
13155: \@code_order);
13156: foreach my $item (@code_order) {
13157: if (grep(/^\Q$item\E$/,@newcodes)) {
13158: push(@clonecode,$item);
13159: }
13160: }
13161: if (@clonecode) {
13162: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
13163: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
13164: if (@diffs) {
13165: $changes{'canclone'} = 1;
13166: }
13167: } else {
13168: $newclone eq '';
13169: }
13170: } elsif ($newclone ne '') {
1.289 raeburn 13171: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
13172: }
1.264 raeburn 13173: if ($newclone ne $currclone) {
13174: $changes{'canclone'} = 1;
13175: }
1.257 raeburn 13176: my %credits;
13177: foreach my $type (@types) {
13178: unless ($type eq 'community') {
13179: $credits{$type} = $env{'form.'.$type.'_credits'};
13180: $credits{$type} =~ s/[^\d.]+//g;
13181: }
13182: }
13183: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
13184: ($env{'form.coursecredits'} eq '1')) {
13185: $changes{'coursecredits'} = 1;
13186: foreach my $type (keys(%credits)) {
13187: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13188: }
13189: } else {
1.289 raeburn 13190: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 13191: foreach my $type (@types) {
13192: unless ($type eq 'community') {
1.289 raeburn 13193: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 13194: $changes{'coursecredits'} = 1;
13195: }
13196: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13197: }
13198: }
13199: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13200: foreach my $type (@types) {
13201: unless ($type eq 'community') {
13202: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
13203: $changes{'coursecredits'} = 1;
13204: last;
13205: }
13206: }
13207: }
13208: }
13209: }
13210: if ($env{'form.postsubmit'} eq '1') {
13211: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
13212: my %currtimeout;
13213: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13214: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
13215: $changes{'postsubmit'} = 1;
13216: }
13217: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13218: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
13219: }
13220: } else {
13221: $changes{'postsubmit'} = 1;
13222: }
13223: foreach my $type (@types) {
13224: my $timeout = $env{'form.'.$type.'_timeout'};
13225: $timeout =~ s/\D//g;
13226: if ($timeout == $staticdefaults{'postsubmit'}) {
13227: $timeout = '';
13228: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
13229: $timeout = '0';
13230: }
13231: unless ($timeout eq '') {
13232: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
13233: }
13234: if (exists($currtimeout{$type})) {
13235: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 13236: $changes{'postsubmit'} = 1;
1.257 raeburn 13237: }
13238: } elsif ($timeout ne '') {
13239: $changes{'postsubmit'} = 1;
13240: }
13241: }
13242: } else {
13243: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
13244: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13245: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
13246: $changes{'postsubmit'} = 1;
13247: }
13248: } else {
13249: $changes{'postsubmit'} = 1;
13250: }
1.192 raeburn 13251: }
1.121 raeburn 13252: }
13253: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13254: $dom);
13255: if ($putresult eq 'ok') {
13256: if (keys(%changes) > 0) {
1.213 raeburn 13257: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 13258: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 13259: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.276 raeburn 13260: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.257 raeburn 13261: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
13262: if ($changes{$item}) {
13263: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
13264: }
1.289 raeburn 13265: }
1.192 raeburn 13266: if ($changes{'coursecredits'}) {
13267: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 13268: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
13269: $domdefaults{$type.'credits'} =
13270: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
13271: }
13272: }
13273: }
13274: if ($changes{'postsubmit'}) {
13275: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13276: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
13277: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13278: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
13279: $domdefaults{$type.'postsubtimeout'} =
13280: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13281: }
13282: }
1.192 raeburn 13283: }
13284: }
1.198 raeburn 13285: if ($changes{'uploadquota'}) {
13286: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13287: foreach my $type (@types) {
13288: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
13289: }
13290: }
13291: }
1.264 raeburn 13292: if ($changes{'canclone'}) {
13293: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13294: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13295: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
13296: if (@clonecodes) {
13297: $domdefaults{'canclone'} = join('+',@clonecodes);
13298: }
13299: }
13300: } else {
13301: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
13302: }
13303: }
1.121 raeburn 13304: my $cachetime = 24*60*60;
13305: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13306: if (ref($lastactref) eq 'HASH') {
13307: $lastactref->{'domdefaults'} = 1;
13308: }
1.121 raeburn 13309: }
13310: $resulttext = &mt('Changes made:').'<ul>';
13311: foreach my $item (sort(keys(%changes))) {
13312: if ($item eq 'canuse_pdfforms') {
13313: if ($env{'form.'.$item} eq '1') {
13314: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
13315: } else {
13316: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
13317: }
1.257 raeburn 13318: } elsif ($item eq 'uselcmath') {
13319: if ($env{'form.'.$item} eq '1') {
13320: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
13321: } else {
13322: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
13323: }
13324: } elsif ($item eq 'usejsme') {
13325: if ($env{'form.'.$item} eq '1') {
13326: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
13327: } else {
1.289 raeburn 13328: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 13329: }
1.139 raeburn 13330: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 13331: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 13332: } elsif ($item eq 'uploadquota') {
13333: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13334: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
13335: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
13336: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 13337: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 13338: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 13339: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
13340: '</ul>'.
13341: '</li>';
13342: } else {
13343: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
13344: }
1.276 raeburn 13345: } elsif ($item eq 'mysqltables') {
13346: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
13347: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
13348: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
13349: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
13350: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
13351: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
13352: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
13353: '</ul>'.
13354: '</li>';
13355: } else {
13356: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
13357: }
1.257 raeburn 13358: } elsif ($item eq 'postsubmit') {
13359: if ($domdefaults{'postsubmit'} eq 'off') {
13360: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
13361: } else {
13362: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 13363: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 13364: $resulttext .= &mt('durations:').'<ul>';
13365: foreach my $type (@types) {
13366: $resulttext .= '<li>';
13367: my $timeout;
13368: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13369: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13370: }
13371: my $display;
13372: if ($timeout eq '0') {
13373: $display = &mt('unlimited');
13374: } elsif ($timeout eq '') {
13375: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
13376: } else {
13377: $display = &mt('[quant,_1,second]',$timeout);
13378: }
13379: if ($type eq 'community') {
13380: $resulttext .= &mt('Communities');
13381: } elsif ($type eq 'official') {
13382: $resulttext .= &mt('Official courses');
13383: } elsif ($type eq 'unofficial') {
13384: $resulttext .= &mt('Unofficial courses');
13385: } elsif ($type eq 'textbook') {
13386: $resulttext .= &mt('Textbook courses');
1.271 raeburn 13387: } elsif ($type eq 'placement') {
13388: $resulttext .= &mt('Placement tests');
1.257 raeburn 13389: }
13390: $resulttext .= ' -- '.$display.'</li>';
13391: }
13392: $resulttext .= '</ul>';
13393: }
1.289 raeburn 13394: $resulttext .= '</li>';
1.257 raeburn 13395: }
1.192 raeburn 13396: } elsif ($item eq 'coursecredits') {
13397: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13398: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 13399: ($domdefaults{'unofficialcredits'} eq '') &&
13400: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 13401: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13402: } else {
13403: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
13404: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
13405: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 13406: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 13407: '</ul>'.
13408: '</li>';
13409: }
13410: } else {
13411: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13412: }
1.264 raeburn 13413: } elsif ($item eq 'canclone') {
13414: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13415: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13416: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
13417: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
13418: }
13419: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
13420: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
13421: } else {
1.289 raeburn 13422: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 13423: }
1.140 raeburn 13424: }
1.121 raeburn 13425: }
13426: $resulttext .= '</ul>';
13427: } else {
13428: $resulttext = &mt('No changes made to course defaults');
13429: }
13430: } else {
13431: $resulttext = '<span class="LC_error">'.
13432: &mt('An error occurred: [_1]',$putresult).'</span>';
13433: }
13434: return $resulttext;
13435: }
13436:
1.231 raeburn 13437: sub modify_selfenrollment {
13438: my ($dom,$lastactref,%domconfig) = @_;
13439: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 13440: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 13441: my %titles = &tool_titles();
1.232 raeburn 13442: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
13443: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 13444: $ordered{'default'} = ['types','registered','approval','limit'];
13445:
13446: my (%roles,%shown,%toplevel);
13447: $roles{'0'} = &Apache::lonnet::plaintext('dc');
13448:
13449: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
13450: if ($domconfig{'selfenrollment'} eq '') {
13451: $domconfig{'selfenrollment'} = {};
13452: }
13453: }
13454: %toplevel = (
13455: admin => 'Configuration Rights',
13456: default => 'Default settings',
13457: validation => 'Validation of self-enrollment requests',
13458: );
1.233 raeburn 13459: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 13460:
13461: if (ref($ordered{'admin'}) eq 'ARRAY') {
13462: foreach my $item (@{$ordered{'admin'}}) {
13463: foreach my $type (@types) {
13464: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
13465: $selfenrollhash{'admin'}{$type}{$item} = 1;
13466: } else {
13467: $selfenrollhash{'admin'}{$type}{$item} = 0;
13468: }
13469: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
13470: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
13471: if ($selfenrollhash{'admin'}{$type}{$item} ne
13472: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
13473: push(@{$changes{'admin'}{$type}},$item);
13474: }
13475: } else {
13476: if (!$selfenrollhash{'admin'}{$type}{$item}) {
13477: push(@{$changes{'admin'}{$type}},$item);
13478: }
13479: }
13480: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
13481: push(@{$changes{'admin'}{$type}},$item);
13482: }
13483: }
13484: }
13485: }
13486:
13487: foreach my $item (@{$ordered{'default'}}) {
13488: foreach my $type (@types) {
13489: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
13490: if ($item eq 'types') {
13491: unless (($value eq 'all') || ($value eq 'dom')) {
13492: $value = '';
13493: }
13494: } elsif ($item eq 'registered') {
13495: unless ($value eq '1') {
13496: $value = 0;
13497: }
13498: } elsif ($item eq 'approval') {
13499: unless ($value =~ /^[012]$/) {
13500: $value = 0;
13501: }
13502: } else {
13503: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13504: $value = 'none';
13505: }
13506: }
13507: $selfenrollhash{'default'}{$type}{$item} = $value;
13508: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
13509: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13510: if ($selfenrollhash{'default'}{$type}{$item} ne
13511: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
13512: push(@{$changes{'default'}{$type}},$item);
13513: }
13514: } else {
13515: push(@{$changes{'default'}{$type}},$item);
13516: }
13517: } else {
13518: push(@{$changes{'default'}{$type}},$item);
13519: }
13520: if ($item eq 'limit') {
13521: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13522: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
13523: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
13524: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
13525: }
13526: } else {
13527: $selfenrollhash{'default'}{$type}{'cap'} = '';
13528: }
13529: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13530: if ($selfenrollhash{'default'}{$type}{'cap'} ne
13531: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
13532: push(@{$changes{'default'}{$type}},'cap');
13533: }
13534: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
13535: push(@{$changes{'default'}{$type}},'cap');
13536: }
13537: }
13538: }
13539: }
13540:
13541: foreach my $item (@{$itemsref}) {
13542: if ($item eq 'fields') {
13543: my @changed;
13544: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
13545: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
13546: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
13547: }
13548: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13549: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
13550: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
13551: $domconfig{'selfenrollment'}{'validation'}{$item});
13552: } else {
13553: @changed = @{$selfenrollhash{'validation'}{$item}};
13554: }
13555: } else {
13556: @changed = @{$selfenrollhash{'validation'}{$item}};
13557: }
13558: if (@changed) {
13559: if ($selfenrollhash{'validation'}{$item}) {
13560: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
13561: } else {
13562: $changes{'validation'}{$item} = &mt('None');
13563: }
13564: }
13565: } else {
13566: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
13567: if ($item eq 'markup') {
13568: if ($env{'form.selfenroll_validation_'.$item}) {
13569: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13570: }
13571: }
13572: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13573: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
13574: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
13575: }
13576: }
13577: }
13578: }
13579:
13580: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
13581: $dom);
13582: if ($putresult eq 'ok') {
13583: if (keys(%changes) > 0) {
13584: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13585: $resulttext = &mt('Changes made:').'<ul>';
13586: foreach my $key ('admin','default','validation') {
13587: if (ref($changes{$key}) eq 'HASH') {
13588: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
13589: if ($key eq 'validation') {
13590: foreach my $item (@{$itemsref}) {
13591: if (exists($changes{$key}{$item})) {
13592: if ($item eq 'markup') {
13593: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13594: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
13595: } else {
13596: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13597: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
13598: }
13599: }
13600: }
13601: } else {
13602: foreach my $type (@types) {
13603: if ($type eq 'community') {
13604: $roles{'1'} = &mt('Community personnel');
13605: } else {
13606: $roles{'1'} = &mt('Course personnel');
13607: }
13608: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 13609: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13610: if ($key eq 'admin') {
13611: my @mgrdc = ();
13612: if (ref($ordered{$key}) eq 'ARRAY') {
13613: foreach my $item (@{$ordered{'admin'}}) {
13614: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13615: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
13616: push(@mgrdc,$item);
13617: }
13618: }
13619: }
13620: if (@mgrdc) {
13621: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
13622: } else {
13623: delete($domdefaults{$type.'selfenrolladmdc'});
13624: }
13625: }
13626: } else {
13627: if (ref($ordered{$key}) eq 'ARRAY') {
13628: foreach my $item (@{$ordered{$key}}) {
13629: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13630: $domdefaults{$type.'selfenroll'.$item} =
13631: $selfenrollhash{$key}{$type}{$item};
13632: }
13633: }
13634: }
13635: }
13636: }
1.231 raeburn 13637: $resulttext .= '<li>'.$titles{$type}.'<ul>';
13638: foreach my $item (@{$ordered{$key}}) {
13639: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13640: $resulttext .= '<li>';
13641: if ($key eq 'admin') {
13642: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
13643: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
13644: } else {
13645: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
13646: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
13647: }
13648: $resulttext .= '</li>';
13649: }
13650: }
13651: $resulttext .= '</ul></li>';
13652: }
13653: }
13654: $resulttext .= '</ul></li>';
13655: }
13656: }
1.232 raeburn 13657: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
13658: my $cachetime = 24*60*60;
13659: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13660: if (ref($lastactref) eq 'HASH') {
13661: $lastactref->{'domdefaults'} = 1;
13662: }
13663: }
1.231 raeburn 13664: }
13665: $resulttext .= '</ul>';
13666: } else {
13667: $resulttext = &mt('No changes made to self-enrollment settings');
13668: }
13669: } else {
13670: $resulttext = '<span class="LC_error">'.
13671: &mt('An error occurred: [_1]',$putresult).'</span>';
13672: }
13673: return $resulttext;
13674: }
13675:
1.137 raeburn 13676: sub modify_usersessions {
1.212 raeburn 13677: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 13678: my @hostingtypes = ('version','excludedomain','includedomain');
13679: my @offloadtypes = ('primary','default');
13680: my %types = (
13681: remote => \@hostingtypes,
13682: hosted => \@hostingtypes,
13683: spares => \@offloadtypes,
13684: );
13685: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 13686: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 13687: my (%by_ip,%by_location,@intdoms,@instdoms);
13688: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 13689: my @locations = sort(keys(%by_location));
1.137 raeburn 13690: my (%defaultshash,%changes);
13691: foreach my $prefix (@prefixes) {
13692: $defaultshash{'usersessions'}{$prefix} = {};
13693: }
1.212 raeburn 13694: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 13695: my $resulttext;
1.138 raeburn 13696: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 13697: foreach my $prefix (@prefixes) {
1.145 raeburn 13698: next if ($prefix eq 'spares');
13699: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 13700: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13701: if ($type eq 'version') {
13702: my $value = $env{'form.'.$prefix.'_'.$type};
13703: my $okvalue;
13704: if ($value ne '') {
13705: if (grep(/^\Q$value\E$/,@lcversions)) {
13706: $okvalue = $value;
13707: }
13708: }
13709: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13710: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13711: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
13712: if ($inuse == 0) {
13713: $changes{$prefix}{$type} = 1;
13714: } else {
13715: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
13716: $changes{$prefix}{$type} = 1;
13717: }
13718: if ($okvalue ne '') {
13719: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13720: }
13721: }
13722: } else {
13723: if (($inuse == 1) && ($okvalue ne '')) {
13724: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13725: $changes{$prefix}{$type} = 1;
13726: }
13727: }
13728: } else {
13729: if (($inuse == 1) && ($okvalue ne '')) {
13730: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13731: $changes{$prefix}{$type} = 1;
13732: }
13733: }
13734: } else {
13735: if (($inuse == 1) && ($okvalue ne '')) {
13736: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13737: $changes{$prefix}{$type} = 1;
13738: }
13739: }
13740: } else {
13741: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13742: my @okvals;
13743: foreach my $val (@vals) {
1.138 raeburn 13744: if ($val =~ /:/) {
13745: my @items = split(/:/,$val);
13746: foreach my $item (@items) {
13747: if (ref($by_location{$item}) eq 'ARRAY') {
13748: push(@okvals,$item);
13749: }
13750: }
13751: } else {
13752: if (ref($by_location{$val}) eq 'ARRAY') {
13753: push(@okvals,$val);
13754: }
1.137 raeburn 13755: }
13756: }
13757: @okvals = sort(@okvals);
13758: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13759: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13760: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13761: if ($inuse == 0) {
13762: $changes{$prefix}{$type} = 1;
13763: } else {
13764: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13765: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
13766: if (@changed > 0) {
13767: $changes{$prefix}{$type} = 1;
13768: }
13769: }
13770: } else {
13771: if ($inuse == 1) {
13772: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13773: $changes{$prefix}{$type} = 1;
13774: }
13775: }
13776: } else {
13777: if ($inuse == 1) {
13778: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13779: $changes{$prefix}{$type} = 1;
13780: }
13781: }
13782: } else {
13783: if ($inuse == 1) {
13784: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13785: $changes{$prefix}{$type} = 1;
13786: }
13787: }
13788: }
13789: }
13790: }
1.145 raeburn 13791:
13792: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 13793: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 13794: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
13795: my $savespares;
13796:
13797: foreach my $lonhost (sort(keys(%servers))) {
13798: my $serverhomeID =
13799: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 13800: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 13801: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
13802: my %spareschg;
13803: foreach my $type (@{$types{'spares'}}) {
13804: my @okspares;
13805: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
13806: foreach my $server (@checked) {
1.152 raeburn 13807: if (&Apache::lonnet::hostname($server) ne '') {
13808: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
13809: unless (grep(/^\Q$server\E$/,@okspares)) {
13810: push(@okspares,$server);
13811: }
1.145 raeburn 13812: }
13813: }
13814: }
13815: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
13816: my $newspare;
1.152 raeburn 13817: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
13818: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 13819: $newspare = $new;
13820: }
13821: }
1.152 raeburn 13822: my @spares;
13823: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
13824: @spares = sort(@okspares,$newspare);
13825: } else {
13826: @spares = sort(@okspares);
13827: }
13828: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 13829: if (ref($spareid{$lonhost}) eq 'HASH') {
13830: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 13831: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 13832: if (@diffs > 0) {
13833: $spareschg{$type} = 1;
13834: }
13835: }
13836: }
13837: }
13838: if (keys(%spareschg) > 0) {
13839: $changes{'spares'}{$lonhost} = \%spareschg;
13840: }
13841: }
1.261 raeburn 13842: $defaultshash{'usersessions'}{'offloadnow'} = {};
13843: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
13844: my @okoffload;
13845: if (@offloadnow) {
13846: foreach my $server (@offloadnow) {
13847: if (&Apache::lonnet::hostname($server) ne '') {
13848: unless (grep(/^\Q$server\E$/,@okoffload)) {
13849: push(@okoffload,$server);
13850: }
13851: }
13852: }
13853: if (@okoffload) {
13854: foreach my $lonhost (@okoffload) {
13855: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
13856: }
13857: }
13858: }
1.145 raeburn 13859: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13860: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
13861: if (ref($changes{'spares'}) eq 'HASH') {
13862: if (keys(%{$changes{'spares'}}) > 0) {
13863: $savespares = 1;
13864: }
13865: }
13866: } else {
13867: $savespares = 1;
13868: }
1.261 raeburn 13869: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
13870: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
13871: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
13872: $changes{'offloadnow'} = 1;
13873: last;
13874: }
13875: }
13876: unless ($changes{'offloadnow'}) {
1.289 raeburn 13877: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 13878: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
13879: $changes{'offloadnow'} = 1;
13880: last;
13881: }
13882: }
13883: }
13884: } elsif (@okoffload) {
13885: $changes{'offloadnow'} = 1;
13886: }
13887: } elsif (@okoffload) {
13888: $changes{'offloadnow'} = 1;
1.145 raeburn 13889: }
1.147 raeburn 13890: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
13891: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 13892: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13893: $dom);
13894: if ($putresult eq 'ok') {
13895: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13896: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
13897: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
13898: }
13899: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
13900: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
13901: }
1.261 raeburn 13902: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13903: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
13904: }
1.137 raeburn 13905: }
13906: my $cachetime = 24*60*60;
13907: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 13908: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 13909: if (ref($lastactref) eq 'HASH') {
13910: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 13911: $lastactref->{'usersessions'} = 1;
1.212 raeburn 13912: }
1.147 raeburn 13913: if (keys(%changes) > 0) {
13914: my %lt = &usersession_titles();
13915: $resulttext = &mt('Changes made:').'<ul>';
13916: foreach my $prefix (@prefixes) {
13917: if (ref($changes{$prefix}) eq 'HASH') {
13918: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
13919: if ($prefix eq 'spares') {
13920: if (ref($changes{$prefix}) eq 'HASH') {
13921: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
13922: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 13923: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 13924: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
13925: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 13926: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
13927: foreach my $type (@{$types{$prefix}}) {
13928: if ($changes{$prefix}{$lonhost}{$type}) {
13929: my $offloadto = &mt('None');
13930: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
13931: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
13932: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
13933: }
1.145 raeburn 13934: }
1.147 raeburn 13935: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 13936: }
1.137 raeburn 13937: }
13938: }
1.147 raeburn 13939: $resulttext .= '</li>';
1.137 raeburn 13940: }
13941: }
1.147 raeburn 13942: } else {
13943: foreach my $type (@{$types{$prefix}}) {
13944: if (defined($changes{$prefix}{$type})) {
13945: my $newvalue;
13946: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13947: if (ref($defaultshash{'usersessions'}{$prefix})) {
13948: if ($type eq 'version') {
13949: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
13950: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13951: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
13952: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
13953: }
1.145 raeburn 13954: }
13955: }
13956: }
1.147 raeburn 13957: if ($newvalue eq '') {
13958: if ($type eq 'version') {
13959: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
13960: } else {
13961: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
13962: }
1.145 raeburn 13963: } else {
1.147 raeburn 13964: if ($type eq 'version') {
13965: $newvalue .= ' '.&mt('(or later)');
13966: }
13967: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 13968: }
1.137 raeburn 13969: }
13970: }
13971: }
1.147 raeburn 13972: $resulttext .= '</ul>';
1.137 raeburn 13973: }
13974: }
1.261 raeburn 13975: if ($changes{'offloadnow'}) {
13976: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13977: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
13978: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
13979: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
13980: $resulttext .= '<li>'.$lonhost.'</li>';
13981: }
13982: $resulttext .= '</ul>';
13983: } else {
13984: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
13985: }
13986: } else {
13987: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
13988: }
13989: }
1.147 raeburn 13990: $resulttext .= '</ul>';
13991: } else {
13992: $resulttext = $nochgmsg;
1.137 raeburn 13993: }
13994: } else {
13995: $resulttext = '<span class="LC_error">'.
13996: &mt('An error occurred: [_1]',$putresult).'</span>';
13997: }
13998: } else {
1.147 raeburn 13999: $resulttext = $nochgmsg;
1.137 raeburn 14000: }
14001: return $resulttext;
14002: }
14003:
1.275 raeburn 14004: sub modify_ssl {
14005: my ($dom,$lastactref,%domconfig) = @_;
14006: my (%by_ip,%by_location,@intdoms,@instdoms);
14007: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14008: my @locations = sort(keys(%by_location));
14009: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14010: my (%defaultshash,%changes);
14011: my $action = 'ssl';
1.293 raeburn 14012: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 14013: foreach my $prefix (@prefixes) {
14014: $defaultshash{$action}{$prefix} = {};
14015: }
14016: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14017: my $resulttext;
14018: my %iphost = &Apache::lonnet::get_iphost();
14019: my @reptypes = ('certreq','nocertreq');
14020: my @connecttypes = ('dom','intdom','other');
14021: my %types = (
1.293 raeburn 14022: connto => \@connecttypes,
14023: connfrom => \@connecttypes,
14024: replication => \@reptypes,
1.275 raeburn 14025: );
14026: foreach my $prefix (sort(keys(%types))) {
14027: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 14028: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 14029: my $value = 'yes';
14030: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
14031: $value = $env{'form.'.$prefix.'_'.$type};
14032: }
14033: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
14034: if ($domconfig{$action}{$prefix}{$type} ne '') {
14035: if ($value ne $domconfig{$action}{$prefix}{$type}) {
14036: $changes{$prefix}{$type} = 1;
14037: }
14038: $defaultshash{$action}{$prefix}{$type} = $value;
14039: } else {
14040: $defaultshash{$action}{$prefix}{$type} = $value;
14041: $changes{$prefix}{$type} = 1;
14042: }
14043: } else {
14044: $defaultshash{$action}{$prefix}{$type} = $value;
14045: $changes{$prefix}{$type} = 1;
14046: }
14047: if (($type eq 'dom') && (keys(%servers) == 1)) {
14048: delete($changes{$prefix}{$type});
14049: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
14050: delete($changes{$prefix}{$type});
14051: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
14052: delete($changes{$prefix}{$type});
14053: }
14054: } elsif ($prefix eq 'replication') {
14055: if (@locations > 0) {
14056: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14057: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14058: my @okvals;
14059: foreach my $val (@vals) {
14060: if ($val =~ /:/) {
14061: my @items = split(/:/,$val);
14062: foreach my $item (@items) {
14063: if (ref($by_location{$item}) eq 'ARRAY') {
14064: push(@okvals,$item);
14065: }
14066: }
14067: } else {
14068: if (ref($by_location{$val}) eq 'ARRAY') {
14069: push(@okvals,$val);
14070: }
14071: }
14072: }
14073: @okvals = sort(@okvals);
14074: if (ref($domconfig{$action}) eq 'HASH') {
14075: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
14076: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
14077: if ($inuse == 0) {
14078: $changes{$prefix}{$type} = 1;
14079: } else {
14080: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14081: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
14082: if (@changed > 0) {
14083: $changes{$prefix}{$type} = 1;
14084: }
14085: }
14086: } else {
14087: if ($inuse == 1) {
14088: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14089: $changes{$prefix}{$type} = 1;
14090: }
14091: }
14092: } else {
14093: if ($inuse == 1) {
14094: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14095: $changes{$prefix}{$type} = 1;
14096: }
14097: }
14098: } else {
14099: if ($inuse == 1) {
14100: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14101: $changes{$prefix}{$type} = 1;
14102: }
14103: }
14104: }
14105: }
14106: }
14107: }
14108: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
14109: if (keys(%changes) > 0) {
14110: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14111: $dom);
14112: if ($putresult eq 'ok') {
14113: if (ref($defaultshash{$action}) eq 'HASH') {
14114: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
14115: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
14116: }
1.293 raeburn 14117: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
14118: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
14119: }
14120: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
14121: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275 raeburn 14122: }
14123: }
14124: my $cachetime = 24*60*60;
14125: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14126: if (ref($lastactref) eq 'HASH') {
14127: $lastactref->{'domdefaults'} = 1;
14128: }
14129: if (keys(%changes) > 0) {
14130: my %titles = &ssl_titles();
14131: $resulttext = &mt('Changes made:').'<ul>';
14132: foreach my $prefix (@prefixes) {
14133: if (ref($changes{$prefix}) eq 'HASH') {
14134: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
14135: foreach my $type (@{$types{$prefix}}) {
14136: if (defined($changes{$prefix}{$type})) {
14137: my $newvalue;
14138: if (ref($defaultshash{$action}) eq 'HASH') {
14139: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 14140: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 14141: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
14142: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
14143: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
14144: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
14145: }
14146: }
14147: }
14148: if ($newvalue eq '') {
14149: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
14150: } else {
14151: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
14152: }
14153: }
14154: }
14155: }
14156: $resulttext .= '</ul>';
14157: }
14158: }
14159: } else {
14160: $resulttext = $nochgmsg;
14161: }
14162: } else {
14163: $resulttext = '<span class="LC_error">'.
14164: &mt('An error occurred: [_1]',$putresult).'</span>';
14165: }
14166: } else {
14167: $resulttext = $nochgmsg;
14168: }
14169: return $resulttext;
14170: }
14171:
1.279 raeburn 14172: sub modify_trust {
14173: my ($dom,$lastactref,%domconfig) = @_;
14174: my (%by_ip,%by_location,@intdoms,@instdoms);
14175: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14176: my @locations = sort(keys(%by_location));
14177: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
14178: my @types = ('exc','inc');
14179: my (%defaultshash,%changes);
14180: foreach my $prefix (@prefixes) {
14181: $defaultshash{'trust'}{$prefix} = {};
14182: }
14183: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14184: my $resulttext;
14185: foreach my $prefix (@prefixes) {
14186: foreach my $type (@types) {
14187: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14188: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14189: my @okvals;
14190: foreach my $val (@vals) {
14191: if ($val =~ /:/) {
14192: my @items = split(/:/,$val);
14193: foreach my $item (@items) {
14194: if (ref($by_location{$item}) eq 'ARRAY') {
14195: push(@okvals,$item);
14196: }
14197: }
14198: } else {
14199: if (ref($by_location{$val}) eq 'ARRAY') {
14200: push(@okvals,$val);
14201: }
14202: }
14203: }
14204: @okvals = sort(@okvals);
14205: if (ref($domconfig{'trust'}) eq 'HASH') {
14206: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
14207: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14208: if ($inuse == 0) {
14209: $changes{$prefix}{$type} = 1;
14210: } else {
14211: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14212: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
14213: if (@changed > 0) {
14214: $changes{$prefix}{$type} = 1;
14215: }
14216: }
14217: } else {
14218: if ($inuse == 1) {
14219: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14220: $changes{$prefix}{$type} = 1;
14221: }
14222: }
14223: } else {
14224: if ($inuse == 1) {
14225: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14226: $changes{$prefix}{$type} = 1;
14227: }
14228: }
14229: } else {
14230: if ($inuse == 1) {
14231: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14232: $changes{$prefix}{$type} = 1;
14233: }
14234: }
14235: }
14236: }
14237: my $nochgmsg = &mt('No changes made to trust settings.');
14238: if (keys(%changes) > 0) {
14239: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14240: $dom);
14241: if ($putresult eq 'ok') {
14242: if (ref($defaultshash{'trust'}) eq 'HASH') {
14243: foreach my $prefix (@prefixes) {
14244: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
14245: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
14246: }
14247: }
14248: }
14249: my $cachetime = 24*60*60;
14250: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14251: if (ref($lastactref) eq 'HASH') {
14252: $lastactref->{'domdefaults'} = 1;
14253: }
14254: if (keys(%changes) > 0) {
14255: my %lt = &trust_titles();
14256: $resulttext = &mt('Changes made:').'<ul>';
14257: foreach my $prefix (@prefixes) {
14258: if (ref($changes{$prefix}) eq 'HASH') {
14259: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14260: foreach my $type (@types) {
14261: if (defined($changes{$prefix}{$type})) {
14262: my $newvalue;
14263: if (ref($defaultshash{'trust'}) eq 'HASH') {
14264: if (ref($defaultshash{'trust'}{$prefix})) {
14265: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14266: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
14267: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
14268: }
14269: }
14270: }
14271: }
14272: if ($newvalue eq '') {
14273: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14274: } else {
14275: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
14276: }
14277: }
14278: }
14279: $resulttext .= '</ul>';
14280: }
14281: }
14282: $resulttext .= '</ul>';
14283: } else {
14284: $resulttext = $nochgmsg;
14285: }
14286: } else {
14287: $resulttext = '<span class="LC_error">'.
14288: &mt('An error occurred: [_1]',$putresult).'</span>';
14289: }
14290: } else {
14291: $resulttext = $nochgmsg;
14292: }
14293: return $resulttext;
14294: }
14295:
1.150 raeburn 14296: sub modify_loadbalancing {
14297: my ($dom,%domconfig) = @_;
14298: my $primary_id = &Apache::lonnet::domain($dom,'primary');
14299: my $intdom = &Apache::lonnet::internet_dom($primary_id);
14300: my ($othertitle,$usertypes,$types) =
14301: &Apache::loncommon::sorted_inst_types($dom);
14302: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 14303: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 14304: my @sparestypes = ('primary','default');
14305: my %typetitles = &sparestype_titles();
14306: my $resulttext;
1.171 raeburn 14307: my (%currbalancer,%currtargets,%currrules,%existing);
14308: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14309: %existing = %{$domconfig{'loadbalancing'}};
14310: }
14311: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
14312: \%currtargets,\%currrules);
14313: my ($saveloadbalancing,%defaultshash,%changes);
14314: my ($alltypes,$othertypes,$titles) =
14315: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
14316: my %ruletitles = &offloadtype_text();
14317: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
14318: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
14319: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
14320: if ($balancer eq '') {
14321: next;
14322: }
1.210 raeburn 14323: if (!exists($servers{$balancer})) {
1.171 raeburn 14324: if (exists($currbalancer{$balancer})) {
14325: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 14326: }
1.171 raeburn 14327: next;
14328: }
14329: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
14330: push(@{$changes{'delete'}},$balancer);
14331: next;
14332: }
14333: if (!exists($currbalancer{$balancer})) {
14334: push(@{$changes{'add'}},$balancer);
14335: }
14336: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
14337: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
14338: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
14339: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14340: $saveloadbalancing = 1;
14341: }
14342: foreach my $sparetype (@sparestypes) {
14343: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
14344: my @offloadto;
14345: foreach my $target (@targets) {
14346: if (($servers{$target}) && ($target ne $balancer)) {
14347: if ($sparetype eq 'default') {
14348: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
14349: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 14350: }
14351: }
1.171 raeburn 14352: unless(grep(/^\Q$target\E$/,@offloadto)) {
14353: push(@offloadto,$target);
14354: }
1.150 raeburn 14355: }
14356: }
1.284 raeburn 14357: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
14358: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
14359: push(@offloadto,$balancer);
14360: }
14361: }
14362: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 14363: }
1.171 raeburn 14364: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 14365: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14366: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
14367: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 14368: if (@targetdiffs > 0) {
1.171 raeburn 14369: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14370: }
1.171 raeburn 14371: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14372: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14373: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14374: }
14375: }
14376: }
14377: } else {
1.171 raeburn 14378: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 14379: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14380: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14381: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14382: $changes{'curr'}{$balancer}{'targets'} = 1;
14383: }
1.150 raeburn 14384: }
14385: }
1.210 raeburn 14386: }
1.150 raeburn 14387: }
14388: my $ishomedom;
1.171 raeburn 14389: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
14390: $ishomedom = 1;
1.150 raeburn 14391: }
14392: if (ref($alltypes) eq 'ARRAY') {
14393: foreach my $type (@{$alltypes}) {
14394: my $rule;
1.210 raeburn 14395: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 14396: (!$ishomedom)) {
1.171 raeburn 14397: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
14398: }
14399: if ($rule eq 'specific') {
1.255 raeburn 14400: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 14401: if (exists($servers{$specifiedhost})) {
1.255 raeburn 14402: $rule = $specifiedhost;
14403: }
1.150 raeburn 14404: }
1.171 raeburn 14405: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
14406: if (ref($currrules{$balancer}) eq 'HASH') {
14407: if ($rule ne $currrules{$balancer}{$type}) {
14408: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14409: }
14410: } elsif ($rule ne '') {
1.171 raeburn 14411: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14412: }
14413: }
14414: }
1.171 raeburn 14415: }
14416: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
14417: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
14418: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
14419: $defaultshash{'loadbalancing'} = {};
14420: }
14421: my $putresult = &Apache::lonnet::put_dom('configuration',
14422: \%defaultshash,$dom);
14423: if ($putresult eq 'ok') {
14424: if (keys(%changes) > 0) {
1.252 raeburn 14425: my %toupdate;
1.171 raeburn 14426: if (ref($changes{'delete'}) eq 'ARRAY') {
14427: foreach my $balancer (sort(@{$changes{'delete'}})) {
14428: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 14429: $toupdate{$balancer} = 1;
1.150 raeburn 14430: }
1.171 raeburn 14431: }
14432: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 14433: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 14434: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 14435: $toupdate{$balancer} = 1;
1.171 raeburn 14436: }
14437: }
14438: if (ref($changes{'curr'}) eq 'HASH') {
14439: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 14440: $toupdate{$balancer} = 1;
1.171 raeburn 14441: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
14442: if ($changes{'curr'}{$balancer}{'targets'}) {
14443: my %offloadstr;
14444: foreach my $sparetype (@sparestypes) {
14445: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14446: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14447: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14448: }
14449: }
1.150 raeburn 14450: }
1.171 raeburn 14451: if (keys(%offloadstr) == 0) {
14452: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 14453: } else {
1.171 raeburn 14454: my $showoffload;
14455: foreach my $sparetype (@sparestypes) {
14456: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
14457: if (defined($offloadstr{$sparetype})) {
14458: $showoffload .= $offloadstr{$sparetype};
14459: } else {
14460: $showoffload .= &mt('None');
14461: }
14462: $showoffload .= (' 'x3);
14463: }
14464: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 14465: }
14466: }
14467: }
1.171 raeburn 14468: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
14469: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
14470: foreach my $type (@{$alltypes}) {
14471: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
14472: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14473: my $balancetext;
14474: if ($rule eq '') {
14475: $balancetext = $ruletitles{'default'};
1.209 raeburn 14476: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 14477: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 14478: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 14479: foreach my $sparetype (@sparestypes) {
14480: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14481: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14482: }
14483: }
1.253 raeburn 14484: foreach my $item (@{$alltypes}) {
14485: next if ($item =~ /^_LC_ipchange/);
14486: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
14487: if ($hasrule eq 'homeserver') {
14488: map { $toupdate{$_} = 1; } (keys(%libraryservers));
14489: } else {
14490: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
14491: if ($servers{$hasrule}) {
14492: $toupdate{$hasrule} = 1;
14493: }
14494: }
14495: }
14496: }
1.254 raeburn 14497: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
14498: $balancetext = $ruletitles{$rule};
14499: } else {
14500: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14501: $balancetext = $ruletitles{'particular'}.' '.$receiver;
14502: if ($receiver) {
14503: $toupdate{$receiver};
14504: }
14505: }
14506: } else {
14507: $balancetext = $ruletitles{$rule};
1.252 raeburn 14508: }
1.171 raeburn 14509: } else {
14510: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
14511: }
1.210 raeburn 14512: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 14513: }
14514: }
14515: }
14516: }
1.252 raeburn 14517: if (keys(%toupdate)) {
14518: my %thismachine;
14519: my $updatedhere;
14520: my $cachetime = 60*60*24;
14521: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
14522: foreach my $lonhost (keys(%toupdate)) {
14523: if ($thismachine{$lonhost}) {
14524: unless ($updatedhere) {
14525: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
14526: $defaultshash{'loadbalancing'},
14527: $cachetime);
14528: $updatedhere = 1;
14529: }
14530: } else {
14531: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
14532: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
14533: }
14534: }
14535: }
1.150 raeburn 14536: }
1.171 raeburn 14537: }
14538: if ($resulttext ne '') {
14539: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 14540: } else {
14541: $resulttext = $nochgmsg;
14542: }
14543: } else {
1.171 raeburn 14544: $resulttext = $nochgmsg;
1.150 raeburn 14545: }
14546: } else {
1.171 raeburn 14547: $resulttext = '<span class="LC_error">'.
14548: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 14549: }
14550: } else {
1.171 raeburn 14551: $resulttext = $nochgmsg;
1.150 raeburn 14552: }
14553: return $resulttext;
14554: }
14555:
1.48 raeburn 14556: sub recurse_check {
14557: my ($chkcats,$categories,$depth,$name) = @_;
14558: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
14559: my $chg = 0;
14560: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
14561: my $category = $chkcats->[$depth]{$name}[$j];
14562: my $item;
14563: if ($category eq '') {
14564: $chg ++;
14565: } else {
14566: my $deeper = $depth + 1;
14567: $item = &escape($category).':'.&escape($name).':'.$depth;
14568: if ($chg) {
14569: $categories->{$item} -= $chg;
14570: }
14571: &recurse_check($chkcats,$categories,$deeper,$category);
14572: $deeper --;
14573: }
14574: }
14575: }
14576: return;
14577: }
14578:
14579: sub recurse_cat_deletes {
14580: my ($item,$coursecategories,$deletions) = @_;
14581: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14582: my $subdepth = $depth + 1;
14583: if (ref($coursecategories) eq 'HASH') {
14584: foreach my $subitem (keys(%{$coursecategories})) {
14585: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
14586: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
14587: delete($coursecategories->{$subitem});
14588: $deletions->{$subitem} = 1;
14589: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 14590: }
1.48 raeburn 14591: }
14592: }
14593: return;
14594: }
14595:
1.125 raeburn 14596: sub active_dc_picker {
1.191 raeburn 14597: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 14598: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 14599: my @domcoord = keys(%domcoords);
14600: if (keys(%currhash)) {
14601: foreach my $dc (keys(%currhash)) {
14602: unless (exists($domcoords{$dc})) {
14603: push(@domcoord,$dc);
14604: }
14605: }
14606: }
14607: @domcoord = sort(@domcoord);
1.210 raeburn 14608: my $numdcs = scalar(@domcoord);
1.191 raeburn 14609: my $rows = 0;
14610: my $table;
1.125 raeburn 14611: if ($numdcs > 1) {
1.191 raeburn 14612: $table = '<table>';
14613: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 14614: my $rem = $i%($numinrow);
14615: if ($rem == 0) {
14616: if ($i > 0) {
1.191 raeburn 14617: $table .= '</tr>';
1.125 raeburn 14618: }
1.191 raeburn 14619: $table .= '<tr>';
14620: $rows ++;
1.125 raeburn 14621: }
1.191 raeburn 14622: my $check = '';
14623: if ($inputtype eq 'radio') {
14624: if (keys(%currhash) == 0) {
14625: if (!$i) {
14626: $check = ' checked="checked"';
14627: }
14628: } elsif (exists($currhash{$domcoord[$i]})) {
14629: $check = ' checked="checked"';
14630: }
14631: } else {
14632: if (exists($currhash{$domcoord[$i]})) {
14633: $check = ' checked="checked"';
1.125 raeburn 14634: }
14635: }
1.191 raeburn 14636: if ($i == @domcoord - 1) {
1.125 raeburn 14637: my $colsleft = $numinrow - $rem;
14638: if ($colsleft > 1) {
1.191 raeburn 14639: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 14640: } else {
1.191 raeburn 14641: $table .= '<td class="LC_left_item">';
1.125 raeburn 14642: }
14643: } else {
1.191 raeburn 14644: $table .= '<td class="LC_left_item">';
14645: }
14646: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
14647: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
14648: $table .= '<span class="LC_nobreak"><label>'.
14649: '<input type="'.$inputtype.'" name="'.$name.'"'.
14650: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
14651: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 14652: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 14653: }
1.219 raeburn 14654: $table .= '</label></span></td>';
1.191 raeburn 14655: }
14656: $table .= '</tr></table>';
14657: } elsif ($numdcs == 1) {
1.219 raeburn 14658: my ($dcname,$dcdom) = split(':',$domcoord[0]);
14659: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 14660: if ($inputtype eq 'radio') {
1.247 raeburn 14661: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 14662: if ($user ne $dcname.':'.$dcdom) {
14663: $table .= ' ('.$dcname.':'.$dcdom.')';
14664: }
1.191 raeburn 14665: } else {
14666: my $check;
14667: if (exists($currhash{$domcoord[0]})) {
14668: $check = ' checked="checked"';
1.125 raeburn 14669: }
1.247 raeburn 14670: $table = '<span class="LC_nobreak"><label>'.
14671: '<input type="checkbox" name="'.$name.'" '.
14672: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 14673: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 14674: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 14675: }
1.220 raeburn 14676: $table .= '</label></span>';
1.191 raeburn 14677: $rows ++;
1.125 raeburn 14678: }
14679: }
1.191 raeburn 14680: return ($numdcs,$table,$rows);
1.125 raeburn 14681: }
14682:
1.137 raeburn 14683: sub usersession_titles {
14684: return &Apache::lonlocal::texthash(
14685: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
14686: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 14687: spares => 'Servers offloaded to, when busy',
1.137 raeburn 14688: version => 'LON-CAPA version requirement',
1.138 raeburn 14689: excludedomain => 'Allow all, but exclude specific domains',
14690: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 14691: primary => 'Primary (checked first)',
1.154 raeburn 14692: default => 'Default',
1.137 raeburn 14693: );
14694: }
14695:
1.152 raeburn 14696: sub id_for_thisdom {
14697: my (%servers) = @_;
14698: my %altids;
14699: foreach my $server (keys(%servers)) {
14700: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
14701: if ($serverhome ne $server) {
14702: $altids{$serverhome} = $server;
14703: }
14704: }
14705: return %altids;
14706: }
14707:
1.150 raeburn 14708: sub count_servers {
14709: my ($currbalancer,%servers) = @_;
14710: my (@spares,$numspares);
14711: foreach my $lonhost (sort(keys(%servers))) {
14712: next if ($currbalancer eq $lonhost);
14713: push(@spares,$lonhost);
14714: }
14715: if ($currbalancer) {
14716: $numspares = scalar(@spares);
14717: } else {
14718: $numspares = scalar(@spares) - 1;
14719: }
14720: return ($numspares,@spares);
14721: }
14722:
14723: sub lonbalance_targets_js {
1.171 raeburn 14724: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 14725: my $select = &mt('Select');
14726: my ($alltargets,$allishome,$allinsttypes,@alltypes);
14727: if (ref($servers) eq 'HASH') {
14728: $alltargets = join("','",sort(keys(%{$servers})));
14729: my @homedoms;
14730: foreach my $server (sort(keys(%{$servers}))) {
14731: if (&Apache::lonnet::host_domain($server) eq $dom) {
14732: push(@homedoms,'1');
14733: } else {
14734: push(@homedoms,'0');
14735: }
14736: }
14737: $allishome = join("','",@homedoms);
14738: }
14739: if (ref($types) eq 'ARRAY') {
14740: if (@{$types} > 0) {
14741: @alltypes = @{$types};
14742: }
14743: }
14744: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
14745: $allinsttypes = join("','",@alltypes);
1.171 raeburn 14746: my (%currbalancer,%currtargets,%currrules,%existing);
14747: if (ref($settings) eq 'HASH') {
14748: %existing = %{$settings};
14749: }
14750: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
14751: \%currtargets,\%currrules);
1.210 raeburn 14752: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 14753: return <<"END";
14754:
14755: <script type="text/javascript">
14756: // <![CDATA[
14757:
1.171 raeburn 14758: currBalancers = new Array('$balancers');
14759:
14760: function toggleTargets(balnum) {
14761: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14762: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
14763: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
14764: var prevbalancer = prevhostitem.value;
14765: var baltotal = document.getElementById('loadbalancing_total').value;
14766: prevhostitem.value = balancer;
14767: if (prevbalancer != '') {
14768: var prevIdx = currBalancers.indexOf(prevbalancer);
14769: if (prevIdx != -1) {
14770: currBalancers.splice(prevIdx,1);
14771: }
14772: }
1.150 raeburn 14773: if (balancer == '') {
1.171 raeburn 14774: hideSpares(balnum);
1.150 raeburn 14775: } else {
1.171 raeburn 14776: var currIdx = currBalancers.indexOf(balancer);
14777: if (currIdx == -1) {
14778: currBalancers.push(balancer);
14779: }
1.150 raeburn 14780: var homedoms = new Array('$allishome');
1.171 raeburn 14781: var ishomedom = homedoms[lonhostitem.selectedIndex];
14782: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 14783: }
1.171 raeburn 14784: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 14785: return;
14786: }
14787:
1.171 raeburn 14788: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 14789: var alltargets = new Array('$alltargets');
14790: var insttypes = new Array('$allinsttypes');
1.151 raeburn 14791: var offloadtypes = new Array('primary','default');
14792:
1.171 raeburn 14793: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
14794: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 14795:
1.151 raeburn 14796: for (var i=0; i<offloadtypes.length; i++) {
14797: var count = 0;
14798: for (var j=0; j<alltargets.length; j++) {
14799: if (alltargets[j] != balancer) {
1.171 raeburn 14800: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
14801: item.value = alltargets[j];
14802: item.style.textAlign='left';
14803: item.style.textFace='normal';
14804: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
14805: if (currBalancers.indexOf(alltargets[j]) == -1) {
14806: item.disabled = '';
14807: } else {
14808: item.disabled = 'disabled';
14809: item.checked = false;
14810: }
1.151 raeburn 14811: count ++;
14812: }
1.150 raeburn 14813: }
14814: }
1.151 raeburn 14815: for (var k=0; k<insttypes.length; k++) {
14816: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 14817: if (ishomedom == 1) {
1.171 raeburn 14818: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14819: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14820: } else {
1.171 raeburn 14821: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14822: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 14823: }
14824: } else {
1.171 raeburn 14825: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14826: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14827: }
1.151 raeburn 14828: if ((insttypes[k] != '_LC_external') &&
14829: ((insttypes[k] != '_LC_internetdom') ||
14830: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 14831: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
14832: item.options.length = 0;
14833: item.options[0] = new Option("","",true,true);
1.210 raeburn 14834: var idx = 0;
1.151 raeburn 14835: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 14836: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
14837: idx ++;
14838: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 14839: }
14840: }
14841: }
14842: }
14843: return;
14844: }
14845:
1.171 raeburn 14846: function hideSpares(balnum) {
1.150 raeburn 14847: var alltargets = new Array('$alltargets');
14848: var insttypes = new Array('$allinsttypes');
14849: var offloadtypes = new Array('primary','default');
14850:
1.171 raeburn 14851: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
14852: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 14853:
14854: var total = alltargets.length - 1;
14855: for (var i=0; i<offloadtypes; i++) {
14856: for (var j=0; j<total; j++) {
1.171 raeburn 14857: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
14858: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
14859: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 14860: }
1.150 raeburn 14861: }
14862: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 14863: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14864: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 14865: if (insttypes[k] != '_LC_external') {
1.171 raeburn 14866: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
14867: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 14868: }
14869: }
14870: return;
14871: }
14872:
1.171 raeburn 14873: function checkOffloads(item,balnum,type) {
1.150 raeburn 14874: var alltargets = new Array('$alltargets');
14875: var offloadtypes = new Array('primary','default');
14876: if (item.checked) {
14877: var total = alltargets.length - 1;
14878: var other;
14879: if (type == offloadtypes[0]) {
1.151 raeburn 14880: other = offloadtypes[1];
1.150 raeburn 14881: } else {
1.151 raeburn 14882: other = offloadtypes[0];
1.150 raeburn 14883: }
14884: for (var i=0; i<total; i++) {
1.171 raeburn 14885: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 14886: if (server == item.value) {
1.171 raeburn 14887: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
14888: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 14889: }
14890: }
14891: }
14892: }
14893: return;
14894: }
14895:
1.171 raeburn 14896: function singleServerToggle(balnum,type) {
14897: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 14898: if (offloadtoSelIdx == 0) {
1.171 raeburn 14899: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
14900: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14901:
14902: } else {
1.171 raeburn 14903: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
14904: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 14905: }
14906: return;
14907: }
14908:
1.171 raeburn 14909: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 14910: if (type == '_LC_external') {
1.171 raeburn 14911: return;
1.150 raeburn 14912: }
1.171 raeburn 14913: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 14914: for (var i=0; i<typesRules.length; i++) {
14915: if (formname.elements[typesRules[i]].checked) {
14916: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 14917: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
14918: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14919: } else {
1.171 raeburn 14920: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
14921: }
14922: }
14923: }
14924: return;
14925: }
14926:
14927: function balancerDeleteChange(balnum) {
14928: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14929: var baltotal = document.getElementById('loadbalancing_total').value;
14930: var addtarget;
14931: var removetarget;
14932: var action = 'delete';
14933: if (document.getElementById('loadbalancing_delete_'+balnum)) {
14934: var lonhost = hostitem.value;
14935: var currIdx = currBalancers.indexOf(lonhost);
14936: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
14937: if (currIdx != -1) {
14938: currBalancers.splice(currIdx,1);
14939: }
14940: addtarget = lonhost;
14941: } else {
14942: if (currIdx == -1) {
14943: currBalancers.push(lonhost);
14944: }
14945: removetarget = lonhost;
14946: action = 'undelete';
14947: }
14948: balancerChange(balnum,baltotal,action,addtarget,removetarget);
14949: }
14950: return;
14951: }
14952:
14953: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
14954: if (baltotal > 1) {
14955: var offloadtypes = new Array('primary','default');
14956: var alltargets = new Array('$alltargets');
14957: var insttypes = new Array('$allinsttypes');
14958: for (var i=0; i<baltotal; i++) {
14959: if (i != balnum) {
14960: for (var j=0; j<offloadtypes.length; j++) {
14961: var total = alltargets.length - 1;
14962: for (var k=0; k<total; k++) {
14963: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
14964: var server = serveritem.value;
14965: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14966: if (server == addtarget) {
14967: serveritem.disabled = '';
14968: }
14969: }
14970: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14971: if (server == removetarget) {
14972: serveritem.disabled = 'disabled';
14973: serveritem.checked = false;
14974: }
14975: }
14976: }
14977: }
14978: for (var j=0; j<insttypes.length; j++) {
14979: if (insttypes[j] != '_LC_external') {
14980: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
14981: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
14982: var currSel = singleserver.selectedIndex;
14983: var currVal = singleserver.options[currSel].value;
14984: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14985: var numoptions = singleserver.options.length;
14986: var needsnew = 1;
14987: for (var k=0; k<numoptions; k++) {
14988: if (singleserver.options[k] == addtarget) {
14989: needsnew = 0;
14990: break;
14991: }
14992: }
14993: if (needsnew == 1) {
14994: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
14995: }
14996: }
14997: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14998: singleserver.options.length = 0;
14999: if ((currVal) && (currVal != removetarget)) {
15000: singleserver.options[0] = new Option("","",false,false);
15001: } else {
15002: singleserver.options[0] = new Option("","",true,true);
15003: }
15004: var idx = 0;
15005: for (var m=0; m<alltargets.length; m++) {
15006: if (currBalancers.indexOf(alltargets[m]) == -1) {
15007: idx ++;
15008: if (currVal == alltargets[m]) {
15009: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
15010: } else {
15011: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
15012: }
15013: }
15014: }
15015: }
15016: }
15017: }
15018: }
1.150 raeburn 15019: }
15020: }
15021: }
15022: return;
15023: }
15024:
1.152 raeburn 15025: // ]]>
15026: </script>
15027:
15028: END
15029: }
15030:
15031: sub new_spares_js {
15032: my @sparestypes = ('primary','default');
15033: my $types = join("','",@sparestypes);
15034: my $select = &mt('Select');
15035: return <<"END";
15036:
15037: <script type="text/javascript">
15038: // <![CDATA[
15039:
15040: function updateNewSpares(formname,lonhost) {
15041: var types = new Array('$types');
15042: var include = new Array();
15043: var exclude = new Array();
15044: for (var i=0; i<types.length; i++) {
15045: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
15046: for (var j=0; j<spareboxes.length; j++) {
15047: if (formname.elements[spareboxes[j]].checked) {
15048: exclude.push(formname.elements[spareboxes[j]].value);
15049: } else {
15050: include.push(formname.elements[spareboxes[j]].value);
15051: }
15052: }
15053: }
15054: for (var i=0; i<types.length; i++) {
15055: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
15056: var selIdx = newSpare.selectedIndex;
15057: var currnew = newSpare.options[selIdx].value;
15058: var okSpares = new Array();
15059: for (var j=0; j<newSpare.options.length; j++) {
15060: var possible = newSpare.options[j].value;
15061: if (possible != '') {
15062: if (exclude.indexOf(possible) == -1) {
15063: okSpares.push(possible);
15064: } else {
15065: if (currnew == possible) {
15066: selIdx = 0;
15067: }
15068: }
15069: }
15070: }
15071: for (var k=0; k<include.length; k++) {
15072: if (okSpares.indexOf(include[k]) == -1) {
15073: okSpares.push(include[k]);
15074: }
15075: }
15076: okSpares.sort();
15077: newSpare.options.length = 0;
15078: if (selIdx == 0) {
15079: newSpare.options[0] = new Option("$select","",true,true);
15080: } else {
15081: newSpare.options[0] = new Option("$select","",false,false);
15082: }
15083: for (var m=0; m<okSpares.length; m++) {
15084: var idx = m+1;
15085: var selThis = 0;
15086: if (selIdx != 0) {
15087: if (okSpares[m] == currnew) {
15088: selThis = 1;
15089: }
15090: }
15091: if (selThis == 1) {
15092: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
15093: } else {
15094: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
15095: }
15096: }
15097: }
15098: return;
15099: }
15100:
15101: function checkNewSpares(lonhost,type) {
15102: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
15103: var chosen = newSpare.options[newSpare.selectedIndex].value;
15104: if (chosen != '') {
15105: var othertype;
15106: var othernewSpare;
15107: if (type == 'primary') {
15108: othernewSpare = document.getElementById('newspare_default_'+lonhost);
15109: }
15110: if (type == 'default') {
15111: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
15112: }
15113: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
15114: othernewSpare.selectedIndex = 0;
15115: }
15116: }
15117: return;
15118: }
15119:
15120: // ]]>
15121: </script>
15122:
15123: END
15124:
15125: }
15126:
15127: sub common_domprefs_js {
15128: return <<"END";
15129:
15130: <script type="text/javascript">
15131: // <![CDATA[
15132:
1.150 raeburn 15133: function getIndicesByName(formname,item) {
1.152 raeburn 15134: var group = new Array();
1.150 raeburn 15135: for (var i=0;i<formname.elements.length;i++) {
15136: if (formname.elements[i].name == item) {
1.152 raeburn 15137: group.push(formname.elements[i].id);
1.150 raeburn 15138: }
15139: }
1.152 raeburn 15140: return group;
1.150 raeburn 15141: }
15142:
15143: // ]]>
15144: </script>
15145:
15146: END
1.152 raeburn 15147:
1.150 raeburn 15148: }
15149:
1.165 raeburn 15150: sub recaptcha_js {
15151: my %lt = &captcha_phrases();
15152: return <<"END";
15153:
15154: <script type="text/javascript">
15155: // <![CDATA[
15156:
15157: function updateCaptcha(caller,context) {
15158: var privitem;
15159: var pubitem;
15160: var privtext;
15161: var pubtext;
1.269 raeburn 15162: var versionitem;
15163: var versiontext;
1.165 raeburn 15164: if (document.getElementById(context+'_recaptchapub')) {
15165: pubitem = document.getElementById(context+'_recaptchapub');
15166: } else {
15167: return;
15168: }
15169: if (document.getElementById(context+'_recaptchapriv')) {
15170: privitem = document.getElementById(context+'_recaptchapriv');
15171: } else {
15172: return;
15173: }
15174: if (document.getElementById(context+'_recaptchapubtxt')) {
15175: pubtext = document.getElementById(context+'_recaptchapubtxt');
15176: } else {
15177: return;
15178: }
15179: if (document.getElementById(context+'_recaptchaprivtxt')) {
15180: privtext = document.getElementById(context+'_recaptchaprivtxt');
15181: } else {
15182: return;
15183: }
1.269 raeburn 15184: if (document.getElementById(context+'_recaptchaversion')) {
15185: versionitem = document.getElementById(context+'_recaptchaversion');
15186: } else {
15187: return;
15188: }
15189: if (document.getElementById(context+'_recaptchavertxt')) {
15190: versiontext = document.getElementById(context+'_recaptchavertxt');
15191: } else {
15192: return;
15193: }
1.165 raeburn 15194: if (caller.checked) {
15195: if (caller.value == 'recaptcha') {
15196: pubitem.type = 'text';
15197: privitem.type = 'text';
15198: pubitem.size = '40';
15199: privitem.size = '40';
15200: pubtext.innerHTML = "$lt{'pub'}";
15201: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 15202: versionitem.type = 'text';
15203: versionitem.size = '3';
1.289 raeburn 15204: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 15205: } else {
15206: pubitem.type = 'hidden';
15207: privitem.type = 'hidden';
1.269 raeburn 15208: versionitem.type = 'hidden';
1.165 raeburn 15209: pubtext.innerHTML = '';
15210: privtext.innerHTML = '';
1.269 raeburn 15211: versiontext.innerHTML = '';
1.165 raeburn 15212: }
15213: }
15214: return;
15215: }
15216:
15217: // ]]>
15218: </script>
15219:
15220: END
15221:
15222: }
15223:
1.236 raeburn 15224: sub toggle_display_js {
1.192 raeburn 15225: return <<"END";
15226:
15227: <script type="text/javascript">
15228: // <![CDATA[
15229:
1.236 raeburn 15230: function toggleDisplay(domForm,caller) {
15231: if (document.getElementById(caller)) {
15232: var divitem = document.getElementById(caller);
15233: var optionsElement = domForm.coursecredits;
1.264 raeburn 15234: var checkval = 1;
15235: var dispval = 'block';
1.236 raeburn 15236: if (caller == 'emailoptions') {
15237: optionsElement = domForm.cancreate_email;
15238: }
1.257 raeburn 15239: if (caller == 'studentsubmission') {
15240: optionsElement = domForm.postsubmit;
15241: }
1.264 raeburn 15242: if (caller == 'cloneinstcode') {
15243: optionsElement = domForm.canclone;
15244: checkval = 'instcode';
15245: }
1.236 raeburn 15246: if (optionsElement.length) {
1.192 raeburn 15247: var currval;
1.236 raeburn 15248: for (var i=0; i<optionsElement.length; i++) {
15249: if (optionsElement[i].checked) {
15250: currval = optionsElement[i].value;
1.192 raeburn 15251: }
15252: }
1.264 raeburn 15253: if (currval == checkval) {
15254: divitem.style.display = dispval;
1.192 raeburn 15255: } else {
1.236 raeburn 15256: divitem.style.display = 'none';
1.192 raeburn 15257: }
15258: }
15259: }
15260: return;
15261: }
15262:
15263: // ]]>
15264: </script>
15265:
15266: END
15267:
15268: }
15269:
1.165 raeburn 15270: sub captcha_phrases {
15271: return &Apache::lonlocal::texthash (
15272: priv => 'Private key',
15273: pub => 'Public key',
15274: original => 'original (CAPTCHA)',
15275: recaptcha => 'successor (ReCAPTCHA)',
15276: notused => 'unused',
1.289 raeburn 15277: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 15278: );
15279: }
15280:
1.205 raeburn 15281: sub devalidate_remote_domconfs {
1.212 raeburn 15282: my ($dom,$cachekeys) = @_;
15283: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 15284: my %servers = &Apache::lonnet::internet_dom_servers($dom);
15285: my %thismachine;
15286: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 15287: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 15288: if (keys(%servers)) {
1.205 raeburn 15289: foreach my $server (keys(%servers)) {
15290: next if ($thismachine{$server});
1.212 raeburn 15291: my @cached;
15292: foreach my $name (@posscached) {
15293: if ($cachekeys->{$name}) {
15294: push(@cached,&escape($name).':'.&escape($dom));
15295: }
15296: }
15297: if (@cached) {
15298: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
15299: }
1.205 raeburn 15300: }
15301: }
15302: return;
15303: }
15304:
1.3 raeburn 15305: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>