Annotation of loncom/interface/domainprefs.pm, revision 1.319
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.319 ! raeburn 4: # $Id: domainprefs.pm,v 1.318 2017/11/30 01:52: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',
1.305 raeburn 284: col2 => 'Name displayed'}],
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'},
1.303 raeburn 366: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 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.305 raeburn 601: if (grep(/^selfcreation$/,@actions)) {
602: $js .= &selfcreate_javascript();
603: }
1.286 raeburn 604: if (grep(/^contacts$/,@actions)) {
605: $js .= &contacts_javascript();
606: }
1.150 raeburn 607: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 608: } else {
1.180 raeburn 609: # check if domconfig user exists for the domain.
610: my $servadm = $r->dir_config('lonAdmEMail');
611: my ($configuserok,$author_ok,$switchserver) =
612: &config_check($dom,$confname,$servadm);
613: unless ($configuserok eq 'ok') {
1.181 raeburn 614: &Apache::lonconfigsettings::print_header($r,$phase,$context);
615: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 616: $confname).
1.181 raeburn 617: '<br />'
618: );
1.180 raeburn 619: if ($switchserver) {
1.181 raeburn 620: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
621: '<br />'.
622: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
623: '<br />'.
624: &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).
625: '<br />'.
626: &mt('To do that now, use the following link: [_1]',$switchserver)
627: );
628: } else {
629: $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.').
630: '<br />'.
631: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
632: );
1.180 raeburn 633: }
634: $r->print(&Apache::loncommon::end_page());
635: return OK;
636: }
1.21 raeburn 637: if (keys(%domconfig) == 0) {
638: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 639: my @ids=&Apache::lonnet::current_machine_ids();
640: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 641: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 642: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 643: my $custom_img_count = 0;
644: foreach my $img (@loginimages) {
645: if ($designhash{$dom.'.login.'.$img} ne '') {
646: $custom_img_count ++;
647: }
648: }
649: foreach my $role (@roles) {
650: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
651: $custom_img_count ++;
652: }
653: }
654: if ($custom_img_count > 0) {
1.94 raeburn 655: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 656: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 657: $r->print(
658: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
659: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
660: &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 />'.
661: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
662: if ($switch_server) {
1.30 raeburn 663: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 664: }
1.91 raeburn 665: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 666: return OK;
667: }
668: }
669: }
1.91 raeburn 670: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 671: }
672: return OK;
673: }
674:
675: sub process_changes {
1.205 raeburn 676: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 677: my %domconfig;
678: if (ref($values) eq 'HASH') {
679: %domconfig = %{$values};
680: }
1.3 raeburn 681: my $output;
682: if ($action eq 'login') {
1.205 raeburn 683: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 684: } elsif ($action eq 'rolecolors') {
1.9 raeburn 685: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 686: $lastactref,%domconfig);
1.3 raeburn 687: } elsif ($action eq 'quotas') {
1.216 raeburn 688: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 689: } elsif ($action eq 'autoenroll') {
1.205 raeburn 690: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 691: } elsif ($action eq 'autoupdate') {
692: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 693: } elsif ($action eq 'autocreate') {
694: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 695: } elsif ($action eq 'directorysrch') {
1.295 raeburn 696: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 697: } elsif ($action eq 'usercreation') {
1.28 raeburn 698: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 699: } elsif ($action eq 'selfcreation') {
1.305 raeburn 700: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 701: } elsif ($action eq 'usermodification') {
702: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 703: } elsif ($action eq 'contacts') {
1.205 raeburn 704: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 705: } elsif ($action eq 'defaults') {
1.212 raeburn 706: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 707: } elsif ($action eq 'scantron') {
1.205 raeburn 708: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 709: } elsif ($action eq 'coursecategories') {
1.239 raeburn 710: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 711: } elsif ($action eq 'serverstatuses') {
712: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 713: } elsif ($action eq 'requestcourses') {
1.216 raeburn 714: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 715: } elsif ($action eq 'requestauthor') {
1.216 raeburn 716: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 717: } elsif ($action eq 'helpsettings') {
1.285 raeburn 718: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 719: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 720: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 721: } elsif ($action eq 'selfenrollment') {
722: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 723: } elsif ($action eq 'usersessions') {
1.212 raeburn 724: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 725: } elsif ($action eq 'loadbalancing') {
726: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 727: } elsif ($action eq 'ltitools') {
728: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 729: } elsif ($action eq 'ssl') {
730: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 731: } elsif ($action eq 'trust') {
732: $output = &modify_trust($dom,$lastactref,%domconfig);
1.3 raeburn 733: }
734: return $output;
735: }
736:
737: sub print_config_box {
1.9 raeburn 738: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 739: my $rowtotal = 0;
1.49 raeburn 740: my $output;
741: if ($action eq 'coursecategories') {
742: $output = &coursecategories_javascript($settings);
1.236 raeburn 743: } elsif ($action eq 'defaults') {
744: $output = &defaults_javascript($settings);
1.282 raeburn 745: } elsif ($action eq 'helpsettings') {
746: my (%privs,%levelscurrent);
747: my %full=();
748: my %levels=(
749: course => {},
750: domain => {},
751: system => {},
752: );
753: my $context = 'domain';
754: my $crstype = 'Course';
755: my $formname = 'display';
756: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
757: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
758: $output =
759: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
760: \@templateroles);
1.91 raeburn 761: }
1.236 raeburn 762: $output .=
1.30 raeburn 763: '<table class="LC_nested_outer">
1.3 raeburn 764: <tr>
1.306 raeburn 765: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 766: &mt($item->{text}).' '.
767: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
768: '</tr>';
1.30 raeburn 769: $rowtotal ++;
1.110 raeburn 770: my $numheaders = 1;
771: if (ref($item->{'header'}) eq 'ARRAY') {
772: $numheaders = scalar(@{$item->{'header'}});
773: }
774: if ($numheaders > 1) {
1.64 raeburn 775: my $colspan = '';
1.145 raeburn 776: my $rightcolspan = '';
1.238 raeburn 777: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 778: ($action eq 'directorysrch') ||
1.256 raeburn 779: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 780: $colspan = ' colspan="2"';
781: }
1.145 raeburn 782: if ($action eq 'usersessions') {
783: $rightcolspan = ' colspan="3"';
784: }
1.30 raeburn 785: $output .= '
1.3 raeburn 786: <tr>
787: <td>
788: <table class="LC_nested">
789: <tr class="LC_info_row">
1.59 bisitz 790: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 791: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 792: </tr>';
1.69 raeburn 793: $rowtotal ++;
1.230 raeburn 794: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 795: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 796: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 797: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
798: ($action eq 'contacts')) {
1.230 raeburn 799: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 800: } elsif ($action eq 'coursecategories') {
1.230 raeburn 801: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 802: } elsif ($action eq 'login') {
1.256 raeburn 803: if ($numheaders == 4) {
1.168 raeburn 804: $colspan = ' colspan="2"';
805: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
806: } else {
807: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
808: }
1.230 raeburn 809: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 810: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 811: } elsif ($action eq 'rolecolors') {
1.30 raeburn 812: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 813: }
1.30 raeburn 814: $output .= '
1.6 raeburn 815: </table>
816: </td>
817: </tr>
818: <tr>
819: <td>
820: <table class="LC_nested">
821: <tr class="LC_info_row">
1.230 raeburn 822: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 823: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 824: </tr>';
825: $rowtotal ++;
1.230 raeburn 826: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
827: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 828: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.294 raeburn 829: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults')) {
1.238 raeburn 830: if ($action eq 'coursecategories') {
831: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
832: $colspan = ' colspan="2"';
1.279 raeburn 833: } elsif ($action eq 'trust') {
834: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.238 raeburn 835: } else {
836: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
837: }
1.279 raeburn 838: if ($action eq 'trust') {
839: $output .= '
840: </table>
841: </td>
842: </tr>';
843: my @trusthdrs = qw(2 3 4 5 6 7);
844: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
845: for (my $i=0; $i<@trusthdrs; $i++) {
846: $output .= '
847: <tr>
848: <td>
849: <table class="LC_nested">
850: <tr class="LC_info_row">
851: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
852: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
853: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
854: </table>
855: </td>
856: </tr>';
857: }
858: $output .= '
859: <tr>
860: <td>
861: <table class="LC_nested">
862: <tr class="LC_info_row">
863: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
864: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
865: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
866: } else {
867: $output .= '
1.63 raeburn 868: </table>
869: </td>
870: </tr>
871: <tr>
872: <td>
873: <table class="LC_nested">
874: <tr class="LC_info_row">
875: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 876: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 877: </tr>'."\n";
1.279 raeburn 878: if ($action eq 'coursecategories') {
879: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
880: } else {
881: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
882: }
1.238 raeburn 883: }
1.63 raeburn 884: $rowtotal ++;
1.236 raeburn 885: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 886: ($action eq 'defaults') || ($action eq 'directorysrch') ||
887: ($action eq 'helpsettings')) {
1.230 raeburn 888: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.293 raeburn 889: } elsif ($action eq 'ssl') {
890: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
891: </table>
892: </td>
893: </tr>
894: <tr>
895: <td>
896: <table class="LC_nested">
897: <tr class="LC_info_row">
898: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
899: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
900: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
901: </table>
902: </td>
903: </tr>
904: <tr>
905: <td>
906: <table class="LC_nested">
907: <tr class="LC_info_row">
908: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
909: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
910: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 911: } elsif ($action eq 'login') {
1.256 raeburn 912: if ($numheaders == 4) {
1.168 raeburn 913: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
914: </table>
915: </td>
916: </tr>
917: <tr>
918: <td>
919: <table class="LC_nested">
920: <tr class="LC_info_row">
921: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 922: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 923: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
924: $rowtotal ++;
925: } else {
926: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
927: }
1.256 raeburn 928: $output .= '
929: </table>
930: </td>
931: </tr>
932: <tr>
933: <td>
934: <table class="LC_nested">
935: <tr class="LC_info_row">';
936: if ($numheaders == 4) {
937: $output .= '
938: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
939: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
940: </tr>';
941: } else {
942: $output .= '
943: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
944: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
945: </tr>';
946: }
947: $rowtotal ++;
948: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 949: } elsif ($action eq 'requestcourses') {
1.247 raeburn 950: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
951: $rowtotal ++;
952: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 953: </table>
954: </td>
955: </tr>
956: <tr>
957: <td>
958: <table class="LC_nested">
959: <tr class="LC_info_row">
960: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
961: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 962: &textbookcourses_javascript($settings).
963: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
964: </table>
965: </td>
966: </tr>
967: <tr>
968: <td>
969: <table class="LC_nested">
970: <tr class="LC_info_row">
971: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
972: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
973: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 974: </table>
975: </td>
976: </tr>
977: <tr>
978: <td>
979: <table class="LC_nested">
980: <tr class="LC_info_row">
1.306 raeburn 981: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
982: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 983: </tr>'.
984: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 985: } elsif ($action eq 'requestauthor') {
986: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 987: $rowtotal ++;
1.122 jms 988: } elsif ($action eq 'rolecolors') {
1.30 raeburn 989: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 990: </table>
991: </td>
992: </tr>
993: <tr>
994: <td>
995: <table class="LC_nested">
996: <tr class="LC_info_row">
1.306 raeburn 997: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 998: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 999: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1000: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1001: </tr>'.
1.30 raeburn 1002: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1003: </table>
1004: </td>
1005: </tr>
1006: <tr>
1007: <td>
1008: <table class="LC_nested">
1009: <tr class="LC_info_row">
1.59 bisitz 1010: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1011: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1012: </tr>'.
1.30 raeburn 1013: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1014: $rowtotal += 2;
1.6 raeburn 1015: }
1.3 raeburn 1016: } else {
1.30 raeburn 1017: $output .= '
1.3 raeburn 1018: <tr>
1019: <td>
1020: <table class="LC_nested">
1.30 raeburn 1021: <tr class="LC_info_row">';
1.277 raeburn 1022: if ($action eq 'login') {
1.30 raeburn 1023: $output .= '
1.59 bisitz 1024: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1025: } elsif ($action eq 'serverstatuses') {
1026: $output .= '
1.306 raeburn 1027: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1028: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1029:
1.6 raeburn 1030: } else {
1.30 raeburn 1031: $output .= '
1.306 raeburn 1032: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1033: }
1.72 raeburn 1034: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1035: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1036: &mt($item->{'header'}->[0]->{'col2'});
1037: if ($action eq 'serverstatuses') {
1038: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1039: }
1.69 raeburn 1040: } else {
1.306 raeburn 1041: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1042: &mt($item->{'header'}->[0]->{'col2'});
1043: }
1044: $output .= '</td>';
1045: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1046: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1047: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1048: &mt($item->{'header'}->[0]->{'col3'});
1049: } else {
1.306 raeburn 1050: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1051: &mt($item->{'header'}->[0]->{'col3'});
1052: }
1.69 raeburn 1053: if ($action eq 'serverstatuses') {
1054: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1055: }
1056: $output .= '</td>';
1.6 raeburn 1057: }
1.150 raeburn 1058: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1059: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1060: &mt($item->{'header'}->[0]->{'col4'});
1061: }
1.69 raeburn 1062: $output .= '</tr>';
1.48 raeburn 1063: $rowtotal ++;
1.168 raeburn 1064: if ($action eq 'quotas') {
1.86 raeburn 1065: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1066: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1067: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1068: ($action eq 'ltitools')) {
1.230 raeburn 1069: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 1070: } elsif ($action eq 'scantron') {
1071: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 1072: }
1.3 raeburn 1073: }
1.30 raeburn 1074: $output .= '
1.3 raeburn 1075: </table>
1076: </td>
1077: </tr>
1.30 raeburn 1078: </table><br />';
1079: return ($output,$rowtotal);
1.1 raeburn 1080: }
1081:
1.3 raeburn 1082: sub print_login {
1.168 raeburn 1083: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1084: my ($css_class,$datatable);
1.6 raeburn 1085: my %choices = &login_choices();
1.110 raeburn 1086:
1.168 raeburn 1087: if ($caller eq 'service') {
1.149 raeburn 1088: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1089: my $choice = $choices{'disallowlogin'};
1090: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1091: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1092: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1093: '<th>'.$choices{'server'}.'</th>'.
1094: '<th>'.$choices{'serverpath'}.'</th>'.
1095: '<th>'.$choices{'custompath'}.'</th>'.
1096: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1097: my %disallowed;
1098: if (ref($settings) eq 'HASH') {
1099: if (ref($settings->{'loginvia'}) eq 'HASH') {
1100: %disallowed = %{$settings->{'loginvia'}};
1101: }
1102: }
1103: foreach my $lonhost (sort(keys(%servers))) {
1104: my $direct = 'selected="selected"';
1.128 raeburn 1105: if (ref($disallowed{$lonhost}) eq 'HASH') {
1106: if ($disallowed{$lonhost}{'server'} ne '') {
1107: $direct = '';
1108: }
1.110 raeburn 1109: }
1.115 raeburn 1110: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1111: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1112: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1113: '</option>';
1.184 raeburn 1114: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1115: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1116: my $selected = '';
1.128 raeburn 1117: if (ref($disallowed{$lonhost}) eq 'HASH') {
1118: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1119: $selected = 'selected="selected"';
1120: }
1.110 raeburn 1121: }
1122: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1123: $servers{$hostid}.'</option>';
1124: }
1.128 raeburn 1125: $datatable .= '</select></td>'.
1126: '<td><select name="'.$lonhost.'_serverpath">';
1127: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1128: my $pathname = $path;
1129: if ($path eq 'custom') {
1130: $pathname = &mt('Custom Path').' ->';
1131: }
1132: my $selected = '';
1133: if (ref($disallowed{$lonhost}) eq 'HASH') {
1134: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1135: $selected = 'selected="selected"';
1136: }
1137: } elsif ($path eq '') {
1138: $selected = 'selected="selected"';
1139: }
1140: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1141: }
1142: $datatable .= '</select></td>';
1143: my ($custom,$exempt);
1144: if (ref($disallowed{$lonhost}) eq 'HASH') {
1145: $custom = $disallowed{$lonhost}{'custompath'};
1146: $exempt = $disallowed{$lonhost}{'exempt'};
1147: }
1148: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1149: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1150: '</tr>';
1.110 raeburn 1151: }
1152: $datatable .= '</table></td></tr>';
1153: return $datatable;
1.168 raeburn 1154: } elsif ($caller eq 'page') {
1155: my %defaultchecked = (
1156: 'coursecatalog' => 'on',
1.188 raeburn 1157: 'helpdesk' => 'on',
1.168 raeburn 1158: 'adminmail' => 'off',
1159: 'newuser' => 'off',
1160: );
1.188 raeburn 1161: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1162: my (%checkedon,%checkedoff);
1.42 raeburn 1163: foreach my $item (@toggles) {
1.168 raeburn 1164: if ($defaultchecked{$item} eq 'on') {
1165: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1166: $checkedoff{$item} = ' ';
1.168 raeburn 1167: } elsif ($defaultchecked{$item} eq 'off') {
1168: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1169: $checkedon{$item} = ' ';
1170: }
1.1 raeburn 1171: }
1.168 raeburn 1172: my @images = ('img','logo','domlogo','login');
1173: my @logintext = ('textcol','bgcol');
1174: my @bgs = ('pgbg','mainbg','sidebg');
1175: my @links = ('link','alink','vlink');
1176: my %designhash = &Apache::loncommon::get_domainconf($dom);
1177: my %defaultdesign = %Apache::loncommon::defaultdesign;
1178: my (%is_custom,%designs);
1179: my %defaults = (
1180: font => $defaultdesign{'login.font'},
1181: );
1.6 raeburn 1182: foreach my $item (@images) {
1.168 raeburn 1183: $defaults{$item} = $defaultdesign{'login.'.$item};
1184: $defaults{'showlogo'}{$item} = 1;
1185: }
1186: foreach my $item (@bgs) {
1187: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1188: }
1.41 raeburn 1189: foreach my $item (@logintext) {
1.168 raeburn 1190: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1191: }
1.168 raeburn 1192: foreach my $item (@links) {
1193: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1194: }
1.168 raeburn 1195: if (ref($settings) eq 'HASH') {
1196: foreach my $item (@toggles) {
1197: if ($settings->{$item} eq '1') {
1198: $checkedon{$item} = ' checked="checked" ';
1199: $checkedoff{$item} = ' ';
1200: } elsif ($settings->{$item} eq '0') {
1201: $checkedoff{$item} = ' checked="checked" ';
1202: $checkedon{$item} = ' ';
1203: }
1204: }
1205: foreach my $item (@images) {
1206: if (defined($settings->{$item})) {
1207: $designs{$item} = $settings->{$item};
1208: $is_custom{$item} = 1;
1209: }
1210: if (defined($settings->{'showlogo'}{$item})) {
1211: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1212: }
1213: }
1214: foreach my $item (@logintext) {
1215: if ($settings->{$item} ne '') {
1216: $designs{'logintext'}{$item} = $settings->{$item};
1217: $is_custom{$item} = 1;
1218: }
1219: }
1220: if ($settings->{'font'} ne '') {
1221: $designs{'font'} = $settings->{'font'};
1222: $is_custom{'font'} = 1;
1223: }
1224: foreach my $item (@bgs) {
1225: if ($settings->{$item} ne '') {
1226: $designs{'bgs'}{$item} = $settings->{$item};
1227: $is_custom{$item} = 1;
1228: }
1229: }
1230: foreach my $item (@links) {
1231: if ($settings->{$item} ne '') {
1232: $designs{'links'}{$item} = $settings->{$item};
1233: $is_custom{$item} = 1;
1234: }
1235: }
1236: } else {
1237: if ($designhash{$dom.'.login.font'} ne '') {
1238: $designs{'font'} = $designhash{$dom.'.login.font'};
1239: $is_custom{'font'} = 1;
1240: }
1241: foreach my $item (@images) {
1242: if ($designhash{$dom.'.login.'.$item} ne '') {
1243: $designs{$item} = $designhash{$dom.'.login.'.$item};
1244: $is_custom{$item} = 1;
1245: }
1246: }
1247: foreach my $item (@bgs) {
1248: if ($designhash{$dom.'.login.'.$item} ne '') {
1249: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1250: $is_custom{$item} = 1;
1251: }
1.6 raeburn 1252: }
1.168 raeburn 1253: foreach my $item (@links) {
1254: if ($designhash{$dom.'.login.'.$item} ne '') {
1255: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1256: $is_custom{$item} = 1;
1257: }
1.6 raeburn 1258: }
1259: }
1.168 raeburn 1260: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1261: logo => 'Institution Logo',
1262: domlogo => 'Domain Logo',
1263: login => 'Login box');
1264: my $itemcount = 1;
1265: foreach my $item (@toggles) {
1266: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1267: $datatable .=
1268: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1269: '</td><td>'.
1270: '<span class="LC_nobreak"><label><input type="radio" name="'.
1271: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1272: '</label> <label><input type="radio" name="'.$item.'"'.
1273: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1274: '</tr>';
1275: $itemcount ++;
1.6 raeburn 1276: }
1.168 raeburn 1277: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1278: $datatable .= '</tr></table></td></tr>';
1279: } elsif ($caller eq 'help') {
1280: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1281: my $switchserver = &check_switchserver($dom,$confname);
1282: my $itemcount = 1;
1283: $defaulturl = '/adm/loginproblems.html';
1284: $defaulttype = 'default';
1285: %lt = &Apache::lonlocal::texthash (
1286: del => 'Delete?',
1287: rep => 'Replace:',
1288: upl => 'Upload:',
1289: default => 'Default',
1290: custom => 'Custom',
1291: );
1292: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1293: my @currlangs;
1294: if (ref($settings) eq 'HASH') {
1295: if (ref($settings->{'helpurl'}) eq 'HASH') {
1296: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1297: next if ($settings->{'helpurl'}{$key} eq '');
1298: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1299: $type{$key} = 'custom';
1300: unless ($key eq 'nolang') {
1301: push(@currlangs,$key);
1302: }
1303: }
1304: } elsif ($settings->{'helpurl'} ne '') {
1305: $type{'nolang'} = 'custom';
1306: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1307: }
1308: }
1.168 raeburn 1309: foreach my $lang ('nolang',sort(@currlangs)) {
1310: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1311: $datatable .= '<tr'.$css_class.'>';
1312: if ($url{$lang} eq '') {
1313: $url{$lang} = $defaulturl;
1314: }
1315: if ($type{$lang} eq '') {
1316: $type{$lang} = $defaulttype;
1317: }
1318: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1319: if ($lang eq 'nolang') {
1320: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1321: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1322: } else {
1323: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1324: $langchoices{$lang},
1325: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1326: }
1327: $datatable .= '</span></td>'."\n".
1328: '<td class="LC_left_item">';
1329: if ($type{$lang} eq 'custom') {
1330: $datatable .= '<span class="LC_nobreak"><label>'.
1331: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1332: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1333: } else {
1334: $datatable .= $lt{'upl'};
1335: }
1336: $datatable .='<br />';
1337: if ($switchserver) {
1338: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1339: } else {
1340: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1341: }
1.168 raeburn 1342: $datatable .= '</td></tr>';
1343: $itemcount ++;
1.6 raeburn 1344: }
1.168 raeburn 1345: my @addlangs;
1346: foreach my $lang (sort(keys(%langchoices))) {
1347: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1348: push(@addlangs,$lang);
1349: }
1350: if (@addlangs > 0) {
1351: my %toadd;
1352: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1353: $toadd{''} = &mt('Select');
1354: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1355: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1356: &mt('Add log-in help page for a specific language:').' '.
1357: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1358: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1359: if ($switchserver) {
1360: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1361: } else {
1362: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1363: }
1.168 raeburn 1364: $datatable .= '</td></tr>';
1.169 raeburn 1365: $itemcount ++;
1.6 raeburn 1366: }
1.169 raeburn 1367: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1368: } elsif ($caller eq 'headtag') {
1369: my %domservers = &Apache::lonnet::get_servers($dom);
1370: my $choice = $choices{'headtag'};
1371: $css_class = ' class="LC_odd_row"';
1372: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1373: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1374: '<th>'.$choices{'current'}.'</th>'.
1375: '<th>'.$choices{'action'}.'</th>'.
1376: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1377: my (%currurls,%currexempt);
1378: if (ref($settings) eq 'HASH') {
1379: if (ref($settings->{'headtag'}) eq 'HASH') {
1380: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1381: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1382: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1383: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1384: }
1385: }
1386: }
1387: }
1388: my %lt = &Apache::lonlocal::texthash(
1389: del => 'Delete?',
1390: rep => 'Replace:',
1391: upl => 'Upload:',
1392: curr => 'View contents',
1393: none => 'None',
1394: );
1395: my $switchserver = &check_switchserver($dom,$confname);
1396: foreach my $lonhost (sort(keys(%domservers))) {
1397: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1398: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1399: if ($currurls{$lonhost}) {
1400: $datatable .= '<td class="LC_right_item"><a href="'.
1401: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1402: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1403: '">'.$lt{'curr'}.'</a></td>'.
1404: '<td><span class="LC_nobreak"><label>'.
1405: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1406: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1407: } else {
1408: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1409: }
1410: $datatable .='<br />';
1411: if ($switchserver) {
1412: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1413: } else {
1414: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1415: }
1416: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1417: }
1418: $datatable .= '</table></td></tr>';
1.1 raeburn 1419: }
1.6 raeburn 1420: return $datatable;
1421: }
1422:
1423: sub login_choices {
1424: my %choices =
1425: &Apache::lonlocal::texthash (
1.116 bisitz 1426: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1427: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1428: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1429: disallowlogin => "Login page requests redirected",
1430: hostid => "Server",
1.128 raeburn 1431: server => "Redirect to:",
1432: serverpath => "Path",
1433: custompath => "Custom",
1434: exempt => "Exempt IP(s)",
1.110 raeburn 1435: directlogin => "No redirect",
1436: newuser => "Link to create a user account",
1437: img => "Header",
1438: logo => "Main Logo",
1439: domlogo => "Domain Logo",
1440: login => "Log-in Header",
1441: textcol => "Text color",
1442: bgcol => "Box color",
1443: bgs => "Background colors",
1444: links => "Link colors",
1445: font => "Font color",
1446: pgbg => "Header",
1447: mainbg => "Page",
1448: sidebg => "Login box",
1449: link => "Link",
1450: alink => "Active link",
1451: vlink => "Visited link",
1.256 raeburn 1452: headtag => "Custom markup",
1453: action => "Action",
1454: current => "Current",
1.6 raeburn 1455: );
1456: return %choices;
1457: }
1458:
1459: sub print_rolecolors {
1.30 raeburn 1460: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1461: my %choices = &color_font_choices();
1462: my @bgs = ('pgbg','tabbg','sidebg');
1463: my @links = ('link','alink','vlink');
1464: my @images = ('img');
1465: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1466: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1467: my %defaultdesign = %Apache::loncommon::defaultdesign;
1468: my (%is_custom,%designs);
1.200 raeburn 1469: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1470: if (ref($settings) eq 'HASH') {
1471: if (ref($settings->{$role}) eq 'HASH') {
1472: if ($settings->{$role}->{'img'} ne '') {
1473: $designs{'img'} = $settings->{$role}->{'img'};
1474: $is_custom{'img'} = 1;
1475: }
1476: if ($settings->{$role}->{'font'} ne '') {
1477: $designs{'font'} = $settings->{$role}->{'font'};
1478: $is_custom{'font'} = 1;
1479: }
1.97 tempelho 1480: if ($settings->{$role}->{'fontmenu'} ne '') {
1481: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1482: $is_custom{'fontmenu'} = 1;
1483: }
1.6 raeburn 1484: foreach my $item (@bgs) {
1485: if ($settings->{$role}->{$item} ne '') {
1486: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1487: $is_custom{$item} = 1;
1488: }
1489: }
1490: foreach my $item (@links) {
1491: if ($settings->{$role}->{$item} ne '') {
1492: $designs{'links'}{$item} = $settings->{$role}->{$item};
1493: $is_custom{$item} = 1;
1494: }
1495: }
1496: }
1497: } else {
1498: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1499: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1500: $is_custom{'img'} = 1;
1501: }
1.97 tempelho 1502: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1503: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1504: $is_custom{'fontmenu'} = 1;
1505: }
1.6 raeburn 1506: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1507: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1508: $is_custom{'font'} = 1;
1509: }
1510: foreach my $item (@bgs) {
1511: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1512: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1513: $is_custom{$item} = 1;
1514:
1515: }
1516: }
1517: foreach my $item (@links) {
1518: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1519: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1520: $is_custom{$item} = 1;
1521: }
1522: }
1523: }
1524: my $itemcount = 1;
1.30 raeburn 1525: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1526: $datatable .= '</tr></table></td></tr>';
1527: return $datatable;
1528: }
1529:
1.200 raeburn 1530: sub role_defaults {
1531: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1532: my %defaults;
1533: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1534: return %defaults;
1535: }
1536: my %defaultdesign = %Apache::loncommon::defaultdesign;
1537: if ($role eq 'login') {
1538: %defaults = (
1539: font => $defaultdesign{$role.'.font'},
1540: );
1541: if (ref($logintext) eq 'ARRAY') {
1542: foreach my $item (@{$logintext}) {
1543: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1544: }
1545: }
1546: foreach my $item (@{$images}) {
1547: $defaults{'showlogo'}{$item} = 1;
1548: }
1549: } else {
1550: %defaults = (
1551: img => $defaultdesign{$role.'.img'},
1552: font => $defaultdesign{$role.'.font'},
1553: fontmenu => $defaultdesign{$role.'.fontmenu'},
1554: );
1555: }
1556: foreach my $item (@{$bgs}) {
1557: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1558: }
1559: foreach my $item (@{$links}) {
1560: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1561: }
1562: foreach my $item (@{$images}) {
1563: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1564: }
1565: return %defaults;
1566: }
1567:
1.6 raeburn 1568: sub display_color_options {
1.9 raeburn 1569: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1570: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1571: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1572: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1573: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1574: '<td>'.$choices->{'font'}.'</td>';
1575: if (!$is_custom->{'font'}) {
1.30 raeburn 1576: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1577: } else {
1578: $datatable .= '<td> </td>';
1579: }
1.174 foxr 1580: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1581:
1.8 raeburn 1582: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1583: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1584: ' value="'.$current_color.'" /> '.
1.174 foxr 1585: ' </td></tr>';
1.107 raeburn 1586: unless ($role eq 'login') {
1587: $datatable .= '<tr'.$css_class.'>'.
1588: '<td>'.$choices->{'fontmenu'}.'</td>';
1589: if (!$is_custom->{'fontmenu'}) {
1590: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1591: } else {
1592: $datatable .= '<td> </td>';
1593: }
1.202 raeburn 1594: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1595: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1596: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1597: '<input class="colorchooser" type="text" size="10" name="'
1598: .$role.'_fontmenu"'.
1599: ' value="'.$current_color.'" /> '.
1600: ' </td></tr>';
1.97 tempelho 1601: }
1.9 raeburn 1602: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1603: foreach my $img (@{$images}) {
1.18 albertel 1604: $itemcount ++;
1.6 raeburn 1605: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1606: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1607: '<td>'.$choices->{$img};
1.41 raeburn 1608: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1609: if ($role eq 'login') {
1610: if ($img eq 'login') {
1611: $login_hdr_pick =
1.135 bisitz 1612: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1613: $logincolors =
1614: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1615: $designs,$defaults);
1.70 raeburn 1616: } elsif ($img ne 'domlogo') {
1617: $datatable.= &logo_display_options($img,$defaults,$designs);
1618: }
1619: }
1620: $datatable .= '</td>';
1.6 raeburn 1621: if ($designs->{$img} ne '') {
1622: $imgfile = $designs->{$img};
1.18 albertel 1623: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1624: } else {
1625: $imgfile = $defaults->{$img};
1626: }
1627: if ($imgfile) {
1.9 raeburn 1628: my ($showfile,$fullsize);
1629: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1630: my $urldir = $1;
1631: my $filename = $2;
1632: my @info = &Apache::lonnet::stat_file($designs->{$img});
1633: if (@info) {
1634: my $thumbfile = 'tn-'.$filename;
1635: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1636: if (@thumb) {
1637: $showfile = $urldir.'/'.$thumbfile;
1638: } else {
1639: $showfile = $imgfile;
1640: }
1641: } else {
1642: $showfile = '';
1643: }
1644: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1645: $showfile = $imgfile;
1.6 raeburn 1646: my $imgdir = $1;
1647: my $filename = $2;
1.159 raeburn 1648: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1649: $showfile = "/$imgdir/tn-".$filename;
1650: } else {
1.159 raeburn 1651: my $input = $londocroot.$imgfile;
1652: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1653: if (!-e $output) {
1.9 raeburn 1654: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1655: my ($fullwidth,$fullheight) = &check_dimensions($input);
1656: if ($fullwidth ne '' && $fullheight ne '') {
1657: if ($fullwidth > $width && $fullheight > $height) {
1658: my $size = $width.'x'.$height;
1.316 raeburn 1659: my @args = ('convert','-sample',$size,$input,$output);
1660: system({$args[0]} @args);
1.159 raeburn 1661: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1662: }
1663: }
1.6 raeburn 1664: }
1665: }
1.16 raeburn 1666: }
1.6 raeburn 1667: if ($showfile) {
1.40 raeburn 1668: if ($showfile =~ m{^/(adm|res)/}) {
1669: if ($showfile =~ m{^/res/}) {
1670: my $local_showfile =
1671: &Apache::lonnet::filelocation('',$showfile);
1672: &Apache::lonnet::repcopy($local_showfile);
1673: }
1674: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1675: }
1676: if ($imgfile) {
1677: if ($imgfile =~ m{^/(adm|res)/}) {
1678: if ($imgfile =~ m{^/res/}) {
1679: my $local_imgfile =
1680: &Apache::lonnet::filelocation('',$imgfile);
1681: &Apache::lonnet::repcopy($local_imgfile);
1682: }
1683: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1684: } else {
1685: $fullsize = $imgfile;
1686: }
1687: }
1.41 raeburn 1688: $datatable .= '<td>';
1689: if ($img eq 'login') {
1.135 bisitz 1690: $datatable .= $login_hdr_pick;
1691: }
1.41 raeburn 1692: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1693: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1694: } else {
1.201 raeburn 1695: $datatable .= '<td> </td><td class="LC_left_item">'.
1696: &mt('Upload:').'<br />';
1.6 raeburn 1697: }
1698: } else {
1.201 raeburn 1699: $datatable .= '<td> </td><td class="LC_left_item">'.
1700: &mt('Upload:').'<br />';
1.6 raeburn 1701: }
1.9 raeburn 1702: if ($switchserver) {
1703: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1704: } else {
1.135 bisitz 1705: if ($img ne 'login') { # suppress file selection for Log-in header
1706: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1707: }
1.9 raeburn 1708: }
1709: $datatable .= '</td></tr>';
1.6 raeburn 1710: }
1711: $itemcount ++;
1712: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1713: $datatable .= '<tr'.$css_class.'>'.
1714: '<td>'.$choices->{'bgs'}.'</td>';
1715: my $bgs_def;
1716: foreach my $item (@{$bgs}) {
1717: if (!$is_custom->{$item}) {
1.70 raeburn 1718: $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 1719: }
1720: }
1721: if ($bgs_def) {
1.8 raeburn 1722: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1723: } else {
1724: $datatable .= '<td> </td>';
1725: }
1726: $datatable .= '<td class="LC_right_item">'.
1727: '<table border="0"><tr>';
1.174 foxr 1728:
1.6 raeburn 1729: foreach my $item (@{$bgs}) {
1.306 raeburn 1730: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 1731: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1732: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1733: $datatable .= ' ';
1.6 raeburn 1734: }
1.174 foxr 1735: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1736: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1737: }
1738: $datatable .= '</tr></table></td></tr>';
1739: $itemcount ++;
1740: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1741: $datatable .= '<tr'.$css_class.'>'.
1742: '<td>'.$choices->{'links'}.'</td>';
1743: my $links_def;
1744: foreach my $item (@{$links}) {
1745: if (!$is_custom->{$item}) {
1.30 raeburn 1746: $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 1747: }
1748: }
1749: if ($links_def) {
1.8 raeburn 1750: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1751: } else {
1752: $datatable .= '<td> </td>';
1753: }
1754: $datatable .= '<td class="LC_right_item">'.
1755: '<table border="0"><tr>';
1756: foreach my $item (@{$links}) {
1.234 raeburn 1757: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 1758: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 1759: if ($designs->{'links'}{$item}) {
1.174 foxr 1760: $datatable.=' ';
1.6 raeburn 1761: }
1.174 foxr 1762: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1763: '" /></td>';
1764: }
1.30 raeburn 1765: $$rowtotal += $itemcount;
1.3 raeburn 1766: return $datatable;
1767: }
1768:
1.70 raeburn 1769: sub logo_display_options {
1770: my ($img,$defaults,$designs) = @_;
1771: my $checkedon;
1772: if (ref($defaults) eq 'HASH') {
1773: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1774: if ($defaults->{'showlogo'}{$img}) {
1775: $checkedon = 'checked="checked" ';
1776: }
1777: }
1778: }
1779: if (ref($designs) eq 'HASH') {
1780: if (ref($designs->{'showlogo'}) eq 'HASH') {
1781: if (defined($designs->{'showlogo'}{$img})) {
1782: if ($designs->{'showlogo'}{$img} == 0) {
1783: $checkedon = '';
1784: } elsif ($designs->{'showlogo'}{$img} == 1) {
1785: $checkedon = 'checked="checked" ';
1786: }
1787: }
1788: }
1789: }
1790: return '<br /><label> <input type="checkbox" name="'.
1791: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1792: &mt('show').'</label>'."\n";
1793: }
1794:
1.41 raeburn 1795: sub login_header_options {
1.135 bisitz 1796: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1797: my $output = '';
1.41 raeburn 1798: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1799: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1800: if (!$is_custom->{'textcol'}) {
1801: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1802: ' ';
1803: }
1804: if (!$is_custom->{'bgcol'}) {
1805: $output .= $choices->{'bgcol'}.': '.
1806: '<span id="css_'.$role.'_font" style="background-color: '.
1807: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1808: }
1809: $output .= '<br />';
1810: }
1811: $output .='<br />';
1812: return $output;
1813: }
1814:
1815: sub login_text_colors {
1.201 raeburn 1816: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1817: my $color_menu = '<table border="0"><tr>';
1818: foreach my $item (@{$logintext}) {
1.306 raeburn 1819: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 1820: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1821: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1822: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1823: }
1824: $color_menu .= '</tr></table><br />';
1825: return $color_menu;
1826: }
1827:
1828: sub image_changes {
1829: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1830: my $output;
1.135 bisitz 1831: if ($img eq 'login') {
1832: # suppress image for Log-in header
1833: } elsif (!$is_custom) {
1.70 raeburn 1834: if ($img ne 'domlogo') {
1.41 raeburn 1835: $output .= &mt('Default image:').'<br />';
1836: } else {
1837: $output .= &mt('Default in use:').'<br />';
1838: }
1839: }
1.135 bisitz 1840: if ($img eq 'login') { # suppress image for Log-in header
1841: $output .= '<td>'.$logincolors;
1.41 raeburn 1842: } else {
1.135 bisitz 1843: if ($img_import) {
1844: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1845: }
1846: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1847: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1848: if ($is_custom) {
1849: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1850: '<input type="checkbox" name="'.
1851: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1852: '</label> '.&mt('Replace:').'</span><br />';
1853: } else {
1.306 raeburn 1854: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1855: }
1.41 raeburn 1856: }
1857: return $output;
1858: }
1859:
1.3 raeburn 1860: sub print_quotas {
1.86 raeburn 1861: my ($dom,$settings,$rowtotal,$action) = @_;
1862: my $context;
1863: if ($action eq 'quotas') {
1864: $context = 'tools';
1865: } else {
1866: $context = $action;
1867: }
1.197 raeburn 1868: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1869: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1870: my $typecount = 0;
1.101 raeburn 1871: my ($css_class,%titles);
1.86 raeburn 1872: if ($context eq 'requestcourses') {
1.271 raeburn 1873: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 1874: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1875: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1876: %titles = &courserequest_titles();
1.163 raeburn 1877: } elsif ($context eq 'requestauthor') {
1878: @usertools = ('author');
1879: @options = ('norequest','approval','automatic');
1.210 raeburn 1880: %titles = &authorrequest_titles();
1.86 raeburn 1881: } else {
1.162 raeburn 1882: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1883: %titles = &tool_titles();
1.86 raeburn 1884: }
1.26 raeburn 1885: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1886: foreach my $type (@{$types}) {
1.197 raeburn 1887: my ($currdefquota,$currauthorquota);
1.163 raeburn 1888: unless (($context eq 'requestcourses') ||
1889: ($context eq 'requestauthor')) {
1.86 raeburn 1890: if (ref($settings) eq 'HASH') {
1891: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1892: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1893: } else {
1894: $currdefquota = $settings->{$type};
1895: }
1.197 raeburn 1896: if (ref($settings->{authorquota}) eq 'HASH') {
1897: $currauthorquota = $settings->{authorquota}->{$type};
1898: }
1.78 raeburn 1899: }
1.72 raeburn 1900: }
1.3 raeburn 1901: if (defined($usertypes->{$type})) {
1902: $typecount ++;
1903: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1904: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1905: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1906: '<td class="LC_left_item">';
1.101 raeburn 1907: if ($context eq 'requestcourses') {
1908: $datatable .= '<table><tr>';
1909: }
1910: my %cell;
1.72 raeburn 1911: foreach my $item (@usertools) {
1.101 raeburn 1912: if ($context eq 'requestcourses') {
1913: my ($curroption,$currlimit);
1914: if (ref($settings) eq 'HASH') {
1915: if (ref($settings->{$item}) eq 'HASH') {
1916: $curroption = $settings->{$item}->{$type};
1917: if ($curroption =~ /^autolimit=(\d*)$/) {
1918: $currlimit = $1;
1919: }
1920: }
1921: }
1922: if (!$curroption) {
1923: $curroption = 'norequest';
1924: }
1925: $datatable .= '<th>'.$titles{$item}.'</th>';
1926: foreach my $option (@options) {
1927: my $val = $option;
1928: if ($option eq 'norequest') {
1929: $val = 0;
1930: }
1931: if ($option eq 'validate') {
1932: my $canvalidate = 0;
1933: if (ref($validations{$item}) eq 'HASH') {
1934: if ($validations{$item}{$type}) {
1935: $canvalidate = 1;
1936: }
1937: }
1938: next if (!$canvalidate);
1939: }
1940: my $checked = '';
1941: if ($option eq $curroption) {
1942: $checked = ' checked="checked"';
1943: } elsif ($option eq 'autolimit') {
1944: if ($curroption =~ /^autolimit/) {
1945: $checked = ' checked="checked"';
1946: }
1947: }
1948: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1949: '<input type="radio" name="crsreq_'.$item.
1950: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1951: $titles{$option}.'</label>';
1.101 raeburn 1952: if ($option eq 'autolimit') {
1.127 raeburn 1953: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1954: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1955: 'value="'.$currlimit.'" />';
1.101 raeburn 1956: }
1.127 raeburn 1957: $cell{$item} .= '</span> ';
1.103 raeburn 1958: if ($option eq 'autolimit') {
1.127 raeburn 1959: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1960: }
1.101 raeburn 1961: }
1.163 raeburn 1962: } elsif ($context eq 'requestauthor') {
1963: my $curroption;
1964: if (ref($settings) eq 'HASH') {
1965: $curroption = $settings->{$type};
1966: }
1967: if (!$curroption) {
1968: $curroption = 'norequest';
1969: }
1970: foreach my $option (@options) {
1971: my $val = $option;
1972: if ($option eq 'norequest') {
1973: $val = 0;
1974: }
1975: my $checked = '';
1976: if ($option eq $curroption) {
1977: $checked = ' checked="checked"';
1978: }
1979: $datatable .= '<span class="LC_nobreak"><label>'.
1980: '<input type="radio" name="authorreq_'.$type.
1981: '" value="'.$val.'"'.$checked.' />'.
1982: $titles{$option}.'</label></span> ';
1983: }
1.101 raeburn 1984: } else {
1985: my $checked = 'checked="checked" ';
1986: if (ref($settings) eq 'HASH') {
1987: if (ref($settings->{$item}) eq 'HASH') {
1988: if ($settings->{$item}->{$type} == 0) {
1989: $checked = '';
1990: } elsif ($settings->{$item}->{$type} == 1) {
1991: $checked = 'checked="checked" ';
1992: }
1.78 raeburn 1993: }
1.72 raeburn 1994: }
1.101 raeburn 1995: $datatable .= '<span class="LC_nobreak"><label>'.
1996: '<input type="checkbox" name="'.$context.'_'.$item.
1997: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1998: '</label></span> ';
1.72 raeburn 1999: }
1.101 raeburn 2000: }
2001: if ($context eq 'requestcourses') {
2002: $datatable .= '</tr><tr>';
2003: foreach my $item (@usertools) {
1.106 raeburn 2004: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2005: }
2006: $datatable .= '</tr></table>';
1.72 raeburn 2007: }
1.86 raeburn 2008: $datatable .= '</td>';
1.163 raeburn 2009: unless (($context eq 'requestcourses') ||
2010: ($context eq 'requestauthor')) {
1.86 raeburn 2011: $datatable .=
1.197 raeburn 2012: '<td class="LC_right_item">'.
2013: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2014: '<input type="text" name="quota_'.$type.
1.72 raeburn 2015: '" value="'.$currdefquota.
1.197 raeburn 2016: '" size="5" /></span>'.(' ' x 2).
2017: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2018: '<input type="text" name="authorquota_'.$type.
2019: '" value="'.$currauthorquota.
2020: '" size="5" /></span></td>';
1.86 raeburn 2021: }
2022: $datatable .= '</tr>';
1.3 raeburn 2023: }
2024: }
2025: }
1.163 raeburn 2026: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2027: $defaultquota = '20';
1.197 raeburn 2028: $authorquota = '500';
1.86 raeburn 2029: if (ref($settings) eq 'HASH') {
2030: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2031: $defaultquota = $settings->{'defaultquota'}->{'default'};
2032: } elsif (defined($settings->{'default'})) {
2033: $defaultquota = $settings->{'default'};
2034: }
1.197 raeburn 2035: if (ref($settings->{'authorquota'}) eq 'HASH') {
2036: $authorquota = $settings->{'authorquota'}->{'default'};
2037: }
1.3 raeburn 2038: }
2039: }
2040: $typecount ++;
2041: $css_class = $typecount%2?' class="LC_odd_row"':'';
2042: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2043: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2044: '<td class="LC_left_item">';
1.101 raeburn 2045: if ($context eq 'requestcourses') {
2046: $datatable .= '<table><tr>';
2047: }
2048: my %defcell;
1.72 raeburn 2049: foreach my $item (@usertools) {
1.101 raeburn 2050: if ($context eq 'requestcourses') {
2051: my ($curroption,$currlimit);
2052: if (ref($settings) eq 'HASH') {
2053: if (ref($settings->{$item}) eq 'HASH') {
2054: $curroption = $settings->{$item}->{'default'};
2055: if ($curroption =~ /^autolimit=(\d*)$/) {
2056: $currlimit = $1;
2057: }
2058: }
2059: }
2060: if (!$curroption) {
2061: $curroption = 'norequest';
2062: }
2063: $datatable .= '<th>'.$titles{$item}.'</th>';
2064: foreach my $option (@options) {
2065: my $val = $option;
2066: if ($option eq 'norequest') {
2067: $val = 0;
2068: }
2069: if ($option eq 'validate') {
2070: my $canvalidate = 0;
2071: if (ref($validations{$item}) eq 'HASH') {
2072: if ($validations{$item}{'default'}) {
2073: $canvalidate = 1;
2074: }
2075: }
2076: next if (!$canvalidate);
2077: }
2078: my $checked = '';
2079: if ($option eq $curroption) {
2080: $checked = ' checked="checked"';
2081: } elsif ($option eq 'autolimit') {
2082: if ($curroption =~ /^autolimit/) {
2083: $checked = ' checked="checked"';
2084: }
2085: }
2086: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2087: '<input type="radio" name="crsreq_'.$item.
2088: '_default" value="'.$val.'"'.$checked.' />'.
2089: $titles{$option}.'</label>';
2090: if ($option eq 'autolimit') {
1.127 raeburn 2091: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2092: $item.'_limit_default" size="1" '.
2093: 'value="'.$currlimit.'" />';
2094: }
1.127 raeburn 2095: $defcell{$item} .= '</span> ';
1.104 raeburn 2096: if ($option eq 'autolimit') {
1.127 raeburn 2097: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2098: }
1.101 raeburn 2099: }
1.163 raeburn 2100: } elsif ($context eq 'requestauthor') {
2101: my $curroption;
2102: if (ref($settings) eq 'HASH') {
1.172 raeburn 2103: $curroption = $settings->{'default'};
1.163 raeburn 2104: }
2105: if (!$curroption) {
2106: $curroption = 'norequest';
2107: }
2108: foreach my $option (@options) {
2109: my $val = $option;
2110: if ($option eq 'norequest') {
2111: $val = 0;
2112: }
2113: my $checked = '';
2114: if ($option eq $curroption) {
2115: $checked = ' checked="checked"';
2116: }
2117: $datatable .= '<span class="LC_nobreak"><label>'.
2118: '<input type="radio" name="authorreq_default"'.
2119: ' value="'.$val.'"'.$checked.' />'.
2120: $titles{$option}.'</label></span> ';
2121: }
1.101 raeburn 2122: } else {
2123: my $checked = 'checked="checked" ';
2124: if (ref($settings) eq 'HASH') {
2125: if (ref($settings->{$item}) eq 'HASH') {
2126: if ($settings->{$item}->{'default'} == 0) {
2127: $checked = '';
2128: } elsif ($settings->{$item}->{'default'} == 1) {
2129: $checked = 'checked="checked" ';
2130: }
1.78 raeburn 2131: }
1.72 raeburn 2132: }
1.101 raeburn 2133: $datatable .= '<span class="LC_nobreak"><label>'.
2134: '<input type="checkbox" name="'.$context.'_'.$item.
2135: '" value="default" '.$checked.'/>'.$titles{$item}.
2136: '</label></span> ';
2137: }
2138: }
2139: if ($context eq 'requestcourses') {
2140: $datatable .= '</tr><tr>';
2141: foreach my $item (@usertools) {
1.106 raeburn 2142: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2143: }
1.101 raeburn 2144: $datatable .= '</tr></table>';
1.72 raeburn 2145: }
1.86 raeburn 2146: $datatable .= '</td>';
1.163 raeburn 2147: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2148: $datatable .= '<td class="LC_right_item">'.
2149: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2150: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2151: $defaultquota.'" size="5" /></span>'.(' ' x2).
2152: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2153: '<input type="text" name="authorquota" value="'.
2154: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2155: }
2156: $datatable .= '</tr>';
1.72 raeburn 2157: $typecount ++;
2158: $css_class = $typecount%2?' class="LC_odd_row"':'';
2159: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2160: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2161: if ($context eq 'requestcourses') {
1.109 raeburn 2162: $datatable .= &mt('(overrides affiliation, if set)').
2163: '</td>'.
2164: '<td class="LC_left_item">'.
2165: '<table><tr>';
1.101 raeburn 2166: } else {
1.109 raeburn 2167: $datatable .= &mt('(overrides affiliation, if checked)').
2168: '</td>'.
2169: '<td class="LC_left_item" colspan="2">'.
2170: '<br />';
1.101 raeburn 2171: }
2172: my %advcell;
1.72 raeburn 2173: foreach my $item (@usertools) {
1.101 raeburn 2174: if ($context eq 'requestcourses') {
2175: my ($curroption,$currlimit);
2176: if (ref($settings) eq 'HASH') {
2177: if (ref($settings->{$item}) eq 'HASH') {
2178: $curroption = $settings->{$item}->{'_LC_adv'};
2179: if ($curroption =~ /^autolimit=(\d*)$/) {
2180: $currlimit = $1;
2181: }
2182: }
2183: }
2184: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2185: my $checked = '';
2186: if ($curroption eq '') {
2187: $checked = ' checked="checked"';
2188: }
2189: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2190: '<input type="radio" name="crsreq_'.$item.
2191: '__LC_adv" value=""'.$checked.' />'.
2192: &mt('No override set').'</label></span> ';
1.101 raeburn 2193: foreach my $option (@options) {
2194: my $val = $option;
2195: if ($option eq 'norequest') {
2196: $val = 0;
2197: }
2198: if ($option eq 'validate') {
2199: my $canvalidate = 0;
2200: if (ref($validations{$item}) eq 'HASH') {
2201: if ($validations{$item}{'_LC_adv'}) {
2202: $canvalidate = 1;
2203: }
2204: }
2205: next if (!$canvalidate);
2206: }
2207: my $checked = '';
1.104 raeburn 2208: if ($val eq $curroption) {
1.101 raeburn 2209: $checked = ' checked="checked"';
2210: } elsif ($option eq 'autolimit') {
2211: if ($curroption =~ /^autolimit/) {
2212: $checked = ' checked="checked"';
2213: }
2214: }
2215: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2216: '<input type="radio" name="crsreq_'.$item.
2217: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2218: $titles{$option}.'</label>';
2219: if ($option eq 'autolimit') {
1.127 raeburn 2220: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2221: $item.'_limit__LC_adv" size="1" '.
2222: 'value="'.$currlimit.'" />';
2223: }
1.127 raeburn 2224: $advcell{$item} .= '</span> ';
1.104 raeburn 2225: if ($option eq 'autolimit') {
1.127 raeburn 2226: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2227: }
1.101 raeburn 2228: }
1.163 raeburn 2229: } elsif ($context eq 'requestauthor') {
2230: my $curroption;
2231: if (ref($settings) eq 'HASH') {
2232: $curroption = $settings->{'_LC_adv'};
2233: }
2234: my $checked = '';
2235: if ($curroption eq '') {
2236: $checked = ' checked="checked"';
2237: }
2238: $datatable .= '<span class="LC_nobreak"><label>'.
2239: '<input type="radio" name="authorreq__LC_adv"'.
2240: ' value=""'.$checked.' />'.
2241: &mt('No override set').'</label></span> ';
2242: foreach my $option (@options) {
2243: my $val = $option;
2244: if ($option eq 'norequest') {
2245: $val = 0;
2246: }
2247: my $checked = '';
2248: if ($val eq $curroption) {
2249: $checked = ' checked="checked"';
2250: }
2251: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2252: '<input type="radio" name="authorreq__LC_adv"'.
2253: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2254: $titles{$option}.'</label></span> ';
2255: }
1.101 raeburn 2256: } else {
2257: my $checked = 'checked="checked" ';
2258: if (ref($settings) eq 'HASH') {
2259: if (ref($settings->{$item}) eq 'HASH') {
2260: if ($settings->{$item}->{'_LC_adv'} == 0) {
2261: $checked = '';
2262: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2263: $checked = 'checked="checked" ';
2264: }
1.79 raeburn 2265: }
1.72 raeburn 2266: }
1.101 raeburn 2267: $datatable .= '<span class="LC_nobreak"><label>'.
2268: '<input type="checkbox" name="'.$context.'_'.$item.
2269: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2270: '</label></span> ';
2271: }
2272: }
2273: if ($context eq 'requestcourses') {
2274: $datatable .= '</tr><tr>';
2275: foreach my $item (@usertools) {
1.106 raeburn 2276: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2277: }
1.101 raeburn 2278: $datatable .= '</tr></table>';
1.72 raeburn 2279: }
1.98 raeburn 2280: $datatable .= '</td></tr>';
1.30 raeburn 2281: $$rowtotal += $typecount;
1.3 raeburn 2282: return $datatable;
2283: }
2284:
1.163 raeburn 2285: sub print_requestmail {
1.305 raeburn 2286: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2287: my ($now,$datatable,%currapp);
1.102 raeburn 2288: $now = time;
2289: if (ref($settings) eq 'HASH') {
2290: if (ref($settings->{'notify'}) eq 'HASH') {
2291: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2292: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2293: }
2294: }
2295: }
1.191 raeburn 2296: my $numinrow = 2;
1.224 raeburn 2297: my $css_class;
1.305 raeburn 2298: if ($$rowtotal%2) {
2299: $css_class = 'LC_odd_row';
2300: }
2301: if ($customcss) {
2302: $css_class .= " $customcss";
2303: }
2304: $css_class =~ s/^\s+//;
2305: if ($css_class) {
2306: $css_class = ' class="'.$css_class.'"';
2307: }
2308: if ($rowstyle) {
2309: $css_class .= ' style="'.$rowstyle.'"';
2310: }
1.163 raeburn 2311: my $text;
2312: if ($action eq 'requestcourses') {
2313: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2314: } elsif ($action eq 'requestauthor') {
2315: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2316: } else {
1.224 raeburn 2317: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2318: }
1.224 raeburn 2319: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2320: ' <td>'.$text.'</td>'.
1.102 raeburn 2321: ' <td class="LC_left_item">';
1.191 raeburn 2322: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2323: $action.'notifyapproval',%currapp);
1.191 raeburn 2324: if ($numdc > 0) {
2325: $datatable .= $table;
1.102 raeburn 2326: } else {
2327: $datatable .= &mt('There are no active Domain Coordinators');
2328: }
2329: $datatable .='</td></tr>';
2330: return $datatable;
2331: }
2332:
1.216 raeburn 2333: sub print_studentcode {
2334: my ($settings,$rowtotal) = @_;
2335: my $rownum = 0;
1.218 raeburn 2336: my ($output,%current);
1.271 raeburn 2337: my @crstypes = ('official','unofficial','community','textbook','placement');
1.248 raeburn 2338: if (ref($settings) eq 'HASH') {
2339: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2340: foreach my $type (@crstypes) {
2341: $current{$type} = $settings->{'uniquecode'}{$type};
2342: }
1.218 raeburn 2343: }
2344: }
2345: $output .= '<tr>'.
2346: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2347: '<td class="LC_left_item">';
2348: foreach my $type (@crstypes) {
2349: my $check = ' ';
2350: if ($current{$type}) {
2351: $check = ' checked="checked" ';
2352: }
2353: $output .= '<span class="LC_nobreak"><label>'.
2354: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2355: &mt($type).'</label></span>'.(' 'x2).' ';
2356: }
2357: $output .= '</td></tr>';
2358: $$rowtotal ++;
2359: return $output;
1.216 raeburn 2360: }
2361:
2362: sub print_textbookcourses {
1.242 raeburn 2363: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2364: my $rownum = 0;
2365: my $css_class;
2366: my $itemcount = 1;
2367: my $maxnum = 0;
2368: my $bookshash;
2369: if (ref($settings) eq 'HASH') {
1.242 raeburn 2370: $bookshash = $settings->{$type};
1.216 raeburn 2371: }
2372: my %ordered;
2373: if (ref($bookshash) eq 'HASH') {
2374: foreach my $item (keys(%{$bookshash})) {
2375: if (ref($bookshash->{$item}) eq 'HASH') {
2376: my $num = $bookshash->{$item}{'order'};
2377: $ordered{$num} = $item;
2378: }
2379: }
2380: }
2381: my $confname = $dom.'-domainconfig';
2382: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2383: my $maxnum = scalar(keys(%ordered));
2384: my $datatable;
1.216 raeburn 2385: if (keys(%ordered)) {
2386: my @items = sort { $a <=> $b } keys(%ordered);
2387: for (my $i=0; $i<@items; $i++) {
2388: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2389: my $key = $ordered{$items[$i]};
2390: my %coursehash=&Apache::lonnet::coursedescription($key);
2391: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2392: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2393: if (ref($bookshash->{$key}) eq 'HASH') {
2394: $subject = $bookshash->{$key}->{'subject'};
2395: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2396: if ($type eq 'textbooks') {
1.243 raeburn 2397: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2398: $author = $bookshash->{$key}->{'author'};
2399: $image = $bookshash->{$key}->{'image'};
2400: if ($image ne '') {
2401: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2402: my $imagethumb = "$path/tn-".$imagefile;
2403: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2404: }
1.216 raeburn 2405: }
2406: }
1.242 raeburn 2407: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2408: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2409: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2410: for (my $k=0; $k<=$maxnum; $k++) {
2411: my $vpos = $k+1;
2412: my $selstr;
2413: if ($k == $i) {
2414: $selstr = ' selected="selected" ';
2415: }
2416: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2417: }
2418: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2419: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2420: &mt('Delete?').'</label></span></td>'.
2421: '<td colspan="2">'.
1.242 raeburn 2422: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2423: (' 'x2).
1.242 raeburn 2424: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2425: if ($type eq 'textbooks') {
2426: $datatable .= (' 'x2).
1.243 raeburn 2427: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2428: (' 'x2).
1.242 raeburn 2429: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2430: (' 'x2).
2431: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2432: if ($image) {
1.267 raeburn 2433: $datatable .= $imgsrc.
1.242 raeburn 2434: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2435: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2436: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2437: }
2438: if ($switchserver) {
2439: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2440: } else {
2441: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2442: }
1.216 raeburn 2443: }
1.242 raeburn 2444: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2445: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2446: $coursetitle.'</span></td></tr>'."\n";
2447: $itemcount ++;
2448: }
2449: }
2450: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2451: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2452: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2453: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2454: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2455: for (my $k=0; $k<$maxnum+1; $k++) {
2456: my $vpos = $k+1;
2457: my $selstr;
2458: if ($k == $maxnum) {
2459: $selstr = ' selected="selected" ';
2460: }
2461: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2462: }
2463: $datatable .= '</select> '."\n".
1.242 raeburn 2464: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2465: '<td colspan="2">'.
1.242 raeburn 2466: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2467: (' 'x2).
1.242 raeburn 2468: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2469: (' 'x2);
2470: if ($type eq 'textbooks') {
1.243 raeburn 2471: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2472: (' 'x2).
2473: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2474: (' 'x2).
2475: '<span class="LC_nobreak">'.&mt('Image:').' ';
2476: if ($switchserver) {
2477: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2478: } else {
2479: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2480: }
1.216 raeburn 2481: }
2482: $datatable .= '</span>'."\n".
2483: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2484: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2485: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2486: &Apache::loncommon::selectcourse_link
1.242 raeburn 2487: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2488: '</span></td>'."\n".
2489: '</tr>'."\n";
2490: $itemcount ++;
2491: return $datatable;
2492: }
2493:
1.217 raeburn 2494: sub textbookcourses_javascript {
1.242 raeburn 2495: my ($settings) = @_;
2496: return unless(ref($settings) eq 'HASH');
2497: my (%ordered,%total,%jstext);
2498: foreach my $type ('textbooks','templates') {
2499: $total{$type} = 0;
2500: if (ref($settings->{$type}) eq 'HASH') {
2501: foreach my $item (keys(%{$settings->{$type}})) {
2502: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2503: my $num = $settings->{$type}->{$item}{'order'};
2504: $ordered{$type}{$num} = $item;
2505: }
2506: }
2507: $total{$type} = scalar(keys(%{$settings->{$type}}));
2508: }
2509: my @jsarray = ();
2510: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2511: push(@jsarray,$ordered{$type}{$item});
2512: }
2513: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2514: }
2515: return <<"ENDSCRIPT";
2516: <script type="text/javascript">
2517: // <![CDATA[
1.242 raeburn 2518: function reorderBooks(form,item,caller) {
1.217 raeburn 2519: var changedVal;
1.242 raeburn 2520: $jstext{'textbooks'};
2521: $jstext{'templates'};
2522: var newpos;
2523: var maxh;
2524: if (caller == 'textbooks') {
2525: newpos = 'textbooks_addbook_pos';
2526: maxh = 1 + $total{'textbooks'};
2527: } else {
2528: newpos = 'templates_addbook_pos';
2529: maxh = 1 + $total{'templates'};
2530: }
1.217 raeburn 2531: var current = new Array;
2532: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2533: if (item == newpos) {
2534: changedVal = newitemVal;
2535: } else {
2536: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2537: current[newitemVal] = newpos;
2538: }
1.242 raeburn 2539: if (caller == 'textbooks') {
2540: for (var i=0; i<textbooks.length; i++) {
2541: var elementName = 'textbooks_'+textbooks[i];
2542: if (elementName != item) {
2543: if (form.elements[elementName]) {
2544: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2545: current[currVal] = elementName;
2546: }
2547: }
2548: }
2549: }
2550: if (caller == 'templates') {
2551: for (var i=0; i<templates.length; i++) {
2552: var elementName = 'templates_'+templates[i];
2553: if (elementName != item) {
2554: if (form.elements[elementName]) {
2555: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2556: current[currVal] = elementName;
2557: }
1.217 raeburn 2558: }
2559: }
2560: }
2561: var oldVal;
2562: for (var j=0; j<maxh; j++) {
2563: if (current[j] == undefined) {
2564: oldVal = j;
2565: }
2566: }
2567: if (oldVal < changedVal) {
2568: for (var k=oldVal+1; k<=changedVal ; k++) {
2569: var elementName = current[k];
2570: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2571: }
2572: } else {
2573: for (var k=changedVal; k<oldVal; k++) {
2574: var elementName = current[k];
2575: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2576: }
2577: }
2578: return;
2579: }
2580:
2581: // ]]>
2582: </script>
2583:
2584: ENDSCRIPT
2585: }
2586:
1.267 raeburn 2587: sub ltitools_javascript {
2588: my ($settings) = @_;
1.319 ! raeburn 2589: my $togglejs = <itools_toggle_js();
! 2590: unless (ref($settings) eq 'HASH') {
! 2591: return $togglejs;
! 2592: }
1.267 raeburn 2593: my (%ordered,$total,%jstext);
2594: $total = 0;
2595: foreach my $item (keys(%{$settings})) {
2596: if (ref($settings->{$item}) eq 'HASH') {
2597: my $num = $settings->{$item}{'order'};
2598: $ordered{$num} = $item;
2599: }
2600: }
2601: $total = scalar(keys(%{$settings}));
2602: my @jsarray = ();
2603: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2604: push(@jsarray,$ordered{$item});
2605: }
2606: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2607: return <<"ENDSCRIPT";
2608: <script type="text/javascript">
2609: // <![CDATA[
1.319 ! raeburn 2610: function reorderLTITools(form,item) {
1.267 raeburn 2611: var changedVal;
2612: $jstext
2613: var newpos = 'ltitools_add_pos';
2614: var maxh = 1 + $total;
2615: var current = new Array;
2616: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2617: if (item == newpos) {
2618: changedVal = newitemVal;
2619: } else {
2620: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2621: current[newitemVal] = newpos;
2622: }
2623: for (var i=0; i<ltitools.length; i++) {
2624: var elementName = 'ltitools_'+ltitools[i];
2625: if (elementName != item) {
2626: if (form.elements[elementName]) {
2627: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2628: current[currVal] = elementName;
2629: }
2630: }
2631: }
2632: var oldVal;
2633: for (var j=0; j<maxh; j++) {
2634: if (current[j] == undefined) {
2635: oldVal = j;
2636: }
2637: }
2638: if (oldVal < changedVal) {
2639: for (var k=oldVal+1; k<=changedVal ; k++) {
2640: var elementName = current[k];
2641: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2642: }
2643: } else {
2644: for (var k=changedVal; k<oldVal; k++) {
2645: var elementName = current[k];
2646: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2647: }
2648: }
2649: return;
2650: }
2651:
2652: // ]]>
2653: </script>
2654:
1.319 ! raeburn 2655: $togglejs
! 2656:
! 2657: ENDSCRIPT
! 2658: }
! 2659:
! 2660: sub ltitools_toggle_js {
! 2661: return <<"ENDSCRIPT";
! 2662: <script type="text/javascript">
! 2663: // <![CDATA[
! 2664:
! 2665: function toggleLTITools(form,setting,item) {
! 2666: var radioname = '';
! 2667: var divid = '';
! 2668: if ((setting == 'passback') || (setting == 'roster')) {
! 2669: radioname = 'ltitools_'+setting+'_'+item;
! 2670: divid = 'ltitools_'+setting+'time_'+item;
! 2671: var num = form.elements[radioname].length;
! 2672: if (num) {
! 2673: var setvis = '';
! 2674: for (var i=0; i<num; i++) {
! 2675: if (form.elements[radioname][i].checked) {
! 2676: if (form.elements[radioname][i].value == '1') {
! 2677: if (document.getElementById(divid)) {
! 2678: document.getElementById(divid).style.display = 'inline-block';
! 2679: }
! 2680: setvis = 1;
! 2681: }
! 2682: break;
! 2683: }
! 2684: }
! 2685: }
! 2686: if (!setvis) {
! 2687: if (document.getElementById(divid)) {
! 2688: document.getElementById(divid).style.display = 'none';
! 2689: }
! 2690: }
! 2691: }
! 2692: return;
! 2693: }
! 2694: // ]]>
! 2695: </script>
! 2696:
1.267 raeburn 2697: ENDSCRIPT
2698: }
2699:
1.3 raeburn 2700: sub print_autoenroll {
1.30 raeburn 2701: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2702: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2703: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2704: if (ref($settings) eq 'HASH') {
2705: if (exists($settings->{'run'})) {
2706: if ($settings->{'run'} eq '0') {
2707: $runoff = ' checked="checked" ';
2708: $runon = ' ';
2709: } else {
2710: $runon = ' checked="checked" ';
2711: $runoff = ' ';
2712: }
2713: } else {
2714: if ($autorun) {
2715: $runon = ' checked="checked" ';
2716: $runoff = ' ';
2717: } else {
2718: $runoff = ' checked="checked" ';
2719: $runon = ' ';
2720: }
2721: }
1.129 raeburn 2722: if (exists($settings->{'co-owners'})) {
2723: if ($settings->{'co-owners'} eq '0') {
2724: $coownersoff = ' checked="checked" ';
2725: $coownerson = ' ';
2726: } else {
2727: $coownerson = ' checked="checked" ';
2728: $coownersoff = ' ';
2729: }
2730: } else {
2731: $coownersoff = ' checked="checked" ';
2732: $coownerson = ' ';
2733: }
1.3 raeburn 2734: if (exists($settings->{'sender_domain'})) {
2735: $defdom = $settings->{'sender_domain'};
2736: }
1.274 raeburn 2737: if (exists($settings->{'autofailsafe'})) {
2738: $failsafe = $settings->{'autofailsafe'};
2739: }
1.14 raeburn 2740: } else {
2741: if ($autorun) {
2742: $runon = ' checked="checked" ';
2743: $runoff = ' ';
2744: } else {
2745: $runoff = ' checked="checked" ';
2746: $runon = ' ';
2747: }
1.3 raeburn 2748: }
2749: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2750: my $notif_sender;
2751: if (ref($settings) eq 'HASH') {
2752: $notif_sender = $settings->{'sender_uname'};
2753: }
1.3 raeburn 2754: my $datatable='<tr class="LC_odd_row">'.
2755: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2756: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2757: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2758: $runon.' value="1" />'.&mt('Yes').'</label> '.
2759: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2760: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2761: '</tr><tr>'.
2762: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2763: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2764: &mt('username').': '.
2765: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2766: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2767: ': '.$domform.'</span></td></tr>'.
2768: '<tr class="LC_odd_row">'.
2769: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2770: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2771: '<input type="radio" name="autoassign_coowners"'.
2772: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2773: '<label><input type="radio" name="autoassign_coowners"'.
2774: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 2775: '</tr><tr>'.
2776: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2777: '<td class="LC_right_item"><span class="LC_nobreak">'.
2778: '<input type="text" name="autoenroll_failsafe"'.
2779: ' value="'.$failsafe.'" size="4" /></td></tr>';
2780: $$rowtotal += 4;
1.3 raeburn 2781: return $datatable;
2782: }
2783:
2784: sub print_autoupdate {
1.30 raeburn 2785: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2786: my $datatable;
2787: if ($position eq 'top') {
2788: my $updateon = ' ';
2789: my $updateoff = ' checked="checked" ';
2790: my $classlistson = ' ';
2791: my $classlistsoff = ' checked="checked" ';
2792: if (ref($settings) eq 'HASH') {
2793: if ($settings->{'run'} eq '1') {
2794: $updateon = $updateoff;
2795: $updateoff = ' ';
2796: }
2797: if ($settings->{'classlists'} eq '1') {
2798: $classlistson = $classlistsoff;
2799: $classlistsoff = ' ';
2800: }
2801: }
2802: my %title = (
2803: run => 'Auto-update active?',
2804: classlists => 'Update information in classlists?',
2805: );
2806: $datatable = '<tr class="LC_odd_row">'.
2807: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2808: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2809: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2810: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2811: '<label><input type="radio" name="autoupdate_run"'.
2812: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2813: '</tr><tr>'.
2814: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2815: '<td class="LC_right_item"><span class="LC_nobreak">'.
2816: '<label><input type="radio" name="classlists"'.
2817: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2818: '<label><input type="radio" name="classlists"'.
2819: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2820: '</tr>';
1.30 raeburn 2821: $$rowtotal += 2;
1.131 raeburn 2822: } elsif ($position eq 'middle') {
2823: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2824: my $numinrow = 3;
2825: my $locknamesettings;
2826: $datatable .= &insttypes_row($settings,$types,$usertypes,
2827: $dom,$numinrow,$othertitle,
1.305 raeburn 2828: 'lockablenames',$rowtotal);
1.131 raeburn 2829: $$rowtotal ++;
1.3 raeburn 2830: } else {
1.44 raeburn 2831: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2832: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2833: 'permanentemail','id');
1.33 raeburn 2834: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2835: my $numrows = 0;
1.26 raeburn 2836: if (ref($types) eq 'ARRAY') {
2837: if (@{$types} > 0) {
2838: $datatable =
2839: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2840: \@fields,$types,\$numrows);
1.30 raeburn 2841: $$rowtotal += @{$types};
1.26 raeburn 2842: }
1.3 raeburn 2843: }
2844: $datatable .=
2845: &usertype_update_row($settings,{'default' => $othertitle},
2846: \%fieldtitles,\@fields,['default'],
2847: \$numrows);
1.30 raeburn 2848: $$rowtotal ++;
1.3 raeburn 2849: }
2850: return $datatable;
2851: }
2852:
1.125 raeburn 2853: sub print_autocreate {
2854: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2855: my (%createon,%createoff,%currhash);
1.125 raeburn 2856: my @types = ('xml','req');
2857: if (ref($settings) eq 'HASH') {
2858: foreach my $item (@types) {
2859: $createoff{$item} = ' checked="checked" ';
2860: $createon{$item} = ' ';
2861: if (exists($settings->{$item})) {
2862: if ($settings->{$item}) {
2863: $createon{$item} = ' checked="checked" ';
2864: $createoff{$item} = ' ';
2865: }
2866: }
2867: }
1.210 raeburn 2868: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2869: $currhash{$settings->{'xmldc'}} = 1;
2870: }
1.125 raeburn 2871: } else {
2872: foreach my $item (@types) {
2873: $createoff{$item} = ' checked="checked" ';
2874: $createon{$item} = ' ';
2875: }
2876: }
2877: $$rowtotal += 2;
1.191 raeburn 2878: my $numinrow = 2;
1.125 raeburn 2879: my $datatable='<tr class="LC_odd_row">'.
2880: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2881: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2882: '<input type="radio" name="autocreate_xml"'.
2883: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2884: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2885: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2886: '</td></tr><tr>'.
2887: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2888: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2889: '<input type="radio" name="autocreate_req"'.
2890: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2891: '<label><input type="radio" name="autocreate_req"'.
2892: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2893: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2894: 'autocreate_xmldc',%currhash);
1.247 raeburn 2895: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2896: if ($numdc > 1) {
1.247 raeburn 2897: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2898: '</td><td class="LC_left_item">';
1.125 raeburn 2899: } else {
1.247 raeburn 2900: $datatable .= &mt('Course creation processed as:').
2901: '</td><td class="LC_right_item">';
1.125 raeburn 2902: }
1.247 raeburn 2903: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 2904: $$rowtotal += $rows;
1.125 raeburn 2905: return $datatable;
2906: }
2907:
1.23 raeburn 2908: sub print_directorysrch {
1.277 raeburn 2909: my ($position,$dom,$settings,$rowtotal) = @_;
2910: my $datatable;
2911: if ($position eq 'top') {
2912: my $instsrchon = ' ';
2913: my $instsrchoff = ' checked="checked" ';
2914: my ($exacton,$containson,$beginson);
2915: my $instlocalon = ' ';
2916: my $instlocaloff = ' checked="checked" ';
2917: if (ref($settings) eq 'HASH') {
2918: if ($settings->{'available'} eq '1') {
2919: $instsrchon = $instsrchoff;
2920: $instsrchoff = ' ';
2921: }
2922: if ($settings->{'localonly'} eq '1') {
2923: $instlocalon = $instlocaloff;
2924: $instlocaloff = ' ';
2925: }
2926: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2927: foreach my $type (@{$settings->{'searchtypes'}}) {
2928: if ($type eq 'exact') {
2929: $exacton = ' checked="checked" ';
2930: } elsif ($type eq 'contains') {
2931: $containson = ' checked="checked" ';
2932: } elsif ($type eq 'begins') {
2933: $beginson = ' checked="checked" ';
2934: }
2935: }
2936: } else {
2937: if ($settings->{'searchtypes'} eq 'exact') {
2938: $exacton = ' checked="checked" ';
2939: } elsif ($settings->{'searchtypes'} eq 'contains') {
2940: $containson = ' checked="checked" ';
2941: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2942: $exacton = ' checked="checked" ';
2943: $containson = ' checked="checked" ';
2944: }
2945: }
1.277 raeburn 2946: }
2947: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2948: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2949:
2950: my $numinrow = 4;
2951: my $cansrchrow = 0;
2952: $datatable='<tr class="LC_odd_row">'.
2953: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2954: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2955: '<input type="radio" name="dirsrch_available"'.
2956: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2957: '<label><input type="radio" name="dirsrch_available"'.
2958: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2959: '</tr><tr>'.
2960: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2961: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2962: '<input type="radio" name="dirsrch_instlocalonly"'.
2963: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2964: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2965: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2966: '</tr>';
2967: $$rowtotal += 2;
2968: if (ref($usertypes) eq 'HASH') {
2969: if (keys(%{$usertypes}) > 0) {
2970: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 2971: $numinrow,$othertitle,'cansearch',
2972: $rowtotal);
1.277 raeburn 2973: $cansrchrow = 1;
1.25 raeburn 2974: }
1.23 raeburn 2975: }
1.277 raeburn 2976: if ($cansrchrow) {
2977: $$rowtotal ++;
2978: $datatable .= '<tr>';
2979: } else {
2980: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 2981: }
1.277 raeburn 2982: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2983: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2984: foreach my $title (@{$titleorder}) {
2985: if (defined($searchtitles->{$title})) {
2986: my $check = ' ';
2987: if (ref($settings) eq 'HASH') {
2988: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2989: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2990: $check = ' checked="checked" ';
2991: }
1.39 raeburn 2992: }
1.25 raeburn 2993: }
1.277 raeburn 2994: $datatable .= '<td class="LC_left_item">'.
2995: '<span class="LC_nobreak"><label>'.
2996: '<input type="checkbox" name="searchby" '.
2997: 'value="'.$title.'"'.$check.'/>'.
2998: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2999: }
3000: }
1.277 raeburn 3001: $datatable .= '</tr></table></td></tr>';
3002: $$rowtotal ++;
3003: if ($cansrchrow) {
3004: $datatable .= '<tr class="LC_odd_row">';
3005: } else {
3006: $datatable .= '<tr>';
3007: }
3008: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3009: '<td class="LC_left_item" colspan="2">'.
3010: '<span class="LC_nobreak"><label>'.
3011: '<input type="checkbox" name="searchtypes" '.
3012: $exacton.' value="exact" />'.&mt('Exact match').
3013: '</label> '.
3014: '<label><input type="checkbox" name="searchtypes" '.
3015: $beginson.' value="begins" />'.&mt('Begins with').
3016: '</label> '.
3017: '<label><input type="checkbox" name="searchtypes" '.
3018: $containson.' value="contains" />'.&mt('Contains').
3019: '</label></span></td></tr>';
3020: $$rowtotal ++;
1.26 raeburn 3021: } else {
1.277 raeburn 3022: my $domsrchon = ' checked="checked" ';
3023: my $domsrchoff = ' ';
3024: my $domlocalon = ' ';
3025: my $domlocaloff = ' checked="checked" ';
3026: if (ref($settings) eq 'HASH') {
3027: if ($settings->{'lclocalonly'} eq '1') {
3028: $domlocalon = $domlocaloff;
3029: $domlocaloff = ' ';
3030: }
3031: if ($settings->{'lcavailable'} eq '0') {
3032: $domsrchoff = $domsrchon;
3033: $domsrchon = ' ';
3034: }
3035: }
3036: $datatable='<tr class="LC_odd_row">'.
3037: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3038: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3039: '<input type="radio" name="dirsrch_domavailable"'.
3040: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3041: '<label><input type="radio" name="dirsrch_domavailable"'.
3042: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3043: '</tr><tr>'.
3044: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3045: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3046: '<input type="radio" name="dirsrch_domlocalonly"'.
3047: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3048: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3049: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3050: '</tr>';
3051: $$rowtotal += 2;
1.26 raeburn 3052: }
1.25 raeburn 3053: return $datatable;
3054: }
3055:
1.28 raeburn 3056: sub print_contacts {
1.286 raeburn 3057: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3058: my $datatable;
3059: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3060: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
3061: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
3062: if ($position eq 'top') {
3063: if (ref($settings) eq 'HASH') {
3064: foreach my $item (@contacts) {
3065: if (exists($settings->{$item})) {
3066: $to{$item} = $settings->{$item};
3067: }
3068: }
3069: }
3070: } elsif ($position eq 'middle') {
3071: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
3072: 'updatesmail','idconflictsmail');
1.288 raeburn 3073: foreach my $type (@mailings) {
3074: $otheremails{$type} = '';
3075: }
1.286 raeburn 3076: } else {
3077: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3078: foreach my $type (@mailings) {
3079: $otheremails{$type} = '';
3080: }
1.286 raeburn 3081: $bccemails{'helpdeskmail'} = '';
3082: $bccemails{'otherdomsmail'} = '';
3083: $includestr{'helpdeskmail'} = '';
3084: $includestr{'otherdomsmail'} = '';
3085: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3086: }
1.28 raeburn 3087: if (ref($settings) eq 'HASH') {
1.286 raeburn 3088: unless ($position eq 'top') {
3089: foreach my $type (@mailings) {
3090: if (exists($settings->{$type})) {
3091: if (ref($settings->{$type}) eq 'HASH') {
3092: foreach my $item (@contacts) {
3093: if ($settings->{$type}{$item}) {
3094: $checked{$type}{$item} = ' checked="checked" ';
3095: }
3096: }
3097: $otheremails{$type} = $settings->{$type}{'others'};
3098: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3099: $bccemails{$type} = $settings->{$type}{'bcc'};
3100: if ($settings->{$type}{'include'} ne '') {
3101: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3102: $includestr{$type} = &unescape($includestr{$type});
3103: }
3104: }
3105: }
3106: } elsif ($type eq 'lonstatusmail') {
3107: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3108: }
1.28 raeburn 3109: }
3110: }
1.286 raeburn 3111: if ($position eq 'bottom') {
3112: foreach my $type (@mailings) {
3113: $bccemails{$type} = $settings->{$type}{'bcc'};
3114: if ($settings->{$type}{'include'} ne '') {
3115: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3116: $includestr{$type} = &unescape($includestr{$type});
3117: }
3118: }
3119: if (ref($settings->{'helpform'}) eq 'HASH') {
3120: if (ref($fields) eq 'ARRAY') {
3121: foreach my $field (@{$fields}) {
3122: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3123: }
1.286 raeburn 3124: }
3125: if (exists($settings->{'helpform'}{'maxsize'})) {
3126: $maxsize = $settings->{'helpform'}{'maxsize'};
3127: } else {
1.289 raeburn 3128: $maxsize = '1.0';
1.286 raeburn 3129: }
3130: } else {
3131: if (ref($fields) eq 'ARRAY') {
3132: foreach my $field (@{$fields}) {
3133: $currfield{$field} = 'yes';
1.134 raeburn 3134: }
1.28 raeburn 3135: }
1.286 raeburn 3136: $maxsize = '1.0';
1.28 raeburn 3137: }
3138: }
3139: } else {
1.286 raeburn 3140: if ($position eq 'top') {
3141: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3142: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3143: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3144: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3145: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3146: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3147: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3148: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3149: } elsif ($position eq 'bottom') {
3150: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3151: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3152: if (ref($fields) eq 'ARRAY') {
3153: foreach my $field (@{$fields}) {
3154: $currfield{$field} = 'yes';
3155: }
3156: }
3157: $maxsize = '1.0';
3158: }
1.28 raeburn 3159: }
3160: my ($titles,$short_titles) = &contact_titles();
3161: my $rownum = 0;
3162: my $css_class;
1.286 raeburn 3163: if ($position eq 'top') {
3164: foreach my $item (@contacts) {
3165: $css_class = $rownum%2?' class="LC_odd_row"':'';
3166: $datatable .= '<tr'.$css_class.'>'.
3167: '<td><span class="LC_nobreak">'.$titles->{$item}.
3168: '</span></td><td class="LC_right_item">'.
3169: '<input type="text" name="'.$item.'" value="'.
3170: $to{$item}.'" /></td></tr>';
3171: $rownum ++;
3172: }
1.315 raeburn 3173: } elsif ($position eq 'bottom') {
3174: $css_class = $rownum%2?' class="LC_odd_row"':'';
3175: $datatable .= '<tr'.$css_class.'>'.
3176: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3177: &mt('(e-mail, subject, and description always shown)').
3178: '</td><td class="LC_left_item">';
3179: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3180: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3181: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3182: foreach my $field (@{$fields}) {
3183: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3184: if (($field eq 'screenshot') || ($field eq 'cc')) {
3185: $datatable .= ' '.&mt('(logged-in users)');
3186: }
3187: $datatable .='</td><td>';
3188: my $clickaction;
3189: if ($field eq 'screenshot') {
3190: $clickaction = ' onclick="screenshotSize(this);"';
3191: }
3192: if (ref($possoptions->{$field}) eq 'ARRAY') {
3193: foreach my $option (@{$possoptions->{$field}}) {
3194: my $checked;
3195: if ($currfield{$field} eq $option) {
3196: $checked = ' checked="checked"';
3197: }
3198: $datatable .= '<span class="LC_nobreak"><label>'.
3199: '<input type="radio" name="helpform_'.$field.'" '.
3200: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3201: '</label></span>'.(' 'x2);
3202: }
3203: }
3204: if ($field eq 'screenshot') {
3205: my $display;
3206: if ($currfield{$field} eq 'no') {
3207: $display = ' style="display:none"';
3208: }
3209: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
3210: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3211: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3212: }
3213: $datatable .= '</td></tr>';
3214: }
3215: $datatable .= '</table>';
3216: }
3217: $datatable .= '</td></tr>'."\n";
3218: $rownum ++;
3219: }
3220: unless ($position eq 'top') {
1.286 raeburn 3221: foreach my $type (@mailings) {
3222: $css_class = $rownum%2?' class="LC_odd_row"':'';
3223: $datatable .= '<tr'.$css_class.'>'.
3224: '<td><span class="LC_nobreak">'.
3225: $titles->{$type}.': </span></td>'.
3226: '<td class="LC_left_item">';
3227: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3228: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3229: }
3230: $datatable .= '<span class="LC_nobreak">';
3231: foreach my $item (@contacts) {
3232: $datatable .= '<label>'.
3233: '<input type="checkbox" name="'.$type.'"'.
3234: $checked{$type}{$item}.
3235: ' value="'.$item.'" />'.$short_titles->{$item}.
3236: '</label> ';
3237: }
3238: $datatable .= '</span><br />'.&mt('Others').': '.
3239: '<input type="text" name="'.$type.'_others" '.
3240: 'value="'.$otheremails{$type}.'" />';
3241: my %locchecked;
3242: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3243: foreach my $loc ('s','b') {
3244: if ($includeloc{$type} eq $loc) {
3245: $locchecked{$loc} = ' checked="checked"';
3246: last;
3247: }
3248: }
3249: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3250: '<input type="text" name="'.$type.'_bcc" '.
3251: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3252: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3253: &mt('Text automatically added to e-mail:').' '.
3254: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
3255: '<span class="LC_nobreak">'.&mt('Location:').' '.
3256: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3257: (' 'x2).
3258: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3259: '</span></fieldset>';
3260: }
3261: $datatable .= '</td></tr>'."\n";
3262: $rownum ++;
3263: }
1.28 raeburn 3264: }
1.286 raeburn 3265: if ($position eq 'middle') {
3266: my %choices;
3267: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
1.289 raeburn 3268: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3269: &mt('LON-CAPA core group - MSU'),600,500));
1.286 raeburn 3270: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3271: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3272: &mt('LON-CAPA core group - MSU'),600,500));
3273: my @toggles = ('reporterrors','reportupdates');
3274: my %defaultchecked = ('reporterrors' => 'on',
3275: 'reportupdates' => 'on');
3276: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3277: \%choices,$rownum);
3278: $datatable .= $reports;
3279: } elsif ($position eq 'bottom') {
1.315 raeburn 3280: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3281: my (@posstypes,%usertypeshash);
3282: if (ref($types) eq 'ARRAY') {
3283: @posstypes = @{$types};
3284: }
3285: if (@posstypes) {
3286: if (ref($usertypes) eq 'HASH') {
3287: %usertypeshash = %{$usertypes};
3288: }
3289: my @overridden;
3290: my $numinrow = 4;
3291: if (ref($settings) eq 'HASH') {
3292: if (ref($settings->{'overrides'}) eq 'HASH') {
3293: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3294: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3295: push(@overridden,$key);
3296: foreach my $item (@contacts) {
3297: if ($settings->{'overrides'}{$key}{$item}) {
3298: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3299: }
3300: }
3301: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3302: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3303: $includeloc{'override_'.$key} = '';
3304: $includestr{'override_'.$key} = '';
3305: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3306: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3307: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3308: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3309: }
1.286 raeburn 3310: }
3311: }
3312: }
1.315 raeburn 3313: }
3314: my $customclass = 'LC_helpdesk_override';
3315: my $optionsprefix = 'LC_options_helpdesk_';
3316:
3317: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3318:
3319: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3320: $numinrow,$othertitle,'overrides',
3321: \$rownum,$onclicktypes,$customclass);
3322: $rownum ++;
3323: $usertypeshash{'default'} = $othertitle;
3324: foreach my $status (@posstypes) {
3325: my $css_class;
3326: if ($rownum%2) {
3327: $css_class = 'LC_odd_row ';
3328: }
3329: $css_class .= $customclass;
3330: my $rowid = $optionsprefix.$status;
3331: my $hidden = 1;
3332: my $currstyle = 'display:none';
3333: if (grep(/^\Q$status\E$/,@overridden)) {
3334: $currstyle = 'display:table-row';
3335: $hidden = 0;
3336: }
3337: my $key = 'override_'.$status;
3338: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3339: $includeloc{$key},$includestr{$key},$status,$rowid,
3340: $usertypeshash{$status},$css_class,$currstyle,
3341: \@contacts,$short_titles);
3342: unless ($hidden) {
3343: $rownum ++;
1.286 raeburn 3344: }
3345: }
1.134 raeburn 3346: }
1.28 raeburn 3347: }
1.30 raeburn 3348: $$rowtotal += $rownum;
1.28 raeburn 3349: return $datatable;
3350: }
3351:
1.315 raeburn 3352: sub overridden_helpdesk {
3353: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3354: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3355: my $class = 'LC_left_item';
3356: if ($css_class) {
3357: $css_class = ' class="'.$css_class.'"';
3358: }
3359: if ($rowid) {
3360: $rowid = ' id="'.$rowid.'"';
3361: }
3362: if ($rowstyle) {
3363: $rowstyle = ' style="'.$rowstyle.'"';
3364: }
3365: my ($output,$description);
3366: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3367: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3368: "<td>$description</td>\n".
3369: '<td class="'.$class.'" colspan="2">'.
3370: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3371: '<span class="LC_nobreak">';
3372: if (ref($contacts) eq 'ARRAY') {
3373: foreach my $item (@{$contacts}) {
3374: my $check;
3375: if (ref($checked) eq 'HASH') {
3376: $check = $checked->{$item};
3377: }
3378: my $title;
3379: if (ref($short_titles) eq 'HASH') {
3380: $title = $short_titles->{$item};
3381: }
3382: $output .= '<label>'.
3383: '<input type="checkbox" name="override_'.$type.'"'.$check.
3384: ' value="'.$item.'" />'.$title.'</label> ';
3385: }
3386: }
3387: $output .= '</span><br />'.&mt('Others').': '.
3388: '<input type="text" name="override_'.$type.'_others" '.
3389: 'value="'.$otheremails.'" />';
3390: my %locchecked;
3391: foreach my $loc ('s','b') {
3392: if ($includeloc eq $loc) {
3393: $locchecked{$loc} = ' checked="checked"';
3394: last;
3395: }
3396: }
3397: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3398: '<input type="text" name="override_'.$type.'_bcc" '.
3399: 'value="'.$bccemails.'" /></fieldset>'.
3400: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3401: &mt('Text automatically added to e-mail:').' '.
3402: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br >'.
3403: '<span class="LC_nobreak">'.&mt('Location:').' '.
3404: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3405: (' 'x2).
3406: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3407: '</span></fieldset>'.
3408: '</td></tr>'."\n";
3409: return $output;
3410: }
3411:
1.286 raeburn 3412: sub contacts_javascript {
3413: return <<"ENDSCRIPT";
3414:
3415: <script type="text/javascript">
3416: // <![CDATA[
3417:
3418: function screenshotSize(field) {
3419: if (document.getElementById('help_screenshotsize')) {
3420: if (field.value == 'no') {
1.289 raeburn 3421: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3422: } else {
3423: document.getElementById('help_screenshotsize').style.display="";
3424: }
3425: }
3426: return;
3427: }
3428:
1.315 raeburn 3429: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3430: if (form.elements[checkbox].length != undefined) {
3431: var count = 0;
3432: if (docount) {
3433: for (var i=0; i<form.elements[checkbox].length; i++) {
3434: if (form.elements[checkbox][i].checked) {
3435: count ++;
3436: }
3437: }
3438: }
3439: for (var i=0; i<form.elements[checkbox].length; i++) {
3440: var type = form.elements[checkbox][i].value;
3441: if (document.getElementById(prefix+type)) {
3442: if (form.elements[checkbox][i].checked) {
3443: document.getElementById(prefix+type).style.display = 'table-row';
3444: if (count % 2 == 1) {
3445: document.getElementById(prefix+type).className = target+' LC_odd_row';
3446: } else {
3447: document.getElementById(prefix+type).className = target;
3448: }
3449: count ++;
3450: } else {
3451: document.getElementById(prefix+type).style.display = 'none';
3452: }
3453: }
3454: }
3455: }
3456: return;
3457: }
3458:
3459:
1.286 raeburn 3460: // ]]>
3461: </script>
3462:
3463: ENDSCRIPT
3464: }
3465:
1.118 jms 3466: sub print_helpsettings {
1.282 raeburn 3467: my ($position,$dom,$settings,$rowtotal) = @_;
3468: my $confname = $dom.'-domainconfig';
1.285 raeburn 3469: my $formname = 'display';
1.168 raeburn 3470: my ($datatable,$itemcount);
1.282 raeburn 3471: if ($position eq 'top') {
3472: $itemcount = 1;
3473: my (%choices,%defaultchecked,@toggles);
3474: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3475: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3476: &mt('LON-CAPA bug tracker'),600,500));
3477: %defaultchecked = ('submitbugs' => 'on');
3478: @toggles = ('submitbugs');
3479: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3480: \%choices,$itemcount);
3481: $$rowtotal ++;
3482: } else {
3483: my $css_class;
3484: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3485: my (%customroles,%ordered,%current);
1.301 raeburn 3486: if (ref($settings) eq 'HASH') {
3487: if (ref($settings->{'adhoc'}) eq 'HASH') {
3488: %current = %{$settings->{'adhoc'}};
3489: }
1.285 raeburn 3490: }
3491: my $count = 0;
3492: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3493: if ($key=~/^rolesdef\_(\w+)$/) {
3494: my $rolename = $1;
1.285 raeburn 3495: my (%privs,$order);
1.282 raeburn 3496: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3497: $customroles{$rolename} = \%privs;
1.285 raeburn 3498: if (ref($current{$rolename}) eq 'HASH') {
3499: $order = $current{$rolename}{'order'};
3500: }
3501: if ($order eq '') {
3502: $order = $count;
3503: }
3504: $ordered{$order} = $rolename;
3505: $count++;
3506: }
3507: }
3508: my $maxnum = scalar(keys(%ordered));
3509: my @roles_by_num = ();
3510: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3511: push(@roles_by_num,$item);
3512: }
3513: my $context = 'domprefs';
3514: my $crstype = 'Course';
3515: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3516: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3517: my ($numstatustypes,@jsarray);
3518: if (ref($types) eq 'ARRAY') {
3519: if (@{$types} > 0) {
3520: $numstatustypes = scalar(@{$types});
3521: push(@accesstypes,'status');
3522: @jsarray = ('bystatus');
1.282 raeburn 3523: }
3524: }
1.290 raeburn 3525: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3526: if (keys(%domhelpdesk)) {
3527: push(@accesstypes,('inc','exc'));
3528: push(@jsarray,('notinc','notexc'));
3529: }
3530: my $hiddenstr = join("','",@jsarray);
3531: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.282 raeburn 3532: my $context = 'domprefs';
3533: my $crstype = 'Course';
1.285 raeburn 3534: my $prefix = 'helproles_';
3535: my $add_class = 'LC_hidden';
3536: foreach my $num (@roles_by_num) {
3537: my $role = $ordered{$num};
3538: my ($desc,$access,@statuses);
3539: if (ref($current{$role}) eq 'HASH') {
3540: $desc = $current{$role}{'desc'};
3541: $access = $current{$role}{'access'};
3542: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3543: @statuses = @{$current{$role}{'insttypes'}};
3544: }
3545: }
3546: if ($desc eq '') {
3547: $desc = $role;
3548: }
3549: my $identifier = 'custhelp'.$num;
1.282 raeburn 3550: my %full=();
3551: my %levels= (
3552: course => {},
3553: domain => {},
3554: system => {},
3555: );
3556: my %levelscurrent=(
3557: course => {},
3558: domain => {},
3559: system => {},
3560: );
3561: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3562: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3563: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 3564: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 3565: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 3566: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3567: for (my $k=0; $k<=$maxnum; $k++) {
3568: my $vpos = $k+1;
3569: my $selstr;
3570: if ($k == $num) {
3571: $selstr = ' selected="selected" ';
3572: }
3573: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3574: }
3575: $datatable .= '</select>'.(' 'x2).
3576: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3577: '</td>'.
3578: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3579: &mt('Name shown to users:').
3580: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3581: '</fieldset>'.
3582: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3583: $othertitle,$usertypes,$types,\%domhelpdesk).
3584: '<fieldset>'.
3585: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 3586: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 3587: \%levelscurrent,$identifier,
3588: 'LC_hidden',$prefix.$num.'_privs').
3589: '</fieldset></td>';
1.282 raeburn 3590: $itemcount ++;
3591: }
3592: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3593: my $newcust = 'custhelp'.$count;
3594: my (%privs,%levelscurrent);
3595: my %full=();
3596: my %levels= (
3597: course => {},
3598: domain => {},
3599: system => {},
3600: );
3601: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3602: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 3603: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 3604: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 3605: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3606: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3607: for (my $k=0; $k<$maxnum+1; $k++) {
3608: my $vpos = $k+1;
3609: my $selstr;
3610: if ($k == $maxnum) {
3611: $selstr = ' selected="selected" ';
3612: }
3613: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3614: }
3615: $datatable .= '</select> '."\n".
1.282 raeburn 3616: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3617: '</label></span></td>'.
1.285 raeburn 3618: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3619: '<span class="LC_nobreak">'.
3620: &mt('Internal name:').
3621: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3622: '</span>'.(' 'x4).
3623: '<span class="LC_nobreak">'.
3624: &mt('Name shown to users:').
3625: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3626: '</span></fieldset>'.
3627: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3628: $usertypes,$types,\%domhelpdesk).
3629: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 3630: &Apache::lonuserutils::custom_role_header($context,$crstype,
3631: \@templateroles,$newcust).
3632: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3633: \%levelscurrent,$newcust).
1.285 raeburn 3634: '</fieldset></td></tr>';
1.282 raeburn 3635: $count ++;
3636: $$rowtotal += $count;
3637: }
1.166 raeburn 3638: return $datatable;
1.121 raeburn 3639: }
3640:
1.285 raeburn 3641: sub adhocbutton {
3642: my ($prefix,$num,$field,$visibility) = @_;
3643: my %lt = &Apache::lonlocal::texthash(
3644: show => 'Show details',
3645: hide => 'Hide details',
3646: );
3647: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3648: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3649: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3650: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3651: }
3652:
3653: sub helpsettings_javascript {
3654: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3655: return unless(ref($roles_by_num) eq 'ARRAY');
3656: my %html_js_lt = &Apache::lonlocal::texthash(
3657: show => 'Show details',
3658: hide => 'Hide details',
3659: );
3660: &html_escape(\%html_js_lt);
3661: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3662: return <<"ENDSCRIPT";
3663: <script type="text/javascript">
3664: // <![CDATA[
3665:
3666: function reorderHelpRoles(form,item) {
3667: var changedVal;
3668: $jstext
3669: var newpos = 'helproles_${total}_pos';
3670: var maxh = 1 + $total;
3671: var current = new Array();
3672: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3673: if (item == newpos) {
3674: changedVal = newitemVal;
3675: } else {
3676: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3677: current[newitemVal] = newpos;
3678: }
3679: for (var i=0; i<helproles.length; i++) {
3680: var elementName = 'helproles_'+helproles[i]+'_pos';
3681: if (elementName != item) {
3682: if (form.elements[elementName]) {
3683: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3684: current[currVal] = elementName;
3685: }
3686: }
3687: }
3688: var oldVal;
3689: for (var j=0; j<maxh; j++) {
3690: if (current[j] == undefined) {
3691: oldVal = j;
3692: }
3693: }
3694: if (oldVal < changedVal) {
3695: for (var k=oldVal+1; k<=changedVal ; k++) {
3696: var elementName = current[k];
3697: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3698: }
3699: } else {
3700: for (var k=changedVal; k<oldVal; k++) {
3701: var elementName = current[k];
3702: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3703: }
3704: }
3705: return;
3706: }
3707:
3708: function helpdeskAccess(num) {
3709: var curraccess = null;
3710: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3711: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3712: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3713: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3714: }
3715: }
3716: }
3717: var shown = Array();
3718: var hidden = Array();
3719: if (curraccess == 'none') {
3720: hidden = Array('$hiddenstr');
3721: } else {
3722: if (curraccess == 'status') {
3723: shown = Array('bystatus');
3724: hidden = Array('notinc','notexc');
3725: } else {
3726: if (curraccess == 'exc') {
3727: shown = Array('notexc');
3728: hidden = Array('notinc','bystatus');
3729: }
3730: if (curraccess == 'inc') {
3731: shown = Array('notinc');
3732: hidden = Array('notexc','bystatus');
3733: }
1.293 raeburn 3734: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 3735: hidden = Array('notinc','notexc','bystatus');
3736: }
3737: }
3738: }
3739: if (hidden.length > 0) {
3740: for (var i=0; i<hidden.length; i++) {
3741: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3742: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3743: }
3744: }
3745: }
3746: if (shown.length > 0) {
3747: for (var i=0; i<shown.length; i++) {
3748: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3749: if (shown[i] == 'privs') {
3750: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3751: } else {
3752: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3753: }
3754: }
3755: }
3756: }
3757: return;
3758: }
3759:
3760: function toggleHelpdeskItem(num,field) {
3761: if (document.getElementById('helproles_'+num+'_'+field)) {
3762: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 3763: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 3764: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3765: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3766: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3767: }
3768: } else {
3769: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3770: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3771: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3772: }
3773: }
3774: }
3775: return;
3776: }
3777:
3778: // ]]>
3779: </script>
3780:
3781: ENDSCRIPT
3782: }
3783:
3784: sub helpdeskroles_access {
3785: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3786: $usertypes,$types,$domhelpdesk) = @_;
3787: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3788: my %lt = &Apache::lonlocal::texthash(
3789: 'rou' => 'Role usage',
3790: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 3791: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3792: 'dh' => 'All with domain helpdesk role',
3793: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 3794: 'none' => 'None',
3795: 'status' => 'Determined based on institutional status',
3796: 'inc' => 'Include all, but exclude specific personnel',
3797: 'exc' => 'Exclude all, but include specific personnel',
3798: );
3799: my %usecheck = (
3800: all => ' checked="checked"',
3801: );
3802: my %displaydiv = (
3803: status => 'none',
3804: inc => 'none',
3805: exc => 'none',
3806: priv => 'block',
3807: );
3808: my $output;
3809: if (ref($current) eq 'HASH') {
3810: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3811: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3812: $usecheck{$current->{access}} = $usecheck{'all'};
3813: delete($usecheck{'all'});
3814: if ($current->{access} =~ /^(status|inc|exc)$/) {
3815: my $access = $1;
3816: $displaydiv{$access} = 'inline';
3817: } elsif ($current->{access} eq 'none') {
3818: $displaydiv{'priv'} = 'none';
3819: }
3820: }
3821: }
3822: }
3823: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3824: '<p>'.$lt{'whi'}.'</p>';
3825: foreach my $access (@{$accesstypes}) {
3826: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3827: ' onclick="helpdeskAccess('."'$num'".');" />'.
3828: $lt{$access}.'</label>';
3829: if ($access eq 'status') {
3830: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3831: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3832: $othertitle,$usertypes,$types).
3833: '</div>';
3834: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3835: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3836: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3837: '</div>';
3838: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3839: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3840: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3841: '</div>';
3842: }
3843: $output .= '</p>';
3844: }
3845: $output .= '</fieldset>';
3846: return $output;
3847: }
3848:
1.121 raeburn 3849: sub radiobutton_prefs {
1.192 raeburn 3850: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 3851: $additional,$align) = @_;
1.121 raeburn 3852: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3853: (ref($choices) eq 'HASH'));
3854:
1.170 raeburn 3855: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 3856:
3857: foreach my $item (@{$toggles}) {
3858: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3859: $checkedon{$item} = ' checked="checked" ';
3860: $checkedoff{$item} = ' ';
1.121 raeburn 3861: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3862: $checkedoff{$item} = ' checked="checked" ';
3863: $checkedon{$item} = ' ';
3864: }
3865: }
3866: if (ref($settings) eq 'HASH') {
1.121 raeburn 3867: foreach my $item (@{$toggles}) {
1.118 jms 3868: if ($settings->{$item} eq '1') {
3869: $checkedon{$item} = ' checked="checked" ';
3870: $checkedoff{$item} = ' ';
3871: } elsif ($settings->{$item} eq '0') {
3872: $checkedoff{$item} = ' checked="checked" ';
3873: $checkedon{$item} = ' ';
3874: }
3875: }
1.121 raeburn 3876: }
1.192 raeburn 3877: if ($onclick) {
3878: $onclick = ' onclick="'.$onclick.'"';
3879: }
1.121 raeburn 3880: foreach my $item (@{$toggles}) {
1.118 jms 3881: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3882: $datatable .=
1.306 raeburn 3883: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 3884: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 3885: '</span></td>';
3886: if ($align eq 'left') {
3887: $datatable .= '<td class="LC_left_item">';
3888: } else {
3889: $datatable .= '<td class="LC_right_item">';
3890: }
1.289 raeburn 3891: $datatable .=
1.257 raeburn 3892: '<span class="LC_nobreak">'.
1.118 jms 3893: '<label><input type="radio" name="'.
1.192 raeburn 3894: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3895: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 3896: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3897: '</span>'.$additional.
3898: '</td>'.
1.118 jms 3899: '</tr>';
3900: $itemcount ++;
1.121 raeburn 3901: }
3902: return ($datatable,$itemcount);
3903: }
3904:
1.267 raeburn 3905: sub print_ltitools {
3906: my ($dom,$settings,$rowtotal) = @_;
3907: my $rownum = 0;
3908: my $css_class;
3909: my $itemcount = 1;
3910: my $maxnum = 0;
3911: my %ordered;
3912: if (ref($settings) eq 'HASH') {
3913: foreach my $item (keys(%{$settings})) {
3914: if (ref($settings->{$item}) eq 'HASH') {
3915: my $num = $settings->{$item}{'order'};
3916: $ordered{$num} = $item;
3917: }
3918: }
3919: }
3920: my $confname = $dom.'-domainconfig';
3921: my $switchserver = &check_switchserver($dom,$confname);
3922: my $maxnum = scalar(keys(%ordered));
3923: my $datatable = <itools_javascript($settings);
3924: my %lt = <itools_names();
3925: my @courseroles = ('cc','in','ta','ep','st');
3926: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3927: my @fields = ('fullname','firstname','lastname','email','user','roles');
3928: if (keys(%ordered)) {
3929: my @items = sort { $a <=> $b } keys(%ordered);
3930: for (my $i=0; $i<@items; $i++) {
3931: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3932: my $item = $ordered{$items[$i]};
1.317 raeburn 3933: my ($title,$key,$secret,$url,$imgsrc);
1.267 raeburn 3934: if (ref($settings->{$item}) eq 'HASH') {
3935: $title = $settings->{$item}->{'title'};
3936: $url = $settings->{$item}->{'url'};
3937: $key = $settings->{$item}->{'key'};
3938: $secret = $settings->{$item}->{'secret'};
3939: my $image = $settings->{$item}->{'image'};
3940: if ($image ne '') {
3941: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3942: }
3943: }
1.319 ! raeburn 3944: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 3945: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3946: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3947: for (my $k=0; $k<=$maxnum; $k++) {
3948: my $vpos = $k+1;
3949: my $selstr;
3950: if ($k == $i) {
3951: $selstr = ' selected="selected" ';
3952: }
3953: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3954: }
3955: $datatable .= '</select>'.(' 'x2).
3956: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3957: &mt('Delete?').'</label></span></td>'.
3958: '<td colspan="2">'.
3959: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3960: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3961: (' 'x2).
3962: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3963: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3964: (' 'x2).
3965: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3966: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3967: '<br /><br />'.
3968: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3969: ' value="'.$url.'" /></span>'.
3970: (' 'x2).
1.319 ! raeburn 3971: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 3972: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3973: (' 'x2).
3974: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3975: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3976: '<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>'.
3977: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3978: '</fieldset>'.
3979: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3980: '<span class="LC_nobreak">'.&mt('Display target:');
3981: my %currdisp;
3982: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3983: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3984: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 3985: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
3986: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 3987: } else {
3988: $currdisp{'iframe'} = ' checked="checked"';
3989: }
3990: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3991: $currdisp{'width'} = $1;
3992: }
3993: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3994: $currdisp{'height'} = $1;
3995: }
1.296 raeburn 3996: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
3997: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 3998: } else {
3999: $currdisp{'iframe'} = ' checked="checked"';
4000: }
1.298 raeburn 4001: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4002: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4003: $lt{$disp}.'</label>'.(' 'x2);
4004: }
4005: $datatable .= (' 'x4);
4006: foreach my $dimen ('width','height') {
4007: $datatable .= '<label>'.$lt{$dimen}.' '.
4008: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4009: (' 'x2);
4010: }
1.296 raeburn 4011: $datatable .= '<br />'.
4012: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4013: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
4014: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4015: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4016: '</textarea></div><div style=""></div><br />';
1.319 ! raeburn 4017: my %units = (
! 4018: 'passback' => 'days',
! 4019: 'roster' => 'seconds',
! 4020: );
1.267 raeburn 4021: foreach my $extra ('passback','roster') {
1.319 ! raeburn 4022: my $validsty = 'none';
! 4023: my $currvalid;
1.267 raeburn 4024: my $checkedon = '';
4025: my $checkedoff = ' checked="checked"';
4026: if ($settings->{$item}->{$extra}) {
4027: $checkedon = $checkedoff;
4028: $checkedoff = '';
1.319 ! raeburn 4029: $validsty = 'inline-block';
! 4030: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
! 4031: $currvalid = $settings->{$item}->{$extra.'valid'};
! 4032: }
! 4033: }
! 4034: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
! 4035: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
! 4036: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
! 4037: &mt('No').'</label>'.(' 'x2).
! 4038: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
! 4039: &mt('Yes').'</label></span></div>'.
! 4040: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
! 4041: '<span class="LC_nobreak">'.
! 4042: &mt("at least [_1] $units{$extra} after launch",
! 4043: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
! 4044: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4045: }
1.319 ! raeburn 4046: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4047: if ($imgsrc) {
4048: $datatable .= $imgsrc.
4049: '<label><input type="checkbox" name="ltitools_image_del"'.
4050: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4051: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4052: } else {
4053: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4054: }
4055: if ($switchserver) {
4056: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4057: } else {
4058: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4059: }
4060: $datatable .= '</span></fieldset>';
4061: my (%checkedfields,%rolemaps);
4062: if (ref($settings->{$item}) eq 'HASH') {
4063: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4064: %checkedfields = %{$settings->{$item}->{'fields'}};
4065: }
4066: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4067: %rolemaps = %{$settings->{$item}->{'roles'}};
4068: $checkedfields{'roles'} = 1;
4069: }
4070: }
4071: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4072: '<span class="LC_nobreak">';
4073: foreach my $field (@fields) {
4074: my $checked;
4075: if ($checkedfields{$field}) {
4076: $checked = ' checked="checked"';
4077: }
4078: $datatable .= '<label>'.
4079: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
4080: $lt{$field}.'</label>'.(' ' x2);
4081: }
4082: $datatable .= '</span></fieldset>'.
4083: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4084: foreach my $role (@courseroles) {
4085: my ($selected,$selectnone);
4086: if (!$rolemaps{$role}) {
4087: $selectnone = ' selected="selected"';
4088: }
1.306 raeburn 4089: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4090: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4091: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4092: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4093: foreach my $ltirole (@ltiroles) {
4094: unless ($selectnone) {
4095: if ($rolemaps{$role} eq $ltirole) {
4096: $selected = ' selected="selected"';
4097: } else {
4098: $selected = '';
4099: }
4100: }
4101: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4102: }
4103: $datatable .= '</select></td>';
4104: }
1.273 raeburn 4105: $datatable .= '</tr></table></fieldset>';
4106: my %courseconfig;
4107: if (ref($settings->{$item}) eq 'HASH') {
4108: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4109: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4110: }
4111: }
4112: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4113: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4114: my $checked;
4115: if ($courseconfig{$item}) {
4116: $checked = ' checked="checked"';
4117: }
4118: $datatable .= '<label>'.
4119: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4120: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4121: }
4122: $datatable .= '</span></fieldset>'.
1.267 raeburn 4123: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4124: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4125: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4126: my %custom = %{$settings->{$item}->{'custom'}};
4127: if (keys(%custom) > 0) {
4128: foreach my $key (sort(keys(%custom))) {
4129: $datatable .= '<tr><td><span class="LC_nobreak">'.
4130: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4131: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4132: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4133: ' value="'.$custom{$key}.'" /></td></tr>';
4134: }
4135: }
4136: }
4137: $datatable .= '<tr><td><span class="LC_nobreak">'.
4138: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4139: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4140: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4141: $datatable .= '</table></fieldset></td></tr>'."\n";
4142: $itemcount ++;
4143: }
4144: }
4145: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 ! raeburn 4146: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4147: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4148: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4149: '<select name="ltitools_add_pos"'.$chgstr.'>';
4150: for (my $k=0; $k<$maxnum+1; $k++) {
4151: my $vpos = $k+1;
4152: my $selstr;
4153: if ($k == $maxnum) {
4154: $selstr = ' selected="selected" ';
4155: }
4156: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4157: }
4158: $datatable .= '</select> '."\n".
4159: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
4160: '<td colspan="2">'.
4161: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4162: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
4163: (' 'x2).
4164: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4165: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4166: (' 'x2).
4167: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4168: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
4169: '<br />'.
4170: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
4171: (' 'x2).
4172: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4173: (' 'x2).
4174: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4175: '<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".
4176: '</fieldset>'.
4177: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4178: '<span class="LC_nobreak">'.&mt('Display target:');
4179: my %defaultdisp;
4180: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4181: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4182: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4183: $lt{$disp}.'</label>'.(' 'x2);
4184: }
4185: $datatable .= (' 'x4);
4186: foreach my $dimen ('width','height') {
4187: $datatable .= '<label>'.$lt{$dimen}.' '.
4188: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4189: (' 'x2);
4190: }
1.296 raeburn 4191: $datatable .= '<br />'.
4192: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4193: '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
4194: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4195: '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
4196: '</div><div style=""></div><br />';
1.319 ! raeburn 4197: my %units = (
! 4198: 'passback' => 'days',
! 4199: 'roster' => 'seconds',
! 4200: );
! 4201: my %defaulttimes = (
! 4202: 'passback' => '7',
! 4203: 'roster' => '300',
! 4204: );
1.267 raeburn 4205: foreach my $extra ('passback','roster') {
1.319 ! raeburn 4206: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
! 4207: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
! 4208: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
! 4209: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
! 4210: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
! 4211: &mt('Yes').'</label></span></div>'.
! 4212: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
! 4213: '<span class="LC_nobreak">'.
! 4214: &mt("at least [_1] $units{$extra} after launch",
! 4215: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
! 4216: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4217: }
1.319 ! raeburn 4218: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4219: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4220: if ($switchserver) {
4221: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4222: } else {
4223: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4224: }
4225: $datatable .= '</span></fieldset>'.
4226: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4227: '<span class="LC_nobreak">';
4228: foreach my $field (@fields) {
4229: $datatable .= '<label>'.
4230: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
4231: $lt{$field}.'</label>'.(' ' x2);
4232: }
4233: $datatable .= '</span></fieldset>'.
4234: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4235: foreach my $role (@courseroles) {
4236: my ($checked,$checkednone);
1.306 raeburn 4237: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4238: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4239: '<select name="ltitools_add_roles_'.$role.'">'.
4240: '<option value="" selected="selected">'.&mt('Select').'</option>';
4241: foreach my $ltirole (@ltiroles) {
4242: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4243: }
4244: $datatable .= '</select></td>';
4245: }
4246: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4247: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4248: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 4249: $datatable .= '<label>'.
4250: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4251: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4252: }
4253: $datatable .= '</span></fieldset>'.
1.267 raeburn 4254: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4255: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4256: '<tr><td><span class="LC_nobreak">'.
4257: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4258: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4259: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
4260: '</table></fieldset></td></tr>'."\n".
4261: '</td>'."\n".
4262: '</tr>'."\n";
4263: $itemcount ++;
4264: return $datatable;
4265: }
4266:
4267: sub ltitools_names {
4268: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4269: 'title' => 'Title',
4270: 'version' => 'Version',
4271: 'msgtype' => 'Message Type',
4272: 'url' => 'URL',
4273: 'key' => 'Key',
4274: 'secret' => 'Secret',
4275: 'icon' => 'Icon',
4276: 'user' => 'Username:domain',
4277: 'fullname' => 'Full Name',
4278: 'firstname' => 'First Name',
4279: 'lastname' => 'Last Name',
4280: 'email' => 'E-mail',
4281: 'roles' => 'Role',
1.298 raeburn 4282: 'window' => 'Window',
4283: 'tab' => 'Tab',
1.296 raeburn 4284: 'iframe' => 'iFrame',
4285: 'height' => 'Height',
4286: 'width' => 'Width',
4287: 'linktext' => 'Default Link Text',
4288: 'explanation' => 'Default Explanation',
4289: 'passback' => 'Tool can return grades:',
4290: 'roster' => 'Tool can retrieve roster:',
4291: 'crstarget' => 'Display target',
4292: 'crslabel' => 'Course label',
4293: 'crstitle' => 'Course title',
4294: 'crslinktext' => 'Link Text',
4295: 'crsexplanation' => 'Explanation',
1.318 raeburn 4296: 'crsappend' => 'Provider URL',
1.267 raeburn 4297: );
4298: return %lt;
4299: }
4300:
1.121 raeburn 4301: sub print_coursedefaults {
1.139 raeburn 4302: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 4303: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4304: my $itemcount = 1;
1.192 raeburn 4305: my %choices = &Apache::lonlocal::texthash (
4306: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 4307: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 4308: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4309: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 4310: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4311: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 4312: texengine => 'Default method to display mathematics',
1.257 raeburn 4313: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 4314: canclone => "People who may clone a course (besides course's owner and coordinators)",
4315: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 4316: );
1.198 raeburn 4317: my %staticdefaults = (
1.314 raeburn 4318: texengine => 'MathJax',
1.198 raeburn 4319: anonsurvey_threshold => 10,
4320: uploadquota => 500,
1.257 raeburn 4321: postsubmit => 60,
1.276 raeburn 4322: mysqltables => 172800,
1.198 raeburn 4323: );
1.139 raeburn 4324: if ($position eq 'top') {
1.257 raeburn 4325: %defaultchecked = (
4326: 'canuse_pdfforms' => 'off',
4327: 'uselcmath' => 'on',
4328: 'usejsme' => 'on',
1.289 raeburn 4329: 'canclone' => 'none',
1.257 raeburn 4330: );
4331: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.314 raeburn 4332: my $deftex = $staticdefaults{'texengine'};
4333: if (ref($settings) eq 'HASH') {
4334: if ($settings->{'texengine'}) {
4335: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
4336: $deftex = $settings->{'texengine'};
4337: }
4338: }
4339: }
4340: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4341: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
4342: '<span class="LC_nobreak">'.$choices{'texengine'}.
4343: '</span></td><td class="LC_right_item">'.
4344: '<select name="texengine">'."\n";
4345: my %texoptions = (
4346: MathJax => 'MathJax',
4347: mimetex => &mt('Convert to Images'),
4348: tth => &mt('TeX to HTML'),
4349: );
4350: foreach my $renderer ('MathJax','mimetex','tth') {
4351: my $selected = '';
4352: if ($renderer eq $deftex) {
4353: $selected = ' selected="selected"';
4354: }
4355: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
4356: }
4357: $mathdisp .= '</select></td></tr>'."\n";
4358: $itemcount ++;
1.139 raeburn 4359: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 4360: \%choices,$itemcount);
1.314 raeburn 4361: $datatable = $mathdisp.$datatable;
1.264 raeburn 4362: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4363: $datatable .=
1.306 raeburn 4364: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 4365: '<span class="LC_nobreak">'.$choices{'canclone'}.
4366: '</span></td><td class="LC_left_item">';
4367: my $currcanclone = 'none';
4368: my $onclick;
4369: my @cloneoptions = ('none','domain');
4370: my %clonetitles = (
4371: none => 'No additional course requesters',
4372: domain => "Any course requester in course's domain",
4373: instcode => 'Course requests for official courses ...',
4374: );
4375: my (%codedefaults,@code_order,@posscodes);
4376: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4377: \@code_order) eq 'ok') {
4378: if (@code_order > 0) {
4379: push(@cloneoptions,'instcode');
4380: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4381: }
4382: }
4383: if (ref($settings) eq 'HASH') {
4384: if ($settings->{'canclone'}) {
4385: if (ref($settings->{'canclone'}) eq 'HASH') {
4386: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4387: if (@code_order > 0) {
4388: $currcanclone = 'instcode';
4389: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4390: }
4391: }
4392: } elsif ($settings->{'canclone'} eq 'domain') {
4393: $currcanclone = $settings->{'canclone'};
4394: }
4395: }
1.289 raeburn 4396: }
1.264 raeburn 4397: foreach my $option (@cloneoptions) {
4398: my ($checked,$additional);
4399: if ($currcanclone eq $option) {
4400: $checked = ' checked="checked"';
4401: }
4402: if ($option eq 'instcode') {
4403: if (@code_order) {
4404: my $show = 'none';
4405: if ($checked) {
4406: $show = 'block';
4407: }
1.317 raeburn 4408: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 4409: &mt('Institutional codes for new and cloned course have identical:').
4410: '<br />';
4411: foreach my $item (@code_order) {
4412: my $codechk;
4413: if ($checked) {
4414: if (grep(/^\Q$item\E$/,@posscodes)) {
4415: $codechk = ' checked="checked"';
4416: }
4417: }
4418: $additional .= '<label>'.
4419: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4420: $item.'</label>';
4421: }
4422: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4423: }
4424: }
4425: $datatable .=
4426: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4427: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4428: '</label> '.$additional.'</span><br />';
4429: }
4430: $datatable .= '</td>'.
4431: '</tr>';
4432: $itemcount ++;
1.139 raeburn 4433: } else {
4434: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 4435: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 4436: my $currusecredits = 0;
1.257 raeburn 4437: my $postsubmitclient = 1;
1.271 raeburn 4438: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 4439: if (ref($settings) eq 'HASH') {
4440: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 4441: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4442: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4443: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4444: }
4445: }
1.192 raeburn 4446: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 4447: foreach my $type (@types) {
4448: next if ($type eq 'community');
4449: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4450: if ($defcredits{$type} ne '') {
4451: $currusecredits = 1;
4452: }
4453: }
4454: }
4455: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4456: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4457: $postsubmitclient = 0;
4458: foreach my $type (@types) {
4459: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4460: }
4461: } else {
4462: foreach my $type (@types) {
4463: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4464: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 4465: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 4466: } else {
4467: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4468: }
4469: } else {
4470: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4471: }
4472: }
4473: }
4474: } else {
4475: foreach my $type (@types) {
4476: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 4477: }
4478: }
1.276 raeburn 4479: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4480: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4481: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4482: }
4483: } else {
4484: foreach my $type (@types) {
4485: $currmysql{$type} = $staticdefaults{'mysqltables'};
4486: }
4487: }
1.258 raeburn 4488: } else {
4489: foreach my $type (@types) {
4490: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4491: }
1.139 raeburn 4492: }
4493: if (!$currdefresponder) {
1.198 raeburn 4494: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4495: } elsif ($currdefresponder < 1) {
4496: $currdefresponder = 1;
4497: }
1.198 raeburn 4498: foreach my $type (@types) {
4499: if ($curruploadquota{$type} eq '') {
4500: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4501: }
4502: }
1.139 raeburn 4503: $datatable .=
1.192 raeburn 4504: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4505: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4506: '</span></td>'.
4507: '<td class="LC_right_item"><span class="LC_nobreak">'.
4508: '<input type="text" name="anonsurvey_threshold"'.
4509: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 4510: '</td></tr>'."\n";
4511: $itemcount ++;
4512: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4513: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4514: $choices{'uploadquota'}.
4515: '</span></td>'.
1.306 raeburn 4516: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 4517: '<table><tr>';
1.198 raeburn 4518: foreach my $type (@types) {
1.306 raeburn 4519: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 4520: '<input type="text" name="uploadquota_'.$type.'"'.
4521: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4522: }
4523: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 4524: $itemcount ++;
1.236 raeburn 4525: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 4526: my $display = 'none';
1.192 raeburn 4527: if ($currusecredits) {
4528: $display = 'block';
4529: }
4530: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 4531: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4532: foreach my $type (@types) {
4533: next if ($type eq 'community');
1.306 raeburn 4534: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 4535: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 4536: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 4537: }
4538: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 4539: %defaultchecked = ('coursecredits' => 'off');
4540: @toggles = ('coursecredits');
4541: my $current = {
4542: 'coursecredits' => $currusecredits,
4543: };
4544: (my $table,$itemcount) =
4545: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 4546: \%choices,$itemcount,$onclick,$additional,'left');
4547: $datatable .= $table;
4548: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4549: my $display = 'none';
4550: if ($postsubmitclient) {
4551: $display = 'block';
4552: }
4553: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 4554: &mt('Number of seconds submit is disabled').'<br />'.
4555: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4556: '<table><tr>';
1.257 raeburn 4557: foreach my $type (@types) {
1.306 raeburn 4558: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 4559: '<input type="text" name="'.$type.'_timeout" value="'.
4560: $deftimeout{$type}.'" size="5" /></td>';
4561: }
4562: $additional .= '</tr></table></div>'."\n";
4563: %defaultchecked = ('postsubmit' => 'on');
4564: @toggles = ('postsubmit');
1.280 raeburn 4565: $current = {
4566: 'postsubmit' => $postsubmitclient,
4567: };
1.257 raeburn 4568: ($table,$itemcount) =
4569: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4570: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 4571: $datatable .= $table;
1.276 raeburn 4572: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4573: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4574: $choices{'mysqltables'}.
4575: '</span></td>'.
1.306 raeburn 4576: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 4577: '<table><tr>';
4578: foreach my $type (@types) {
1.306 raeburn 4579: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 4580: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 4581: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 4582: }
4583: $datatable .= '</tr></table></td></tr>'."\n";
4584: $itemcount ++;
4585:
1.139 raeburn 4586: }
1.192 raeburn 4587: $$rowtotal += $itemcount;
1.121 raeburn 4588: return $datatable;
1.118 jms 4589: }
4590:
1.231 raeburn 4591: sub print_selfenrollment {
4592: my ($position,$dom,$settings,$rowtotal) = @_;
4593: my ($css_class,$datatable);
4594: my $itemcount = 1;
1.271 raeburn 4595: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 4596: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 4597: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4598: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 4599: my @rows;
4600: my $key;
4601: if ($position eq 'top') {
4602: $key = 'admin';
4603: if (ref($rowsref) eq 'ARRAY') {
4604: @rows = @{$rowsref};
4605: }
4606: } elsif ($position eq 'middle') {
4607: $key = 'default';
4608: @rows = ('types','registered','approval','limit');
4609: }
4610: foreach my $row (@rows) {
4611: if (defined($titlesref->{$row})) {
4612: $itemcount ++;
4613: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4614: $datatable .= '<tr'.$css_class.'>'.
4615: '<td>'.$titlesref->{$row}.'</td>'.
4616: '<td class="LC_left_item">'.
4617: '<table><tr>';
4618: my (%current,%currentcap);
4619: if (ref($settings) eq 'HASH') {
4620: if (ref($settings->{$key}) eq 'HASH') {
4621: foreach my $type (@types) {
4622: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4623: $current{$type} = $settings->{$key}->{$type}->{$row};
4624: }
4625: if (($row eq 'limit') && ($key eq 'default')) {
4626: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4627: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4628: }
4629: }
4630: }
4631: }
4632: }
4633: my %roles = (
4634: '0' => &Apache::lonnet::plaintext('dc'),
4635: );
4636:
4637: foreach my $type (@types) {
4638: unless (($row eq 'registered') && ($key eq 'default')) {
4639: $datatable .= '<th>'.&mt($type).'</th>';
4640: }
4641: }
4642: unless (($row eq 'registered') && ($key eq 'default')) {
4643: $datatable .= '</tr><tr>';
4644: }
4645: foreach my $type (@types) {
4646: if ($type eq 'community') {
4647: $roles{'1'} = &mt('Community personnel');
4648: } else {
4649: $roles{'1'} = &mt('Course personnel');
4650: }
4651: $datatable .= '<td style="vertical-align: top">';
4652: if ($position eq 'top') {
4653: my %checked;
4654: if ($current{$type} eq '0') {
4655: $checked{'0'} = ' checked="checked"';
4656: } else {
4657: $checked{'1'} = ' checked="checked"';
4658: }
4659: foreach my $role ('1','0') {
4660: $datatable .= '<span class="LC_nobreak"><label>'.
4661: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4662: 'value="'.$role.'"'.$checked{$role}.' />'.
4663: $roles{$role}.'</label></span> ';
4664: }
4665: } else {
4666: if ($row eq 'types') {
4667: my %checked;
4668: if ($current{$type} =~ /^(all|dom)$/) {
4669: $checked{$1} = ' checked="checked"';
4670: } else {
4671: $checked{''} = ' checked="checked"';
4672: }
4673: foreach my $val ('','dom','all') {
4674: $datatable .= '<span class="LC_nobreak"><label>'.
4675: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4676: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4677: }
4678: } elsif ($row eq 'registered') {
4679: my %checked;
4680: if ($current{$type} eq '1') {
4681: $checked{'1'} = ' checked="checked"';
4682: } else {
4683: $checked{'0'} = ' checked="checked"';
4684: }
4685: foreach my $val ('0','1') {
4686: $datatable .= '<span class="LC_nobreak"><label>'.
4687: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4688: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4689: }
4690: } elsif ($row eq 'approval') {
4691: my %checked;
4692: if ($current{$type} =~ /^([12])$/) {
4693: $checked{$1} = ' checked="checked"';
4694: } else {
4695: $checked{'0'} = ' checked="checked"';
4696: }
4697: for my $val (0..2) {
4698: $datatable .= '<span class="LC_nobreak"><label>'.
4699: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4700: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4701: }
4702: } elsif ($row eq 'limit') {
4703: my %checked;
4704: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4705: $checked{$1} = ' checked="checked"';
4706: } else {
4707: $checked{'none'} = ' checked="checked"';
4708: }
4709: my $cap;
4710: if ($currentcap{$type} =~ /^\d+$/) {
4711: $cap = $currentcap{$type};
4712: }
4713: foreach my $val ('none','allstudents','selfenrolled') {
4714: $datatable .= '<span class="LC_nobreak"><label>'.
4715: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4716: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4717: }
4718: $datatable .= '<br />'.
4719: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4720: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4721: '</span>';
4722: }
4723: }
4724: $datatable .= '</td>';
4725: }
4726: $datatable .= '</tr>';
4727: }
4728: $datatable .= '</table></td></tr>';
4729: }
4730: } elsif ($position eq 'bottom') {
1.235 raeburn 4731: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4732: }
4733: $$rowtotal += $itemcount;
4734: return $datatable;
4735: }
4736:
4737: sub print_validation_rows {
4738: my ($caller,$dom,$settings,$rowtotal) = @_;
4739: my ($itemsref,$namesref,$fieldsref);
4740: if ($caller eq 'selfenroll') {
4741: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4742: } elsif ($caller eq 'requestcourses') {
4743: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4744: }
4745: my %currvalidation;
4746: if (ref($settings) eq 'HASH') {
4747: if (ref($settings->{'validation'}) eq 'HASH') {
4748: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 4749: }
1.235 raeburn 4750: }
4751: my $datatable;
4752: my $itemcount = 0;
4753: foreach my $item (@{$itemsref}) {
4754: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4755: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4756: $namesref->{$item}.
4757: '</span></td>'.
4758: '<td class="LC_left_item">';
4759: if (($item eq 'url') || ($item eq 'button')) {
4760: $datatable .= '<span class="LC_nobreak">'.
4761: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4762: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4763: } elsif ($item eq 'fields') {
4764: my @currfields;
4765: if (ref($currvalidation{$item}) eq 'ARRAY') {
4766: @currfields = @{$currvalidation{$item}};
4767: }
4768: foreach my $field (@{$fieldsref}) {
4769: my $check = '';
4770: if (grep(/^\Q$field\E$/,@currfields)) {
4771: $check = ' checked="checked"';
4772: }
4773: $datatable .= '<span class="LC_nobreak"><label>'.
4774: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4775: ' value="'.$field.'"'.$check.' />'.$field.
4776: '</label></span> ';
4777: }
4778: } elsif ($item eq 'markup') {
4779: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
4780: $currvalidation{$item}.
1.231 raeburn 4781: '</textarea>';
1.235 raeburn 4782: }
4783: $datatable .= '</td></tr>'."\n";
4784: if (ref($rowtotal)) {
1.231 raeburn 4785: $itemcount ++;
4786: }
4787: }
1.235 raeburn 4788: if ($caller eq 'requestcourses') {
4789: my %currhash;
1.248 raeburn 4790: if (ref($settings) eq 'HASH') {
4791: if (ref($settings->{'validation'}) eq 'HASH') {
4792: if ($settings->{'validation'}{'dc'} ne '') {
4793: $currhash{$settings->{'validation'}{'dc'}} = 1;
4794: }
1.235 raeburn 4795: }
4796: }
4797: my $numinrow = 2;
4798: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4799: 'validationdc',%currhash);
1.247 raeburn 4800: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4801: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 4802: if ($numdc > 1) {
1.247 raeburn 4803: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 4804: } else {
1.247 raeburn 4805: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 4806: }
1.247 raeburn 4807: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 4808: $itemcount ++;
4809: }
4810: if (ref($rowtotal)) {
4811: $$rowtotal += $itemcount;
4812: }
1.231 raeburn 4813: return $datatable;
4814: }
4815:
1.137 raeburn 4816: sub print_usersessions {
4817: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 4818: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 4819: my (%by_ip,%by_location,@intdoms,@instdoms);
4820: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 4821:
4822: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4823: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4824: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4825: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4826: if ($position eq 'top') {
1.152 raeburn 4827: if (keys(%serverhomes) > 1) {
1.145 raeburn 4828: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 4829: my $curroffloadnow;
4830: if (ref($settings) eq 'HASH') {
4831: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4832: $curroffloadnow = $settings->{'offloadnow'};
4833: }
4834: }
4835: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4836: } else {
1.140 raeburn 4837: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 4838: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
4839: '</td></tr>';
1.140 raeburn 4840: }
1.137 raeburn 4841: } else {
1.279 raeburn 4842: my %titles = &usersession_titles();
4843: my ($prefix,@types);
4844: if ($position eq 'bottom') {
4845: $prefix = 'remote';
4846: @types = ('version','excludedomain','includedomain');
1.145 raeburn 4847: } else {
1.279 raeburn 4848: $prefix = 'hosted';
4849: @types = ('excludedomain','includedomain');
4850: }
4851: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4852: }
4853: $$rowtotal += $itemcount;
4854: return $datatable;
4855: }
4856:
4857: sub rules_by_location {
4858: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
4859: my ($datatable,$itemcount,$css_class);
4860: if (keys(%{$by_location}) == 0) {
4861: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4862: $datatable = '<tr'.$css_class.'><td colspan="2">'.
4863: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
4864: '</td></tr>';
4865: $itemcount = 1;
4866: } else {
4867: $itemcount = 0;
4868: my $numinrow = 5;
4869: my (%current,%checkedon,%checkedoff);
4870: my @locations = sort(keys(%{$by_location}));
4871: foreach my $type (@{$types}) {
4872: $checkedon{$type} = '';
4873: $checkedoff{$type} = ' checked="checked"';
4874: }
4875: if (ref($settings) eq 'HASH') {
4876: if (ref($settings->{$prefix}) eq 'HASH') {
4877: foreach my $key (keys(%{$settings->{$prefix}})) {
4878: $current{$key} = $settings->{$prefix}{$key};
4879: if ($key eq 'version') {
4880: if ($current{$key} ne '') {
1.145 raeburn 4881: $checkedon{$key} = ' checked="checked"';
4882: $checkedoff{$key} = '';
4883: }
1.279 raeburn 4884: } elsif (ref($current{$key}) eq 'ARRAY') {
4885: $checkedon{$key} = ' checked="checked"';
4886: $checkedoff{$key} = '';
1.137 raeburn 4887: }
4888: }
4889: }
1.279 raeburn 4890: }
4891: foreach my $type (@{$types}) {
4892: next if ($type ne 'version' && !@locations);
4893: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4894: $datatable .= '<tr'.$css_class.'>
4895: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
4896: <span class="LC_nobreak">
4897: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4898: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4899: if ($type eq 'version') {
4900: my @lcversions = &Apache::lonnet::all_loncaparevs();
4901: my $selector = '<select name="'.$prefix.'_version">';
4902: foreach my $version (@lcversions) {
4903: my $selected = '';
4904: if ($current{'version'} eq $version) {
4905: $selected = ' selected="selected"';
1.145 raeburn 4906: }
1.279 raeburn 4907: $selector .= ' <option value="'.$version.'"'.
4908: $selected.'>'.$version.'</option>';
4909: }
4910: $selector .= '</select> ';
4911: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4912: } else {
4913: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4914: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4915: ' />'.(' 'x2).
4916: '<input type="button" value="'.&mt('uncheck all').'" '.
4917: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4918: "\n".
4919: '</div><div><table>';
4920: my $rem;
4921: for (my $i=0; $i<@locations; $i++) {
4922: my ($showloc,$value,$checkedtype);
4923: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
4924: my $ip = $by_location->{$locations[$i]}->[0];
4925: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4926: $value = join(':',@{$by_ip->{$ip}});
4927: $showloc = join(', ',@{$by_ip->{$ip}});
4928: if (ref($current{$type}) eq 'ARRAY') {
4929: foreach my $loc (@{$by_ip->{$ip}}) {
4930: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4931: $checkedtype = ' checked="checked"';
4932: last;
1.145 raeburn 4933: }
1.138 raeburn 4934: }
4935: }
4936: }
1.137 raeburn 4937: }
1.279 raeburn 4938: $rem = $i%($numinrow);
4939: if ($rem == 0) {
4940: if ($i > 0) {
4941: $datatable .= '</tr>';
4942: }
4943: $datatable .= '<tr>';
4944: }
4945: $datatable .= '<td class="LC_left_item">'.
4946: '<span class="LC_nobreak"><label>'.
4947: '<input type="checkbox" name="'.$prefix.'_'.$type.
4948: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4949: '</label></span></td>';
4950: }
4951: $rem = @locations%($numinrow);
4952: my $colsleft = $numinrow - $rem;
4953: if ($colsleft > 1 ) {
4954: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4955: ' </td>';
4956: } elsif ($colsleft == 1) {
4957: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4958: }
1.279 raeburn 4959: $datatable .= '</tr></table>';
1.137 raeburn 4960: }
1.279 raeburn 4961: $datatable .= '</td></tr>';
4962: $itemcount ++;
1.137 raeburn 4963: }
4964: }
1.279 raeburn 4965: return ($datatable,$itemcount);
1.137 raeburn 4966: }
4967:
1.275 raeburn 4968: sub print_ssl {
4969: my ($position,$dom,$settings,$rowtotal) = @_;
4970: my ($css_class,$datatable);
4971: my $itemcount = 1;
4972: if ($position eq 'top') {
1.281 raeburn 4973: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4974: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4975: my $same_institution;
4976: if ($intdom ne '') {
4977: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
4978: if (ref($internet_names) eq 'ARRAY') {
4979: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4980: $same_institution = 1;
4981: }
4982: }
4983: }
1.275 raeburn 4984: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 4985: $datatable = '<tr'.$css_class.'><td colspan="2">';
4986: if ($same_institution) {
4987: my %domservers = &Apache::lonnet::get_servers($dom);
4988: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
4989: } else {
4990: $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.");
4991: }
4992: $datatable .= '</td></tr>';
1.275 raeburn 4993: $itemcount ++;
4994: } else {
4995: my %titles = &ssl_titles();
4996: my (%by_ip,%by_location,@intdoms,@instdoms);
4997: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4998: my @alldoms = &Apache::lonnet::all_domains();
4999: my %serverhomes = %Apache::lonnet::serverhomeIDs;
5000: my @domservers = &Apache::lonnet::get_servers($dom);
5001: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5002: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 5003: if (($position eq 'connto') || ($position eq 'connfrom')) {
5004: my $legacy;
5005: unless (ref($settings) eq 'HASH') {
5006: my $name;
5007: if ($position eq 'connto') {
5008: $name = 'loncAllowInsecure';
5009: } else {
5010: $name = 'londAllowInsecure';
5011: }
5012: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
5013: my @ids=&Apache::lonnet::current_machine_ids();
5014: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
5015: my %what = (
5016: $name => 1,
5017: );
5018: my ($result,$returnhash) =
5019: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
5020: if ($result eq 'ok') {
5021: if (ref($returnhash) eq 'HASH') {
5022: $legacy = $returnhash->{$name};
5023: }
5024: }
5025: } else {
5026: $legacy = $Apache::lonnet::perlvar{$name};
5027: }
5028: }
1.275 raeburn 5029: foreach my $type ('dom','intdom','other') {
5030: my %checked;
5031: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5032: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
5033: '<td class="LC_right_item">';
5034: my $skip;
5035: if ($type eq 'dom') {
5036: unless (keys(%servers) > 1) {
5037: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
5038: $skip = 1;
5039: }
5040: }
5041: if ($type eq 'intdom') {
5042: unless (@instdoms > 1) {
5043: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
5044: $skip = 1;
5045: }
5046: } elsif ($type eq 'other') {
5047: if (keys(%by_location) == 0) {
5048: $datatable .= &mt('Nothing to set here, as there are no other institutions');
5049: $skip = 1;
5050: }
5051: }
5052: unless ($skip) {
5053: $checked{'yes'} = ' checked="checked"';
5054: if (ref($settings) eq 'HASH') {
1.293 raeburn 5055: if (ref($settings->{$position}) eq 'HASH') {
5056: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 5057: $checked{$1} = $checked{'yes'};
5058: delete($checked{'yes'});
5059: }
5060: }
1.293 raeburn 5061: } else {
5062: if ($legacy == 0) {
5063: $checked{'req'} = $checked{'yes'};
5064: delete($checked{'yes'});
5065: }
1.275 raeburn 5066: }
5067: foreach my $option ('no','yes','req') {
5068: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 5069: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 5070: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
5071: '</label></span>'.(' 'x2);
5072: }
5073: }
5074: $datatable .= '</td></tr>';
5075: $itemcount ++;
5076: }
5077: } else {
5078: my $prefix = 'replication';
5079: my @types = ('certreq','nocertreq');
1.279 raeburn 5080: if (keys(%by_location) == 0) {
5081: $datatable .= '<tr'.$css_class.'><td>'.
5082: &mt('Nothing to set here, as there are no other institutions').
5083: '</td></tr>';
5084: $itemcount ++;
1.275 raeburn 5085: } else {
1.279 raeburn 5086: ($datatable,$itemcount) =
5087: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 5088: }
5089: }
5090: }
5091: $$rowtotal += $itemcount;
5092: return $datatable;
5093: }
5094:
5095: sub ssl_titles {
5096: return &Apache::lonlocal::texthash (
5097: dom => 'LON-CAPA servers/VMs from same domain',
5098: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
5099: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 5100: connto => 'Connections to other servers',
5101: connfrom => 'Connections from other servers',
1.275 raeburn 5102: replication => 'Replicating content to other institutions',
5103: certreq => 'Client certificate required, but specific domains exempt',
5104: nocertreq => 'No client certificate required, except for specific domains',
5105: no => 'SSL not used',
5106: yes => 'SSL Optional (used if available)',
5107: req => 'SSL Required',
5108: );
1.279 raeburn 5109: }
5110:
5111: sub print_trust {
5112: my ($prefix,$dom,$settings,$rowtotal) = @_;
5113: my ($css_class,$datatable,%checked,%choices);
5114: my (%by_ip,%by_location,@intdoms,@instdoms);
5115: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5116: my $itemcount = 1;
5117: my %titles = &trust_titles();
5118: my @types = ('exc','inc');
5119: if ($prefix eq 'top') {
5120: $prefix = 'content';
5121: } elsif ($prefix eq 'bottom') {
5122: $prefix = 'msg';
5123: }
5124: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5125: $$rowtotal += $itemcount;
5126: return $datatable;
5127: }
5128:
5129: sub trust_titles {
5130: return &Apache::lonlocal::texthash(
5131: content => "Access to this domain's content by others",
5132: shared => "Access to other domain's content by this domain",
5133: enroll => "Enrollment in this domain's courses by others",
5134: othcoau => "Co-author roles in this domain for others",
5135: coaurem => "Co-author roles for this domain's users elsewhere",
5136: domroles => "Domain roles in this domain assignable to others",
5137: catalog => "Course Catalog for this domain displayed elsewhere",
5138: reqcrs => "Requests for creation of courses in this domain by others",
5139: msg => "Users in other domains can send messages to this domain",
5140: exc => "Allow all, but exclude specific domains",
5141: inc => "Deny all, but include specific domains",
5142: );
1.275 raeburn 5143: }
5144:
1.138 raeburn 5145: sub build_location_hashes {
1.275 raeburn 5146: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 5147: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 5148: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 5149: my %iphost = &Apache::lonnet::get_iphost();
5150: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5151: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5152: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5153: foreach my $id (@{$iphost{$primary_ip}}) {
5154: my $intdom = &Apache::lonnet::internet_dom($id);
5155: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5156: push(@{$intdoms},$intdom);
5157: }
5158: }
5159: }
5160: foreach my $ip (keys(%iphost)) {
5161: if (ref($iphost{$ip}) eq 'ARRAY') {
5162: foreach my $id (@{$iphost{$ip}}) {
5163: my $location = &Apache::lonnet::internet_dom($id);
5164: if ($location) {
1.275 raeburn 5165: if (grep(/^\Q$location\E$/,@{$intdoms})) {
5166: my $dom = &Apache::lonnet::host_domain($id);
5167: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
5168: push(@{$instdoms},$dom);
5169: }
5170: next;
5171: }
1.138 raeburn 5172: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5173: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5174: push(@{$by_ip->{$ip}},$location);
5175: }
5176: } else {
5177: $by_ip->{$ip} = [$location];
5178: }
5179: }
5180: }
5181: }
5182: }
5183: foreach my $ip (sort(keys(%{$by_ip}))) {
5184: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5185: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5186: my $first = $by_ip->{$ip}->[0];
5187: if (ref($by_location->{$first}) eq 'ARRAY') {
5188: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5189: push(@{$by_location->{$first}},$ip);
5190: }
5191: } else {
5192: $by_location->{$first} = [$ip];
5193: }
5194: }
5195: }
5196: return;
5197: }
5198:
1.145 raeburn 5199: sub current_offloads_to {
5200: my ($dom,$settings,$servers) = @_;
5201: my (%spareid,%otherdomconfigs);
1.152 raeburn 5202: if (ref($servers) eq 'HASH') {
1.145 raeburn 5203: foreach my $lonhost (sort(keys(%{$servers}))) {
5204: my $gotspares;
1.152 raeburn 5205: if (ref($settings) eq 'HASH') {
5206: if (ref($settings->{'spares'}) eq 'HASH') {
5207: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5208: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5209: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5210: $gotspares = 1;
5211: }
1.145 raeburn 5212: }
5213: }
5214: unless ($gotspares) {
5215: my $gotspares;
5216: my $serverhomeID =
5217: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
5218: my $serverhomedom =
5219: &Apache::lonnet::host_domain($serverhomeID);
5220: if ($serverhomedom ne $dom) {
5221: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
5222: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5223: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5224: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5225: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5226: $gotspares = 1;
5227: }
5228: }
5229: } else {
5230: $otherdomconfigs{$serverhomedom} =
5231: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
5232: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
5233: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5234: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5235: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
5236: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5237: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5238: $gotspares = 1;
5239: }
5240: }
5241: }
5242: }
5243: }
5244: }
5245: }
5246: unless ($gotspares) {
5247: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
5248: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5249: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5250: } else {
5251: my $server_hostname = &Apache::lonnet::hostname($lonhost);
5252: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
5253: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
5254: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5255: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5256: } else {
1.150 raeburn 5257: my %what = (
5258: spareid => 1,
5259: );
5260: my ($result,$returnhash) =
5261: &Apache::lonnet::get_remote_globals($lonhost,\%what);
5262: if ($result eq 'ok') {
5263: if (ref($returnhash) eq 'HASH') {
5264: if (ref($returnhash->{'spareid'}) eq 'HASH') {
5265: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
5266: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
5267: }
5268: }
1.145 raeburn 5269: }
5270: }
5271: }
5272: }
5273: }
5274: }
5275: return %spareid;
5276: }
5277:
5278: sub spares_row {
1.261 raeburn 5279: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 5280: my $css_class;
5281: my $numinrow = 4;
5282: my $itemcount = 1;
5283: my $datatable;
1.152 raeburn 5284: my %typetitles = &sparestype_titles();
5285: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 5286: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 5287: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5288: my ($othercontrol,$serverdom);
5289: if ($serverhome ne $server) {
5290: $serverdom = &Apache::lonnet::host_domain($serverhome);
5291: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5292: } else {
5293: $serverdom = &Apache::lonnet::host_domain($server);
5294: if ($serverdom ne $dom) {
5295: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5296: }
5297: }
5298: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 5299: my $checkednow;
5300: if (ref($curroffloadnow) eq 'HASH') {
5301: if ($curroffloadnow->{$server}) {
5302: $checkednow = ' checked="checked"';
5303: }
5304: }
1.145 raeburn 5305: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5306: $datatable .= '<tr'.$css_class.'>
5307: <td rowspan="2">
1.183 bisitz 5308: <span class="LC_nobreak">'.
5309: &mt('[_1] when busy, offloads to:'
1.261 raeburn 5310: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 5311: '<span class="LC_nobreak">'."\n".
1.261 raeburn 5312: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
5313: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 5314: "\n";
1.145 raeburn 5315: my (%current,%canselect);
1.152 raeburn 5316: my @choices =
5317: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5318: foreach my $type ('primary','default') {
5319: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 5320: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5321: my @spares = @{$spareid->{$server}{$type}};
5322: if (@spares > 0) {
1.152 raeburn 5323: if ($othercontrol) {
5324: $current{$type} = join(', ',@spares);
5325: } else {
5326: $current{$type} .= '<table>';
5327: my $numspares = scalar(@spares);
5328: for (my $i=0; $i<@spares; $i++) {
5329: my $rem = $i%($numinrow);
5330: if ($rem == 0) {
5331: if ($i > 0) {
5332: $current{$type} .= '</tr>';
5333: }
5334: $current{$type} .= '<tr>';
1.145 raeburn 5335: }
1.152 raeburn 5336: $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'".');" /> '.
5337: $spareid->{$server}{$type}[$i].
5338: '</label></td>'."\n";
5339: }
5340: my $rem = @spares%($numinrow);
5341: my $colsleft = $numinrow - $rem;
5342: if ($colsleft > 1 ) {
5343: $current{$type} .= '<td colspan="'.$colsleft.
5344: '" class="LC_left_item">'.
5345: ' </td>';
5346: } elsif ($colsleft == 1) {
5347: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 5348: }
1.152 raeburn 5349: $current{$type} .= '</tr></table>';
1.150 raeburn 5350: }
1.145 raeburn 5351: }
5352: }
5353: if ($current{$type} eq '') {
5354: $current{$type} = &mt('None specified');
5355: }
1.152 raeburn 5356: if ($othercontrol) {
5357: if ($type eq 'primary') {
5358: $canselect{$type} = $othercontrol;
5359: }
5360: } else {
5361: $canselect{$type} =
5362: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
5363: '<select name="newspare_'.$type.'_'.$server.'" '.
5364: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
5365: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
5366: if (@choices > 0) {
5367: foreach my $lonhost (@choices) {
5368: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
5369: }
5370: }
5371: $canselect{$type} .= '</select>'."\n";
5372: }
5373: } else {
5374: $current{$type} = &mt('Could not be determined');
5375: if ($type eq 'primary') {
5376: $canselect{$type} = $othercontrol;
5377: }
1.145 raeburn 5378: }
1.152 raeburn 5379: if ($type eq 'default') {
5380: $datatable .= '<tr'.$css_class.'>';
5381: }
5382: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5383: '<td>'.$current{$type}.'</td>'."\n".
5384: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 5385: }
5386: $itemcount ++;
5387: }
5388: }
5389: $$rowtotal += $itemcount;
5390: return $datatable;
5391: }
5392:
1.152 raeburn 5393: sub possible_newspares {
5394: my ($server,$currspares,$serverhomes,$altids) = @_;
5395: my $serverhostname = &Apache::lonnet::hostname($server);
5396: my %excluded;
5397: if ($serverhostname ne '') {
5398: %excluded = (
5399: $serverhostname => 1,
5400: );
5401: }
5402: if (ref($currspares) eq 'HASH') {
5403: foreach my $type (keys(%{$currspares})) {
5404: if (ref($currspares->{$type}) eq 'ARRAY') {
5405: if (@{$currspares->{$type}} > 0) {
5406: foreach my $curr (@{$currspares->{$type}}) {
5407: my $hostname = &Apache::lonnet::hostname($curr);
5408: $excluded{$hostname} = 1;
5409: }
5410: }
5411: }
5412: }
5413: }
5414: my @choices;
5415: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5416: if (keys(%{$serverhomes}) > 1) {
5417: foreach my $name (sort(keys(%{$serverhomes}))) {
5418: unless ($excluded{$name}) {
5419: if (exists($altids->{$serverhomes->{$name}})) {
5420: push(@choices,$altids->{$serverhomes->{$name}});
5421: } else {
5422: push(@choices,$serverhomes->{$name});
1.145 raeburn 5423: }
5424: }
5425: }
5426: }
5427: }
1.152 raeburn 5428: return sort(@choices);
1.145 raeburn 5429: }
5430:
1.150 raeburn 5431: sub print_loadbalancing {
5432: my ($dom,$settings,$rowtotal) = @_;
5433: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5434: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5435: my $numinrow = 1;
5436: my $datatable;
5437: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 5438: my (%currbalancer,%currtargets,%currrules,%existing);
5439: if (ref($settings) eq 'HASH') {
5440: %existing = %{$settings};
5441: }
5442: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5443: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
5444: \%currtargets,\%currrules);
1.150 raeburn 5445: } else {
5446: return;
5447: }
5448: my ($othertitle,$usertypes,$types) =
5449: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 5450: my $rownum = 8;
1.150 raeburn 5451: if (ref($types) eq 'ARRAY') {
5452: $rownum += scalar(@{$types});
5453: }
1.171 raeburn 5454: my @css_class = ('LC_odd_row','LC_even_row');
5455: my $balnum = 0;
5456: my $islast;
5457: my (@toshow,$disabledtext);
5458: if (keys(%currbalancer) > 0) {
5459: @toshow = sort(keys(%currbalancer));
5460: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5461: push(@toshow,'');
5462: }
5463: } else {
5464: @toshow = ('');
5465: $disabledtext = &mt('No existing load balancer');
5466: }
5467: foreach my $lonhost (@toshow) {
5468: if ($balnum == scalar(@toshow)-1) {
5469: $islast = 1;
5470: } else {
5471: $islast = 0;
5472: }
5473: my $cssidx = $balnum%2;
5474: my $targets_div_style = 'display: none';
5475: my $disabled_div_style = 'display: block';
5476: my $homedom_div_style = 'display: none';
5477: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 5478: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 5479: '<p>';
5480: if ($lonhost eq '') {
1.210 raeburn 5481: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 5482: if (keys(%currbalancer) > 0) {
5483: $datatable .= &mt('Add balancer:');
5484: } else {
5485: $datatable .= &mt('Enable balancer:');
5486: }
5487: $datatable .= ' '.
5488: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5489: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5490: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5491: '<option value="" selected="selected">'.&mt('None').
5492: '</option>'."\n";
5493: foreach my $server (sort(keys(%servers))) {
5494: next if ($currbalancer{$server});
5495: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5496: }
1.210 raeburn 5497: $datatable .=
1.171 raeburn 5498: '</select>'."\n".
5499: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5500: } else {
5501: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5502: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5503: &mt('Stop balancing').'</label>'.
5504: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5505: $targets_div_style = 'display: block';
5506: $disabled_div_style = 'display: none';
5507: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5508: $homedom_div_style = 'display: block';
5509: }
5510: }
1.306 raeburn 5511: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 5512: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5513: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5514: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5515: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5516: my @sparestypes = ('primary','default');
5517: my %typetitles = &sparestype_titles();
1.284 raeburn 5518: my %hostherechecked = (
5519: no => ' checked="checked"',
5520: );
1.171 raeburn 5521: foreach my $sparetype (@sparestypes) {
5522: my $targettable;
5523: for (my $i=0; $i<$numspares; $i++) {
5524: my $checked;
5525: if (ref($currtargets{$lonhost}) eq 'HASH') {
5526: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5527: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5528: $checked = ' checked="checked"';
5529: }
5530: }
5531: }
5532: my ($chkboxval,$disabled);
5533: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5534: $chkboxval = $spares[$i];
5535: }
5536: if (exists($currbalancer{$spares[$i]})) {
5537: $disabled = ' disabled="disabled"';
5538: }
1.210 raeburn 5539: $targettable .=
1.253 raeburn 5540: '<td><span class="LC_nobreak"><label>'.
5541: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 5542: $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 5543: '</span></label></span></td>';
1.171 raeburn 5544: my $rem = $i%($numinrow);
5545: if ($rem == 0) {
5546: if (($i > 0) && ($i < $numspares-1)) {
5547: $targettable .= '</tr>';
5548: }
5549: if ($i < $numspares-1) {
5550: $targettable .= '<tr>';
1.150 raeburn 5551: }
5552: }
5553: }
1.171 raeburn 5554: if ($targettable ne '') {
5555: my $rem = $numspares%($numinrow);
5556: my $colsleft = $numinrow - $rem;
5557: if ($colsleft > 1 ) {
5558: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5559: ' </td>';
5560: } elsif ($colsleft == 1) {
5561: $targettable .= '<td class="LC_left_item"> </td>';
5562: }
5563: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5564: '<table><tr>'.$targettable.'</tr></table><br />';
5565: }
1.284 raeburn 5566: $hostherechecked{$sparetype} = '';
5567: if (ref($currtargets{$lonhost}) eq 'HASH') {
5568: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5569: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5570: $hostherechecked{$sparetype} = ' checked="checked"';
5571: $hostherechecked{'no'} = '';
5572: }
5573: }
5574: }
5575: }
5576: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5577: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5578: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5579: foreach my $sparetype (@sparestypes) {
5580: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5581: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5582: '</i></label><br />';
1.171 raeburn 5583: }
5584: $datatable .= '</div></td></tr>'.
5585: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5586: $othertitle,$usertypes,$types,\%servers,
5587: \%currbalancer,$lonhost,
5588: $targets_div_style,$homedom_div_style,
5589: $css_class[$cssidx],$balnum,$islast);
5590: $$rowtotal += $rownum;
5591: $balnum ++;
5592: }
5593: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5594: return $datatable;
5595: }
5596:
5597: sub get_loadbalancers_config {
5598: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
5599: return unless ((ref($servers) eq 'HASH') &&
5600: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
5601: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
5602: if (keys(%{$existing}) > 0) {
5603: my $oldlonhost;
5604: foreach my $key (sort(keys(%{$existing}))) {
5605: if ($key eq 'lonhost') {
5606: $oldlonhost = $existing->{'lonhost'};
5607: $currbalancer->{$oldlonhost} = 1;
5608: } elsif ($key eq 'targets') {
5609: if ($oldlonhost) {
5610: $currtargets->{$oldlonhost} = $existing->{'targets'};
5611: }
5612: } elsif ($key eq 'rules') {
5613: if ($oldlonhost) {
5614: $currrules->{$oldlonhost} = $existing->{'rules'};
5615: }
5616: } elsif (ref($existing->{$key}) eq 'HASH') {
5617: $currbalancer->{$key} = 1;
5618: $currtargets->{$key} = $existing->{$key}{'targets'};
5619: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 5620: }
5621: }
1.171 raeburn 5622: } else {
5623: my ($balancerref,$targetsref) =
5624: &Apache::lonnet::get_lonbalancer_config($servers);
5625: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5626: foreach my $server (sort(keys(%{$balancerref}))) {
5627: $currbalancer->{$server} = 1;
5628: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5629: }
5630: }
5631: }
1.171 raeburn 5632: return;
1.150 raeburn 5633: }
5634:
5635: sub loadbalancing_rules {
5636: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 5637: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5638: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5639: my $output;
1.171 raeburn 5640: my $num = 0;
1.210 raeburn 5641: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5642: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5643: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5644: foreach my $type (@{$alltypes}) {
1.171 raeburn 5645: $num ++;
1.150 raeburn 5646: my $current;
5647: if (ref($currrules) eq 'HASH') {
5648: $current = $currrules->{$type};
5649: }
1.253 raeburn 5650: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 5651: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5652: $current = '';
5653: }
5654: }
5655: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 5656: $servers,$currbalancer,$lonhost,$dom,
5657: $targets_div_style,$homedom_div_style,
5658: $css_class,$balnum,$num,$islast);
1.150 raeburn 5659: }
5660: }
5661: return $output;
5662: }
5663:
5664: sub loadbalancing_titles {
5665: my ($dom,$intdom,$usertypes,$types) = @_;
5666: my %othertypes = (
5667: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5668: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5669: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5670: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 5671: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5672: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5673: );
1.209 raeburn 5674: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 5675: my @available;
1.150 raeburn 5676: if (ref($types) eq 'ARRAY') {
1.302 raeburn 5677: @available = @{$types};
1.150 raeburn 5678: }
1.302 raeburn 5679: unless (grep(/^default$/,@available)) {
5680: push(@available,'default');
5681: }
5682: unshift(@alltypes,@available);
1.150 raeburn 5683: my %titles;
5684: foreach my $type (@alltypes) {
5685: if ($type =~ /^_LC_/) {
5686: $titles{$type} = $othertypes{$type};
5687: } elsif ($type eq 'default') {
5688: $titles{$type} = &mt('All users from [_1]',$dom);
5689: if (ref($types) eq 'ARRAY') {
5690: if (@{$types} > 0) {
5691: $titles{$type} = &mt('Other users from [_1]',$dom);
5692: }
5693: }
5694: } elsif (ref($usertypes) eq 'HASH') {
5695: $titles{$type} = $usertypes->{$type};
5696: }
5697: }
5698: return (\@alltypes,\%othertypes,\%titles);
5699: }
5700:
5701: sub loadbalance_rule_row {
1.171 raeburn 5702: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5703: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 5704: my @rulenames;
1.150 raeburn 5705: my %ruletitles = &offloadtype_text();
1.209 raeburn 5706: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 5707: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 5708: } else {
1.209 raeburn 5709: @rulenames = ('default','homeserver');
5710: if ($type eq '_LC_external') {
5711: push(@rulenames,'externalbalancer');
5712: } else {
5713: push(@rulenames,'specific');
5714: }
5715: push(@rulenames,'none');
1.150 raeburn 5716: }
5717: my $style = $targets_div_style;
1.253 raeburn 5718: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 5719: $style = $homedom_div_style;
5720: }
1.171 raeburn 5721: my $space;
5722: if ($islast && $num == 1) {
1.317 raeburn 5723: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 5724: }
1.210 raeburn 5725: my $output =
1.306 raeburn 5726: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 5727: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5728: '<td valaign="top">'.$space.
5729: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 5730: for (my $i=0; $i<@rulenames; $i++) {
5731: my $rule = $rulenames[$i];
5732: my ($checked,$extra);
5733: if ($rulenames[$i] eq 'default') {
5734: $rule = '';
5735: }
5736: if ($rulenames[$i] eq 'specific') {
5737: if (ref($servers) eq 'HASH') {
5738: my $default;
5739: if (($current ne '') && (exists($servers->{$current}))) {
5740: $checked = ' checked="checked"';
5741: }
5742: unless ($checked) {
5743: $default = ' selected="selected"';
5744: }
1.210 raeburn 5745: $extra =
1.171 raeburn 5746: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5747: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5748: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5749: '<option value=""'.$default.'></option>'."\n";
5750: foreach my $server (sort(keys(%{$servers}))) {
5751: if (ref($currbalancer) eq 'HASH') {
5752: next if (exists($currbalancer->{$server}));
5753: }
1.150 raeburn 5754: my $selected;
1.171 raeburn 5755: if ($server eq $current) {
1.150 raeburn 5756: $selected = ' selected="selected"';
5757: }
1.171 raeburn 5758: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 5759: }
5760: $extra .= '</select>';
5761: }
5762: } elsif ($rule eq $current) {
5763: $checked = ' checked="checked"';
5764: }
5765: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 5766: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5767: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5768: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 5769: ')"'.$checked.' /> ';
5770: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
5771: $output .= $ruletitles{'particular'};
5772: } else {
5773: $output .= $ruletitles{$rulenames[$i]};
5774: }
5775: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 5776: }
5777: $output .= '</div></td></tr>'."\n";
5778: return $output;
5779: }
5780:
5781: sub offloadtype_text {
5782: my %ruletitles = &Apache::lonlocal::texthash (
5783: 'default' => 'Offloads to default destinations',
5784: 'homeserver' => "Offloads to user's home server",
5785: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5786: 'specific' => 'Offloads to specific server',
1.161 raeburn 5787: 'none' => 'No offload',
1.209 raeburn 5788: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5789: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 5790: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 5791: );
5792: return %ruletitles;
5793: }
5794:
5795: sub sparestype_titles {
5796: my %typestitles = &Apache::lonlocal::texthash (
5797: 'primary' => 'primary',
5798: 'default' => 'default',
5799: );
5800: return %typestitles;
5801: }
5802:
1.28 raeburn 5803: sub contact_titles {
5804: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 5805: 'supportemail' => 'Support E-mail address',
5806: 'adminemail' => 'Default Server Admin E-mail address',
5807: 'errormail' => 'Error reports to be e-mailed to',
5808: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 5809: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
5810: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 5811: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5812: 'requestsmail' => 'E-mail from course requests requiring approval',
5813: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 5814: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 5815: );
5816: my %short_titles = &Apache::lonlocal::texthash (
5817: adminemail => 'Admin E-mail address',
5818: supportemail => 'Support E-mail',
5819: );
5820: return (\%titles,\%short_titles);
5821: }
5822:
1.286 raeburn 5823: sub helpform_fields {
5824: my %titles = &Apache::lonlocal::texthash (
5825: 'username' => 'Name',
5826: 'user' => 'Username/domain',
5827: 'phone' => 'Phone',
5828: 'cc' => 'Cc e-mail',
5829: 'course' => 'Course Details',
5830: 'section' => 'Sections',
1.289 raeburn 5831: 'screenshot' => 'File upload',
1.286 raeburn 5832: );
5833: my @fields = ('username','phone','user','course','section','cc','screenshot');
5834: my %possoptions = (
5835: username => ['yes','no','req'],
1.289 raeburn 5836: phone => ['yes','no','req'],
1.286 raeburn 5837: user => ['yes','no'],
1.289 raeburn 5838: cc => ['yes','no'],
1.286 raeburn 5839: course => ['yes','no'],
5840: section => ['yes','no'],
5841: screenshot => ['yes','no'],
5842: );
5843: my %fieldoptions = &Apache::lonlocal::texthash (
5844: 'yes' => 'Optional',
5845: 'req' => 'Required',
5846: 'no' => "Not shown",
5847: );
5848: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5849: }
5850:
1.72 raeburn 5851: sub tool_titles {
5852: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 5853: aboutme => 'Personal web page',
1.86 raeburn 5854: blog => 'Blog',
1.162 raeburn 5855: webdav => 'WebDAV',
1.86 raeburn 5856: portfolio => 'Portfolio',
1.88 bisitz 5857: official => 'Official courses (with institutional codes)',
5858: unofficial => 'Unofficial courses',
1.98 raeburn 5859: community => 'Communities',
1.216 raeburn 5860: textbook => 'Textbook courses',
1.271 raeburn 5861: placement => 'Placement tests',
1.86 raeburn 5862: );
1.72 raeburn 5863: return %titles;
5864: }
5865:
1.101 raeburn 5866: sub courserequest_titles {
5867: my %titles = &Apache::lonlocal::texthash (
5868: official => 'Official',
5869: unofficial => 'Unofficial',
5870: community => 'Communities',
1.216 raeburn 5871: textbook => 'Textbook',
1.271 raeburn 5872: placement => 'Placement tests',
1.101 raeburn 5873: norequest => 'Not allowed',
1.104 raeburn 5874: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5875: validate => 'With validation',
5876: autolimit => 'Numerical limit',
1.103 raeburn 5877: unlimited => '(blank for unlimited)',
1.101 raeburn 5878: );
5879: return %titles;
5880: }
5881:
1.163 raeburn 5882: sub authorrequest_titles {
5883: my %titles = &Apache::lonlocal::texthash (
5884: norequest => 'Not allowed',
5885: approval => 'Approval by Dom. Coord.',
5886: automatic => 'Automatic approval',
5887: );
5888: return %titles;
1.210 raeburn 5889: }
1.163 raeburn 5890:
1.101 raeburn 5891: sub courserequest_conditions {
5892: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5893: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 5894: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 5895: );
5896: return %conditions;
5897: }
5898:
5899:
1.27 raeburn 5900: sub print_usercreation {
1.30 raeburn 5901: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 5902: my $numinrow = 4;
1.28 raeburn 5903: my $datatable;
5904: if ($position eq 'top') {
1.30 raeburn 5905: $$rowtotal ++;
1.34 raeburn 5906: my $rowcount = 0;
1.32 raeburn 5907: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 5908: if (ref($rules) eq 'HASH') {
5909: if (keys(%{$rules}) > 0) {
1.32 raeburn 5910: $datatable .= &user_formats_row('username',$settings,$rules,
5911: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 5912: $$rowtotal ++;
1.32 raeburn 5913: $rowcount ++;
5914: }
5915: }
5916: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5917: if (ref($idrules) eq 'HASH') {
5918: if (keys(%{$idrules}) > 0) {
5919: $datatable .= &user_formats_row('id',$settings,$idrules,
5920: $idruleorder,$numinrow,$rowcount);
5921: $$rowtotal ++;
5922: $rowcount ++;
1.28 raeburn 5923: }
5924: }
1.39 raeburn 5925: if ($rowcount == 0) {
5926: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5927: $$rowtotal ++;
5928: $rowcount ++;
5929: }
1.34 raeburn 5930: } elsif ($position eq 'middle') {
1.224 raeburn 5931: my @creators = ('author','course','requestcrs');
1.37 raeburn 5932: my ($rules,$ruleorder) =
5933: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 5934: my %lt = &usercreation_types();
5935: my %checked;
5936: if (ref($settings) eq 'HASH') {
5937: if (ref($settings->{'cancreate'}) eq 'HASH') {
5938: foreach my $item (@creators) {
5939: $checked{$item} = $settings->{'cancreate'}{$item};
5940: }
5941: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5942: foreach my $item (@creators) {
5943: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5944: $checked{$item} = 'none';
5945: }
5946: }
5947: }
5948: }
5949: my $rownum = 0;
5950: foreach my $item (@creators) {
5951: $rownum ++;
1.224 raeburn 5952: if ($checked{$item} eq '') {
5953: $checked{$item} = 'any';
1.34 raeburn 5954: }
5955: my $css_class;
5956: if ($rownum%2) {
5957: $css_class = '';
5958: } else {
5959: $css_class = ' class="LC_odd_row" ';
5960: }
5961: $datatable .= '<tr'.$css_class.'>'.
5962: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 5963: '</span></td><td style="text-align: right">';
1.224 raeburn 5964: my @options = ('any');
5965: if (ref($rules) eq 'HASH') {
5966: if (keys(%{$rules}) > 0) {
5967: push(@options,('official','unofficial'));
1.37 raeburn 5968: }
5969: }
1.224 raeburn 5970: push(@options,'none');
1.37 raeburn 5971: foreach my $option (@options) {
1.50 raeburn 5972: my $type = 'radio';
1.34 raeburn 5973: my $check = ' ';
1.224 raeburn 5974: if ($checked{$item} eq $option) {
5975: $check = ' checked="checked" ';
1.34 raeburn 5976: }
5977: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5978: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5979: $item.'" value="'.$option.'"'.$check.'/> '.
5980: $lt{$option}.'</label> </span>';
5981: }
5982: $datatable .= '</td></tr>';
5983: }
1.28 raeburn 5984: } else {
5985: my @contexts = ('author','course','domain');
5986: my @authtypes = ('int','krb4','krb5','loc');
5987: my %checked;
5988: if (ref($settings) eq 'HASH') {
5989: if (ref($settings->{'authtypes'}) eq 'HASH') {
5990: foreach my $item (@contexts) {
5991: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5992: foreach my $auth (@authtypes) {
5993: if ($settings->{'authtypes'}{$item}{$auth}) {
5994: $checked{$item}{$auth} = ' checked="checked" ';
5995: }
5996: }
5997: }
5998: }
1.27 raeburn 5999: }
1.35 raeburn 6000: } else {
6001: foreach my $item (@contexts) {
1.36 raeburn 6002: foreach my $auth (@authtypes) {
1.35 raeburn 6003: $checked{$item}{$auth} = ' checked="checked" ';
6004: }
6005: }
1.27 raeburn 6006: }
1.28 raeburn 6007: my %title = &context_names();
6008: my %authname = &authtype_names();
6009: my $rownum = 0;
6010: my $css_class;
6011: foreach my $item (@contexts) {
6012: if ($rownum%2) {
6013: $css_class = '';
6014: } else {
6015: $css_class = ' class="LC_odd_row" ';
6016: }
1.30 raeburn 6017: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6018: '<td>'.$title{$item}.
6019: '</td><td class="LC_left_item">'.
6020: '<span class="LC_nobreak">';
6021: foreach my $auth (@authtypes) {
6022: $datatable .= '<label>'.
6023: '<input type="checkbox" name="'.$item.'_auth" '.
6024: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6025: $authname{$auth}.'</label> ';
6026: }
6027: $datatable .= '</span></td></tr>';
6028: $rownum ++;
1.27 raeburn 6029: }
1.30 raeburn 6030: $$rowtotal += $rownum;
1.27 raeburn 6031: }
6032: return $datatable;
6033: }
6034:
1.224 raeburn 6035: sub print_selfcreation {
6036: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 6037: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6038: $emaildomain,$datatable);
1.224 raeburn 6039: if (ref($settings) eq 'HASH') {
6040: if (ref($settings->{'cancreate'}) eq 'HASH') {
6041: $createsettings = $settings->{'cancreate'};
1.236 raeburn 6042: if (ref($createsettings) eq 'HASH') {
6043: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6044: @selfcreate = @{$createsettings->{'selfcreate'}};
6045: } elsif ($createsettings->{'selfcreate'} ne '') {
6046: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6047: @selfcreate = ('email','login','sso');
6048: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6049: @selfcreate = ($createsettings->{'selfcreate'});
6050: }
6051: }
6052: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6053: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 6054: }
1.305 raeburn 6055: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6056: $emailoptions = $createsettings->{'emailoptions'};
6057: }
1.303 raeburn 6058: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6059: $emailverified = $createsettings->{'emailverified'};
6060: }
6061: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6062: $emaildomain = $createsettings->{'emaildomain'};
6063: }
1.224 raeburn 6064: }
6065: }
6066: }
6067: my %radiohash;
6068: my $numinrow = 4;
6069: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 6070: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 6071: if ($position eq 'top') {
6072: my %choices = &Apache::lonlocal::texthash (
6073: cancreate_login => 'Institutional Login',
6074: cancreate_sso => 'Institutional Single Sign On',
6075: );
6076: my @toggles = sort(keys(%choices));
6077: my %defaultchecked = (
6078: 'cancreate_login' => 'off',
6079: 'cancreate_sso' => 'off',
6080: );
1.228 raeburn 6081: my ($onclick,$itemcount);
1.224 raeburn 6082: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6083: \%choices,$itemcount,$onclick);
1.228 raeburn 6084: $$rowtotal += $itemcount;
6085:
1.224 raeburn 6086: if (ref($usertypes) eq 'HASH') {
6087: if (keys(%{$usertypes}) > 0) {
6088: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6089: $dom,$numinrow,$othertitle,
1.305 raeburn 6090: 'statustocreate',$rowtotal);
1.224 raeburn 6091: $$rowtotal ++;
6092: }
6093: }
1.240 raeburn 6094: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6095: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6096: $fieldtitles{'inststatus'} = &mt('Institutional status');
6097: my $rem;
6098: my $numperrow = 2;
6099: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6100: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 6101: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 6102: '<td class="LC_left_item">'."\n".
6103: '<table><tr><td>'."\n";
6104: for (my $i=0; $i<@fields; $i++) {
6105: $rem = $i%($numperrow);
6106: if ($rem == 0) {
6107: if ($i > 0) {
6108: $datatable .= '</tr>';
6109: }
6110: $datatable .= '<tr>';
6111: }
6112: my $currval;
1.248 raeburn 6113: if (ref($createsettings) eq 'HASH') {
6114: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6115: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6116: }
1.240 raeburn 6117: }
6118: $datatable .= '<td class="LC_left_item">'.
6119: '<span class="LC_nobreak">'.
6120: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6121: 'value="'.$currval.'" size="10" /> '.
6122: $fieldtitles{$fields[$i]}.'</span></td>';
6123: }
6124: my $colsleft = $numperrow - $rem;
6125: if ($colsleft > 1 ) {
6126: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6127: ' </td>';
6128: } elsif ($colsleft == 1) {
6129: $datatable .= '<td class="LC_left_item"> </td>';
6130: }
6131: $datatable .= '</tr></table></td></tr>';
6132: $$rowtotal ++;
1.224 raeburn 6133: } elsif ($position eq 'middle') {
6134: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 6135: my @posstypes;
1.224 raeburn 6136: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6137: @posstypes = @{$types};
6138: }
6139: unless (grep(/^default$/,@posstypes)) {
6140: push(@posstypes,'default');
6141: }
6142: my %usertypeshash;
6143: if (ref($usertypes) eq 'HASH') {
6144: %usertypeshash = %{$usertypes};
6145: }
6146: $usertypeshash{'default'} = $othertitle;
6147: foreach my $status (@posstypes) {
6148: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6149: $numinrow,$$rowtotal,\%usertypeshash);
6150: $$rowtotal ++;
1.224 raeburn 6151: }
6152: } else {
1.236 raeburn 6153: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 6154: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 6155: );
6156: my @toggles = sort(keys(%choices));
6157: my %defaultchecked = (
6158: 'cancreate_email' => 'off',
6159: );
1.305 raeburn 6160: my $customclass = 'LC_selfcreate_email';
6161: my $classprefix = 'LC_canmodify_emailusername_';
6162: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 6163: my $display = 'none';
1.305 raeburn 6164: my $rowstyle = 'display:none';
1.236 raeburn 6165: if (grep(/^\Qemail\E$/,@selfcreate)) {
6166: $display = 'block';
1.305 raeburn 6167: $rowstyle = 'display:table-row';
1.236 raeburn 6168: }
1.305 raeburn 6169: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6170: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6171: \%choices,$$rowtotal,$onclick);
6172: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6173: $rowstyle);
6174: $$rowtotal ++;
6175: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6176: $rowstyle);
6177: $$rowtotal ++;
6178: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 6179: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 6180: my ($emailrules,$emailruleorder) =
6181: &Apache::lonnet::inst_userrules($dom,'email');
6182: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6183: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6184: if (ref($types) eq 'ARRAY') {
6185: @posstypes = @{$types};
6186: }
6187: if (@posstypes) {
6188: unless (grep(/^default$/,@posstypes)) {
6189: push(@posstypes,'default');
1.302 raeburn 6190: }
6191: if (ref($usertypes) eq 'HASH') {
6192: %usertypeshash = %{$usertypes};
6193: }
1.305 raeburn 6194: my $currassign;
6195: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6196: $currassign = {
6197: selfassign => $domdefaults{'inststatusguest'},
6198: };
6199: @ordered = @{$domdefaults{'inststatusguest'}};
6200: } else {
6201: $currassign = { selfassign => [] };
6202: }
6203: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6204: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6205: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
6206: $numinrow,$othertitle,'selfassign',
6207: $rowtotal,$onclicktypes,$customclass,
6208: $rowstyle);
6209: $$rowtotal ++;
1.302 raeburn 6210: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 6211: foreach my $status (@posstypes) {
6212: my $css_class;
6213: if ($$rowtotal%2) {
6214: $css_class = 'LC_odd_row ';
6215: }
6216: $css_class .= $customclass;
6217: my $rowid = $optionsprefix.$status;
6218: my $hidden = 1;
6219: my $currstyle = 'display:none';
6220: if (grep(/^\Q$status\E$/,@ordered)) {
6221: $currstyle = $rowstyle;
6222: $hidden = 0;
6223: }
6224: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6225: $emailrules,$emailruleorder,$settings,$status,$rowid,
6226: $usertypeshash{$status},$css_class,$currstyle,$intdom);
6227: unless ($hidden) {
6228: $$rowtotal ++;
6229: }
1.224 raeburn 6230: }
1.302 raeburn 6231: } else {
1.305 raeburn 6232: my $css_class;
6233: if ($$rowtotal%2) {
6234: $css_class = 'LC_odd_row ';
6235: }
6236: $css_class .= $customclass;
1.302 raeburn 6237: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 6238: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6239: $emailrules,$emailruleorder,$settings,'default','',
6240: $othertitle,$css_class,$rowstyle,$intdom);
6241: $$rowtotal ++;
1.224 raeburn 6242: }
6243: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 6244: $numinrow = 1;
1.305 raeburn 6245: if (@posstypes) {
6246: foreach my $status (@posstypes) {
6247: my $rowid = $classprefix.$status;
6248: my $datarowstyle = 'display:none';
6249: if (grep(/^\Q$status\E$/,@ordered)) {
6250: $datarowstyle = $rowstyle;
6251: }
6252: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
6253: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6254: $infotitles,$rowid,$customclass,$datarowstyle);
6255: unless ($datarowstyle eq 'display:none') {
6256: $$rowtotal ++;
6257: }
1.224 raeburn 6258: }
1.305 raeburn 6259: } else {
6260: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
6261: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6262: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 6263: }
6264: }
6265: return $datatable;
6266: }
6267:
1.305 raeburn 6268: sub selfcreate_javascript {
6269: return <<"ENDSCRIPT";
6270:
6271: <script type="text/javascript">
6272: // <![CDATA[
6273:
6274: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
6275: var x = document.getElementsByClassName(target);
6276: var insttypes = 0;
6277: var insttypeRegExp = new RegExp(prefix);
6278: if ((x.length != undefined) && (x.length > 0)) {
6279: if (form.elements[radio].length != undefined) {
6280: for (var i=0; i<form.elements[radio].length; i++) {
6281: if (form.elements[radio][i].checked) {
6282: if (form.elements[radio][i].value == 1) {
6283: for (var j=0; j<x.length; j++) {
6284: if (x[j].id == 'undefined') {
6285: x[j].style.display = 'table-row';
6286: } else if (insttypeRegExp.test(x[j].id)) {
6287: insttypes ++;
6288: } else {
6289: x[j].style.display = 'table-row';
6290: }
6291: }
6292: } else {
6293: for (var j=0; j<x.length; j++) {
6294: x[j].style.display = 'none';
6295: }
1.236 raeburn 6296: }
1.305 raeburn 6297: break;
6298: }
6299: }
6300: if (insttypes > 0) {
6301: toggleDataRow(form,checkbox,target,altprefix);
6302: toggleDataRow(form,checkbox,target,prefix,1);
6303: }
6304: }
6305: }
6306: return;
6307: }
6308:
6309: function toggleDataRow(form,checkbox,target,prefix,docount) {
6310: if (form.elements[checkbox].length != undefined) {
6311: var count = 0;
6312: if (docount) {
6313: for (var i=0; i<form.elements[checkbox].length; i++) {
6314: if (form.elements[checkbox][i].checked) {
6315: count ++;
1.236 raeburn 6316: }
1.305 raeburn 6317: }
6318: }
6319: for (var i=0; i<form.elements[checkbox].length; i++) {
6320: var type = form.elements[checkbox][i].value;
6321: if (document.getElementById(prefix+type)) {
6322: if (form.elements[checkbox][i].checked) {
6323: document.getElementById(prefix+type).style.display = 'table-row';
6324: if (count % 2 == 1) {
6325: document.getElementById(prefix+type).className = target+' LC_odd_row';
6326: } else {
6327: document.getElementById(prefix+type).className = target;
1.236 raeburn 6328: }
1.305 raeburn 6329: count ++;
1.236 raeburn 6330: } else {
1.305 raeburn 6331: document.getElementById(prefix+type).style.display = 'none';
6332: }
6333: }
6334: }
6335: }
6336: return;
6337: }
6338:
6339: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
6340: var caller = radio+'_'+status;
6341: if (form.elements[caller].length != undefined) {
6342: for (var i=0; i<form.elements[caller].length; i++) {
6343: if (form.elements[caller][i].checked) {
6344: if (document.getElementById(altprefix+'_inst_'+status)) {
6345: var curr = form.elements[caller][i].value;
6346: if (prefix) {
6347: document.getElementById(prefix+'_'+status).style.display = 'none';
6348: }
6349: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
6350: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
6351: if (curr == 'custom') {
6352: if (prefix) {
6353: document.getElementById(prefix+'_'+status).style.display = 'inline';
6354: }
6355: } else if (curr == 'inst') {
6356: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
6357: } else if (curr == 'noninst') {
6358: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 6359: }
1.305 raeburn 6360: break;
1.236 raeburn 6361: }
6362: }
6363: }
6364: }
6365: }
6366:
1.305 raeburn 6367: // ]]>
6368: </script>
6369:
6370: ENDSCRIPT
6371: }
6372:
6373: sub noninst_users {
6374: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
6375: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
6376: my $class = 'LC_left_item';
6377: if ($css_class) {
6378: $css_class = ' class="'.$css_class.'"';
6379: }
6380: if ($rowid) {
6381: $rowid = ' id="'.$rowid.'"';
6382: }
6383: if ($rowstyle) {
6384: $rowstyle = ' style="'.$rowstyle.'"';
6385: }
6386: my ($output,$description);
6387: if ($type eq 'default') {
6388: $description = &mt('Requests for: [_1]',$typetitle);
6389: } else {
6390: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
6391: }
6392: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
6393: "<td>$description</td>\n".
6394: '<td class="'.$class.'" colspan="2">'.
6395: '<table><tr>';
6396: my %headers = &Apache::lonlocal::texthash(
6397: approve => 'Processing',
6398: email => 'E-mail',
6399: username => 'Username',
6400: );
6401: foreach my $item ('approve','email','username') {
6402: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 6403: }
1.305 raeburn 6404: $output .= '</tr><tr>';
6405: foreach my $item ('approve','email','username') {
1.306 raeburn 6406: $output .= '<td style="vertical-align: top">';
1.305 raeburn 6407: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
6408: if ($item eq 'approve') {
6409: %choices = &Apache::lonlocal::texthash (
6410: automatic => 'Automatically approved',
6411: approval => 'Queued for approval',
6412: );
6413: @options = ('automatic','approval');
6414: $hashref = $processing;
6415: $defoption = 'automatic';
6416: $name = 'cancreate_emailprocess_'.$type;
6417: } elsif ($item eq 'email') {
6418: %choices = &Apache::lonlocal::texthash (
6419: any => 'Any e-mail',
6420: inst => 'Institutional only',
6421: noninst => 'Non-institutional only',
6422: custom => 'Custom restrictions',
6423: );
6424: @options = ('any','inst','noninst');
6425: my $showcustom;
6426: if (ref($emailrules) eq 'HASH') {
6427: if (keys(%{$emailrules}) > 0) {
6428: push(@options,'custom');
6429: $showcustom = 'cancreate_emailrule';
6430: if (ref($settings) eq 'HASH') {
6431: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
6432: foreach my $rule (@{$settings->{'email_rule'}}) {
6433: if (exists($emailrules->{$rule})) {
6434: $hascustom ++;
6435: }
6436: }
6437: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
6438: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
6439: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
6440: if (exists($emailrules->{$rule})) {
6441: $hascustom ++;
6442: }
6443: }
6444: }
6445: }
6446: }
6447: }
6448: }
6449: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
6450: "'cancreate_emaildomain','$type'".');"';
6451: $hashref = $emailoptions;
6452: $defoption = 'any';
6453: $name = 'cancreate_emailoptions_'.$type;
6454: } elsif ($item eq 'username') {
6455: %choices = &Apache::lonlocal::texthash (
6456: all => 'Same as e-mail',
6457: first => 'Omit @domain',
6458: free => 'Free to choose',
6459: );
6460: @options = ('all','first','free');
6461: $hashref = $emailverified;
6462: $defoption = 'all';
6463: $name = 'cancreate_usernameoptions_'.$type;
6464: }
6465: foreach my $option (@options) {
6466: my $checked;
6467: if (ref($hashref) eq 'HASH') {
6468: if ($type eq '') {
6469: if (!exists($hashref->{'default'})) {
6470: if ($option eq $defoption) {
6471: $checked = ' checked="checked"';
6472: }
6473: } else {
6474: if ($hashref->{'default'} eq $option) {
6475: $checked = ' checked="checked"';
6476: }
1.303 raeburn 6477: }
6478: } else {
1.305 raeburn 6479: if (!exists($hashref->{$type})) {
6480: if ($option eq $defoption) {
6481: $checked = ' checked="checked"';
6482: }
6483: } else {
6484: if ($hashref->{$type} eq $option) {
6485: $checked = ' checked="checked"';
6486: }
1.303 raeburn 6487: }
6488: }
1.305 raeburn 6489: } elsif (($item eq 'email') && ($hascustom)) {
6490: if ($option eq 'custom') {
6491: $checked = ' checked="checked"';
6492: }
6493: } elsif ($option eq $defoption) {
6494: $checked = ' checked="checked"';
6495: }
6496: $output .= '<span class="LC_nobreak"><label>'.
6497: '<input type="radio" name="'.$name.'"'.
6498: $checked.' value="'.$option.'"'.$onclick.' />'.
6499: $choices{$option}.'</label></span><br />';
6500: if ($item eq 'email') {
6501: if ($option eq 'custom') {
6502: my $id = 'cancreate_emailrule_'.$type;
6503: my $display = 'none';
6504: if ($checked) {
6505: $display = 'inline';
1.303 raeburn 6506: }
1.305 raeburn 6507: my $numinrow = 2;
6508: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
6509: '<legend>'.&mt('Disallow').'</legend><table>'.
6510: &user_formats_row('email',$settings,$emailrules,
6511: $emailruleorder,$numinrow,'',$type);
6512: '</table></fieldset>';
6513: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
6514: my %text = &Apache::lonlocal::texthash (
6515: inst => 'must end:',
6516: noninst => 'cannot end:',
6517: );
6518: my $value;
6519: if (ref($emaildomain) eq 'HASH') {
6520: if (ref($emaildomain->{$type}) eq 'HASH') {
6521: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 6522: }
6523: }
1.305 raeburn 6524: if ($value eq '') {
6525: $value = '@'.$intdom;
6526: }
6527: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
6528: my $display = 'none';
6529: if ($checked) {
6530: $display = 'inline';
6531: }
6532: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
6533: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
6534: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
6535: '</div>';
1.303 raeburn 6536: }
6537: }
6538: }
1.305 raeburn 6539: $output .= '</td>'."\n";
1.303 raeburn 6540: }
1.305 raeburn 6541: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 6542: return $output;
6543: }
6544:
1.165 raeburn 6545: sub captcha_choice {
1.305 raeburn 6546: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 6547: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
6548: $vertext,$currver);
1.165 raeburn 6549: my %lt = &captcha_phrases();
6550: $keyentry = 'hidden';
6551: if ($context eq 'cancreate') {
1.224 raeburn 6552: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 6553: } elsif ($context eq 'login') {
6554: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 6555: }
6556: if (ref($settings) eq 'HASH') {
6557: if ($settings->{'captcha'}) {
6558: $checked{$settings->{'captcha'}} = ' checked="checked"';
6559: } else {
6560: $checked{'original'} = ' checked="checked"';
6561: }
6562: if ($settings->{'captcha'} eq 'recaptcha') {
6563: $pubtext = $lt{'pub'};
6564: $privtext = $lt{'priv'};
6565: $keyentry = 'text';
1.269 raeburn 6566: $vertext = $lt{'ver'};
6567: $currver = $settings->{'recaptchaversion'};
6568: if ($currver ne '2') {
6569: $currver = 1;
6570: }
1.165 raeburn 6571: }
6572: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
6573: $currpub = $settings->{'recaptchakeys'}{'public'};
6574: $currpriv = $settings->{'recaptchakeys'}{'private'};
6575: }
6576: } else {
6577: $checked{'original'} = ' checked="checked"';
6578: }
1.305 raeburn 6579: my $css_class;
6580: if ($itemcount%2) {
6581: $css_class = 'LC_odd_row';
6582: }
6583: if ($customcss) {
6584: $css_class .= " $customcss";
6585: }
6586: $css_class =~ s/^\s+//;
6587: if ($css_class) {
6588: $css_class = ' class="'.$css_class.'"';
6589: }
6590: if ($rowstyle) {
6591: $css_class .= ' style="'.$rowstyle.'"';
6592: }
1.169 raeburn 6593: my $output = '<tr'.$css_class.'>'.
6594: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 6595: '<table><tr><td>'."\n";
6596: foreach my $option ('original','recaptcha','notused') {
6597: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
6598: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
6599: $lt{$option}.'</label></span>';
6600: unless ($option eq 'notused') {
6601: $output .= (' 'x2)."\n";
6602: }
6603: }
6604: #
6605: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
6606: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 6607: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 6608: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 6609: #
1.165 raeburn 6610: $output .= '</td></tr>'."\n".
1.305 raeburn 6611: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 6612: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
6613: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
6614: $currpub.'" size="40" /></span><br />'."\n".
6615: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
6616: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 6617: $currpriv.'" size="40" /></span><br />'.
6618: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
6619: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
6620: $currver.'" size="3" /></span><br />'.
6621: '</td></tr></table>'."\n".
1.165 raeburn 6622: '</td></tr>';
6623: return $output;
6624: }
6625:
1.32 raeburn 6626: sub user_formats_row {
1.305 raeburn 6627: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 6628: my $output;
6629: my %text = (
6630: 'username' => 'new usernames',
6631: 'id' => 'IDs',
6632: );
1.305 raeburn 6633: unless ($type eq 'email') {
6634: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6635: $output = '<tr '.$css_class.'>'.
6636: '<td><span class="LC_nobreak">'.
6637: &mt("Format rules to check for $text{$type}: ").
6638: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 6639: }
1.27 raeburn 6640: my $rem;
6641: if (ref($ruleorder) eq 'ARRAY') {
6642: for (my $i=0; $i<@{$ruleorder}; $i++) {
6643: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
6644: my $rem = $i%($numinrow);
6645: if ($rem == 0) {
6646: if ($i > 0) {
6647: $output .= '</tr>';
6648: }
6649: $output .= '<tr>';
6650: }
6651: my $check = ' ';
1.39 raeburn 6652: if (ref($settings) eq 'HASH') {
6653: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
6654: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
6655: $check = ' checked="checked" ';
6656: }
1.305 raeburn 6657: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
6658: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
6659: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
6660: $check = ' checked="checked" ';
6661: }
6662: }
1.27 raeburn 6663: }
6664: }
1.305 raeburn 6665: my $name = $type.'_rule';
6666: if ($type eq 'email') {
6667: $name .= '_'.$status;
6668: }
1.27 raeburn 6669: $output .= '<td class="LC_left_item">'.
6670: '<span class="LC_nobreak"><label>'.
1.311 raeburn 6671: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 6672: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
6673: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
6674: }
6675: }
6676: $rem = @{$ruleorder}%($numinrow);
6677: }
1.305 raeburn 6678: my $colsleft;
6679: if ($rem) {
6680: $colsleft = $numinrow - $rem;
6681: }
1.27 raeburn 6682: if ($colsleft > 1 ) {
6683: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6684: ' </td>';
6685: } elsif ($colsleft == 1) {
6686: $output .= '<td class="LC_left_item"> </td>';
6687: }
1.305 raeburn 6688: $output .= '</tr></table>';
6689: unless ($type eq 'email') {
6690: $output .= '</td></tr>';
6691: }
1.27 raeburn 6692: return $output;
6693: }
6694:
1.34 raeburn 6695: sub usercreation_types {
6696: my %lt = &Apache::lonlocal::texthash (
6697: author => 'When adding a co-author',
6698: course => 'When adding a user to a course',
1.100 raeburn 6699: requestcrs => 'When requesting a course',
1.34 raeburn 6700: any => 'Any',
6701: official => 'Institutional only ',
6702: unofficial => 'Non-institutional only',
6703: none => 'None',
6704: );
6705: return %lt;
1.48 raeburn 6706: }
1.34 raeburn 6707:
1.224 raeburn 6708: sub selfcreation_types {
6709: my %lt = &Apache::lonlocal::texthash (
6710: selfcreate => 'User creates own account',
6711: any => 'Any',
6712: official => 'Institutional only ',
6713: unofficial => 'Non-institutional only',
6714: email => 'E-mail address',
6715: login => 'Institutional Login',
6716: sso => 'SSO',
6717: );
6718: }
6719:
1.28 raeburn 6720: sub authtype_names {
6721: my %lt = &Apache::lonlocal::texthash(
6722: int => 'Internal',
6723: krb4 => 'Kerberos 4',
6724: krb5 => 'Kerberos 5',
6725: loc => 'Local',
6726: );
6727: return %lt;
6728: }
6729:
6730: sub context_names {
6731: my %context_title = &Apache::lonlocal::texthash(
6732: author => 'Creating users when an Author',
6733: course => 'Creating users when in a course',
6734: domain => 'Creating users when a Domain Coordinator',
6735: );
6736: return %context_title;
6737: }
6738:
1.33 raeburn 6739: sub print_usermodification {
6740: my ($position,$dom,$settings,$rowtotal) = @_;
6741: my $numinrow = 4;
6742: my ($context,$datatable,$rowcount);
6743: if ($position eq 'top') {
6744: $rowcount = 0;
6745: $context = 'author';
6746: foreach my $role ('ca','aa') {
6747: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6748: $numinrow,$rowcount);
6749: $$rowtotal ++;
6750: $rowcount ++;
6751: }
1.230 raeburn 6752: } elsif ($position eq 'bottom') {
1.33 raeburn 6753: $context = 'course';
6754: $rowcount = 0;
6755: foreach my $role ('st','ep','ta','in','cr') {
6756: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6757: $numinrow,$rowcount);
6758: $$rowtotal ++;
6759: $rowcount ++;
6760: }
6761: }
6762: return $datatable;
6763: }
6764:
1.43 raeburn 6765: sub print_defaults {
1.236 raeburn 6766: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 6767: my $rownum = 0;
1.294 raeburn 6768: my ($datatable,$css_class,$titles);
6769: unless ($position eq 'bottom') {
6770: $titles = &defaults_titles($dom);
6771: }
1.236 raeburn 6772: if ($position eq 'top') {
6773: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6774: 'datelocale_def','portal_def');
6775: my %defaults;
6776: if (ref($settings) eq 'HASH') {
6777: %defaults = %{$settings};
1.43 raeburn 6778: } else {
1.236 raeburn 6779: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6780: foreach my $item (@items) {
6781: $defaults{$item} = $domdefaults{$item};
6782: }
1.43 raeburn 6783: }
1.236 raeburn 6784: foreach my $item (@items) {
6785: if ($rownum%2) {
6786: $css_class = '';
6787: } else {
6788: $css_class = ' class="LC_odd_row" ';
6789: }
6790: $datatable .= '<tr'.$css_class.'>'.
6791: '<td><span class="LC_nobreak">'.$titles->{$item}.
6792: '</span></td><td class="LC_right_item" colspan="3">';
6793: if ($item eq 'auth_def') {
6794: my @authtypes = ('internal','krb4','krb5','localauth');
6795: my %shortauth = (
6796: internal => 'int',
6797: krb4 => 'krb4',
6798: krb5 => 'krb5',
6799: localauth => 'loc'
6800: );
6801: my %authnames = &authtype_names();
6802: foreach my $auth (@authtypes) {
6803: my $checked = ' ';
6804: if ($defaults{$item} eq $auth) {
6805: $checked = ' checked="checked" ';
6806: }
6807: $datatable .= '<label><input type="radio" name="'.$item.
6808: '" value="'.$auth.'"'.$checked.'/>'.
6809: $authnames{$shortauth{$auth}}.'</label> ';
6810: }
6811: } elsif ($item eq 'timezone_def') {
6812: my $includeempty = 1;
6813: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6814: } elsif ($item eq 'datelocale_def') {
6815: my $includeempty = 1;
6816: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
6817: } elsif ($item eq 'lang_def') {
1.263 raeburn 6818: my $includeempty = 1;
6819: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 6820: } else {
6821: my $size;
6822: if ($item eq 'portal_def') {
6823: $size = ' size="25"';
6824: }
6825: $datatable .= '<input type="text" name="'.$item.'" value="'.
6826: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 6827: }
1.236 raeburn 6828: $datatable .= '</td></tr>';
6829: $rownum ++;
6830: }
1.294 raeburn 6831: } elsif ($position eq 'middle') {
6832: my @items = ('intauth_cost','intauth_check','intauth_switch');
6833: my %defaults;
6834: if (ref($settings) eq 'HASH') {
6835: %defaults = %{$settings};
6836: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6837: $defaults{'intauth_cost'} = 10;
6838: }
6839: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6840: $defaults{'intauth_check'} = 0;
6841: }
6842: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6843: $defaults{'intauth_switch'} = 0;
6844: }
6845: } else {
6846: %defaults = (
6847: 'intauth_cost' => 10,
6848: 'intauth_check' => 0,
6849: 'intauth_switch' => 0,
6850: );
6851: }
6852: foreach my $item (@items) {
6853: if ($rownum%2) {
6854: $css_class = '';
6855: } else {
6856: $css_class = ' class="LC_odd_row" ';
6857: }
6858: $datatable .= '<tr'.$css_class.'>'.
6859: '<td><span class="LC_nobreak">'.$titles->{$item}.
6860: '</span></td><td class="LC_left_item" colspan="3">';
6861: if ($item eq 'intauth_switch') {
6862: my @options = (0,1,2);
6863: my %optiondesc = &Apache::lonlocal::texthash (
6864: 0 => 'No',
6865: 1 => 'Yes',
6866: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6867: );
6868: $datatable .= '<table width="100%">';
6869: foreach my $option (@options) {
6870: my $checked = ' ';
6871: if ($defaults{$item} eq $option) {
6872: $checked = ' checked="checked"';
6873: }
6874: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6875: '<label><input type="radio" name="'.$item.
6876: '" value="'.$option.'"'.$checked.' />'.
6877: $optiondesc{$option}.'</label></span></td></tr>';
6878: }
6879: $datatable .= '</table>';
6880: } elsif ($item eq 'intauth_check') {
6881: my @options = (0,1,2);
6882: my %optiondesc = &Apache::lonlocal::texthash (
6883: 0 => 'No',
6884: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6885: 2 => 'Yes, disallow login if stored cost is less than domain default',
6886: );
6887: $datatable .= '<table wisth="100%">';
6888: foreach my $option (@options) {
6889: my $checked = ' ';
6890: my $onclick;
6891: if ($defaults{$item} eq $option) {
6892: $checked = ' checked="checked"';
6893: }
6894: if ($option == 2) {
6895: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6896: }
6897: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6898: '<label><input type="radio" name="'.$item.
6899: '" value="'.$option.'"'.$checked.$onclick.' />'.
6900: $optiondesc{$option}.'</label></span></td></tr>';
6901: }
6902: $datatable .= '</table>';
6903: } else {
6904: $datatable .= '<input type="text" name="'.$item.'" value="'.
6905: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6906: }
6907: $datatable .= '</td></tr>';
6908: $rownum ++;
6909: }
1.236 raeburn 6910: } else {
1.294 raeburn 6911: my %defaults;
1.236 raeburn 6912: if (ref($settings) eq 'HASH') {
1.305 raeburn 6913: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.236 raeburn 6914: my $maxnum = @{$settings->{'inststatusorder'}};
6915: for (my $i=0; $i<$maxnum; $i++) {
6916: $css_class = $rownum%2?' class="LC_odd_row"':'';
6917: my $item = $settings->{'inststatusorder'}->[$i];
6918: my $title = $settings->{'inststatustypes'}->{$item};
6919: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6920: $datatable .= '<tr'.$css_class.'>'.
6921: '<td><span class="LC_nobreak">'.
6922: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6923: for (my $k=0; $k<=$maxnum; $k++) {
6924: my $vpos = $k+1;
6925: my $selstr;
6926: if ($k == $i) {
6927: $selstr = ' selected="selected" ';
6928: }
6929: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6930: }
6931: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6932: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6933: &mt('delete').'</span></td>'.
1.305 raeburn 6934: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
1.236 raeburn 6935: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.305 raeburn 6936: '</span></td></tr>';
1.236 raeburn 6937: }
6938: $css_class = $rownum%2?' class="LC_odd_row"':'';
6939: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6940: $datatable .= '<tr '.$css_class.'>'.
6941: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6942: for (my $k=0; $k<=$maxnum; $k++) {
6943: my $vpos = $k+1;
6944: my $selstr;
6945: if ($k == $maxnum) {
6946: $selstr = ' selected="selected" ';
6947: }
6948: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6949: }
6950: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 6951: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 6952: ' '.&mt('(new)').
1.305 raeburn 6953: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.236 raeburn 6954: &mt('Name displayed:').
6955: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6956: '</tr>'."\n";
6957: $rownum ++;
1.141 raeburn 6958: }
1.43 raeburn 6959: }
6960: }
6961: $$rowtotal += $rownum;
6962: return $datatable;
6963: }
6964:
1.168 raeburn 6965: sub get_languages_hash {
6966: my %langchoices;
6967: foreach my $id (&Apache::loncommon::languageids()) {
6968: my $code = &Apache::loncommon::supportedlanguagecode($id);
6969: if ($code ne '') {
6970: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6971: }
6972: }
6973: return %langchoices;
6974: }
6975:
1.43 raeburn 6976: sub defaults_titles {
1.141 raeburn 6977: my ($dom) = @_;
1.43 raeburn 6978: my %titles = &Apache::lonlocal::texthash (
6979: 'auth_def' => 'Default authentication type',
6980: 'auth_arg_def' => 'Default authentication argument',
6981: 'lang_def' => 'Default language',
1.54 raeburn 6982: 'timezone_def' => 'Default timezone',
1.68 raeburn 6983: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6984: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 6985: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
6986: 'intauth_check' => 'Check bcrypt cost if authenticated',
6987: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 6988: );
1.141 raeburn 6989: if ($dom) {
6990: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6991: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6992: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6993: $protocol = 'http' if ($protocol ne 'https');
6994: if ($uint_dom) {
6995: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6996: $uint_dom);
6997: }
6998: }
1.43 raeburn 6999: return (\%titles);
7000: }
7001:
1.46 raeburn 7002: sub print_scantronformat {
7003: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7004: my $itemcount = 1;
1.60 raeburn 7005: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7006: %confhash);
1.46 raeburn 7007: my $switchserver = &check_switchserver($dom,$confname);
7008: my %lt = &Apache::lonlocal::texthash (
1.95 www 7009: default => 'Default bubblesheet format file error',
7010: custom => 'Custom bubblesheet format file error',
1.46 raeburn 7011: );
7012: my %scantronfiles = (
7013: default => 'default.tab',
7014: custom => 'custom.tab',
7015: );
7016: foreach my $key (keys(%scantronfiles)) {
7017: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7018: .$scantronfiles{$key};
7019: }
7020: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7021: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7022: if (!$switchserver) {
7023: my $servadm = $r->dir_config('lonAdmEMail');
7024: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7025: if ($configuserok eq 'ok') {
7026: if ($author_ok eq 'ok') {
7027: my %legacyfile = (
7028: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7029: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
7030: );
7031: my %md5chk;
7032: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7033: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7034: chomp($md5chk{$type});
1.46 raeburn 7035: }
7036: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7037: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7038: ($scantronurls{$type},my $error) =
1.46 raeburn 7039: &legacy_scantronformat($r,$dom,$confname,
7040: $type,$legacyfile{$type},
7041: $scantronurls{$type},
7042: $scantronfiles{$type});
1.60 raeburn 7043: if ($error ne '') {
7044: $error{$type} = $error;
7045: }
7046: }
7047: if (keys(%error) == 0) {
7048: $is_custom = 1;
7049: $confhash{'scantron'}{'scantronformat'} =
7050: $scantronurls{'custom'};
7051: my $putresult =
7052: &Apache::lonnet::put_dom('configuration',
7053: \%confhash,$dom);
7054: if ($putresult ne 'ok') {
7055: $error{'custom'} =
7056: '<span class="LC_error">'.
7057: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7058: }
1.46 raeburn 7059: }
7060: } else {
1.60 raeburn 7061: ($scantronurls{'default'},my $error) =
1.46 raeburn 7062: &legacy_scantronformat($r,$dom,$confname,
7063: 'default',$legacyfile{'default'},
7064: $scantronurls{'default'},
7065: $scantronfiles{'default'});
1.60 raeburn 7066: if ($error eq '') {
7067: $confhash{'scantron'}{'scantronformat'} = '';
7068: my $putresult =
7069: &Apache::lonnet::put_dom('configuration',
7070: \%confhash,$dom);
7071: if ($putresult ne 'ok') {
7072: $error{'default'} =
7073: '<span class="LC_error">'.
7074: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7075: }
7076: } else {
7077: $error{'default'} = $error;
7078: }
1.46 raeburn 7079: }
7080: }
7081: }
7082: } else {
1.95 www 7083: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 7084: }
7085: }
7086: if (ref($settings) eq 'HASH') {
7087: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7088: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7089: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7090: $scantronurl = '';
7091: } else {
7092: $scantronurl = $settings->{'scantronformat'};
7093: }
7094: $is_custom = 1;
7095: } else {
7096: $scantronurl = $scantronurls{'default'};
7097: }
7098: } else {
1.60 raeburn 7099: if ($is_custom) {
7100: $scantronurl = $scantronurls{'custom'};
7101: } else {
7102: $scantronurl = $scantronurls{'default'};
7103: }
1.46 raeburn 7104: }
7105: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7106: $datatable .= '<tr'.$css_class.'>';
7107: if (!$is_custom) {
1.65 raeburn 7108: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7109: '<span class="LC_nobreak">';
1.46 raeburn 7110: if ($scantronurl) {
1.199 raeburn 7111: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7112: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 7113: } else {
7114: $datatable = &mt('File unavailable for display');
7115: }
1.65 raeburn 7116: $datatable .= '</span></td>';
1.60 raeburn 7117: if (keys(%error) == 0) {
1.306 raeburn 7118: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 7119: if (!$switchserver) {
7120: $datatable .= &mt('Upload:').'<br />';
7121: }
7122: } else {
7123: my $errorstr;
7124: foreach my $key (sort(keys(%error))) {
7125: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7126: }
7127: $datatable .= '<td>'.$errorstr;
7128: }
1.46 raeburn 7129: } else {
7130: if (keys(%error) > 0) {
7131: my $errorstr;
7132: foreach my $key (sort(keys(%error))) {
7133: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7134: }
1.60 raeburn 7135: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 7136: } elsif ($scantronurl) {
1.199 raeburn 7137: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
7138: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 7139: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 7140: $link.
7141: '<label><input type="checkbox" name="scantronformat_del"'.
7142: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 7143: '<td><span class="LC_nobreak"> '.
7144: &mt('Replace:').'</span><br />';
1.46 raeburn 7145: }
7146: }
7147: if (keys(%error) == 0) {
7148: if ($switchserver) {
7149: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7150: } else {
1.65 raeburn 7151: $datatable .='<span class="LC_nobreak"> '.
7152: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 7153: }
7154: }
7155: $datatable .= '</td></tr>';
7156: $$rowtotal ++;
7157: return $datatable;
7158: }
7159:
7160: sub legacy_scantronformat {
7161: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7162: my ($url,$error);
7163: my @statinfo = &Apache::lonnet::stat_file($newurl);
7164: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7165: (my $result,$url) =
7166: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7167: '','',$newfile);
7168: if ($result ne 'ok') {
1.130 raeburn 7169: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 7170: }
7171: }
7172: return ($url,$error);
7173: }
1.43 raeburn 7174:
1.49 raeburn 7175: sub print_coursecategories {
1.57 raeburn 7176: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
7177: my $datatable;
7178: if ($position eq 'top') {
1.238 raeburn 7179: my (%checked);
7180: my @catitems = ('unauth','auth');
7181: my @cattypes = ('std','domonly','codesrch','none');
7182: $checked{'unauth'} = 'std';
7183: $checked{'auth'} = 'std';
7184: if (ref($settings) eq 'HASH') {
7185: foreach my $type (@cattypes) {
7186: if ($type eq $settings->{'unauth'}) {
7187: $checked{'unauth'} = $type;
7188: }
7189: if ($type eq $settings->{'auth'}) {
7190: $checked{'auth'} = $type;
7191: }
7192: }
7193: }
7194: my %lt = &Apache::lonlocal::texthash (
7195: unauth => 'Catalog type for unauthenticated users',
7196: auth => 'Catalog type for authenticated users',
7197: none => 'No catalog',
7198: std => 'Standard catalog',
7199: domonly => 'Domain-only catalog',
7200: codesrch => "Code search form",
7201: );
7202: my $itemcount = 0;
7203: foreach my $item (@catitems) {
7204: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7205: $datatable .= '<tr '.$css_class.'>'.
7206: '<td>'.$lt{$item}.'</td>'.
7207: '<td class="LC_right_item"><span class="LC_nobreak">';
7208: foreach my $type (@cattypes) {
7209: my $ischecked;
7210: if ($checked{$item} eq $type) {
7211: $ischecked=' checked="checked"';
7212: }
7213: $datatable .= '<label>'.
7214: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
7215: ' />'.$lt{$type}.'</label> ';
7216: }
7217: $datatable .= '</td></tr>';
7218: $itemcount ++;
7219: }
7220: $$rowtotal += $itemcount;
7221: } elsif ($position eq 'middle') {
1.57 raeburn 7222: my $toggle_cats_crs = ' ';
7223: my $toggle_cats_dom = ' checked="checked" ';
7224: my $can_cat_crs = ' ';
7225: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 7226: my $toggle_catscomm_comm = ' ';
7227: my $toggle_catscomm_dom = ' checked="checked" ';
7228: my $can_catcomm_comm = ' ';
7229: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 7230: my $toggle_catsplace_place = ' ';
7231: my $toggle_catsplace_dom = ' checked="checked" ';
7232: my $can_catplace_place = ' ';
7233: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 7234:
1.57 raeburn 7235: if (ref($settings) eq 'HASH') {
7236: if ($settings->{'togglecats'} eq 'crs') {
7237: $toggle_cats_crs = $toggle_cats_dom;
7238: $toggle_cats_dom = ' ';
7239: }
7240: if ($settings->{'categorize'} eq 'crs') {
7241: $can_cat_crs = $can_cat_dom;
7242: $can_cat_dom = ' ';
7243: }
1.120 raeburn 7244: if ($settings->{'togglecatscomm'} eq 'comm') {
7245: $toggle_catscomm_comm = $toggle_catscomm_dom;
7246: $toggle_catscomm_dom = ' ';
7247: }
7248: if ($settings->{'categorizecomm'} eq 'comm') {
7249: $can_catcomm_comm = $can_catcomm_dom;
7250: $can_catcomm_dom = ' ';
7251: }
1.272 raeburn 7252: if ($settings->{'togglecatsplace'} eq 'place') {
7253: $toggle_catsplace_place = $toggle_catsplace_dom;
7254: $toggle_catsplace_dom = ' ';
7255: }
7256: if ($settings->{'categorizeplace'} eq 'place') {
7257: $can_catplace_place = $can_catplace_dom;
7258: $can_catplace_dom = ' ';
7259: }
1.57 raeburn 7260: }
7261: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 7262: togglecats => 'Show/Hide a course in catalog',
7263: togglecatscomm => 'Show/Hide a community in catalog',
7264: togglecatsplace => 'Show/Hide a placement test in catalog',
7265: categorize => 'Assign a category to a course',
7266: categorizecomm => 'Assign a category to a community',
7267: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 7268: );
7269: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 7270: dom => 'Set in Domain',
7271: crs => 'Set in Course',
7272: comm => 'Set in Community',
7273: place => 'Set in Placement Test',
1.57 raeburn 7274: );
7275: $datatable = '<tr class="LC_odd_row">'.
7276: '<td>'.$title{'togglecats'}.'</td>'.
7277: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7278: '<input type="radio" name="togglecats"'.
7279: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7280: '<label><input type="radio" name="togglecats"'.
7281: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
7282: '</tr><tr>'.
7283: '<td>'.$title{'categorize'}.'</td>'.
7284: '<td class="LC_right_item"><span class="LC_nobreak">'.
7285: '<label><input type="radio" name="categorize"'.
7286: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7287: '<label><input type="radio" name="categorize"'.
7288: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 7289: '</tr><tr class="LC_odd_row">'.
7290: '<td>'.$title{'togglecatscomm'}.'</td>'.
7291: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7292: '<input type="radio" name="togglecatscomm"'.
7293: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7294: '<label><input type="radio" name="togglecatscomm"'.
7295: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
7296: '</tr><tr>'.
7297: '<td>'.$title{'categorizecomm'}.'</td>'.
7298: '<td class="LC_right_item"><span class="LC_nobreak">'.
7299: '<label><input type="radio" name="categorizecomm"'.
7300: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7301: '<label><input type="radio" name="categorizecomm"'.
7302: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 7303: '</tr><tr>'.
7304: '<td>'.$title{'togglecatsplace'}.'</td>'.
7305: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7306: '<input type="radio" name="togglecatsplace"'.
7307: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7308: '<label><input type="radio" name="togglecatscomm"'.
7309: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
7310: '</tr><tr>'.
7311: '<td>'.$title{'categorizeplace'}.'</td>'.
7312: '<td class="LC_right_item"><span class="LC_nobreak">'.
7313: '<label><input type="radio" name="categorizeplace"'.
7314: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7315: '<label><input type="radio" name="categorizeplace"'.
7316: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 7317: '</tr>';
1.272 raeburn 7318: $$rowtotal += 6;
1.57 raeburn 7319: } else {
7320: my $css_class;
7321: my $itemcount = 1;
7322: my $cathash;
7323: if (ref($settings) eq 'HASH') {
7324: $cathash = $settings->{'cats'};
7325: }
7326: if (ref($cathash) eq 'HASH') {
7327: my (@cats,@trails,%allitems,%idx,@jsarray);
7328: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
7329: \%allitems,\%idx,\@jsarray);
7330: my $maxdepth = scalar(@cats);
7331: my $colattrib = '';
7332: if ($maxdepth > 2) {
7333: $colattrib = ' colspan="2" ';
7334: }
7335: my @path;
7336: if (@cats > 0) {
7337: if (ref($cats[0]) eq 'ARRAY') {
7338: my $numtop = @{$cats[0]};
7339: my $maxnum = $numtop;
1.120 raeburn 7340: my %default_names = (
7341: instcode => &mt('Official courses'),
7342: communities => &mt('Communities'),
1.272 raeburn 7343: placement => &mt('Placement Tests'),
1.120 raeburn 7344: );
7345:
7346: if ((!grep(/^instcode$/,@{$cats[0]})) ||
7347: ($cathash->{'instcode::0'} eq '') ||
7348: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 7349: ($cathash->{'communities::0'} eq '') ||
7350: (!grep(/^placement$/,@{$cats[0]})) ||
7351: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 7352: $maxnum ++;
7353: }
7354: my $lastidx;
7355: for (my $i=0; $i<$numtop; $i++) {
7356: my $parent = $cats[0][$i];
7357: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7358: my $item = &escape($parent).'::0';
7359: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
7360: $lastidx = $idx{$item};
7361: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7362: .'<select name="'.$item.'"'.$chgstr.'>';
7363: for (my $k=0; $k<=$maxnum; $k++) {
7364: my $vpos = $k+1;
7365: my $selstr;
7366: if ($k == $i) {
7367: $selstr = ' selected="selected" ';
7368: }
7369: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7370: }
1.214 raeburn 7371: $datatable .= '</select></span></td><td>';
1.272 raeburn 7372: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 7373: $datatable .= '<span class="LC_nobreak">'
7374: .$default_names{$parent}.'</span>';
7375: if ($parent eq 'instcode') {
7376: $datatable .= '<br /><span class="LC_nobreak">('
7377: .&mt('with institutional codes')
7378: .')</span></td><td'.$colattrib.'>';
7379: } else {
7380: $datatable .= '<table><tr><td>';
7381: }
7382: $datatable .= '<span class="LC_nobreak">'
7383: .'<label><input type="radio" name="'
7384: .$parent.'" value="1" checked="checked" />'
7385: .&mt('Display').'</label>';
7386: if ($parent eq 'instcode') {
7387: $datatable .= ' ';
7388: } else {
7389: $datatable .= '</span></td></tr><tr><td>'
7390: .'<span class="LC_nobreak">';
7391: }
7392: $datatable .= '<label><input type="radio" name="'
7393: .$parent.'" value="0" />'
7394: .&mt('Do not display').'</label></span>';
1.272 raeburn 7395: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 7396: $datatable .= '</td></tr></table>';
7397: }
7398: $datatable .= '</td>';
1.57 raeburn 7399: } else {
7400: $datatable .= $parent
1.214 raeburn 7401: .' <span class="LC_nobreak"><label>'
7402: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 7403: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
7404: }
7405: my $depth = 1;
7406: push(@path,$parent);
7407: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
7408: pop(@path);
7409: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
7410: $itemcount ++;
7411: }
1.48 raeburn 7412: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 7413: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
7414: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 7415: for (my $k=0; $k<=$maxnum; $k++) {
7416: my $vpos = $k+1;
7417: my $selstr;
1.57 raeburn 7418: if ($k == $numtop) {
1.48 raeburn 7419: $selstr = ' selected="selected" ';
7420: }
7421: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7422: }
1.59 bisitz 7423: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 7424: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
7425: .'</tr>'."\n";
1.48 raeburn 7426: $itemcount ++;
1.272 raeburn 7427: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 7428: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
7429: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7430: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
7431: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
7432: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
7433: for (my $k=0; $k<=$maxnum; $k++) {
7434: my $vpos = $k+1;
7435: my $selstr;
7436: if ($k == $maxnum) {
7437: $selstr = ' selected="selected" ';
7438: }
7439: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 7440: }
1.120 raeburn 7441: $datatable .= '</select></span></td>'.
7442: '<td><span class="LC_nobreak">'.
7443: $default_names{$default}.'</span>';
7444: if ($default eq 'instcode') {
7445: $datatable .= '<br /><span class="LC_nobreak">('
7446: .&mt('with institutional codes').')</span>';
7447: }
7448: $datatable .= '</td>'
7449: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
7450: .&mt('Display').'</label> '
7451: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
7452: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 7453: }
7454: }
7455: }
1.57 raeburn 7456: } else {
7457: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 7458: }
7459: } else {
1.238 raeburn 7460: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 7461: .&initialize_categories($itemcount);
1.48 raeburn 7462: }
1.57 raeburn 7463: $$rowtotal += $itemcount;
1.48 raeburn 7464: }
7465: return $datatable;
7466: }
7467:
1.69 raeburn 7468: sub print_serverstatuses {
7469: my ($dom,$settings,$rowtotal) = @_;
7470: my $datatable;
7471: my @pages = &serverstatus_pages();
7472: my (%namedaccess,%machineaccess);
7473: foreach my $type (@pages) {
7474: $namedaccess{$type} = '';
7475: $machineaccess{$type}= '';
7476: }
7477: if (ref($settings) eq 'HASH') {
7478: foreach my $type (@pages) {
7479: if (exists($settings->{$type})) {
7480: if (ref($settings->{$type}) eq 'HASH') {
7481: foreach my $key (keys(%{$settings->{$type}})) {
7482: if ($key eq 'namedusers') {
7483: $namedaccess{$type} = $settings->{$type}->{$key};
7484: } elsif ($key eq 'machines') {
7485: $machineaccess{$type} = $settings->{$type}->{$key};
7486: }
7487: }
7488: }
7489: }
7490: }
7491: }
1.81 raeburn 7492: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7493: my $rownum = 0;
7494: my $css_class;
7495: foreach my $type (@pages) {
7496: $rownum ++;
7497: $css_class = $rownum%2?' class="LC_odd_row"':'';
7498: $datatable .= '<tr'.$css_class.'>'.
7499: '<td><span class="LC_nobreak">'.
7500: $titles->{$type}.'</span></td>'.
7501: '<td class="LC_left_item">'.
7502: '<input type="text" name="'.$type.'_namedusers" '.
7503: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
7504: '<td class="LC_right_item">'.
7505: '<span class="LC_nobreak">'.
7506: '<input type="text" name="'.$type.'_machines" '.
7507: 'value="'.$machineaccess{$type}.'" size="10" />'.
7508: '</td></tr>'."\n";
7509: }
7510: $$rowtotal += $rownum;
7511: return $datatable;
7512: }
7513:
7514: sub serverstatus_pages {
7515: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 7516: 'checksums','clusterstatus','certstatus','metadata_keywords',
7517: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
7518: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 7519: }
7520:
1.236 raeburn 7521: sub defaults_javascript {
7522: my ($settings) = @_;
1.294 raeburn 7523: 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.');
7524: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
7525: &js_escape(\$intauthcheck);
7526: &js_escape(\$intauthcost);
7527: my $intauthjs = <<"ENDSCRIPT";
7528:
7529: function warnIntAuth(field) {
7530: if (field.name == 'intauth_check') {
7531: if (field.value == '2') {
7532: alert('$intauthcheck');
7533: }
7534: }
7535: if (field.name == 'intauth_cost') {
7536: field.value.replace(/\s/g,'');
7537: if (field.value != '') {
7538: var regexdigit=/^\\d+\$/;
7539: if (!regexdigit.test(field.value)) {
7540: alert('$intauthcost');
7541: }
7542: }
7543: }
7544: return;
7545: }
7546:
7547: ENDSCRIPT
7548:
7549: if (ref($settings) ne 'HASH') {
7550: return &Apache::lonhtmlcommon::scripttag($intauthjs);
7551: }
1.236 raeburn 7552: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
7553: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
7554: if ($maxnum eq '') {
7555: $maxnum = 0;
7556: }
7557: $maxnum ++;
1.249 raeburn 7558: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 7559: return <<"ENDSCRIPT";
7560: <script type="text/javascript">
7561: // <![CDATA[
7562: function reorderTypes(form,caller) {
7563: var changedVal;
7564: $jstext
7565: var newpos = 'addinststatus_pos';
7566: var current = new Array;
7567: var maxh = $maxnum;
7568: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7569: var oldVal;
7570: if (caller == newpos) {
7571: changedVal = newitemVal;
7572: } else {
7573: var curritem = 'inststatus_pos_'+caller;
7574: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
7575: current[newitemVal] = newpos;
7576: }
7577: for (var i=0; i<inststatuses.length; i++) {
7578: if (inststatuses[i] != caller) {
7579: var elementName = 'inststatus_pos_'+inststatuses[i];
7580: if (form.elements[elementName]) {
7581: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7582: current[currVal] = elementName;
7583: }
7584: }
7585: }
7586: for (var j=0; j<maxh; j++) {
7587: if (current[j] == undefined) {
7588: oldVal = j;
7589: }
7590: }
7591: if (oldVal < changedVal) {
7592: for (var k=oldVal+1; k<=changedVal ; k++) {
7593: var elementName = current[k];
7594: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7595: }
7596: } else {
7597: for (var k=changedVal; k<oldVal; k++) {
7598: var elementName = current[k];
7599: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7600: }
7601: }
7602: return;
7603: }
7604:
1.294 raeburn 7605: $intauthjs
7606:
1.236 raeburn 7607: // ]]>
7608: </script>
7609:
7610: ENDSCRIPT
1.294 raeburn 7611: } else {
7612: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 7613: }
7614: }
7615:
1.49 raeburn 7616: sub coursecategories_javascript {
7617: my ($settings) = @_;
1.57 raeburn 7618: my ($output,$jstext,$cathash);
1.49 raeburn 7619: if (ref($settings) eq 'HASH') {
1.57 raeburn 7620: $cathash = $settings->{'cats'};
7621: }
7622: if (ref($cathash) eq 'HASH') {
1.49 raeburn 7623: my (@cats,@jsarray,%idx);
1.57 raeburn 7624: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 7625: if (@jsarray > 0) {
7626: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
7627: for (my $i=0; $i<@jsarray; $i++) {
7628: if (ref($jsarray[$i]) eq 'ARRAY') {
7629: my $catstr = join('","',@{$jsarray[$i]});
7630: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
7631: }
7632: }
7633: }
7634: } else {
7635: $jstext = ' var categories = Array(1);'."\n".
7636: ' categories[0] = Array("instcode_pos");'."\n";
7637: }
1.237 bisitz 7638: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
7639: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 7640: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 7641: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
7642: &js_escape(\$instcode_reserved);
7643: &js_escape(\$communities_reserved);
1.272 raeburn 7644: &js_escape(\$placement_reserved);
1.265 damieng 7645: &js_escape(\$choose_again);
1.49 raeburn 7646: $output = <<"ENDSCRIPT";
7647: <script type="text/javascript">
1.109 raeburn 7648: // <![CDATA[
1.49 raeburn 7649: function reorderCats(form,parent,item,idx) {
7650: var changedVal;
7651: $jstext
7652: var newpos = 'addcategory_pos';
7653: if (parent == '') {
7654: var has_instcode = 0;
7655: var maxtop = categories[idx].length;
7656: for (var j=0; j<maxtop; j++) {
7657: if (categories[idx][j] == 'instcode::0') {
7658: has_instcode == 1;
7659: }
7660: }
7661: if (has_instcode == 0) {
7662: categories[idx][maxtop] = 'instcode_pos';
7663: }
7664: } else {
7665: newpos += '_'+parent;
7666: }
7667: var maxh = 1 + categories[idx].length;
7668: var current = new Array;
7669: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7670: if (item == newpos) {
7671: changedVal = newitemVal;
7672: } else {
7673: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
7674: current[newitemVal] = newpos;
7675: }
7676: for (var i=0; i<categories[idx].length; i++) {
7677: var elementName = categories[idx][i];
7678: if (elementName != item) {
7679: if (form.elements[elementName]) {
7680: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7681: current[currVal] = elementName;
7682: }
7683: }
7684: }
7685: var oldVal;
7686: for (var j=0; j<maxh; j++) {
7687: if (current[j] == undefined) {
7688: oldVal = j;
7689: }
7690: }
7691: if (oldVal < changedVal) {
7692: for (var k=oldVal+1; k<=changedVal ; k++) {
7693: var elementName = current[k];
7694: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7695: }
7696: } else {
7697: for (var k=changedVal; k<oldVal; k++) {
7698: var elementName = current[k];
7699: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7700: }
7701: }
7702: return;
7703: }
1.120 raeburn 7704:
7705: function categoryCheck(form) {
7706: if (form.elements['addcategory_name'].value == 'instcode') {
7707: alert('$instcode_reserved\\n$choose_again');
7708: return false;
7709: }
7710: if (form.elements['addcategory_name'].value == 'communities') {
7711: alert('$communities_reserved\\n$choose_again');
7712: return false;
7713: }
1.272 raeburn 7714: if (form.elements['addcategory_name'].value == 'placement') {
7715: alert('$placement_reserved\\n$choose_again');
7716: return false;
7717: }
1.120 raeburn 7718: return true;
7719: }
7720:
1.109 raeburn 7721: // ]]>
1.49 raeburn 7722: </script>
7723:
7724: ENDSCRIPT
7725: return $output;
7726: }
7727:
1.48 raeburn 7728: sub initialize_categories {
7729: my ($itemcount) = @_;
1.120 raeburn 7730: my ($datatable,$css_class,$chgstr);
7731: my %default_names = (
7732: instcode => 'Official courses (with institutional codes)',
7733: communities => 'Communities',
1.272 raeburn 7734: placement => 'Placement Tests',
1.120 raeburn 7735: );
7736: my $select0 = ' selected="selected"';
7737: my $select1 = '';
1.272 raeburn 7738: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 7739: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7740: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 7741: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 7742: $select1 = $select0;
7743: $select0 = '';
7744: }
7745: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7746: .'<select name="'.$default.'_pos">'
7747: .'<option value="0"'.$select0.'>1</option>'
7748: .'<option value="1"'.$select1.'>2</option>'
7749: .'<option value="2">3</option></select> '
7750: .$default_names{$default}
7751: .'</span></td><td><span class="LC_nobreak">'
7752: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
7753: .&mt('Display').'</label> <label>'
7754: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 7755: .'</label></span></td></tr>';
1.120 raeburn 7756: $itemcount ++;
7757: }
1.48 raeburn 7758: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 7759: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 7760: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 7761: .'<select name="addcategory_pos"'.$chgstr.'>'
7762: .'<option value="0">1</option>'
7763: .'<option value="1">2</option>'
7764: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 7765: .&mt('Add category').'</td><td>'.&mt('Name:')
7766: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
7767: return $datatable;
7768: }
7769:
7770: sub build_category_rows {
1.49 raeburn 7771: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
7772: my ($text,$name,$item,$chgstr);
1.48 raeburn 7773: if (ref($cats) eq 'ARRAY') {
7774: my $maxdepth = scalar(@{$cats});
7775: if (ref($cats->[$depth]) eq 'HASH') {
7776: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
7777: my $numchildren = @{$cats->[$depth]{$parent}};
7778: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 7779: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 7780: my ($idxnum,$parent_name,$parent_item);
7781: my $higher = $depth - 1;
7782: if ($higher == 0) {
7783: $parent_name = &escape($parent).'::'.$higher;
7784: } else {
7785: if (ref($path) eq 'ARRAY') {
7786: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7787: }
7788: }
7789: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 7790: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 7791: if ($j < $numchildren) {
1.48 raeburn 7792: $name = $cats->[$depth]{$parent}[$j];
7793: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 7794: $idxnum = $idx->{$item};
7795: } else {
7796: $name = $parent_name;
7797: $item = $parent_item;
1.48 raeburn 7798: }
1.49 raeburn 7799: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
7800: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 7801: for (my $i=0; $i<=$numchildren; $i++) {
7802: my $vpos = $i+1;
7803: my $selstr;
7804: if ($j == $i) {
7805: $selstr = ' selected="selected" ';
7806: }
7807: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
7808: }
7809: $text .= '</select> ';
7810: if ($j < $numchildren) {
7811: my $deeper = $depth+1;
7812: $text .= $name.' '
7813: .'<label><input type="checkbox" name="deletecategory" value="'
7814: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
7815: if(ref($path) eq 'ARRAY') {
7816: push(@{$path},$name);
1.49 raeburn 7817: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 7818: pop(@{$path});
7819: }
7820: } else {
1.59 bisitz 7821: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 7822: if ($j == $numchildren) {
7823: $text .= $name;
7824: } else {
7825: $text .= $item;
7826: }
7827: $text .= '" value="" />';
7828: }
7829: $text .= '</td></tr>';
7830: }
7831: $text .= '</table></td>';
7832: } else {
7833: my $higher = $depth-1;
7834: if ($higher == 0) {
7835: $name = &escape($parent).'::'.$higher;
7836: } else {
7837: if (ref($path) eq 'ARRAY') {
7838: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7839: }
7840: }
7841: my $colspan;
7842: if ($parent ne 'instcode') {
7843: $colspan = $maxdepth - $depth - 1;
7844: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
7845: }
7846: }
7847: }
7848: }
7849: return $text;
7850: }
7851:
1.33 raeburn 7852: sub modifiable_userdata_row {
1.305 raeburn 7853: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
7854: $rowid,$customcss,$rowstyle) = @_;
1.228 raeburn 7855: my ($role,$rolename,$statustype);
7856: $role = $item;
1.224 raeburn 7857: if ($context eq 'cancreate') {
1.305 raeburn 7858: if ($item =~ /^(emailusername)_(.+)$/) {
7859: $role = $1;
7860: $statustype = $2;
1.228 raeburn 7861: if (ref($usertypes) eq 'HASH') {
7862: if ($usertypes->{$statustype}) {
7863: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7864: } else {
7865: $rolename = &mt('Data provided by user');
7866: }
7867: }
1.224 raeburn 7868: }
7869: } elsif ($context eq 'selfcreate') {
1.63 raeburn 7870: if (ref($usertypes) eq 'HASH') {
7871: $rolename = $usertypes->{$role};
7872: } else {
7873: $rolename = $role;
7874: }
1.33 raeburn 7875: } else {
1.63 raeburn 7876: if ($role eq 'cr') {
7877: $rolename = &mt('Custom role');
7878: } else {
7879: $rolename = &Apache::lonnet::plaintext($role);
7880: }
1.33 raeburn 7881: }
1.224 raeburn 7882: my (@fields,%fieldtitles);
7883: if (ref($fieldsref) eq 'ARRAY') {
7884: @fields = @{$fieldsref};
7885: } else {
7886: @fields = ('lastname','firstname','middlename','generation',
7887: 'permanentemail','id');
7888: }
7889: if ((ref($titlesref) eq 'HASH')) {
7890: %fieldtitles = %{$titlesref};
7891: } else {
7892: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7893: }
1.33 raeburn 7894: my $output;
1.305 raeburn 7895: my $css_class;
7896: if ($rowcount%2) {
7897: $css_class = 'LC_odd_row';
7898: }
7899: if ($customcss) {
7900: $css_class .= " $customcss";
7901: }
7902: $css_class =~ s/^\s+//;
7903: if ($css_class) {
7904: $css_class = ' class="'.$css_class.'"';
7905: }
7906: if ($rowstyle) {
7907: $css_class .= ' style="'.$rowstyle.'"';
7908: }
7909: if ($rowid) {
7910: $rowid = ' id="'.$rowid.'"';
7911: }
7912: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 7913: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7914: '<td class="LC_left_item" colspan="2"><table>';
7915: my $rem;
7916: my %checks;
7917: if (ref($settings) eq 'HASH') {
7918: if (ref($settings->{$context}) eq 'HASH') {
7919: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 7920: my $hashref = $settings->{$context}->{$role};
7921: if ($role eq 'emailusername') {
7922: if ($statustype) {
7923: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7924: $hashref = $settings->{$context}->{$role}->{$statustype};
7925: if (ref($hashref) eq 'HASH') {
7926: foreach my $field (@fields) {
7927: if ($hashref->{$field}) {
7928: $checks{$field} = $hashref->{$field};
7929: }
7930: }
7931: }
7932: }
7933: }
7934: } else {
7935: if (ref($hashref) eq 'HASH') {
7936: foreach my $field (@fields) {
7937: if ($hashref->{$field}) {
7938: $checks{$field} = ' checked="checked" ';
7939: }
7940: }
1.33 raeburn 7941: }
7942: }
7943: }
7944: }
7945: }
1.305 raeburn 7946:
7947: my $total = scalar(@fields);
7948: for (my $i=0; $i<$total; $i++) {
7949: $rem = $i%($numinrow);
1.33 raeburn 7950: if ($rem == 0) {
7951: if ($i > 0) {
7952: $output .= '</tr>';
7953: }
7954: $output .= '<tr>';
7955: }
7956: my $check = ' ';
1.228 raeburn 7957: unless ($role eq 'emailusername') {
7958: if (exists($checks{$fields[$i]})) {
7959: $check = $checks{$fields[$i]}
7960: } else {
7961: if ($role eq 'st') {
7962: if (ref($settings) ne 'HASH') {
7963: $check = ' checked="checked" ';
7964: }
1.33 raeburn 7965: }
7966: }
7967: }
7968: $output .= '<td class="LC_left_item">'.
1.228 raeburn 7969: '<span class="LC_nobreak">';
7970: if ($role eq 'emailusername') {
7971: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7972: $checks{$fields[$i]} = 'omit';
7973: }
7974: foreach my $option ('required','optional','omit') {
7975: my $checked='';
7976: if ($checks{$fields[$i]} eq $option) {
7977: $checked='checked="checked" ';
7978: }
7979: $output .= '<label>'.
7980: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7981: &mt($option).'</label>'.(' ' x2);
7982: }
7983: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7984: } else {
7985: $output .= '<label>'.
7986: '<input type="checkbox" name="canmodify_'.$role.'" '.
7987: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7988: '</label>';
7989: }
7990: $output .= '</span></td>';
1.33 raeburn 7991: }
1.305 raeburn 7992: $rem = $total%$numinrow;
7993: my $colsleft;
7994: if ($rem) {
7995: $colsleft = $numinrow - $rem;
7996: }
7997: if ($colsleft > 1) {
1.33 raeburn 7998: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7999: ' </td>';
8000: } elsif ($colsleft == 1) {
8001: $output .= '<td class="LC_left_item"> </td>';
8002: }
8003: $output .= '</tr></table></td></tr>';
8004: return $output;
8005: }
1.28 raeburn 8006:
1.93 raeburn 8007: sub insttypes_row {
1.305 raeburn 8008: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8009: $customcss,$rowstyle) = @_;
1.93 raeburn 8010: my %lt = &Apache::lonlocal::texthash (
8011: cansearch => 'Users allowed to search',
8012: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8013: lockablenames => 'User preference to lock name',
1.305 raeburn 8014: selfassign => 'Self-reportable affiliations',
1.315 raeburn 8015: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8016: );
8017: my $showdom;
8018: if ($context eq 'cansearch') {
8019: $showdom = ' ('.$dom.')';
8020: }
1.165 raeburn 8021: my $class = 'LC_left_item';
8022: if ($context eq 'statustocreate') {
8023: $class = 'LC_right_item';
8024: }
1.305 raeburn 8025: my $css_class;
8026: if ($$rowtotal%2) {
8027: $css_class = 'LC_odd_row';
8028: }
8029: if ($customcss) {
8030: $css_class .= ' '.$customcss;
8031: }
8032: $css_class =~ s/^\s+//;
8033: if ($css_class) {
8034: $css_class = ' class="'.$css_class.'"';
8035: }
8036: if ($rowstyle) {
8037: $css_class .= ' style="'.$rowstyle.'"';
8038: }
8039: if ($onclick) {
8040: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 8041: }
8042: my $output = '<tr'.$css_class.'>'.
8043: '<td>'.$lt{$context}.$showdom.
8044: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8045: my $rem;
8046: if (ref($types) eq 'ARRAY') {
8047: for (my $i=0; $i<@{$types}; $i++) {
8048: if (defined($usertypes->{$types->[$i]})) {
8049: my $rem = $i%($numinrow);
8050: if ($rem == 0) {
8051: if ($i > 0) {
8052: $output .= '</tr>';
8053: }
8054: $output .= '<tr>';
1.23 raeburn 8055: }
1.26 raeburn 8056: my $check = ' ';
1.99 raeburn 8057: if (ref($settings) eq 'HASH') {
8058: if (ref($settings->{$context}) eq 'ARRAY') {
8059: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8060: $check = ' checked="checked" ';
8061: }
1.315 raeburn 8062: } elsif (ref($settings->{$context}) eq 'HASH') {
8063: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8064: $check = ' checked="checked" ';
8065: }
1.99 raeburn 8066: } elsif ($context eq 'statustocreate') {
1.26 raeburn 8067: $check = ' checked="checked" ';
8068: }
1.23 raeburn 8069: }
1.26 raeburn 8070: $output .= '<td class="LC_left_item">'.
8071: '<span class="LC_nobreak"><label>'.
1.93 raeburn 8072: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 8073: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 8074: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 8075: }
8076: }
1.26 raeburn 8077: $rem = @{$types}%($numinrow);
1.23 raeburn 8078: }
8079: my $colsleft = $numinrow - $rem;
1.315 raeburn 8080: if ($context eq 'overrides') {
8081: if ($colsleft > 1) {
8082: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8083: } else {
8084: $output .= '<td class="LC_left_item">';
8085: }
8086: $output .= ' ';
1.23 raeburn 8087: } else {
1.315 raeburn 8088: if (($rem == 0) && (@{$types} > 0)) {
8089: $output .= '<tr>';
8090: }
8091: if ($colsleft > 1) {
8092: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8093: } else {
8094: $output .= '<td class="LC_left_item">';
8095: }
8096: my $defcheck = ' ';
8097: if (ref($settings) eq 'HASH') {
8098: if (ref($settings->{$context}) eq 'ARRAY') {
8099: if (grep(/^default$/,@{$settings->{$context}})) {
8100: $defcheck = ' checked="checked" ';
8101: }
8102: } elsif ($context eq 'statustocreate') {
1.99 raeburn 8103: $defcheck = ' checked="checked" ';
8104: }
1.26 raeburn 8105: }
1.315 raeburn 8106: $output .= '<span class="LC_nobreak"><label>'.
8107: '<input type="checkbox" name="'.$context.'" '.
8108: 'value="default"'.$defcheck.$onclick.' />'.
8109: $othertitle.'</label></span>';
1.23 raeburn 8110: }
1.315 raeburn 8111: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 8112: return $output;
1.23 raeburn 8113: }
8114:
8115: sub sorted_searchtitles {
8116: my %searchtitles = &Apache::lonlocal::texthash(
8117: 'uname' => 'username',
8118: 'lastname' => 'last name',
8119: 'lastfirst' => 'last name, first name',
8120: );
8121: my @titleorder = ('uname','lastname','lastfirst');
8122: return (\%searchtitles,\@titleorder);
8123: }
8124:
1.25 raeburn 8125: sub sorted_searchtypes {
8126: my %srchtypes_desc = (
8127: exact => 'is exact match',
8128: contains => 'contains ..',
8129: begins => 'begins with ..',
8130: );
8131: my @srchtypeorder = ('exact','begins','contains');
8132: return (\%srchtypes_desc,\@srchtypeorder);
8133: }
8134:
1.3 raeburn 8135: sub usertype_update_row {
8136: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8137: my $datatable;
8138: my $numinrow = 4;
8139: foreach my $type (@{$types}) {
8140: if (defined($usertypes->{$type})) {
8141: $$rownums ++;
8142: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8143: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8144: '</td><td class="LC_left_item"><table>';
8145: for (my $i=0; $i<@{$fields}; $i++) {
8146: my $rem = $i%($numinrow);
8147: if ($rem == 0) {
8148: if ($i > 0) {
8149: $datatable .= '</tr>';
8150: }
8151: $datatable .= '<tr>';
8152: }
8153: my $check = ' ';
1.39 raeburn 8154: if (ref($settings) eq 'HASH') {
8155: if (ref($settings->{'fields'}) eq 'HASH') {
8156: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8157: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8158: $check = ' checked="checked" ';
8159: }
1.3 raeburn 8160: }
8161: }
8162: }
8163:
8164: if ($i == @{$fields}-1) {
8165: my $colsleft = $numinrow - $rem;
8166: if ($colsleft > 1) {
8167: $datatable .= '<td colspan="'.$colsleft.'">';
8168: } else {
8169: $datatable .= '<td>';
8170: }
8171: } else {
8172: $datatable .= '<td>';
8173: }
1.8 raeburn 8174: $datatable .= '<span class="LC_nobreak"><label>'.
8175: '<input type="checkbox" name="updateable_'.$type.
8176: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
8177: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 8178: }
8179: $datatable .= '</tr></table></td></tr>';
8180: }
8181: }
8182: return $datatable;
1.1 raeburn 8183: }
8184:
8185: sub modify_login {
1.205 raeburn 8186: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 8187: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
8188: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
8189: %title = ( coursecatalog => 'Display course catalog',
8190: adminmail => 'Display administrator E-mail address',
1.188 raeburn 8191: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 8192: newuser => 'Link for visitors to create a user account',
8193: loginheader => 'Log-in box header');
8194: @offon = ('off','on');
1.112 raeburn 8195: if (ref($domconfig{login}) eq 'HASH') {
8196: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
8197: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
8198: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
8199: }
8200: }
8201: }
1.9 raeburn 8202: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
8203: \%domconfig,\%loginhash);
1.188 raeburn 8204: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8205: foreach my $item (@toggles) {
8206: $loginhash{login}{$item} = $env{'form.'.$item};
8207: }
1.41 raeburn 8208: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 8209: if (ref($colchanges{'login'}) eq 'HASH') {
8210: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
8211: \%loginhash);
8212: }
1.110 raeburn 8213:
1.149 raeburn 8214: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 8215: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 8216: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 8217: if (keys(%servers) > 1) {
8218: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 8219: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
8220: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
8221: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
8222: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
8223: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
8224: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8225: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8226: $changes{'loginvia'}{$lonhost} = 1;
8227: } else {
8228: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
8229: $changes{'loginvia'}{$lonhost} = 1;
8230: }
8231: } else {
8232: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8233: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8234: $changes{'loginvia'}{$lonhost} = 1;
8235: }
8236: }
8237: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
8238: foreach my $item (@loginvia_attribs) {
8239: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
8240: }
8241: } else {
8242: foreach my $item (@loginvia_attribs) {
8243: my $new = $env{'form.'.$lonhost.'_'.$item};
8244: if (($item eq 'serverpath') && ($new eq 'custom')) {
8245: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
8246: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8247: $new = '/';
8248: }
8249: }
8250: if (($item eq 'custompath') &&
8251: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8252: $new = '';
8253: }
8254: if ($new ne $curr_loginvia{$lonhost}{$item}) {
8255: $changes{'loginvia'}{$lonhost} = 1;
8256: }
8257: if ($item eq 'exempt') {
1.256 raeburn 8258: $new = &check_exempt_addresses($new);
1.128 raeburn 8259: }
8260: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8261: }
8262: }
1.112 raeburn 8263: } else {
1.128 raeburn 8264: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8265: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 8266: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 8267: foreach my $item (@loginvia_attribs) {
8268: my $new = $env{'form.'.$lonhost.'_'.$item};
8269: if (($item eq 'serverpath') && ($new eq 'custom')) {
8270: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8271: $new = '/';
8272: }
8273: }
8274: if (($item eq 'custompath') &&
8275: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8276: $new = '';
8277: }
8278: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8279: }
1.110 raeburn 8280: }
8281: }
8282: }
8283: }
1.119 raeburn 8284:
1.168 raeburn 8285: my $servadm = $r->dir_config('lonAdmEMail');
8286: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
8287: if (ref($domconfig{'login'}) eq 'HASH') {
8288: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
8289: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
8290: if ($lang eq 'nolang') {
8291: push(@currlangs,$lang);
8292: } elsif (defined($langchoices{$lang})) {
8293: push(@currlangs,$lang);
8294: } else {
8295: next;
8296: }
8297: }
8298: }
8299: }
8300: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
8301: if (@currlangs > 0) {
8302: foreach my $lang (@currlangs) {
8303: if (grep(/^\Q$lang\E$/,@delurls)) {
8304: $changes{'helpurl'}{$lang} = 1;
8305: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
8306: $changes{'helpurl'}{$lang} = 1;
8307: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
8308: push(@newlangs,$lang);
8309: } else {
8310: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8311: }
8312: }
8313: }
8314: unless (grep(/^nolang$/,@currlangs)) {
8315: if ($env{'form.loginhelpurl_nolang.filename'}) {
8316: $changes{'helpurl'}{'nolang'} = 1;
8317: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
8318: push(@newlangs,'nolang');
8319: }
8320: }
8321: if ($env{'form.loginhelpurl_add_lang'}) {
8322: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
8323: ($env{'form.loginhelpurl_add_file.filename'})) {
8324: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
8325: $addedfile = $env{'form.loginhelpurl_add_lang'};
8326: }
8327: }
8328: if ((@newlangs > 0) || ($addedfile)) {
8329: my $error;
8330: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8331: if ($configuserok eq 'ok') {
8332: if ($switchserver) {
8333: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
8334: } elsif ($author_ok eq 'ok') {
8335: my @allnew = @newlangs;
8336: if ($addedfile ne '') {
8337: push(@allnew,$addedfile);
8338: }
8339: foreach my $lang (@allnew) {
8340: my $formelem = 'loginhelpurl_'.$lang;
8341: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
8342: $formelem = 'loginhelpurl_add_file';
8343: }
8344: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8345: "help/$lang",'','',$newfile{$lang});
8346: if ($result eq 'ok') {
8347: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
8348: $changes{'helpurl'}{$lang} = 1;
8349: } else {
8350: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
8351: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 8352: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 8353: (!grep(/^\Q$lang\E$/,@delurls))) {
8354: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8355: }
8356: }
8357: }
8358: } else {
8359: $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);
8360: }
8361: } else {
8362: $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);
8363: }
8364: if ($error) {
8365: &Apache::lonnet::logthis($error);
8366: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8367: }
8368: }
1.256 raeburn 8369:
8370: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
8371: if (ref($domconfig{'login'}) eq 'HASH') {
8372: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
8373: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
8374: if ($domservers{$lonhost}) {
8375: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8376: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 8377: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 8378: }
8379: }
8380: }
8381: }
8382: }
8383: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
8384: foreach my $lonhost (sort(keys(%domservers))) {
8385: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8386: $changes{'headtag'}{$lonhost} = 1;
8387: } else {
8388: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
8389: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
8390: }
8391: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
8392: push(@newhosts,$lonhost);
8393: } elsif ($currheadtagurls{$lonhost}) {
8394: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
8395: if ($currexempt{$lonhost}) {
1.289 raeburn 8396: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 8397: $changes{'headtag'}{$lonhost} = 1;
8398: }
8399: } elsif ($possexempt{$lonhost}) {
8400: $changes{'headtag'}{$lonhost} = 1;
8401: }
8402: if ($possexempt{$lonhost}) {
8403: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8404: }
8405: }
8406: }
8407: }
8408: if (@newhosts) {
8409: my $error;
8410: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8411: if ($configuserok eq 'ok') {
8412: if ($switchserver) {
8413: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
8414: } elsif ($author_ok eq 'ok') {
8415: foreach my $lonhost (@newhosts) {
8416: my $formelem = 'loginheadtag_'.$lonhost;
8417: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8418: "login/headtag/$lonhost",'','',
8419: $env{'form.loginheadtag_'.$lonhost.'.filename'});
8420: if ($result eq 'ok') {
8421: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
8422: $changes{'headtag'}{$lonhost} = 1;
8423: if ($possexempt{$lonhost}) {
8424: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8425: }
8426: } else {
8427: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
8428: $newheadtagurls{$lonhost},$result);
8429: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8430: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
8431: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
8432: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
8433: }
8434: }
8435: }
8436: } else {
8437: $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);
8438: }
8439: } else {
8440: $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);
8441: }
8442: if ($error) {
8443: &Apache::lonnet::logthis($error);
8444: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8445: }
8446: }
1.169 raeburn 8447: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 8448:
8449: my $defaulthelpfile = '/adm/loginproblems.html';
8450: my $defaulttext = &mt('Default in use');
8451:
1.1 raeburn 8452: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
8453: $dom);
8454: if ($putresult eq 'ok') {
1.188 raeburn 8455: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8456: my %defaultchecked = (
8457: 'coursecatalog' => 'on',
1.188 raeburn 8458: 'helpdesk' => 'on',
1.42 raeburn 8459: 'adminmail' => 'off',
1.43 raeburn 8460: 'newuser' => 'off',
1.42 raeburn 8461: );
1.55 raeburn 8462: if (ref($domconfig{'login'}) eq 'HASH') {
8463: foreach my $item (@toggles) {
8464: if ($defaultchecked{$item} eq 'on') {
8465: if (($domconfig{'login'}{$item} eq '0') &&
8466: ($env{'form.'.$item} eq '1')) {
8467: $changes{$item} = 1;
8468: } elsif (($domconfig{'login'}{$item} eq '' ||
8469: $domconfig{'login'}{$item} eq '1') &&
8470: ($env{'form.'.$item} eq '0')) {
8471: $changes{$item} = 1;
8472: }
8473: } elsif ($defaultchecked{$item} eq 'off') {
8474: if (($domconfig{'login'}{$item} eq '1') &&
8475: ($env{'form.'.$item} eq '0')) {
8476: $changes{$item} = 1;
8477: } elsif (($domconfig{'login'}{$item} eq '' ||
8478: $domconfig{'login'}{$item} eq '0') &&
8479: ($env{'form.'.$item} eq '1')) {
8480: $changes{$item} = 1;
8481: }
1.42 raeburn 8482: }
8483: }
1.41 raeburn 8484: }
1.6 raeburn 8485: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 8486: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8487: if (ref($lastactref) eq 'HASH') {
8488: $lastactref->{'domainconfig'} = 1;
8489: }
1.1 raeburn 8490: $resulttext = &mt('Changes made:').'<ul>';
8491: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 8492: if ($item eq 'loginvia') {
1.112 raeburn 8493: if (ref($changes{$item}) eq 'HASH') {
8494: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
8495: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 8496: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
8497: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
8498: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
8499: $protocol = 'http' if ($protocol ne 'https');
8500: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
8501:
8502: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
8503: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
8504: } else {
8505: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
8506: }
8507: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
8508: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
8509: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
8510: }
8511: $resulttext .= '</li>';
8512: } else {
8513: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
8514: }
1.112 raeburn 8515: } else {
1.128 raeburn 8516: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 8517: }
8518: }
1.128 raeburn 8519: $resulttext .= '</ul></li>';
1.112 raeburn 8520: }
1.168 raeburn 8521: } elsif ($item eq 'helpurl') {
8522: if (ref($changes{$item}) eq 'HASH') {
8523: foreach my $lang (sort(keys(%{$changes{$item}}))) {
8524: if (grep(/^\Q$lang\E$/,@delurls)) {
8525: my ($chg,$link);
8526: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
8527: if ($lang eq 'nolang') {
8528: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
8529: } else {
8530: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
8531: }
8532: $resulttext .= '<li>'.$chg.'</li>';
8533: } else {
8534: my $chg;
8535: if ($lang eq 'nolang') {
8536: $chg = &mt('custom log-in help file for no preferred language');
8537: } else {
8538: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
8539: }
8540: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
8541: $loginhash{'login'}{'helpurl'}{$lang}.
8542: '?inhibitmenu=yes',$chg,600,500).
8543: '</li>';
8544: }
8545: }
8546: }
1.256 raeburn 8547: } elsif ($item eq 'headtag') {
8548: if (ref($changes{$item}) eq 'HASH') {
8549: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
8550: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8551: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
8552: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8553: $resulttext .= '<li><a href="'.
8554: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
8555: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
8556: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
8557: if ($possexempt{$lonhost}) {
8558: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
8559: } else {
8560: $resulttext .= &mt('included for any client IP');
8561: }
8562: $resulttext .= '</li>';
8563: }
8564: }
8565: }
1.169 raeburn 8566: } elsif ($item eq 'captcha') {
8567: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 8568: my $chgtxt;
1.169 raeburn 8569: if ($loginhash{'login'}{$item} eq 'notused') {
8570: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
8571: } else {
8572: my %captchas = &captcha_phrases();
8573: if ($captchas{$loginhash{'login'}{$item}}) {
8574: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
8575: } else {
8576: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
8577: }
8578: }
8579: $resulttext .= '<li>'.$chgtxt.'</li>';
8580: }
8581: } elsif ($item eq 'recaptchakeys') {
8582: if (ref($loginhash{'login'}) eq 'HASH') {
8583: my ($privkey,$pubkey);
8584: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
8585: $pubkey = $loginhash{'login'}{$item}{'public'};
8586: $privkey = $loginhash{'login'}{$item}{'private'};
8587: }
8588: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
8589: if (!$pubkey) {
8590: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
8591: } else {
8592: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8593: }
8594: if (!$privkey) {
8595: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
8596: } else {
1.251 raeburn 8597: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 8598: }
8599: $chgtxt .= '</ul>';
8600: $resulttext .= '<li>'.$chgtxt.'</li>';
8601: }
1.269 raeburn 8602: } elsif ($item eq 'recaptchaversion') {
8603: if (ref($loginhash{'login'}) eq 'HASH') {
8604: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 8605: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 8606: '</li>';
8607: }
8608: }
1.41 raeburn 8609: } else {
8610: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
8611: }
1.1 raeburn 8612: }
1.6 raeburn 8613: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 8614: } else {
8615: $resulttext = &mt('No changes made to log-in page settings');
8616: }
8617: } else {
1.11 albertel 8618: $resulttext = '<span class="LC_error">'.
8619: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8620: }
1.6 raeburn 8621: if ($errors) {
1.9 raeburn 8622: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 8623: $errors.'</ul>';
8624: }
8625: return $resulttext;
8626: }
8627:
1.256 raeburn 8628: sub check_exempt_addresses {
8629: my ($iplist) = @_;
8630: $iplist =~ s/^\s+//;
8631: $iplist =~ s/\s+$//;
8632: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
8633: my (@okips,$new);
8634: foreach my $ip (@poss_ips) {
8635: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
8636: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
8637: push(@okips,$ip);
8638: }
8639: }
8640: }
8641: if (@okips > 0) {
8642: $new = join(',',@okips);
8643: } else {
8644: $new = '';
8645: }
8646: return $new;
8647: }
8648:
1.6 raeburn 8649: sub color_font_choices {
8650: my %choices =
8651: &Apache::lonlocal::texthash (
8652: img => "Header",
8653: bgs => "Background colors",
8654: links => "Link colors",
1.55 raeburn 8655: images => "Images",
1.6 raeburn 8656: font => "Font color",
1.201 raeburn 8657: fontmenu => "Font menu",
1.76 raeburn 8658: pgbg => "Page",
1.6 raeburn 8659: tabbg => "Header",
8660: sidebg => "Border",
8661: link => "Link",
8662: alink => "Active link",
8663: vlink => "Visited link",
8664: );
8665: return %choices;
8666: }
8667:
8668: sub modify_rolecolors {
1.205 raeburn 8669: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 8670: my ($resulttext,%rolehash);
8671: $rolehash{'rolecolors'} = {};
1.55 raeburn 8672: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
8673: if ($domconfig{'rolecolors'} eq '') {
8674: $domconfig{'rolecolors'} = {};
8675: }
8676: }
1.9 raeburn 8677: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 8678: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
8679: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
8680: $dom);
8681: if ($putresult eq 'ok') {
8682: if (keys(%changes) > 0) {
1.41 raeburn 8683: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8684: if (ref($lastactref) eq 'HASH') {
8685: $lastactref->{'domainconfig'} = 1;
8686: }
1.6 raeburn 8687: $resulttext = &display_colorchgs($dom,\%changes,$roles,
8688: $rolehash{'rolecolors'});
8689: } else {
8690: $resulttext = &mt('No changes made to default color schemes');
8691: }
8692: } else {
1.11 albertel 8693: $resulttext = '<span class="LC_error">'.
8694: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 8695: }
8696: if ($errors) {
8697: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8698: $errors.'</ul>';
8699: }
8700: return $resulttext;
8701: }
8702:
8703: sub modify_colors {
1.9 raeburn 8704: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 8705: my (%changes,%choices);
1.51 raeburn 8706: my @bgs;
1.6 raeburn 8707: my @links = ('link','alink','vlink');
1.41 raeburn 8708: my @logintext;
1.6 raeburn 8709: my @images;
8710: my $servadm = $r->dir_config('lonAdmEMail');
8711: my $errors;
1.200 raeburn 8712: my %defaults;
1.6 raeburn 8713: foreach my $role (@{$roles}) {
8714: if ($role eq 'login') {
1.12 raeburn 8715: %choices = &login_choices();
1.41 raeburn 8716: @logintext = ('textcol','bgcol');
1.12 raeburn 8717: } else {
8718: %choices = &color_font_choices();
8719: }
8720: if ($role eq 'login') {
1.41 raeburn 8721: @images = ('img','logo','domlogo','login');
1.51 raeburn 8722: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 8723: } else {
8724: @images = ('img');
1.200 raeburn 8725: @bgs = ('pgbg','tabbg','sidebg');
8726: }
8727: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
8728: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
8729: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
8730: }
8731: if ($role eq 'login') {
8732: foreach my $item (@logintext) {
1.234 raeburn 8733: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8734: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8735: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8736: }
8737: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 8738: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8739: }
8740: }
8741: } else {
1.234 raeburn 8742: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
8743: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
8744: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
8745: }
8746: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 8747: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
8748: }
1.6 raeburn 8749: }
1.200 raeburn 8750: foreach my $item (@bgs) {
1.234 raeburn 8751: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8752: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8753: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8754: }
8755: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 8756: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8757: }
8758: }
8759: foreach my $item (@links) {
1.234 raeburn 8760: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8761: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8762: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8763: }
8764: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 8765: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8766: }
1.6 raeburn 8767: }
1.46 raeburn 8768: my ($configuserok,$author_ok,$switchserver) =
8769: &config_check($dom,$confname,$servadm);
1.9 raeburn 8770: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 8771: if (ref($domconfig->{$role}) ne 'HASH') {
8772: $domconfig->{$role} = {};
8773: }
1.8 raeburn 8774: foreach my $img (@images) {
1.70 raeburn 8775: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
8776: if (defined($env{'form.login_showlogo_'.$img})) {
8777: $confhash->{$role}{'showlogo'}{$img} = 1;
8778: } else {
8779: $confhash->{$role}{'showlogo'}{$img} = 0;
8780: }
8781: }
1.18 albertel 8782: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
8783: && !defined($domconfig->{$role}{$img})
8784: && !$env{'form.'.$role.'_del_'.$img}
8785: && $env{'form.'.$role.'_import_'.$img}) {
8786: # import the old configured image from the .tab setting
8787: # if they haven't provided a new one
8788: $domconfig->{$role}{$img} =
8789: $env{'form.'.$role.'_import_'.$img};
8790: }
1.6 raeburn 8791: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 8792: my $error;
1.6 raeburn 8793: if ($configuserok eq 'ok') {
1.9 raeburn 8794: if ($switchserver) {
1.12 raeburn 8795: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 8796: } else {
8797: if ($author_ok eq 'ok') {
8798: my ($result,$logourl) =
8799: &publishlogo($r,'upload',$role.'_'.$img,
8800: $dom,$confname,$img,$width,$height);
8801: if ($result eq 'ok') {
8802: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 8803: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8804: } else {
1.12 raeburn 8805: $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 8806: }
8807: } else {
1.46 raeburn 8808: $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 8809: }
8810: }
8811: } else {
1.46 raeburn 8812: $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 8813: }
8814: if ($error) {
1.8 raeburn 8815: &Apache::lonnet::logthis($error);
1.11 albertel 8816: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 8817: }
8818: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 8819: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
8820: my $error;
8821: if ($configuserok eq 'ok') {
8822: # is confname an author?
8823: if ($switchserver eq '') {
8824: if ($author_ok eq 'ok') {
8825: my ($result,$logourl) =
8826: &publishlogo($r,'copy',$domconfig->{$role}{$img},
8827: $dom,$confname,$img,$width,$height);
8828: if ($result eq 'ok') {
8829: $confhash->{$role}{$img} = $logourl;
1.18 albertel 8830: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8831: }
8832: }
8833: }
8834: }
1.6 raeburn 8835: }
8836: }
8837: }
8838: if (ref($domconfig) eq 'HASH') {
8839: if (ref($domconfig->{$role}) eq 'HASH') {
8840: foreach my $img (@images) {
8841: if ($domconfig->{$role}{$img} ne '') {
8842: if ($env{'form.'.$role.'_del_'.$img}) {
8843: $confhash->{$role}{$img} = '';
1.12 raeburn 8844: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8845: } else {
1.9 raeburn 8846: if ($confhash->{$role}{$img} eq '') {
8847: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8848: }
1.6 raeburn 8849: }
8850: } else {
8851: if ($env{'form.'.$role.'_del_'.$img}) {
8852: $confhash->{$role}{$img} = '';
1.12 raeburn 8853: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8854: }
8855: }
1.70 raeburn 8856: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8857: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8858: if ($confhash->{$role}{'showlogo'}{$img} ne
8859: $domconfig->{$role}{'showlogo'}{$img}) {
8860: $changes{$role}{'showlogo'}{$img} = 1;
8861: }
8862: } else {
8863: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8864: $changes{$role}{'showlogo'}{$img} = 1;
8865: }
8866: }
8867: }
8868: }
1.6 raeburn 8869: if ($domconfig->{$role}{'font'} ne '') {
8870: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8871: $changes{$role}{'font'} = 1;
8872: }
8873: } else {
8874: if ($confhash->{$role}{'font'}) {
8875: $changes{$role}{'font'} = 1;
8876: }
8877: }
1.107 raeburn 8878: if ($role ne 'login') {
8879: if ($domconfig->{$role}{'fontmenu'} ne '') {
8880: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8881: $changes{$role}{'fontmenu'} = 1;
8882: }
8883: } else {
8884: if ($confhash->{$role}{'fontmenu'}) {
8885: $changes{$role}{'fontmenu'} = 1;
8886: }
1.97 tempelho 8887: }
8888: }
1.6 raeburn 8889: foreach my $item (@bgs) {
8890: if ($domconfig->{$role}{$item} ne '') {
8891: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8892: $changes{$role}{'bgs'}{$item} = 1;
8893: }
8894: } else {
8895: if ($confhash->{$role}{$item}) {
8896: $changes{$role}{'bgs'}{$item} = 1;
8897: }
8898: }
8899: }
8900: foreach my $item (@links) {
8901: if ($domconfig->{$role}{$item} ne '') {
8902: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8903: $changes{$role}{'links'}{$item} = 1;
8904: }
8905: } else {
8906: if ($confhash->{$role}{$item}) {
8907: $changes{$role}{'links'}{$item} = 1;
8908: }
8909: }
8910: }
1.41 raeburn 8911: foreach my $item (@logintext) {
8912: if ($domconfig->{$role}{$item} ne '') {
8913: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8914: $changes{$role}{'logintext'}{$item} = 1;
8915: }
8916: } else {
8917: if ($confhash->{$role}{$item}) {
8918: $changes{$role}{'logintext'}{$item} = 1;
8919: }
8920: }
8921: }
1.6 raeburn 8922: } else {
8923: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8924: \@logintext,$confhash,\%changes);
1.6 raeburn 8925: }
8926: } else {
8927: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8928: \@logintext,$confhash,\%changes);
1.6 raeburn 8929: }
8930: }
8931: return ($errors,%changes);
8932: }
8933:
1.46 raeburn 8934: sub config_check {
8935: my ($dom,$confname,$servadm) = @_;
8936: my ($configuserok,$author_ok,$switchserver,%currroles);
8937: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8938: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8939: $confname,$servadm);
8940: if ($configuserok eq 'ok') {
8941: $switchserver = &check_switchserver($dom,$confname);
8942: if ($switchserver eq '') {
8943: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8944: }
8945: }
8946: return ($configuserok,$author_ok,$switchserver);
8947: }
8948:
1.6 raeburn 8949: sub default_change_checker {
1.41 raeburn 8950: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8951: foreach my $item (@{$links}) {
8952: if ($confhash->{$role}{$item}) {
8953: $changes->{$role}{'links'}{$item} = 1;
8954: }
8955: }
8956: foreach my $item (@{$bgs}) {
8957: if ($confhash->{$role}{$item}) {
8958: $changes->{$role}{'bgs'}{$item} = 1;
8959: }
8960: }
1.41 raeburn 8961: foreach my $item (@{$logintext}) {
8962: if ($confhash->{$role}{$item}) {
8963: $changes->{$role}{'logintext'}{$item} = 1;
8964: }
8965: }
1.6 raeburn 8966: foreach my $img (@{$images}) {
8967: if ($env{'form.'.$role.'_del_'.$img}) {
8968: $confhash->{$role}{$img} = '';
1.12 raeburn 8969: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8970: }
1.70 raeburn 8971: if ($role eq 'login') {
8972: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8973: $changes->{$role}{'showlogo'}{$img} = 1;
8974: }
8975: }
1.6 raeburn 8976: }
8977: if ($confhash->{$role}{'font'}) {
8978: $changes->{$role}{'font'} = 1;
8979: }
1.48 raeburn 8980: }
1.6 raeburn 8981:
8982: sub display_colorchgs {
8983: my ($dom,$changes,$roles,$confhash) = @_;
8984: my (%choices,$resulttext);
8985: if (!grep(/^login$/,@{$roles})) {
8986: $resulttext = &mt('Changes made:').'<br />';
8987: }
8988: foreach my $role (@{$roles}) {
8989: if ($role eq 'login') {
8990: %choices = &login_choices();
8991: } else {
8992: %choices = &color_font_choices();
8993: }
8994: if (ref($changes->{$role}) eq 'HASH') {
8995: if ($role ne 'login') {
8996: $resulttext .= '<h4>'.&mt($role).'</h4>';
8997: }
8998: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8999: if ($role ne 'login') {
9000: $resulttext .= '<ul>';
9001: }
9002: if (ref($changes->{$role}{$key}) eq 'HASH') {
9003: if ($role ne 'login') {
9004: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
9005: }
9006: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 9007: if (($role eq 'login') && ($key eq 'showlogo')) {
9008: if ($confhash->{$role}{$key}{$item}) {
9009: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
9010: } else {
9011: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
9012: }
9013: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 9014: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
9015: } else {
1.12 raeburn 9016: my $newitem = $confhash->{$role}{$item};
9017: if ($key eq 'images') {
1.306 raeburn 9018: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 9019: }
9020: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 9021: }
9022: }
9023: if ($role ne 'login') {
9024: $resulttext .= '</ul></li>';
9025: }
9026: } else {
9027: if ($confhash->{$role}{$key} eq '') {
9028: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
9029: } else {
9030: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
9031: }
9032: }
9033: if ($role ne 'login') {
9034: $resulttext .= '</ul>';
9035: }
9036: }
9037: }
9038: }
1.3 raeburn 9039: return $resulttext;
1.1 raeburn 9040: }
9041:
1.9 raeburn 9042: sub thumb_dimensions {
9043: return ('200','50');
9044: }
9045:
1.16 raeburn 9046: sub check_dimensions {
9047: my ($inputfile) = @_;
9048: my ($fullwidth,$fullheight);
9049: if ($inputfile =~ m|^[/\w.\-]+$|) {
9050: if (open(PIPE,"identify $inputfile 2>&1 |")) {
9051: my $imageinfo = <PIPE>;
9052: if (!close(PIPE)) {
9053: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
9054: }
9055: chomp($imageinfo);
9056: my ($fullsize) =
1.21 raeburn 9057: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 9058: if ($fullsize) {
9059: ($fullwidth,$fullheight) = split(/x/,$fullsize);
9060: }
9061: }
9062: }
9063: return ($fullwidth,$fullheight);
9064: }
9065:
1.9 raeburn 9066: sub check_configuser {
9067: my ($uhome,$dom,$confname,$servadm) = @_;
9068: my ($configuserok,%currroles);
9069: if ($uhome eq 'no_host') {
9070: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
9071: my $configpass = &LONCAPA::Enrollment::create_password();
9072: $configuserok =
9073: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
9074: $configpass,'','','','','',undef,$servadm);
9075: } else {
9076: $configuserok = 'ok';
9077: %currroles =
9078: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
9079: }
9080: return ($configuserok,%currroles);
9081: }
9082:
9083: sub check_authorstatus {
9084: my ($dom,$confname,%currroles) = @_;
9085: my $author_ok;
1.40 raeburn 9086: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 9087: my $start = time;
9088: my $end = 0;
9089: $author_ok =
9090: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 9091: 'au',$end,$start,'','','domconfig');
1.9 raeburn 9092: } else {
9093: $author_ok = 'ok';
9094: }
9095: return $author_ok;
9096: }
9097:
9098: sub publishlogo {
1.46 raeburn 9099: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 9100: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 9101: if ($action eq 'upload') {
9102: $fname=$env{'form.'.$formname.'.filename'};
9103: chop($env{'form.'.$formname});
9104: } else {
9105: ($fname) = ($formname =~ /([^\/]+)$/);
9106: }
1.46 raeburn 9107: if ($savefileas ne '') {
9108: $fname = $savefileas;
9109: }
1.9 raeburn 9110: $fname=&Apache::lonnet::clean_filename($fname);
9111: # See if there is anything left
9112: unless ($fname) { return ('error: no uploaded file'); }
9113: $fname="$subdir/$fname";
1.210 raeburn 9114: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 9115: my $filepath="$docroot/priv";
9116: my $relpath = "$dom/$confname";
1.9 raeburn 9117: my ($fnamepath,$file,$fetchthumb);
9118: $file=$fname;
9119: if ($fname=~m|/|) {
9120: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
9121: }
1.164 raeburn 9122: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 9123: my $count;
1.164 raeburn 9124: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 9125: $filepath.="/$parts[$count]";
9126: if ((-e $filepath)!=1) {
9127: mkdir($filepath,02770);
9128: }
9129: }
9130: # Check for bad extension and disallow upload
9131: if ($file=~/\.(\w+)$/ &&
9132: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
9133: $output =
1.207 bisitz 9134: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 9135: } elsif ($file=~/\.(\w+)$/ &&
9136: !defined(&Apache::loncommon::fileembstyle($1))) {
9137: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
9138: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 9139: $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 9140: } elsif (-d "$filepath/$file") {
1.195 bisitz 9141: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 9142: } else {
9143: my $source = $filepath.'/'.$file;
9144: my $logfile;
1.316 raeburn 9145: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 9146: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 9147: }
9148: print $logfile
9149: "\n================= Publish ".localtime()." ================\n".
9150: $env{'user.name'}.':'.$env{'user.domain'}."\n";
9151: # Save the file
1.316 raeburn 9152: if (!open(FH,">",$source)) {
1.9 raeburn 9153: &Apache::lonnet::logthis('Failed to create '.$source);
9154: return (&mt('Failed to create file'));
9155: }
9156: if ($action eq 'upload') {
9157: if (!print FH ($env{'form.'.$formname})) {
9158: &Apache::lonnet::logthis('Failed to write to '.$source);
9159: return (&mt('Failed to write file'));
9160: }
9161: } else {
9162: my $original = &Apache::lonnet::filelocation('',$formname);
9163: if(!copy($original,$source)) {
9164: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
9165: return (&mt('Failed to write file'));
9166: }
9167: }
9168: close(FH);
9169: chmod(0660, $source); # Permissions to rw-rw---.
9170:
9171: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
9172: my $copyfile=$targetdir.'/'.$file;
9173:
9174: my @parts=split(/\//,$targetdir);
9175: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
9176: for (my $count=5;$count<=$#parts;$count++) {
9177: $path.="/$parts[$count]";
9178: if (!-e $path) {
9179: print $logfile "\nCreating directory ".$path;
9180: mkdir($path,02770);
9181: }
9182: }
9183: my $versionresult;
9184: if (-e $copyfile) {
9185: $versionresult = &logo_versioning($targetdir,$file,$logfile);
9186: } else {
9187: $versionresult = 'ok';
9188: }
9189: if ($versionresult eq 'ok') {
9190: if (copy($source,$copyfile)) {
9191: print $logfile "\nCopied original source to ".$copyfile."\n";
9192: $output = 'ok';
9193: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 9194: push(@{$modified_urls},[$copyfile,$source]);
9195: my $metaoutput =
9196: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
9197: unless ($registered_cleanup) {
9198: my $handlers = $r->get_handlers('PerlCleanupHandler');
9199: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9200: $registered_cleanup=1;
9201: }
1.9 raeburn 9202: } else {
9203: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
9204: $output = &mt('Failed to copy file to RES space').", $!";
9205: }
9206: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
9207: my $inputfile = $filepath.'/'.$file;
9208: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 9209: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
9210: if ($fullwidth ne '' && $fullheight ne '') {
9211: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
9212: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 9213: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
9214: system({$args[0]} @args);
1.16 raeburn 9215: chmod(0660, $filepath.'/tn-'.$file);
9216: if (-e $outfile) {
9217: my $copyfile=$targetdir.'/tn-'.$file;
9218: if (copy($outfile,$copyfile)) {
9219: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 9220: my $thumb_metaoutput =
9221: &write_metadata($dom,$confname,$formname,
9222: $targetdir,'tn-'.$file,$logfile);
9223: push(@{$modified_urls},[$copyfile,$outfile]);
9224: unless ($registered_cleanup) {
9225: my $handlers = $r->get_handlers('PerlCleanupHandler');
9226: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9227: $registered_cleanup=1;
9228: }
1.267 raeburn 9229: $madethumb = 1;
1.16 raeburn 9230: } else {
9231: print $logfile "\nUnable to write ".$copyfile.
9232: ':'.$!."\n";
9233: }
9234: }
1.9 raeburn 9235: }
9236: }
9237: }
9238: } else {
9239: $output = $versionresult;
9240: }
9241: }
1.267 raeburn 9242: return ($output,$logourl,$madethumb);
1.9 raeburn 9243: }
9244:
9245: sub logo_versioning {
9246: my ($targetdir,$file,$logfile) = @_;
9247: my $target = $targetdir.'/'.$file;
9248: my ($maxversion,$fn,$extn,$output);
9249: $maxversion = 0;
9250: if ($file =~ /^(.+)\.(\w+)$/) {
9251: $fn=$1;
9252: $extn=$2;
9253: }
9254: opendir(DIR,$targetdir);
9255: while (my $filename=readdir(DIR)) {
9256: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
9257: $maxversion=($1>$maxversion)?$1:$maxversion;
9258: }
9259: }
9260: $maxversion++;
9261: print $logfile "\nCreating old version ".$maxversion."\n";
9262: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
9263: if (copy($target,$copyfile)) {
9264: print $logfile "Copied old target to ".$copyfile."\n";
9265: $copyfile=$copyfile.'.meta';
9266: if (copy($target.'.meta',$copyfile)) {
9267: print $logfile "Copied old target metadata to ".$copyfile."\n";
9268: $output = 'ok';
9269: } else {
9270: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
9271: $output = &mt('Failed to copy old meta').", $!, ";
9272: }
9273: } else {
9274: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
9275: $output = &mt('Failed to copy old target').", $!, ";
9276: }
9277: return $output;
9278: }
9279:
9280: sub write_metadata {
9281: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
9282: my (%metadatafields,%metadatakeys,$output);
9283: $metadatafields{'title'}=$formname;
9284: $metadatafields{'creationdate'}=time;
9285: $metadatafields{'lastrevisiondate'}=time;
9286: $metadatafields{'copyright'}='public';
9287: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
9288: $env{'user.domain'};
9289: $metadatafields{'authorspace'}=$confname.':'.$dom;
9290: $metadatafields{'domain'}=$dom;
9291: {
9292: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
9293: my $mfh;
1.316 raeburn 9294: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 9295: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 9296: unless ($_=~/\./) {
9297: my $unikey=$_;
9298: $unikey=~/^([A-Za-z]+)/;
9299: my $tag=$1;
9300: $tag=~tr/A-Z/a-z/;
9301: print $mfh "\n\<$tag";
9302: foreach (split(/\,/,$metadatakeys{$unikey})) {
9303: my $value=$metadatafields{$unikey.'.'.$_};
9304: $value=~s/\"/\'\'/g;
9305: print $mfh ' '.$_.'="'.$value.'"';
9306: }
9307: print $mfh '>'.
9308: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
9309: .'</'.$tag.'>';
9310: }
9311: }
9312: $output = 'ok';
9313: print $logfile "\nWrote metadata";
9314: close($mfh);
9315: } else {
9316: print $logfile "\nFailed to open metadata file";
1.9 raeburn 9317: $output = &mt('Could not write metadata');
9318: }
9319: }
1.155 raeburn 9320: return $output;
9321: }
9322:
9323: sub notifysubscribed {
9324: foreach my $targetsource (@{$modified_urls}){
9325: next unless (ref($targetsource) eq 'ARRAY');
9326: my ($target,$source)=@{$targetsource};
9327: if ($source ne '') {
1.316 raeburn 9328: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 9329: print $logfh "\nCleanup phase: Notifications\n";
9330: my @subscribed=&subscribed_hosts($target);
9331: foreach my $subhost (@subscribed) {
9332: print $logfh "\nNotifying host ".$subhost.':';
9333: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
9334: print $logfh $reply;
9335: }
9336: my @subscribedmeta=&subscribed_hosts("$target.meta");
9337: foreach my $subhost (@subscribedmeta) {
9338: print $logfh "\nNotifying host for metadata only ".$subhost.':';
9339: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
9340: $subhost);
9341: print $logfh $reply;
9342: }
9343: print $logfh "\n============ Done ============\n";
1.160 raeburn 9344: close($logfh);
1.155 raeburn 9345: }
9346: }
9347: }
9348: return OK;
9349: }
9350:
9351: sub subscribed_hosts {
9352: my ($target) = @_;
9353: my @subscribed;
1.316 raeburn 9354: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 9355: while (my $subline=<$fh>) {
9356: if ($subline =~ /^($match_lonid):/) {
9357: my $host = $1;
9358: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
9359: unless (grep(/^\Q$host\E$/,@subscribed)) {
9360: push(@subscribed,$host);
9361: }
9362: }
9363: }
9364: }
9365: }
9366: return @subscribed;
1.9 raeburn 9367: }
9368:
9369: sub check_switchserver {
9370: my ($dom,$confname) = @_;
9371: my ($allowed,$switchserver);
9372: my $home = &Apache::lonnet::homeserver($confname,$dom);
9373: if ($home eq 'no_host') {
9374: $home = &Apache::lonnet::domain($dom,'primary');
9375: }
9376: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 9377: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
9378: if (!$allowed) {
1.180 raeburn 9379: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 9380: }
9381: return $switchserver;
9382: }
9383:
1.1 raeburn 9384: sub modify_quotas {
1.216 raeburn 9385: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 9386: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 9387: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 9388: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
9389: $validationfieldsref);
1.86 raeburn 9390: if ($action eq 'quotas') {
9391: $context = 'tools';
1.163 raeburn 9392: } else {
1.86 raeburn 9393: $context = $action;
9394: }
9395: if ($context eq 'requestcourses') {
1.271 raeburn 9396: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 9397: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 9398: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
9399: %titles = &courserequest_titles();
9400: $toolregexp = join('|',@usertools);
9401: %conditions = &courserequest_conditions();
1.216 raeburn 9402: $confname = $dom.'-domainconfig';
9403: my $servadm = $r->dir_config('lonAdmEMail');
9404: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 9405: ($validationitemsref,$validationnamesref,$validationfieldsref) =
9406: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 9407: } elsif ($context eq 'requestauthor') {
9408: @usertools = ('author');
9409: %titles = &authorrequest_titles();
1.86 raeburn 9410: } else {
1.162 raeburn 9411: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 9412: %titles = &tool_titles();
1.86 raeburn 9413: }
1.212 raeburn 9414: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 9415: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9416: foreach my $key (keys(%env)) {
1.101 raeburn 9417: if ($context eq 'requestcourses') {
9418: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
9419: my $item = $1;
9420: my $type = $2;
9421: if ($type =~ /^limit_(.+)/) {
9422: $limithash{$item}{$1} = $env{$key};
9423: } else {
9424: $confhash{$item}{$type} = $env{$key};
9425: }
9426: }
1.163 raeburn 9427: } elsif ($context eq 'requestauthor') {
9428: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
9429: $confhash{$1} = $env{$key};
9430: }
1.101 raeburn 9431: } else {
1.86 raeburn 9432: if ($key =~ /^form\.quota_(.+)$/) {
9433: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 9434: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
9435: $confhash{'authorquota'}{$1} = $env{$key};
9436: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 9437: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
9438: }
1.72 raeburn 9439: }
9440: }
1.163 raeburn 9441: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 9442: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 9443: @approvalnotify = sort(@approvalnotify);
9444: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 9445: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 9446: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
9447: foreach my $type (@hasuniquecode) {
9448: if (grep(/^\Q$type\E$/,@crstypes)) {
9449: $confhash{'uniquecode'}{$type} = 1;
9450: }
1.216 raeburn 9451: }
1.242 raeburn 9452: my (%newbook,%allpos);
1.216 raeburn 9453: if ($context eq 'requestcourses') {
1.242 raeburn 9454: foreach my $type ('textbooks','templates') {
9455: @{$allpos{$type}} = ();
9456: my $invalid;
9457: if ($type eq 'textbooks') {
9458: $invalid = &mt('Invalid LON-CAPA course for textbook');
9459: } else {
9460: $invalid = &mt('Invalid LON-CAPA course for template');
9461: }
9462: if ($env{'form.'.$type.'_addbook'}) {
9463: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
9464: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
9465: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
9466: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
9467: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
9468: } else {
9469: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
9470: my $position = $env{'form.'.$type.'_addbook_pos'};
9471: $position =~ s/\D+//g;
9472: if ($position ne '') {
9473: $allpos{$type}[$position] = $newbook{$type};
9474: }
1.216 raeburn 9475: }
1.242 raeburn 9476: } else {
9477: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 9478: }
9479: }
1.242 raeburn 9480: }
1.216 raeburn 9481: }
1.102 raeburn 9482: if (ref($domconfig{$action}) eq 'HASH') {
9483: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
9484: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
9485: $changes{'notify'}{'approval'} = 1;
9486: }
9487: } else {
1.144 raeburn 9488: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9489: $changes{'notify'}{'approval'} = 1;
9490: }
9491: }
1.218 raeburn 9492: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
9493: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9494: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
9495: unless ($confhash{'uniquecode'}{$crstype}) {
9496: $changes{'uniquecode'} = 1;
9497: }
9498: }
9499: unless ($changes{'uniquecode'}) {
9500: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
9501: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
9502: $changes{'uniquecode'} = 1;
9503: }
9504: }
9505: }
9506: } else {
9507: $changes{'uniquecode'} = 1;
9508: }
9509: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
9510: $changes{'uniquecode'} = 1;
1.216 raeburn 9511: }
9512: if ($context eq 'requestcourses') {
1.242 raeburn 9513: foreach my $type ('textbooks','templates') {
9514: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9515: my %deletions;
9516: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
9517: if (@todelete) {
9518: map { $deletions{$_} = 1; } @todelete;
9519: }
9520: my %imgdeletions;
9521: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
9522: if (@todeleteimages) {
9523: map { $imgdeletions{$_} = 1; } @todeleteimages;
9524: }
9525: my $maxnum = $env{'form.'.$type.'_maxnum'};
9526: for (my $i=0; $i<=$maxnum; $i++) {
9527: my $itemid = $env{'form.'.$type.'_id_'.$i};
9528: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
9529: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
9530: if ($deletions{$key}) {
9531: if ($domconfig{$action}{$type}{$key}{'image'}) {
9532: #FIXME need to obsolete item in RES space
9533: }
9534: next;
9535: } else {
9536: my $newpos = $env{'form.'.$itemid};
9537: $newpos =~ s/\D+//g;
1.243 raeburn 9538: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 9539: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 9540: ($type eq 'templates'));
1.242 raeburn 9541: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
9542: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
9543: $changes{$type}{$key} = 1;
9544: }
9545: }
9546: $allpos{$type}[$newpos] = $key;
9547: }
9548: if ($imgdeletions{$key}) {
9549: $changes{$type}{$key} = 1;
1.216 raeburn 9550: #FIXME need to obsolete item in RES space
1.242 raeburn 9551: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
9552: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 9553: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
9554: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
9555: } else {
9556: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
9557: $cdom,$cnum,$type,$configuserok,
9558: $switchserver,$author_ok);
9559: if ($imgurl) {
9560: $confhash{$type}{$key}{'image'} = $imgurl;
9561: $changes{$type}{$key} = 1;
9562: }
9563: if ($error) {
9564: &Apache::lonnet::logthis($error);
9565: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9566: }
9567: }
1.242 raeburn 9568: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
9569: $confhash{$type}{$key}{'image'} =
9570: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 9571: }
9572: }
9573: }
9574: }
9575: }
9576: }
1.102 raeburn 9577: } else {
1.144 raeburn 9578: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9579: $changes{'notify'}{'approval'} = 1;
9580: }
1.218 raeburn 9581: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 9582: $changes{'uniquecode'} = 1;
9583: }
9584: }
9585: if ($context eq 'requestcourses') {
1.242 raeburn 9586: foreach my $type ('textbooks','templates') {
9587: if ($newbook{$type}) {
9588: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 9589: foreach my $item ('subject','title','publisher','author') {
9590: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9591: ($type eq 'template'));
1.242 raeburn 9592: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
9593: if ($env{'form.'.$type.'_addbook_'.$item}) {
9594: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
9595: }
9596: }
9597: if ($type eq 'textbooks') {
9598: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
9599: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 9600: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
9601: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
9602: } else {
9603: my ($imageurl,$error) =
9604: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
9605: $configuserok,$switchserver,$author_ok);
9606: if ($imageurl) {
9607: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
9608: }
9609: if ($error) {
9610: &Apache::lonnet::logthis($error);
9611: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9612: }
1.242 raeburn 9613: }
9614: }
1.216 raeburn 9615: }
9616: }
1.242 raeburn 9617: if (@{$allpos{$type}} > 0) {
9618: my $idx = 0;
9619: foreach my $item (@{$allpos{$type}}) {
9620: if ($item ne '') {
9621: $confhash{$type}{$item}{'order'} = $idx;
9622: if (ref($domconfig{$action}) eq 'HASH') {
9623: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9624: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
9625: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
9626: $changes{$type}{$item} = 1;
9627: }
1.216 raeburn 9628: }
9629: }
9630: }
1.242 raeburn 9631: $idx ++;
1.216 raeburn 9632: }
9633: }
9634: }
9635: }
1.235 raeburn 9636: if (ref($validationitemsref) eq 'ARRAY') {
9637: foreach my $item (@{$validationitemsref}) {
9638: if ($item eq 'fields') {
9639: my @changed;
9640: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
9641: if (@{$confhash{'validation'}{$item}} > 0) {
9642: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
9643: }
1.266 raeburn 9644: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9645: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9646: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
9647: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
9648: $domconfig{'requestcourses'}{'validation'}{$item});
9649: } else {
9650: @changed = @{$confhash{'validation'}{$item}};
9651: }
1.235 raeburn 9652: } else {
9653: @changed = @{$confhash{'validation'}{$item}};
9654: }
9655: } else {
9656: @changed = @{$confhash{'validation'}{$item}};
9657: }
9658: if (@changed) {
9659: if ($confhash{'validation'}{$item}) {
9660: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
9661: } else {
9662: $changes{'validation'}{$item} = &mt('None');
9663: }
9664: }
9665: } else {
9666: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
9667: if ($item eq 'markup') {
9668: if ($env{'form.requestcourses_validation_'.$item}) {
9669: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
9670: }
9671: }
1.266 raeburn 9672: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9673: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9674: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
9675: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9676: }
9677: } else {
9678: if ($confhash{'validation'}{$item} ne '') {
9679: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9680: }
1.235 raeburn 9681: }
9682: } else {
9683: if ($confhash{'validation'}{$item} ne '') {
9684: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9685: }
9686: }
9687: }
9688: }
9689: }
9690: if ($env{'form.validationdc'}) {
9691: my $newval = $env{'form.validationdc'};
1.285 raeburn 9692: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 9693: if (exists($domcoords{$newval})) {
9694: $confhash{'validation'}{'dc'} = $newval;
9695: }
9696: }
9697: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 9698: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9699: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9700: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9701: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
9702: if ($confhash{'validation'}{'dc'} eq '') {
9703: $changes{'validation'}{'dc'} = &mt('None');
9704: } else {
9705: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9706: }
1.235 raeburn 9707: }
1.266 raeburn 9708: } elsif ($confhash{'validation'}{'dc'} ne '') {
9709: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 9710: }
9711: } elsif ($confhash{'validation'}{'dc'} ne '') {
9712: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9713: }
9714: } elsif ($confhash{'validation'}{'dc'} ne '') {
9715: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 9716: }
1.266 raeburn 9717: } else {
9718: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9719: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9720: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9721: $changes{'validation'}{'dc'} = &mt('None');
9722: }
9723: }
1.235 raeburn 9724: }
9725: }
1.102 raeburn 9726: }
9727: } else {
1.86 raeburn 9728: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 9729: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 9730: }
1.72 raeburn 9731: foreach my $item (@usertools) {
9732: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 9733: my $unset;
1.101 raeburn 9734: if ($context eq 'requestcourses') {
1.104 raeburn 9735: $unset = '0';
9736: if ($type eq '_LC_adv') {
9737: $unset = '';
9738: }
1.101 raeburn 9739: if ($confhash{$item}{$type} eq 'autolimit') {
9740: $confhash{$item}{$type} .= '=';
9741: unless ($limithash{$item}{$type} =~ /\D/) {
9742: $confhash{$item}{$type} .= $limithash{$item}{$type};
9743: }
9744: }
1.163 raeburn 9745: } elsif ($context eq 'requestauthor') {
9746: $unset = '0';
9747: if ($type eq '_LC_adv') {
9748: $unset = '';
9749: }
1.72 raeburn 9750: } else {
1.101 raeburn 9751: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
9752: $confhash{$item}{$type} = 1;
9753: } else {
9754: $confhash{$item}{$type} = 0;
9755: }
1.72 raeburn 9756: }
1.86 raeburn 9757: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 9758: if ($action eq 'requestauthor') {
9759: if ($domconfig{$action}{$type} ne $confhash{$type}) {
9760: $changes{$type} = 1;
9761: }
9762: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 9763: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
9764: $changes{$item}{$type} = 1;
9765: }
9766: } else {
9767: if ($context eq 'requestcourses') {
1.104 raeburn 9768: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 9769: $changes{$item}{$type} = 1;
9770: }
9771: } else {
9772: if (!$confhash{$item}{$type}) {
9773: $changes{$item}{$type} = 1;
9774: }
9775: }
9776: }
9777: } else {
9778: if ($context eq 'requestcourses') {
1.104 raeburn 9779: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 9780: $changes{$item}{$type} = 1;
9781: }
1.163 raeburn 9782: } elsif ($context eq 'requestauthor') {
9783: if ($confhash{$type} ne $unset) {
9784: $changes{$type} = 1;
9785: }
1.72 raeburn 9786: } else {
9787: if (!$confhash{$item}{$type}) {
9788: $changes{$item}{$type} = 1;
9789: }
9790: }
9791: }
1.1 raeburn 9792: }
9793: }
1.163 raeburn 9794: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 9795: if (ref($domconfig{'quotas'}) eq 'HASH') {
9796: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9797: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
9798: if (exists($confhash{'defaultquota'}{$key})) {
9799: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
9800: $changes{'defaultquota'}{$key} = 1;
9801: }
9802: } else {
9803: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 9804: }
9805: }
1.86 raeburn 9806: } else {
9807: foreach my $key (keys(%{$domconfig{'quotas'}})) {
9808: if (exists($confhash{'defaultquota'}{$key})) {
9809: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
9810: $changes{'defaultquota'}{$key} = 1;
9811: }
9812: } else {
9813: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 9814: }
1.1 raeburn 9815: }
9816: }
1.197 raeburn 9817: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9818: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
9819: if (exists($confhash{'authorquota'}{$key})) {
9820: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
9821: $changes{'authorquota'}{$key} = 1;
9822: }
9823: } else {
9824: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
9825: }
9826: }
9827: }
1.1 raeburn 9828: }
1.86 raeburn 9829: if (ref($confhash{'defaultquota'}) eq 'HASH') {
9830: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
9831: if (ref($domconfig{'quotas'}) eq 'HASH') {
9832: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9833: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
9834: $changes{'defaultquota'}{$key} = 1;
9835: }
9836: } else {
9837: if (!exists($domconfig{'quotas'}{$key})) {
9838: $changes{'defaultquota'}{$key} = 1;
9839: }
1.72 raeburn 9840: }
9841: } else {
1.86 raeburn 9842: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 9843: }
1.1 raeburn 9844: }
9845: }
1.197 raeburn 9846: if (ref($confhash{'authorquota'}) eq 'HASH') {
9847: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9848: if (ref($domconfig{'quotas'}) eq 'HASH') {
9849: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9850: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9851: $changes{'authorquota'}{$key} = 1;
9852: }
9853: } else {
9854: $changes{'authorquota'}{$key} = 1;
9855: }
9856: } else {
9857: $changes{'authorquota'}{$key} = 1;
9858: }
9859: }
9860: }
1.1 raeburn 9861: }
1.72 raeburn 9862:
1.163 raeburn 9863: if ($context eq 'requestauthor') {
9864: $domdefaults{'requestauthor'} = \%confhash;
9865: } else {
9866: foreach my $key (keys(%confhash)) {
1.242 raeburn 9867: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 9868: $domdefaults{$key} = $confhash{$key};
9869: }
1.163 raeburn 9870: }
1.72 raeburn 9871: }
1.163 raeburn 9872:
1.1 raeburn 9873: my %quotahash = (
1.86 raeburn 9874: $action => { %confhash }
1.1 raeburn 9875: );
9876: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9877: $dom);
9878: if ($putresult eq 'ok') {
9879: if (keys(%changes) > 0) {
1.72 raeburn 9880: my $cachetime = 24*60*60;
9881: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9882: if (ref($lastactref) eq 'HASH') {
9883: $lastactref->{'domdefaults'} = 1;
9884: }
1.1 raeburn 9885: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 9886: unless (($context eq 'requestcourses') ||
1.163 raeburn 9887: ($context eq 'requestauthor')) {
1.86 raeburn 9888: if (ref($changes{'defaultquota'}) eq 'HASH') {
9889: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9890: foreach my $type (@{$types},'default') {
9891: if (defined($changes{'defaultquota'}{$type})) {
9892: my $typetitle = $usertypes->{$type};
9893: if ($type eq 'default') {
9894: $typetitle = $othertitle;
9895: }
1.213 raeburn 9896: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9897: }
9898: }
1.86 raeburn 9899: $resulttext .= '</ul></li>';
1.72 raeburn 9900: }
1.197 raeburn 9901: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 9902: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 9903: foreach my $type (@{$types},'default') {
9904: if (defined($changes{'authorquota'}{$type})) {
9905: my $typetitle = $usertypes->{$type};
9906: if ($type eq 'default') {
9907: $typetitle = $othertitle;
9908: }
1.213 raeburn 9909: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 9910: }
9911: }
9912: $resulttext .= '</ul></li>';
9913: }
1.72 raeburn 9914: }
1.80 raeburn 9915: my %newenv;
1.72 raeburn 9916: foreach my $item (@usertools) {
1.163 raeburn 9917: my (%haschgs,%inconf);
9918: if ($context eq 'requestauthor') {
9919: %haschgs = %changes;
1.210 raeburn 9920: %inconf = %confhash;
1.163 raeburn 9921: } else {
9922: if (ref($changes{$item}) eq 'HASH') {
9923: %haschgs = %{$changes{$item}};
9924: }
9925: if (ref($confhash{$item}) eq 'HASH') {
9926: %inconf = %{$confhash{$item}};
9927: }
9928: }
9929: if (keys(%haschgs) > 0) {
1.80 raeburn 9930: my $newacc =
9931: &Apache::lonnet::usertools_access($env{'user.name'},
9932: $env{'user.domain'},
1.86 raeburn 9933: $item,'reload',$context);
1.210 raeburn 9934: if (($context eq 'requestcourses') ||
1.163 raeburn 9935: ($context eq 'requestauthor')) {
1.108 raeburn 9936: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9937: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9938: }
9939: } else {
9940: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9941: $newenv{'environment.availabletools.'.$item} = $newacc;
9942: }
1.80 raeburn 9943: }
1.163 raeburn 9944: unless ($context eq 'requestauthor') {
9945: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9946: }
1.72 raeburn 9947: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 9948: if ($haschgs{$type}) {
1.72 raeburn 9949: my $typetitle = $usertypes->{$type};
9950: if ($type eq 'default') {
9951: $typetitle = $othertitle;
9952: } elsif ($type eq '_LC_adv') {
9953: $typetitle = 'LON-CAPA Advanced Users';
9954: }
1.163 raeburn 9955: if ($inconf{$type}) {
1.101 raeburn 9956: if ($context eq 'requestcourses') {
9957: my $cond;
1.163 raeburn 9958: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9959: if ($1 eq '') {
9960: $cond = &mt('(Automatic processing of any request).');
9961: } else {
9962: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9963: }
9964: } else {
1.163 raeburn 9965: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9966: }
9967: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 9968: } elsif ($context eq 'requestauthor') {
9969: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9970: $titles{$inconf{$type}},$typetitle);
9971:
1.101 raeburn 9972: } else {
9973: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9974: }
1.72 raeburn 9975: } else {
1.104 raeburn 9976: if ($type eq '_LC_adv') {
1.163 raeburn 9977: if ($inconf{$type} eq '0') {
1.104 raeburn 9978: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9979: } else {
9980: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9981: }
9982: } else {
9983: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9984: }
1.72 raeburn 9985: }
9986: }
1.26 raeburn 9987: }
1.163 raeburn 9988: unless ($context eq 'requestauthor') {
9989: $resulttext .= '</ul></li>';
9990: }
1.26 raeburn 9991: }
1.1 raeburn 9992: }
1.163 raeburn 9993: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9994: if (ref($changes{'notify'}) eq 'HASH') {
9995: if ($changes{'notify'}{'approval'}) {
9996: if (ref($confhash{'notify'}) eq 'HASH') {
9997: if ($confhash{'notify'}{'approval'}) {
9998: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9999: } else {
1.163 raeburn 10000: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 10001: }
10002: }
10003: }
10004: }
10005: }
1.216 raeburn 10006: if ($action eq 'requestcourses') {
10007: my @offon = ('off','on');
10008: if ($changes{'uniquecode'}) {
1.218 raeburn 10009: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10010: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
10011: $resulttext .= '<li>'.
10012: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
10013: '</li>';
10014: } else {
10015: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
10016: '</li>';
10017: }
1.216 raeburn 10018: }
1.242 raeburn 10019: foreach my $type ('textbooks','templates') {
10020: if (ref($changes{$type}) eq 'HASH') {
10021: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
10022: foreach my $key (sort(keys(%{$changes{$type}}))) {
10023: my %coursehash = &Apache::lonnet::coursedescription($key);
10024: my $coursetitle = $coursehash{'description'};
10025: my $position = $confhash{$type}{$key}{'order'} + 1;
10026: $resulttext .= '<li>';
1.243 raeburn 10027: foreach my $item ('subject','title','publisher','author') {
10028: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10029: ($type eq 'templates'));
1.242 raeburn 10030: my $name = $item.':';
10031: $name =~ s/^(\w)/\U$1/;
10032: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
10033: }
10034: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
10035: if ($type eq 'textbooks') {
10036: if ($confhash{$type}{$key}{'image'}) {
10037: $resulttext .= ' '.&mt('Image: [_1]',
10038: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
10039: ' alt="Textbook cover" />').'<br />';
10040: }
10041: }
10042: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 10043: }
1.242 raeburn 10044: $resulttext .= '</ul></li>';
1.216 raeburn 10045: }
10046: }
1.235 raeburn 10047: if (ref($changes{'validation'}) eq 'HASH') {
10048: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
10049: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
10050: foreach my $item (@{$validationitemsref}) {
10051: if (exists($changes{'validation'}{$item})) {
10052: if ($item eq 'markup') {
10053: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10054: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
10055: } else {
10056: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10057: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
10058: }
10059: }
10060: }
10061: if (exists($changes{'validation'}{'dc'})) {
10062: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
10063: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
10064: }
10065: }
10066: }
1.216 raeburn 10067: }
1.1 raeburn 10068: $resulttext .= '</ul>';
1.80 raeburn 10069: if (keys(%newenv)) {
10070: &Apache::lonnet::appenv(\%newenv);
10071: }
1.1 raeburn 10072: } else {
1.86 raeburn 10073: if ($context eq 'requestcourses') {
10074: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 10075: } elsif ($context eq 'requestauthor') {
10076: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 10077: } else {
1.90 weissno 10078: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 10079: }
1.1 raeburn 10080: }
10081: } else {
1.11 albertel 10082: $resulttext = '<span class="LC_error">'.
10083: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10084: }
1.216 raeburn 10085: if ($errors) {
10086: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
10087: '<ul>'.$errors.'</ul></p>';
10088: }
1.3 raeburn 10089: return $resulttext;
1.1 raeburn 10090: }
10091:
1.216 raeburn 10092: sub process_textbook_image {
1.242 raeburn 10093: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 10094: my $filename = $env{'form.'.$caller.'.filename'};
10095: my ($error,$url);
10096: my ($width,$height) = (50,50);
10097: if ($configuserok eq 'ok') {
10098: if ($switchserver) {
10099: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
10100: $switchserver);
10101: } elsif ($author_ok eq 'ok') {
10102: my ($result,$imageurl) =
10103: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 10104: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 10105: if ($result eq 'ok') {
10106: $url = $imageurl;
10107: } else {
10108: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10109: }
10110: } else {
10111: $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);
10112: }
10113: } else {
10114: $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);
10115: }
10116: return ($url,$error);
10117: }
10118:
1.267 raeburn 10119: sub modify_ltitools {
10120: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
10121: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 10122: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 10123: my $confname = $dom.'-domainconfig';
10124: my $servadm = $r->dir_config('lonAdmEMail');
10125: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10126: my (%posslti,%possfield);
10127: my @courseroles = ('cc','in','ta','ep','st');
10128: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
10129: map { $posslti{$_} = 1; } @ltiroles;
10130: my @allfields = ('fullname','firstname','lastname','email','user','roles');
10131: map { $possfield{$_} = 1; } @allfields;
10132: my %lt = <itools_names();
10133: if ($env{'form.ltitools_add'}) {
10134: my $title = $env{'form.ltitools_add_title'};
10135: $title =~ s/(`)/'/g;
10136: ($newid,my $error) = &get_ltitools_id($dom,$title);
10137: if ($newid) {
10138: my $position = $env{'form.ltitools_add_pos'};
10139: $position =~ s/\D+//g;
10140: if ($position ne '') {
10141: $allpos[$position] = $newid;
10142: }
10143: $changes{$newid} = 1;
10144: foreach my $item ('title','url','key','secret') {
10145: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
10146: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 10147: if (($item eq 'key') || ($item eq 'secret')) {
10148: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10149: } else {
10150: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10151: }
1.267 raeburn 10152: }
10153: }
10154: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
10155: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
10156: }
10157: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
10158: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
10159: }
1.296 raeburn 10160: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 10161: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
10162: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 10163: if (($item eq 'width') || ($item eq 'height')) {
10164: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
10165: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10166: }
10167: } else {
10168: if ($env{'form.ltitools_add_'.$item} ne '') {
10169: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10170: }
1.267 raeburn 10171: }
10172: }
10173: if ($env{'form.ltitools_add_target'} eq 'window') {
10174: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 10175: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
10176: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 10177: } else {
10178: $confhash{$newid}{'display'}{'target'} = 'iframe';
10179: }
10180: foreach my $item ('passback','roster') {
1.319 ! raeburn 10181: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 10182: $confhash{$newid}{$item} = 1;
1.319 ! raeburn 10183: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
! 10184: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
! 10185: $lifetime =~ s/^\s+|\s+$//g;
! 10186: if ($lifetime =~ /^\d+\.?\d*$/) {
! 10187: $confhash{$newid}{$item.'valid'} = $lifetime;
! 10188: }
! 10189: }
1.267 raeburn 10190: }
10191: }
10192: if ($env{'form.ltitools_add_image.filename'} ne '') {
10193: my ($imageurl,$error) =
1.307 raeburn 10194: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 10195: $configuserok,$switchserver,$author_ok);
10196: if ($imageurl) {
10197: $confhash{$newid}{'image'} = $imageurl;
10198: }
10199: if ($error) {
10200: &Apache::lonnet::logthis($error);
10201: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10202: }
10203: }
10204: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
10205: foreach my $field (@fields) {
10206: if ($possfield{$field}) {
10207: if ($field eq 'roles') {
10208: foreach my $role (@courseroles) {
10209: my $choice = $env{'form.ltitools_add_roles_'.$role};
10210: if (($choice ne '') && ($posslti{$choice})) {
10211: $confhash{$newid}{'roles'}{$role} = $choice;
10212: if ($role eq 'cc') {
10213: $confhash{$newid}{'roles'}{'co'} = $choice;
10214: }
10215: }
10216: }
10217: } else {
10218: $confhash{$newid}{'fields'}{$field} = 1;
10219: }
10220: }
10221: }
1.273 raeburn 10222: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
10223: foreach my $item (@courseconfig) {
10224: $confhash{$newid}{'crsconf'}{$item} = 1;
10225: }
1.267 raeburn 10226: if ($env{'form.ltitools_add_custom'}) {
10227: my $name = $env{'form.ltitools_add_custom_name'};
10228: my $value = $env{'form.ltitools_add_custom_value'};
10229: $value =~ s/(`)/'/g;
10230: $name =~ s/(`)/'/g;
10231: $confhash{$newid}{'custom'}{$name} = $value;
10232: }
10233: } else {
10234: my $error = &mt('Failed to acquire unique ID for new external tool');
10235: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10236: }
10237: }
10238: if (ref($domconfig{$action}) eq 'HASH') {
10239: my %deletions;
10240: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
10241: if (@todelete) {
10242: map { $deletions{$_} = 1; } @todelete;
10243: }
10244: my %customadds;
10245: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
10246: if (@newcustom) {
10247: map { $customadds{$_} = 1; } @newcustom;
10248: }
10249: my %imgdeletions;
10250: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
10251: if (@todeleteimages) {
10252: map { $imgdeletions{$_} = 1; } @todeleteimages;
10253: }
10254: my $maxnum = $env{'form.ltitools_maxnum'};
10255: for (my $i=0; $i<=$maxnum; $i++) {
10256: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 10257: $itemid =~ s/\D+//g;
1.267 raeburn 10258: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10259: if ($deletions{$itemid}) {
10260: if ($domconfig{$action}{$itemid}{'image'}) {
10261: #FIXME need to obsolete item in RES space
10262: }
10263: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
10264: next;
10265: } else {
10266: my $newpos = $env{'form.ltitools_'.$itemid};
10267: $newpos =~ s/\D+//g;
1.297 raeburn 10268: foreach my $item ('title','url') {
1.267 raeburn 10269: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10270: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
10271: $changes{$itemid} = 1;
10272: }
10273: }
1.297 raeburn 10274: foreach my $item ('key','secret') {
10275: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10276: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
10277: $changes{$itemid} = 1;
10278: }
10279: }
1.267 raeburn 10280: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
10281: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
10282: }
10283: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
10284: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
10285: }
10286: foreach my $size ('width','height') {
10287: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
10288: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
10289: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
10290: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
10291: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10292: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
10293: $changes{$itemid} = 1;
10294: }
10295: } else {
10296: $changes{$itemid} = 1;
10297: }
1.296 raeburn 10298: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10299: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
10300: $changes{$itemid} = 1;
10301: }
10302: }
10303: }
10304: foreach my $item ('linktext','explanation') {
10305: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
10306: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
10307: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
10308: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10309: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10310: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
10311: $changes{$itemid} = 1;
10312: }
10313: } else {
10314: $changes{$itemid} = 1;
10315: }
10316: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10317: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
10318: $changes{$itemid} = 1;
10319: }
1.267 raeburn 10320: }
10321: }
10322: if ($env{'form.ltitools_target_'.$i} eq 'window') {
10323: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 10324: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
10325: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 10326: } else {
10327: $confhash{$itemid}{'display'}{'target'} = 'iframe';
10328: }
10329: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10330: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
10331: $changes{$itemid} = 1;
10332: }
10333: } else {
10334: $changes{$itemid} = 1;
10335: }
10336: foreach my $extra ('passback','roster') {
10337: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
10338: $confhash{$itemid}{$extra} = 1;
1.319 ! raeburn 10339: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
! 10340: my $lifetime = $env{'form.ltitools_'.$extra.'valid_add'};
! 10341: $lifetime =~ s/^\s+|\s+$//g;
! 10342: if ($lifetime =~ /^\d+\.?\d*$/) {
! 10343: $confhash{$itemid}{$extra.'valid'} = $lifetime;
! 10344: }
! 10345: }
1.267 raeburn 10346: }
10347: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
10348: $changes{$itemid} = 1;
10349: }
1.319 ! raeburn 10350: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
! 10351: $changes{$itemid} = 1;
! 10352: }
1.267 raeburn 10353: }
1.273 raeburn 10354: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 10355: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 10356: if (grep(/^\Q$item\E$/,@courseconfig)) {
10357: $confhash{$itemid}{'crsconf'}{$item} = 1;
10358: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
10359: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
10360: $changes{$itemid} = 1;
10361: }
10362: } else {
10363: $changes{$itemid} = 1;
10364: }
10365: }
10366: }
1.267 raeburn 10367: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
10368: foreach my $field (@fields) {
10369: if ($possfield{$field}) {
10370: if ($field eq 'roles') {
10371: foreach my $role (@courseroles) {
10372: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
10373: if (($choice ne '') && ($posslti{$choice})) {
10374: $confhash{$itemid}{'roles'}{$role} = $choice;
10375: if ($role eq 'cc') {
10376: $confhash{$itemid}{'roles'}{'co'} = $choice;
10377: }
10378: }
10379: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
10380: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
10381: $changes{$itemid} = 1;
10382: }
10383: } elsif ($confhash{$itemid}{'roles'}{$role}) {
10384: $changes{$itemid} = 1;
10385: }
10386: }
10387: } else {
10388: $confhash{$itemid}{'fields'}{$field} = 1;
10389: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
10390: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
10391: $changes{$itemid} = 1;
10392: }
10393: } else {
10394: $changes{$itemid} = 1;
10395: }
10396: }
10397: }
10398: }
10399: $allpos[$newpos] = $itemid;
10400: }
10401: if ($imgdeletions{$itemid}) {
10402: $changes{$itemid} = 1;
10403: #FIXME need to obsolete item in RES space
10404: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
10405: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
10406: $itemid,$configuserok,$switchserver,
10407: $author_ok);
10408: if ($imgurl) {
10409: $confhash{$itemid}{'image'} = $imgurl;
10410: $changes{$itemid} = 1;
10411: }
10412: if ($error) {
10413: &Apache::lonnet::logthis($error);
10414: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10415: }
10416: } elsif ($domconfig{$action}{$itemid}{'image'}) {
10417: $confhash{$itemid}{'image'} =
10418: $domconfig{$action}{$itemid}{'image'};
10419: }
10420: if ($customadds{$i}) {
10421: my $name = $env{'form.ltitools_custom_name_'.$i};
10422: $name =~ s/(`)/'/g;
10423: $name =~ s/^\s+//;
10424: $name =~ s/\s+$//;
10425: my $value = $env{'form.ltitools_custom_value_'.$i};
10426: $value =~ s/(`)/'/g;
10427: $value =~ s/^\s+//;
10428: $value =~ s/\s+$//;
10429: if ($name ne '') {
10430: $confhash{$itemid}{'custom'}{$name} = $value;
10431: $changes{$itemid} = 1;
10432: }
10433: }
10434: my %customdels;
10435: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
10436: if (@customdeletions) {
10437: $changes{$itemid} = 1;
10438: }
10439: map { $customdels{$_} = 1; } @customdeletions;
10440: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
10441: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
10442: unless ($customdels{$key}) {
10443: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
10444: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
10445: }
10446: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
10447: $changes{$itemid} = 1;
10448: }
10449: }
10450: }
10451: }
10452: unless ($changes{$itemid}) {
10453: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
10454: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
10455: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
10456: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
10457: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
10458: $changes{$itemid} = 1;
10459: last;
10460: }
10461: }
10462: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
10463: $changes{$itemid} = 1;
10464: }
10465: }
10466: last if ($changes{$itemid});
10467: }
10468: }
10469: }
10470: }
10471: }
10472: if (@allpos > 0) {
10473: my $idx = 0;
10474: foreach my $itemid (@allpos) {
10475: if ($itemid ne '') {
10476: $confhash{$itemid}{'order'} = $idx;
10477: if (ref($domconfig{$action}) eq 'HASH') {
10478: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10479: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
10480: $changes{$itemid} = 1;
10481: }
10482: }
10483: }
10484: $idx ++;
10485: }
10486: }
10487: }
10488: my %ltitoolshash = (
10489: $action => { %confhash }
10490: );
10491: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
10492: $dom);
10493: if ($putresult eq 'ok') {
1.297 raeburn 10494: my %ltienchash = (
10495: $action => { %encconfig }
10496: );
10497: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 10498: if (keys(%changes) > 0) {
10499: my $cachetime = 24*60*60;
1.297 raeburn 10500: my %ltiall = %confhash;
10501: foreach my $id (keys(%ltiall)) {
10502: if (ref($encconfig{$id}) eq 'HASH') {
10503: foreach my $item ('key','secret') {
10504: $ltiall{$id}{$item} = $encconfig{$id}{$item};
10505: }
10506: }
10507: }
10508: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 10509: if (ref($lastactref) eq 'HASH') {
10510: $lastactref->{'ltitools'} = 1;
10511: }
10512: $resulttext = &mt('Changes made:').'<ul>';
10513: my %bynum;
10514: foreach my $itemid (sort(keys(%changes))) {
10515: my $position = $confhash{$itemid}{'order'};
10516: $bynum{$position} = $itemid;
10517: }
10518: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
10519: my $itemid = $bynum{$pos};
10520: if (ref($confhash{$itemid}) ne 'HASH') {
10521: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
10522: } else {
10523: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
10524: if ($confhash{$itemid}{'image'}) {
10525: $resulttext .= ' '.
10526: '<img src="'.$confhash{$itemid}{'image'}.'"'.
10527: ' alt="'.&mt('Tool Provider icon').'" />';
10528: }
10529: $resulttext .= '</li><ul>';
10530: my $position = $pos + 1;
10531: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.297 raeburn 10532: foreach my $item ('version','msgtype','url') {
1.267 raeburn 10533: if ($confhash{$itemid}{$item} ne '') {
10534: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
10535: }
10536: }
1.297 raeburn 10537: if ($encconfig{$itemid}{'key'} ne '') {
10538: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
10539: }
10540: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 10541: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 10542: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 10543: $resulttext .= ('*'x$num).'</li>';
10544: }
1.273 raeburn 10545: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 10546: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 10547: my $numconfig = 0;
10548: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
10549: foreach my $item (@possconfig) {
10550: if ($confhash{$itemid}{'crsconf'}{$item}) {
10551: $numconfig ++;
1.296 raeburn 10552: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 10553: }
10554: }
10555: }
10556: if (!$numconfig) {
10557: $resulttext .= &mt('None');
10558: }
10559: $resulttext .= '</li>';
1.267 raeburn 10560: foreach my $item ('passback','roster') {
10561: $resulttext .= '<li>'.$lt{$item}.' ';
10562: if ($confhash{$itemid}{$item}) {
10563: $resulttext .= &mt('Yes');
1.319 ! raeburn 10564: if ($confhash{$itemid}{$item.'valid'}) {
! 10565: if ($item eq 'passback') {
! 10566: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
! 10567: $confhash{$itemid}{$item.'valid'});
! 10568: } else {
! 10569: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
! 10570: $confhash{$itemid}{$item.'valid'});
! 10571: }
! 10572: }
1.267 raeburn 10573: } else {
10574: $resulttext .= &mt('No');
10575: }
10576: $resulttext .= '</li>';
10577: }
10578: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
10579: my $displaylist;
10580: if ($confhash{$itemid}{'display'}{'target'}) {
10581: $displaylist = &mt('Display target').': '.
10582: $confhash{$itemid}{'display'}{'target'}.',';
10583: }
10584: foreach my $size ('width','height') {
10585: if ($confhash{$itemid}{'display'}{$size}) {
10586: $displaylist .= (' 'x2).$lt{$size}.': '.
10587: $confhash{$itemid}{'display'}{$size}.',';
10588: }
10589: }
10590: if ($displaylist) {
10591: $displaylist =~ s/,$//;
10592: $resulttext .= '<li>'.$displaylist.'</li>';
10593: }
1.296 raeburn 10594: foreach my $item ('linktext','explanation') {
10595: if ($confhash{$itemid}{'display'}{$item}) {
10596: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
10597: }
10598: }
10599: }
1.267 raeburn 10600: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
10601: my $fieldlist;
10602: foreach my $field (@allfields) {
10603: if ($confhash{$itemid}{'fields'}{$field}) {
10604: $fieldlist .= (' 'x2).$lt{$field}.',';
10605: }
10606: }
10607: if ($fieldlist) {
10608: $fieldlist =~ s/,$//;
10609: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
10610: }
10611: }
10612: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
10613: my $rolemaps;
10614: foreach my $role (@courseroles) {
10615: if ($confhash{$itemid}{'roles'}{$role}) {
10616: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
10617: $confhash{$itemid}{'roles'}{$role}.',';
10618: }
10619: }
10620: if ($rolemaps) {
10621: $rolemaps =~ s/,$//;
10622: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
10623: }
10624: }
10625: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
10626: my $customlist;
10627: if (keys(%{$confhash{$itemid}{'custom'}})) {
10628: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
10629: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
10630: }
10631: }
10632: if ($customlist) {
1.317 raeburn 10633: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 10634: }
10635: }
10636: $resulttext .= '</ul></li>';
10637: }
10638: }
10639: $resulttext .= '</ul>';
10640: } else {
10641: $resulttext = &mt('No changes made.');
10642: }
10643: } else {
10644: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
10645: }
10646: if ($errors) {
10647: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10648: $errors.'</ul>';
10649: }
10650: return $resulttext;
10651: }
10652:
10653: sub process_ltitools_image {
10654: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
10655: my $filename = $env{'form.'.$caller.'.filename'};
10656: my ($error,$url);
10657: my ($width,$height) = (21,21);
10658: if ($configuserok eq 'ok') {
10659: if ($switchserver) {
10660: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
10661: $switchserver);
10662: } elsif ($author_ok eq 'ok') {
10663: my ($result,$imageurl,$madethumb) =
10664: &publishlogo($r,'upload',$caller,$dom,$confname,
10665: "ltitools/$itemid/icon",$width,$height);
10666: if ($result eq 'ok') {
10667: if ($madethumb) {
10668: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
10669: my $imagethumb = "$path/tn-".$imagefile;
10670: $url = $imagethumb;
10671: } else {
10672: $url = $imageurl;
10673: }
10674: } else {
10675: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10676: }
10677: } else {
10678: $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);
10679: }
10680: } else {
10681: $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);
10682: }
10683: return ($url,$error);
10684: }
10685:
10686: sub get_ltitools_id {
10687: my ($cdom,$title) = @_;
10688: # get lock on ltitools db
10689: my $lockhash = {
10690: lock => $env{'user.name'}.
10691: ':'.$env{'user.domain'},
10692: };
10693: my $tries = 0;
10694: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10695: my ($id,$error);
10696:
10697: while (($gotlock ne 'ok') && ($tries<10)) {
10698: $tries ++;
10699: sleep (0.1);
10700: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10701: }
10702: if ($gotlock eq 'ok') {
10703: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
10704: if ($currids{'lock'}) {
10705: delete($currids{'lock'});
10706: if (keys(%currids)) {
10707: my @curr = sort { $a <=> $b } keys(%currids);
10708: if ($curr[-1] =~ /^\d+$/) {
10709: $id = 1 + $curr[-1];
10710: }
10711: } else {
10712: $id = 1;
10713: }
10714: if ($id) {
10715: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
10716: $error = 'nostore';
10717: }
10718: } else {
10719: $error = 'nonumber';
10720: }
10721: }
10722: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
10723: } else {
10724: $error = 'nolock';
10725: }
10726: return ($id,$error);
10727: }
10728:
1.3 raeburn 10729: sub modify_autoenroll {
1.205 raeburn 10730: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 10731: my ($resulttext,%changes);
10732: my %currautoenroll;
10733: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
10734: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
10735: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
10736: }
10737: }
10738: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
10739: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 10740: sender => 'Sender for notification messages',
1.274 raeburn 10741: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
10742: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 10743: my @offon = ('off','on');
1.17 raeburn 10744: my $sender_uname = $env{'form.sender_uname'};
10745: my $sender_domain = $env{'form.sender_domain'};
10746: if ($sender_domain eq '') {
10747: $sender_uname = '';
10748: } elsif ($sender_uname eq '') {
10749: $sender_domain = '';
10750: }
1.129 raeburn 10751: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 10752: my $failsafe = $env{'form.autoenroll_failsafe'};
10753: $failsafe =~ s{^\s+|\s+$}{}g;
10754: if ($failsafe =~ /\D/) {
10755: undef($failsafe);
10756: }
1.1 raeburn 10757: my %autoenrollhash = (
1.129 raeburn 10758: autoenroll => { 'run' => $env{'form.autoenroll_run'},
10759: 'sender_uname' => $sender_uname,
10760: 'sender_domain' => $sender_domain,
10761: 'co-owners' => $coowners,
1.274 raeburn 10762: 'autofailsafe' => $failsafe,
1.1 raeburn 10763: }
10764: );
1.4 raeburn 10765: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
10766: $dom);
1.1 raeburn 10767: if ($putresult eq 'ok') {
10768: if (exists($currautoenroll{'run'})) {
10769: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
10770: $changes{'run'} = 1;
10771: }
10772: } elsif ($autorun) {
10773: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 10774: $changes{'run'} = 1;
1.1 raeburn 10775: }
10776: }
1.17 raeburn 10777: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 10778: $changes{'sender'} = 1;
10779: }
1.17 raeburn 10780: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 10781: $changes{'sender'} = 1;
10782: }
1.129 raeburn 10783: if ($currautoenroll{'co-owners'} ne '') {
10784: if ($currautoenroll{'co-owners'} ne $coowners) {
10785: $changes{'coowners'} = 1;
10786: }
10787: } elsif ($coowners) {
10788: $changes{'coowners'} = 1;
1.274 raeburn 10789: }
10790: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
10791: $changes{'autofailsafe'} = 1;
10792: }
1.1 raeburn 10793: if (keys(%changes) > 0) {
10794: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 10795: if ($changes{'run'}) {
1.1 raeburn 10796: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
10797: }
10798: if ($changes{'sender'}) {
1.17 raeburn 10799: if ($sender_uname eq '' || $sender_domain eq '') {
10800: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
10801: } else {
10802: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
10803: }
1.1 raeburn 10804: }
1.129 raeburn 10805: if ($changes{'coowners'}) {
10806: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
10807: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10808: if (ref($lastactref) eq 'HASH') {
10809: $lastactref->{'domainconfig'} = 1;
10810: }
1.129 raeburn 10811: }
1.274 raeburn 10812: if ($changes{'autofailsafe'}) {
10813: if ($failsafe ne '') {
1.299 raeburn 10814: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 10815: } else {
1.299 raeburn 10816: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 10817: }
10818: &Apache::lonnet::get_domain_defaults($dom,1);
10819: if (ref($lastactref) eq 'HASH') {
10820: $lastactref->{'domdefaults'} = 1;
10821: }
10822: }
1.1 raeburn 10823: $resulttext .= '</ul>';
10824: } else {
10825: $resulttext = &mt('No changes made to auto-enrollment settings');
10826: }
10827: } else {
1.11 albertel 10828: $resulttext = '<span class="LC_error">'.
10829: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10830: }
1.3 raeburn 10831: return $resulttext;
1.1 raeburn 10832: }
10833:
10834: sub modify_autoupdate {
1.3 raeburn 10835: my ($dom,%domconfig) = @_;
1.1 raeburn 10836: my ($resulttext,%currautoupdate,%fields,%changes);
10837: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
10838: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
10839: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
10840: }
10841: }
10842: my @offon = ('off','on');
10843: my %title = &Apache::lonlocal::texthash (
10844: run => 'Auto-update:',
10845: classlists => 'Updates to user information in classlists?'
10846: );
1.44 raeburn 10847: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10848: my %fieldtitles = &Apache::lonlocal::texthash (
10849: id => 'Student/Employee ID',
1.20 raeburn 10850: permanentemail => 'E-mail address',
1.1 raeburn 10851: lastname => 'Last Name',
10852: firstname => 'First Name',
10853: middlename => 'Middle Name',
1.132 raeburn 10854: generation => 'Generation',
1.1 raeburn 10855: );
1.142 raeburn 10856: $othertitle = &mt('All users');
1.1 raeburn 10857: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 10858: $othertitle = &mt('Other users');
1.1 raeburn 10859: }
10860: foreach my $key (keys(%env)) {
10861: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 10862: my ($usertype,$item) = ($1,$2);
10863: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
10864: if ($usertype eq 'default') {
10865: push(@{$fields{$1}},$2);
10866: } elsif (ref($types) eq 'ARRAY') {
10867: if (grep(/^\Q$usertype\E$/,@{$types})) {
10868: push(@{$fields{$1}},$2);
10869: }
10870: }
10871: }
1.1 raeburn 10872: }
10873: }
1.131 raeburn 10874: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
10875: @lockablenames = sort(@lockablenames);
10876: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
10877: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10878: if (@changed) {
10879: $changes{'lockablenames'} = 1;
10880: }
10881: } else {
10882: if (@lockablenames) {
10883: $changes{'lockablenames'} = 1;
10884: }
10885: }
1.1 raeburn 10886: my %updatehash = (
10887: autoupdate => { run => $env{'form.autoupdate_run'},
10888: classlists => $env{'form.classlists'},
10889: fields => {%fields},
1.131 raeburn 10890: lockablenames => \@lockablenames,
1.1 raeburn 10891: }
10892: );
10893: foreach my $key (keys(%currautoupdate)) {
10894: if (($key eq 'run') || ($key eq 'classlists')) {
10895: if (exists($updatehash{autoupdate}{$key})) {
10896: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
10897: $changes{$key} = 1;
10898: }
10899: }
10900: } elsif ($key eq 'fields') {
10901: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 10902: foreach my $item (@{$types},'default') {
1.1 raeburn 10903: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
10904: my $change = 0;
10905: foreach my $type (@{$currautoupdate{$key}{$item}}) {
10906: if (!exists($fields{$item})) {
10907: $change = 1;
1.132 raeburn 10908: last;
1.1 raeburn 10909: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 10910: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 10911: $change = 1;
1.132 raeburn 10912: last;
1.1 raeburn 10913: }
10914: }
10915: }
10916: if ($change) {
10917: push(@{$changes{$key}},$item);
10918: }
1.26 raeburn 10919: }
1.1 raeburn 10920: }
10921: }
1.131 raeburn 10922: } elsif ($key eq 'lockablenames') {
10923: if (ref($currautoupdate{$key}) eq 'ARRAY') {
10924: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10925: if (@changed) {
10926: $changes{'lockablenames'} = 1;
10927: }
10928: } else {
10929: if (@lockablenames) {
10930: $changes{'lockablenames'} = 1;
10931: }
10932: }
10933: }
10934: }
10935: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10936: if (@lockablenames) {
10937: $changes{'lockablenames'} = 1;
1.1 raeburn 10938: }
10939: }
1.26 raeburn 10940: foreach my $item (@{$types},'default') {
10941: if (defined($fields{$item})) {
10942: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 10943: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10944: my $change = 0;
10945: if (ref($fields{$item}) eq 'ARRAY') {
10946: foreach my $type (@{$fields{$item}}) {
10947: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10948: $change = 1;
10949: last;
10950: }
10951: }
10952: }
10953: if ($change) {
10954: push(@{$changes{'fields'}},$item);
10955: }
10956: } else {
1.26 raeburn 10957: push(@{$changes{'fields'}},$item);
10958: }
10959: } else {
10960: push(@{$changes{'fields'}},$item);
1.1 raeburn 10961: }
10962: }
10963: }
10964: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10965: $dom);
10966: if ($putresult eq 'ok') {
10967: if (keys(%changes) > 0) {
10968: $resulttext = &mt('Changes made:').'<ul>';
10969: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 10970: if ($key eq 'lockablenames') {
10971: $resulttext .= '<li>';
10972: if (@lockablenames) {
10973: $usertypes->{'default'} = $othertitle;
10974: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10975: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10976: } else {
10977: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10978: }
10979: $resulttext .= '</li>';
10980: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 10981: foreach my $item (@{$changes{$key}}) {
10982: my @newvalues;
10983: foreach my $type (@{$fields{$item}}) {
10984: push(@newvalues,$fieldtitles{$type});
10985: }
1.3 raeburn 10986: my $newvaluestr;
10987: if (@newvalues > 0) {
10988: $newvaluestr = join(', ',@newvalues);
10989: } else {
10990: $newvaluestr = &mt('none');
1.6 raeburn 10991: }
1.1 raeburn 10992: if ($item eq 'default') {
1.26 raeburn 10993: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 10994: } else {
1.26 raeburn 10995: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 10996: }
10997: }
10998: } else {
10999: my $newvalue;
11000: if ($key eq 'run') {
11001: $newvalue = $offon[$env{'form.autoupdate_run'}];
11002: } else {
11003: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 11004: }
1.1 raeburn 11005: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
11006: }
11007: }
11008: $resulttext .= '</ul>';
11009: } else {
1.3 raeburn 11010: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 11011: }
11012: } else {
1.11 albertel 11013: $resulttext = '<span class="LC_error">'.
11014: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11015: }
1.3 raeburn 11016: return $resulttext;
1.1 raeburn 11017: }
11018:
1.125 raeburn 11019: sub modify_autocreate {
11020: my ($dom,%domconfig) = @_;
11021: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
11022: if (ref($domconfig{'autocreate'}) eq 'HASH') {
11023: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
11024: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
11025: }
11026: }
11027: my %title= ( xml => 'Auto-creation of courses in XML course description files',
11028: req => 'Auto-creation of validated requests for official courses',
11029: xmldc => 'Identity of course creator of courses from XML files',
11030: );
11031: my @types = ('xml','req');
11032: foreach my $item (@types) {
11033: $newvals{$item} = $env{'form.autocreate_'.$item};
11034: $newvals{$item} =~ s/\D//g;
11035: $newvals{$item} = 0 if ($newvals{$item} eq '');
11036: }
11037: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 11038: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 11039: unless (exists($domcoords{$newvals{'xmldc'}})) {
11040: $newvals{'xmldc'} = '';
11041: }
11042: %autocreatehash = (
11043: autocreate => { xml => $newvals{'xml'},
11044: req => $newvals{'req'},
11045: }
11046: );
11047: if ($newvals{'xmldc'} ne '') {
11048: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
11049: }
11050: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
11051: $dom);
11052: if ($putresult eq 'ok') {
11053: my @items = @types;
11054: if ($newvals{'xml'}) {
11055: push(@items,'xmldc');
11056: }
11057: foreach my $item (@items) {
11058: if (exists($currautocreate{$item})) {
11059: if ($currautocreate{$item} ne $newvals{$item}) {
11060: $changes{$item} = 1;
11061: }
11062: } elsif ($newvals{$item}) {
11063: $changes{$item} = 1;
11064: }
11065: }
11066: if (keys(%changes) > 0) {
11067: my @offon = ('off','on');
11068: $resulttext = &mt('Changes made:').'<ul>';
11069: foreach my $item (@types) {
11070: if ($changes{$item}) {
11071: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 11072: $resulttext .= '<li>'.
11073: &mt("$title{$item} set to [_1]$newtxt [_2]",
11074: '<b>','</b>').
11075: '</li>';
1.125 raeburn 11076: }
11077: }
11078: if ($changes{'xmldc'}) {
11079: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
11080: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 11081: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 11082: }
11083: $resulttext .= '</ul>';
11084: } else {
11085: $resulttext = &mt('No changes made to auto-creation settings');
11086: }
11087: } else {
11088: $resulttext = '<span class="LC_error">'.
11089: &mt('An error occurred: [_1]',$putresult).'</span>';
11090: }
11091: return $resulttext;
11092: }
11093:
1.23 raeburn 11094: sub modify_directorysrch {
1.295 raeburn 11095: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 11096: my ($resulttext,%changes);
11097: my %currdirsrch;
11098: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
11099: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
11100: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
11101: }
11102: }
1.277 raeburn 11103: my %title = ( available => 'Institutional directory search available',
11104: localonly => 'Other domains can search institution',
11105: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 11106: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 11107: searchby => 'Search types',
11108: searchtypes => 'Search latitude');
11109: my @offon = ('off','on');
1.24 raeburn 11110: my @otherdoms = ('Yes','No');
1.23 raeburn 11111:
1.25 raeburn 11112: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 11113: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
11114: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
11115:
1.44 raeburn 11116: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 11117: if (keys(%{$usertypes}) == 0) {
11118: @cansearch = ('default');
11119: } else {
11120: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
11121: foreach my $type (@{$currdirsrch{'cansearch'}}) {
11122: if (!grep(/^\Q$type\E$/,@cansearch)) {
11123: push(@{$changes{'cansearch'}},$type);
11124: }
1.23 raeburn 11125: }
1.26 raeburn 11126: foreach my $type (@cansearch) {
11127: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
11128: push(@{$changes{'cansearch'}},$type);
11129: }
1.23 raeburn 11130: }
1.26 raeburn 11131: } else {
11132: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 11133: }
11134: }
11135:
11136: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
11137: foreach my $by (@{$currdirsrch{'searchby'}}) {
11138: if (!grep(/^\Q$by\E$/,@searchby)) {
11139: push(@{$changes{'searchby'}},$by);
11140: }
11141: }
11142: foreach my $by (@searchby) {
11143: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
11144: push(@{$changes{'searchby'}},$by);
11145: }
11146: }
11147: } else {
11148: push(@{$changes{'searchby'}},@searchby);
11149: }
1.25 raeburn 11150:
11151: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
11152: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
11153: if (!grep(/^\Q$type\E$/,@searchtypes)) {
11154: push(@{$changes{'searchtypes'}},$type);
11155: }
11156: }
11157: foreach my $type (@searchtypes) {
11158: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
11159: push(@{$changes{'searchtypes'}},$type);
11160: }
11161: }
11162: } else {
11163: if (exists($currdirsrch{'searchtypes'})) {
11164: foreach my $type (@searchtypes) {
11165: if ($type ne $currdirsrch{'searchtypes'}) {
11166: push(@{$changes{'searchtypes'}},$type);
11167: }
11168: }
11169: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
11170: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
11171: }
11172: } else {
11173: push(@{$changes{'searchtypes'}},@searchtypes);
11174: }
11175: }
11176:
1.23 raeburn 11177: my %dirsrch_hash = (
11178: directorysrch => { available => $env{'form.dirsrch_available'},
11179: cansearch => \@cansearch,
1.277 raeburn 11180: localonly => $env{'form.dirsrch_instlocalonly'},
11181: lclocalonly => $env{'form.dirsrch_domlocalonly'},
11182: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 11183: searchby => \@searchby,
1.25 raeburn 11184: searchtypes => \@searchtypes,
1.23 raeburn 11185: }
11186: );
11187: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
11188: $dom);
11189: if ($putresult eq 'ok') {
11190: if (exists($currdirsrch{'available'})) {
11191: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
11192: $changes{'available'} = 1;
11193: }
11194: } else {
11195: if ($env{'form.dirsrch_available'} eq '1') {
11196: $changes{'available'} = 1;
11197: }
11198: }
1.277 raeburn 11199: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 11200: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
11201: $changes{'lcavailable'} = 1;
11202: }
1.277 raeburn 11203: } else {
11204: if ($env{'form.dirsrch_lcavailable'} eq '1') {
11205: $changes{'lcavailable'} = 1;
11206: }
11207: }
1.24 raeburn 11208: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 11209: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
11210: $changes{'localonly'} = 1;
11211: }
1.24 raeburn 11212: } else {
1.277 raeburn 11213: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 11214: $changes{'localonly'} = 1;
11215: }
11216: }
1.277 raeburn 11217: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 11218: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
11219: $changes{'lclocalonly'} = 1;
11220: }
1.277 raeburn 11221: } else {
11222: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
11223: $changes{'lclocalonly'} = 1;
11224: }
11225: }
1.23 raeburn 11226: if (keys(%changes) > 0) {
11227: $resulttext = &mt('Changes made:').'<ul>';
11228: if ($changes{'available'}) {
11229: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
11230: }
1.277 raeburn 11231: if ($changes{'lcavailable'}) {
11232: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
11233: }
1.24 raeburn 11234: if ($changes{'localonly'}) {
1.277 raeburn 11235: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 11236: }
1.277 raeburn 11237: if ($changes{'lclocalonly'}) {
11238: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 11239: }
1.23 raeburn 11240: if (ref($changes{'cansearch'}) eq 'ARRAY') {
11241: my $chgtext;
1.26 raeburn 11242: if (ref($usertypes) eq 'HASH') {
11243: if (keys(%{$usertypes}) > 0) {
11244: foreach my $type (@{$types}) {
11245: if (grep(/^\Q$type\E$/,@cansearch)) {
11246: $chgtext .= $usertypes->{$type}.'; ';
11247: }
11248: }
11249: if (grep(/^default$/,@cansearch)) {
11250: $chgtext .= $othertitle;
11251: } else {
11252: $chgtext =~ s/\; $//;
11253: }
1.210 raeburn 11254: $resulttext .=
1.178 raeburn 11255: '<li>'.
11256: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
11257: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
11258: '</li>';
1.23 raeburn 11259: }
11260: }
11261: }
11262: if (ref($changes{'searchby'}) eq 'ARRAY') {
11263: my ($searchtitles,$titleorder) = &sorted_searchtitles();
11264: my $chgtext;
11265: foreach my $type (@{$titleorder}) {
11266: if (grep(/^\Q$type\E$/,@searchby)) {
11267: if (defined($searchtitles->{$type})) {
11268: $chgtext .= $searchtitles->{$type}.'; ';
11269: }
11270: }
11271: }
11272: $chgtext =~ s/\; $//;
11273: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
11274: }
1.25 raeburn 11275: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
11276: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
11277: my $chgtext;
11278: foreach my $type (@{$srchtypeorder}) {
11279: if (grep(/^\Q$type\E$/,@searchtypes)) {
11280: if (defined($srchtypes_desc->{$type})) {
11281: $chgtext .= $srchtypes_desc->{$type}.'; ';
11282: }
11283: }
11284: }
11285: $chgtext =~ s/\; $//;
1.178 raeburn 11286: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 11287: }
11288: $resulttext .= '</ul>';
1.295 raeburn 11289: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
11290: if (ref($lastactref) eq 'HASH') {
11291: $lastactref->{'directorysrch'} = 1;
11292: }
1.23 raeburn 11293: } else {
1.277 raeburn 11294: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 11295: }
11296: } else {
11297: $resulttext = '<span class="LC_error">'.
1.27 raeburn 11298: &mt('An error occurred: [_1]',$putresult).'</span>';
11299: }
11300: return $resulttext;
11301: }
11302:
1.28 raeburn 11303: sub modify_contacts {
1.205 raeburn 11304: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 11305: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
11306: if (ref($domconfig{'contacts'}) eq 'HASH') {
11307: foreach my $key (keys(%{$domconfig{'contacts'}})) {
11308: $currsetting{$key} = $domconfig{'contacts'}{$key};
11309: }
11310: }
1.286 raeburn 11311: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 11312: my @contacts = ('supportemail','adminemail');
1.286 raeburn 11313: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
11314: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 11315: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 11316: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 11317: foreach my $type (@mailings) {
11318: @{$newsetting{$type}} =
11319: &Apache::loncommon::get_env_multiple('form.'.$type);
11320: foreach my $item (@contacts) {
11321: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
11322: $contacts_hash{contacts}{$type}{$item} = 1;
11323: } else {
11324: $contacts_hash{contacts}{$type}{$item} = 0;
11325: }
1.289 raeburn 11326: }
1.28 raeburn 11327: $others{$type} = $env{'form.'.$type.'_others'};
11328: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 11329: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11330: $bcc{$type} = $env{'form.'.$type.'_bcc'};
11331: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 11332: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
11333: $includestr{$type} = $env{'form.'.$type.'_includestr'};
11334: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
11335: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
11336: }
1.134 raeburn 11337: }
1.28 raeburn 11338: }
11339: foreach my $item (@contacts) {
11340: $to{$item} = $env{'form.'.$item};
11341: $contacts_hash{'contacts'}{$item} = $to{$item};
11342: }
1.203 raeburn 11343: foreach my $item (@toggles) {
11344: if ($env{'form.'.$item} =~ /^(0|1)$/) {
11345: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
11346: }
11347: }
1.286 raeburn 11348: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
11349: foreach my $field (@{$fields}) {
11350: if (ref($possoptions->{$field}) eq 'ARRAY') {
11351: my $value = $env{'form.helpform_'.$field};
11352: $value =~ s/^\s+|\s+$//g;
11353: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 11354: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 11355: if ($field eq 'screenshot') {
11356: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
11357: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 11358: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 11359: }
11360: }
11361: }
11362: }
11363: }
11364: }
1.315 raeburn 11365: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11366: my (@statuses,%usertypeshash,@overrides);
11367: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
11368: @statuses = @{$types};
11369: if (ref($usertypes) eq 'HASH') {
11370: %usertypeshash = %{$usertypes};
11371: }
11372: }
11373: if (@statuses) {
11374: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
11375: foreach my $type (@possoverrides) {
11376: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
11377: push(@overrides,$type);
11378: }
11379: }
11380: if (@overrides) {
11381: foreach my $type (@overrides) {
11382: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
11383: foreach my $item (@contacts) {
11384: if (grep(/^\Q$item\E$/,@standard)) {
11385: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
11386: $newsetting{'override_'.$type}{$item} = 1;
11387: } else {
11388: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
11389: $newsetting{'override_'.$type}{$item} = 0;
11390: }
11391: }
11392: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
11393: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
11394: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
11395: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
11396: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
11397: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
11398: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
11399: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
11400: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
11401: }
11402: }
11403: }
11404: }
1.28 raeburn 11405: if (keys(%currsetting) > 0) {
11406: foreach my $item (@contacts) {
11407: if ($to{$item} ne $currsetting{$item}) {
11408: $changes{$item} = 1;
11409: }
11410: }
11411: foreach my $type (@mailings) {
11412: foreach my $item (@contacts) {
11413: if (ref($currsetting{$type}) eq 'HASH') {
11414: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
11415: push(@{$changes{$type}},$item);
11416: }
11417: } else {
11418: push(@{$changes{$type}},@{$newsetting{$type}});
11419: }
11420: }
11421: if ($others{$type} ne $currsetting{$type}{'others'}) {
11422: push(@{$changes{$type}},'others');
11423: }
1.289 raeburn 11424: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11425: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
11426: push(@{$changes{$type}},'bcc');
11427: }
1.286 raeburn 11428: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
11429: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
11430: push(@{$changes{$type}},'include');
11431: }
11432: }
11433: }
11434: if (ref($fields) eq 'ARRAY') {
11435: if (ref($currsetting{'helpform'}) eq 'HASH') {
11436: foreach my $field (@{$fields}) {
11437: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
11438: push(@{$changes{'helpform'}},$field);
11439: }
11440: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11441: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
11442: push(@{$changes{'helpform'}},'maxsize');
11443: }
11444: }
11445: }
11446: } else {
11447: foreach my $field (@{$fields}) {
11448: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
11449: push(@{$changes{'helpform'}},$field);
11450: }
11451: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11452: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
11453: push(@{$changes{'helpform'}},'maxsize');
11454: }
11455: }
11456: }
1.134 raeburn 11457: }
1.28 raeburn 11458: }
1.315 raeburn 11459: if (@statuses) {
11460: if (ref($currsetting{'overrides'}) eq 'HASH') {
11461: foreach my $key (keys(%{$currsetting{'overrides'}})) {
11462: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
11463: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
11464: foreach my $item (@contacts,'bcc','others','include') {
11465: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
11466: push(@{$changes{'overrides'}},$key);
11467: last;
11468: }
11469: }
11470: } else {
11471: push(@{$changes{'overrides'}},$key);
11472: }
11473: }
11474: }
11475: foreach my $key (@overrides) {
11476: unless (exists($currsetting{'overrides'}{$key})) {
11477: push(@{$changes{'overrides'}},$key);
11478: }
11479: }
11480: } else {
11481: foreach my $key (@overrides) {
11482: push(@{$changes{'overrides'}},$key);
11483: }
11484: }
11485: }
1.28 raeburn 11486: } else {
11487: my %default;
11488: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
11489: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
11490: $default{'errormail'} = 'adminemail';
11491: $default{'packagesmail'} = 'adminemail';
11492: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 11493: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 11494: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 11495: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 11496: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 11497: foreach my $item (@contacts) {
11498: if ($to{$item} ne $default{$item}) {
1.286 raeburn 11499: $changes{$item} = 1;
1.203 raeburn 11500: }
1.28 raeburn 11501: }
11502: foreach my $type (@mailings) {
11503: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
11504: push(@{$changes{$type}},@{$newsetting{$type}});
11505: }
11506: if ($others{$type} ne '') {
11507: push(@{$changes{$type}},'others');
1.134 raeburn 11508: }
1.286 raeburn 11509: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11510: if ($bcc{$type} ne '') {
11511: push(@{$changes{$type}},'bcc');
11512: }
1.286 raeburn 11513: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
11514: push(@{$changes{$type}},'include');
11515: }
1.134 raeburn 11516: }
1.28 raeburn 11517: }
1.286 raeburn 11518: if (ref($fields) eq 'ARRAY') {
11519: foreach my $field (@{$fields}) {
11520: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
11521: push(@{$changes{'helpform'}},$field);
11522: }
11523: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11524: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
11525: push(@{$changes{'helpform'}},'maxsize');
11526: }
11527: }
11528: }
1.289 raeburn 11529: }
1.28 raeburn 11530: }
1.203 raeburn 11531: foreach my $item (@toggles) {
11532: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
11533: $changes{$item} = 1;
11534: } elsif ((!$env{'form.'.$item}) &&
11535: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
11536: $changes{$item} = 1;
11537: }
11538: }
1.28 raeburn 11539: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
11540: $dom);
11541: if ($putresult eq 'ok') {
11542: if (keys(%changes) > 0) {
1.205 raeburn 11543: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11544: if (ref($lastactref) eq 'HASH') {
11545: $lastactref->{'domainconfig'} = 1;
11546: }
1.28 raeburn 11547: my ($titles,$short_titles) = &contact_titles();
11548: $resulttext = &mt('Changes made:').'<ul>';
11549: foreach my $item (@contacts) {
11550: if ($changes{$item}) {
11551: $resulttext .= '<li>'.$titles->{$item}.
11552: &mt(' set to: ').
11553: '<span class="LC_cusr_emph">'.
11554: $to{$item}.'</span></li>';
11555: }
11556: }
11557: foreach my $type (@mailings) {
11558: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 11559: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 11560: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 11561: } else {
11562: $resulttext .= '<li>'.$titles->{$type}.': ';
11563: }
1.28 raeburn 11564: my @text;
11565: foreach my $item (@{$newsetting{$type}}) {
11566: push(@text,$short_titles->{$item});
11567: }
11568: if ($others{$type} ne '') {
11569: push(@text,$others{$type});
11570: }
1.286 raeburn 11571: if (@text) {
11572: $resulttext .= '<span class="LC_cusr_emph">'.
11573: join(', ',@text).'</span>';
11574: }
11575: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11576: if ($bcc{$type} ne '') {
1.286 raeburn 11577: my $bcctext;
11578: if (@text) {
1.289 raeburn 11579: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 11580: } else {
11581: $bcctext = '(Bcc)';
11582: }
11583: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
11584: } elsif (!@text) {
11585: $resulttext .= &mt('No one');
11586: }
1.289 raeburn 11587: if ($includestr{$type} ne '') {
1.286 raeburn 11588: if ($includeloc{$type} eq 'b') {
11589: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
11590: } elsif ($includeloc{$type} eq 's') {
11591: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
11592: }
1.134 raeburn 11593: }
1.286 raeburn 11594: } elsif (!@text) {
11595: $resulttext .= &mt('No recipients');
1.134 raeburn 11596: }
11597: $resulttext .= '</li>';
1.28 raeburn 11598: }
11599: }
1.315 raeburn 11600: if (ref($changes{'overrides'}) eq 'ARRAY') {
11601: my @deletions;
11602: foreach my $type (@{$changes{'overrides'}}) {
11603: if ($usertypeshash{$type}) {
11604: if (grep(/^\Q$type\E/,@overrides)) {
11605: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
11606: $usertypeshash{$type}).'<ul><li>';
11607: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
11608: my @text;
11609: foreach my $item (@contacts) {
11610: if ($newsetting{'override_'.$type}{$item}) {
11611: push(@text,$short_titles->{$item});
11612: }
11613: }
11614: if ($newsetting{'override_'.$type}{'others'} ne '') {
11615: push(@text,$newsetting{'override_'.$type}{'others'});
11616: }
11617:
11618: if (@text) {
11619: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
11620: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
11621: }
11622: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
11623: my $bcctext;
11624: if (@text) {
11625: $bcctext = ' '.&mt('with Bcc to');
11626: } else {
11627: $bcctext = '(Bcc)';
11628: }
11629: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
11630: } elsif (!@text) {
11631: $resulttext .= &mt('Helpdesk e-mail sent to no one');
11632: }
11633: $resulttext .= '</li>';
11634: if ($newsetting{'override_'.$type}{'include'} ne '') {
11635: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
11636: if ($loc eq 'b') {
11637: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
11638: } elsif ($loc eq 's') {
11639: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
11640: }
11641: }
11642: }
11643: $resulttext .= '</li></ul></li>';
11644: } else {
11645: push(@deletions,$usertypeshash{$type});
11646: }
11647: }
11648: }
11649: if (@deletions) {
11650: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
11651: join(', ',@deletions)).'</li>';
11652: }
11653: }
1.203 raeburn 11654: my @offon = ('off','on');
11655: if ($changes{'reporterrors'}) {
11656: $resulttext .= '<li>'.
11657: &mt('E-mail error reports to [_1] set to "'.
11658: $offon[$env{'form.reporterrors'}].'".',
11659: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
11660: &mt('LON-CAPA core group - MSU'),600,500)).
11661: '</li>';
11662: }
11663: if ($changes{'reportupdates'}) {
11664: $resulttext .= '<li>'.
11665: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
11666: $offon[$env{'form.reportupdates'}].'".',
11667: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
11668: &mt('LON-CAPA core group - MSU'),600,500)).
11669: '</li>';
11670: }
1.286 raeburn 11671: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
11672: my (@optional,@required,@unused,$maxsizechg);
11673: foreach my $field (@{$changes{'helpform'}}) {
11674: if ($field eq 'maxsize') {
11675: $maxsizechg = 1;
11676: next;
11677: }
11678: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 11679: push(@optional,$field);
1.286 raeburn 11680: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
11681: push(@unused,$field);
11682: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 11683: push(@required,$field);
1.286 raeburn 11684: }
11685: }
11686: if (@optional) {
11687: $resulttext .= '<li>'.
11688: &mt('Help form fields changed to "Optional": [_1].',
11689: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
11690: '</li>';
11691: }
11692: if (@required) {
11693: $resulttext .= '<li>'.
11694: &mt('Help form fields changed to "Required": [_1].',
11695: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
11696: '</li>';
11697: }
11698: if (@unused) {
11699: $resulttext .= '<li>'.
11700: &mt('Help form fields changed to "Not shown": [_1].',
11701: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
11702: '</li>';
11703: }
11704: if ($maxsizechg) {
11705: $resulttext .= '<li>'.
11706: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
11707: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
11708: '</li>';
11709: }
11710: }
1.28 raeburn 11711: $resulttext .= '</ul>';
11712: } else {
1.288 raeburn 11713: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 11714: }
11715: } else {
11716: $resulttext = '<span class="LC_error">'.
11717: &mt('An error occurred: [_1].',$putresult).'</span>';
11718: }
11719: return $resulttext;
11720: }
11721:
11722: sub modify_usercreation {
1.27 raeburn 11723: my ($dom,%domconfig) = @_;
1.224 raeburn 11724: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 11725: my $warningmsg;
1.27 raeburn 11726: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11727: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 11728: if ($key eq 'cancreate') {
11729: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11730: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 11731: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
11732: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11733: } else {
1.224 raeburn 11734: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11735: }
11736: }
11737: }
11738: } elsif ($key eq 'email_rule') {
11739: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11740: } else {
11741: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11742: }
1.27 raeburn 11743: }
11744: }
11745: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 11746: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 11747: my @contexts = ('author','course','requestcrs');
1.34 raeburn 11748: foreach my $item(@contexts) {
1.224 raeburn 11749: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 11750: }
1.34 raeburn 11751: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11752: foreach my $item (@contexts) {
1.224 raeburn 11753: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
11754: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 11755: }
1.27 raeburn 11756: }
1.34 raeburn 11757: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
11758: foreach my $item (@contexts) {
1.43 raeburn 11759: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 11760: if ($cancreate{$item} ne 'any') {
11761: push(@{$changes{'cancreate'}},$item);
11762: }
11763: } else {
11764: if ($cancreate{$item} ne 'none') {
11765: push(@{$changes{'cancreate'}},$item);
11766: }
1.27 raeburn 11767: }
11768: }
11769: } else {
1.43 raeburn 11770: foreach my $item (@contexts) {
1.34 raeburn 11771: push(@{$changes{'cancreate'}},$item);
11772: }
1.27 raeburn 11773: }
1.34 raeburn 11774:
1.27 raeburn 11775: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
11776: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
11777: if (!grep(/^\Q$type\E$/,@username_rule)) {
11778: push(@{$changes{'username_rule'}},$type);
11779: }
11780: }
11781: foreach my $type (@username_rule) {
11782: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
11783: push(@{$changes{'username_rule'}},$type);
11784: }
11785: }
11786: } else {
11787: push(@{$changes{'username_rule'}},@username_rule);
11788: }
11789:
1.32 raeburn 11790: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
11791: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
11792: if (!grep(/^\Q$type\E$/,@id_rule)) {
11793: push(@{$changes{'id_rule'}},$type);
11794: }
11795: }
11796: foreach my $type (@id_rule) {
11797: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
11798: push(@{$changes{'id_rule'}},$type);
11799: }
11800: }
11801: } else {
11802: push(@{$changes{'id_rule'}},@id_rule);
11803: }
11804:
1.43 raeburn 11805: my @authen_contexts = ('author','course','domain');
1.28 raeburn 11806: my @authtypes = ('int','krb4','krb5','loc');
11807: my %authhash;
1.43 raeburn 11808: foreach my $item (@authen_contexts) {
1.28 raeburn 11809: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
11810: foreach my $auth (@authtypes) {
11811: if (grep(/^\Q$auth\E$/,@authallowed)) {
11812: $authhash{$item}{$auth} = 1;
11813: } else {
11814: $authhash{$item}{$auth} = 0;
11815: }
11816: }
11817: }
11818: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 11819: foreach my $item (@authen_contexts) {
1.28 raeburn 11820: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
11821: foreach my $auth (@authtypes) {
11822: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
11823: push(@{$changes{'authtypes'}},$item);
11824: last;
11825: }
11826: }
11827: }
11828: }
11829: } else {
1.43 raeburn 11830: foreach my $item (@authen_contexts) {
1.28 raeburn 11831: push(@{$changes{'authtypes'}},$item);
11832: }
11833: }
11834:
1.224 raeburn 11835: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
11836: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
11837: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
11838: $save_usercreate{'id_rule'} = \@id_rule;
11839: $save_usercreate{'username_rule'} = \@username_rule,
11840: $save_usercreate{'authtypes'} = \%authhash;
11841:
1.27 raeburn 11842: my %usercreation_hash = (
1.224 raeburn 11843: usercreation => \%save_usercreate,
11844: );
1.27 raeburn 11845:
11846: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
11847: $dom);
1.50 raeburn 11848:
1.224 raeburn 11849: if ($putresult eq 'ok') {
11850: if (keys(%changes) > 0) {
11851: $resulttext = &mt('Changes made:').'<ul>';
11852: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11853: my %lt = &usercreation_types();
11854: foreach my $type (@{$changes{'cancreate'}}) {
11855: my $chgtext = $lt{$type}.', ';
11856: if ($cancreate{$type} eq 'none') {
11857: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
11858: } elsif ($cancreate{$type} eq 'any') {
11859: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
11860: } elsif ($cancreate{$type} eq 'official') {
11861: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
11862: } elsif ($cancreate{$type} eq 'unofficial') {
11863: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
11864: }
11865: $resulttext .= '<li>'.$chgtext.'</li>';
11866: }
11867: }
11868: if (ref($changes{'username_rule'}) eq 'ARRAY') {
11869: my ($rules,$ruleorder) =
11870: &Apache::lonnet::inst_userrules($dom,'username');
11871: my $chgtext = '<ul>';
11872: foreach my $type (@username_rule) {
11873: if (ref($rules->{$type}) eq 'HASH') {
11874: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
11875: }
11876: }
11877: $chgtext .= '</ul>';
11878: if (@username_rule > 0) {
11879: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11880: } else {
11881: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
11882: }
11883: }
11884: if (ref($changes{'id_rule'}) eq 'ARRAY') {
11885: my ($idrules,$idruleorder) =
11886: &Apache::lonnet::inst_userrules($dom,'id');
11887: my $chgtext = '<ul>';
11888: foreach my $type (@id_rule) {
11889: if (ref($idrules->{$type}) eq 'HASH') {
11890: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
11891: }
11892: }
11893: $chgtext .= '</ul>';
11894: if (@id_rule > 0) {
11895: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11896: } else {
11897: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
11898: }
11899: }
11900: my %authname = &authtype_names();
11901: my %context_title = &context_names();
11902: if (ref($changes{'authtypes'}) eq 'ARRAY') {
11903: my $chgtext = '<ul>';
11904: foreach my $type (@{$changes{'authtypes'}}) {
11905: my @allowed;
11906: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
11907: foreach my $auth (@authtypes) {
11908: if ($authhash{$type}{$auth}) {
11909: push(@allowed,$authname{$auth});
11910: }
11911: }
11912: if (@allowed > 0) {
11913: $chgtext .= join(', ',@allowed).'</li>';
11914: } else {
11915: $chgtext .= &mt('none').'</li>';
11916: }
11917: }
11918: $chgtext .= '</ul>';
11919: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
11920: $resulttext .= '</li>';
11921: }
11922: $resulttext .= '</ul>';
11923: } else {
11924: $resulttext = &mt('No changes made to user creation settings');
11925: }
11926: } else {
11927: $resulttext = '<span class="LC_error">'.
11928: &mt('An error occurred: [_1]',$putresult).'</span>';
11929: }
11930: if ($warningmsg ne '') {
11931: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11932: }
11933: return $resulttext;
11934: }
11935:
11936: sub modify_selfcreation {
1.305 raeburn 11937: my ($dom,$lastactref,%domconfig) = @_;
11938: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
11939: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
11940: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 11941: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
11942: if (ref($typesref) eq 'ARRAY') {
11943: @types = @{$typesref};
11944: }
11945: if (ref($usertypesref) eq 'HASH') {
11946: %usertypes = %{$usertypesref};
1.228 raeburn 11947: }
1.303 raeburn 11948: $usertypes{'default'} = $othertitle;
1.224 raeburn 11949: #
11950: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
11951: #
11952: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11953: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11954: if ($key eq 'cancreate') {
11955: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11956: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11957: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 11958: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
11959: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
11960: ($item eq 'emailusername') || ($item eq 'shibenv') ||
11961: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 11962: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 11963: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11964: } else {
11965: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11966: }
11967: }
11968: }
11969: } elsif ($key eq 'email_rule') {
11970: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11971: } else {
11972: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11973: }
11974: }
11975: }
11976: #
11977: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
11978: #
11979: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11980: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11981: if ($key eq 'selfcreate') {
11982: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
11983: } else {
11984: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
11985: }
11986: }
11987: }
1.305 raeburn 11988: #
11989: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
11990: #
11991: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11992: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
11993: if ($key eq 'inststatusguest') {
11994: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
11995: } else {
11996: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
11997: }
11998: }
11999: }
1.224 raeburn 12000:
12001: my @contexts = ('selfcreate');
12002: @{$cancreate{'selfcreate'}} = ();
12003: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 12004: if (@types) {
12005: @{$cancreate{'statustocreate'}} = ();
12006: }
1.236 raeburn 12007: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 12008: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 12009: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 12010: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 12011: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 12012: my %selfcreatetypes = (
12013: sso => 'users authenticated by institutional single sign on',
12014: login => 'users authenticated by institutional log-in',
1.303 raeburn 12015: email => 'users verified by e-mail',
1.50 raeburn 12016: );
1.224 raeburn 12017: #
12018: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
12019: # is permitted.
12020: #
1.305 raeburn 12021: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 12022:
1.305 raeburn 12023: my (@statuses,%email_rule);
1.228 raeburn 12024: foreach my $item ('login','sso','email') {
1.224 raeburn 12025: if ($item eq 'email') {
1.236 raeburn 12026: if ($env{'form.cancreate_email'}) {
1.305 raeburn 12027: if (@types) {
12028: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
12029: foreach my $status (@poss_statuses) {
12030: if (grep(/^\Q$status\E$/,(@types,'default'))) {
12031: push(@statuses,$status);
12032: }
12033: }
12034: $save_inststatus{'inststatusguest'} = \@statuses;
12035: } else {
12036: push(@statuses,'default');
12037: }
12038: if (@statuses) {
12039: my %curr_rule;
12040: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
12041: foreach my $type (@statuses) {
12042: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 12043: }
1.305 raeburn 12044: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
12045: foreach my $type (@statuses) {
12046: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
12047: }
12048: }
12049: push(@{$cancreate{'selfcreate'}},'email');
12050: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
12051: my %curremaildom;
12052: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
12053: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
12054: }
12055: foreach my $type (@statuses) {
12056: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
12057: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
12058: }
12059: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
12060: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
12061: }
12062: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
12063: #
12064: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
12065: #
12066: my $chosen = $1;
12067: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
12068: my $emaildom;
12069: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
12070: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
12071: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
12072: if (ref($curremaildom{$type}) eq 'HASH') {
12073: if (exists($curremaildom{$type}{$chosen})) {
12074: if ($curremaildom{$type}{$chosen} ne $emaildom) {
12075: push(@{$changes{'cancreate'}},'emaildomain');
12076: }
12077: } elsif ($emaildom ne '') {
12078: push(@{$changes{'cancreate'}},'emaildomain');
12079: }
12080: } elsif ($emaildom ne '') {
12081: push(@{$changes{'cancreate'}},'emaildomain');
12082: }
12083: }
12084: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
12085: } elsif ($chosen eq 'custom') {
12086: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
12087: $email_rule{$type} = [];
12088: if (ref($emailrules) eq 'HASH') {
12089: foreach my $rule (@possemail_rules) {
12090: if (exists($emailrules->{$rule})) {
12091: push(@{$email_rule{$type}},$rule);
12092: }
12093: }
12094: }
12095: if (@{$email_rule{$type}}) {
12096: $cancreate{'emailoptions'}{$type} = 'custom';
12097: if (ref($curr_rule{$type}) eq 'ARRAY') {
12098: if (@{$curr_rule{$type}} > 0) {
12099: foreach my $rule (@{$curr_rule{$type}}) {
12100: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
12101: push(@{$changes{'email_rule'}},$type);
12102: }
12103: }
12104: }
12105: foreach my $type (@{$email_rule{$type}}) {
12106: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
12107: push(@{$changes{'email_rule'}},$type);
12108: }
12109: }
12110: } else {
12111: push(@{$changes{'email_rule'}},$type);
12112: }
12113: }
12114: } else {
12115: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
12116: }
12117: }
12118: }
12119: if (@types) {
12120: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
12121: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
12122: if (@changed) {
12123: push(@{$changes{'inststatus'}},'inststatusguest');
12124: }
12125: } else {
12126: push(@{$changes{'inststatus'}},'inststatusguest');
12127: }
12128: }
12129: } else {
12130: delete($env{'form.cancreate_email'});
12131: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
12132: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
12133: push(@{$changes{'inststatus'}},'inststatusguest');
12134: }
12135: }
12136: }
12137: } else {
12138: $save_inststatus{'inststatusguest'} = [];
12139: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
12140: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
12141: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 12142: }
12143: }
1.224 raeburn 12144: }
12145: } else {
12146: if ($env{'form.cancreate_'.$item}) {
12147: push(@{$cancreate{'selfcreate'}},$item);
12148: }
12149: }
12150: }
1.305 raeburn 12151: my (%userinfo,%savecaptcha);
1.224 raeburn 12152: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
12153: #
1.228 raeburn 12154: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
12155: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 12156: #
1.236 raeburn 12157:
1.244 raeburn 12158: if ($env{'form.cancreate_email'}) {
1.228 raeburn 12159: push(@contexts,'emailusername');
1.305 raeburn 12160: if (@statuses) {
12161: foreach my $type (@statuses) {
1.228 raeburn 12162: if (ref($infofields) eq 'ARRAY') {
12163: foreach my $field (@{$infofields}) {
12164: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
12165: $cancreate{'emailusername'}{$type}{$field} = $1;
12166: }
12167: }
1.224 raeburn 12168: }
12169: }
12170: }
12171: #
12172: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 12173: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 12174: #
12175:
12176: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
12177: @approvalnotify = sort(@approvalnotify);
12178: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
12179: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
12180: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
12181: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
12182: push(@{$changes{'cancreate'}},'notify');
12183: }
12184: } else {
12185: if ($cancreate{'notify'}{'approval'}) {
12186: push(@{$changes{'cancreate'}},'notify');
12187: }
12188: }
12189: } elsif ($cancreate{'notify'}{'approval'}) {
12190: push(@{$changes{'cancreate'}},'notify');
12191: }
12192:
12193: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
12194: }
12195: #
1.236 raeburn 12196: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 12197: # institutional log-in.
12198: #
12199: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
12200: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
12201: ($domdefaults{'auth_def'} eq 'localauth'))) {
12202: $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.').' '.
12203: &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.');
12204: }
12205: }
12206: my @fields = ('lastname','firstname','middlename','generation',
12207: 'permanentemail','id');
1.240 raeburn 12208: my @shibfields = (@fields,'inststatus');
1.224 raeburn 12209: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12210: #
12211: # Where usernames may created for institutional log-in and/or institutional single sign on:
12212: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
12213: # may self-create accounts
12214: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
12215: # which the user may supply, if institutional data is unavailable.
12216: #
12217: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 12218: if (@types) {
1.305 raeburn 12219: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
12220: push(@contexts,'statustocreate');
1.303 raeburn 12221: foreach my $type (@types) {
1.224 raeburn 12222: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
12223: foreach my $field (@fields) {
12224: if (grep(/^\Q$field\E$/,@modifiable)) {
12225: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
12226: } else {
12227: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
12228: }
12229: }
12230: }
12231: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 12232: foreach my $type (@types) {
1.224 raeburn 12233: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
12234: foreach my $field (@fields) {
12235: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
12236: $curr_usermodify{'selfcreate'}{$type}{$field}) {
12237: push(@{$changes{'selfcreate'}},$type);
12238: last;
12239: }
12240: }
12241: }
12242: }
12243: } else {
1.303 raeburn 12244: foreach my $type (@types) {
1.224 raeburn 12245: push(@{$changes{'selfcreate'}},$type);
12246: }
12247: }
12248: }
1.240 raeburn 12249: foreach my $field (@shibfields) {
12250: if ($env{'form.shibenv_'.$field} ne '') {
12251: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
12252: }
12253: }
12254: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
12255: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
12256: foreach my $field (@shibfields) {
12257: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
12258: push(@{$changes{'cancreate'}},'shibenv');
12259: }
12260: }
12261: } else {
12262: foreach my $field (@shibfields) {
12263: if ($env{'form.shibenv_'.$field}) {
12264: push(@{$changes{'cancreate'}},'shibenv');
12265: last;
12266: }
12267: }
12268: }
12269: }
1.224 raeburn 12270: }
12271: foreach my $item (@contexts) {
12272: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
12273: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
12274: if (ref($cancreate{$item}) eq 'ARRAY') {
12275: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
12276: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12277: push(@{$changes{'cancreate'}},$item);
12278: }
12279: }
12280: }
12281: }
12282: if (ref($cancreate{$item}) eq 'ARRAY') {
12283: foreach my $type (@{$cancreate{$item}}) {
12284: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
12285: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12286: push(@{$changes{'cancreate'}},$item);
12287: }
12288: }
12289: }
12290: }
12291: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
12292: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 12293: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
12294: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
12295: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
12296: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 12297: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12298: push(@{$changes{'cancreate'}},$item);
12299: }
12300: }
12301: }
1.305 raeburn 12302: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
12303: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 12304: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12305: push(@{$changes{'cancreate'}},$item);
12306: }
1.224 raeburn 12307: }
12308: }
12309: }
1.305 raeburn 12310: foreach my $type (keys(%{$cancreate{$item}})) {
12311: if (ref($cancreate{$item}{$type}) eq 'HASH') {
12312: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
12313: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
12314: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 12315: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12316: push(@{$changes{'cancreate'}},$item);
12317: }
12318: }
12319: } else {
12320: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12321: push(@{$changes{'cancreate'}},$item);
12322: }
12323: }
12324: }
1.305 raeburn 12325: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
12326: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 12327: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12328: push(@{$changes{'cancreate'}},$item);
12329: }
1.224 raeburn 12330: }
12331: }
12332: }
12333: }
12334: } elsif ($curr_usercreation{'cancreate'}{$item}) {
12335: if (ref($cancreate{$item}) eq 'ARRAY') {
12336: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
12337: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12338: push(@{$changes{'cancreate'}},$item);
12339: }
12340: }
1.305 raeburn 12341: }
12342: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
12343: if (ref($cancreate{$item}) eq 'HASH') {
12344: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12345: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 12346: }
12347: }
12348: } elsif ($item eq 'emailusername') {
1.228 raeburn 12349: if (ref($cancreate{$item}) eq 'HASH') {
12350: foreach my $type (keys(%{$cancreate{$item}})) {
12351: if (ref($cancreate{$item}{$type}) eq 'HASH') {
12352: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
12353: if ($cancreate{$item}{$type}{$field}) {
12354: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12355: push(@{$changes{'cancreate'}},$item);
12356: }
12357: last;
12358: }
12359: }
12360: }
12361: }
1.224 raeburn 12362: }
12363: }
12364: }
12365: #
12366: # Populate %save_usercreate hash with updates to self-creation configuration.
12367: #
12368: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
12369: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 12370: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 12371: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
12372: if (ref($cancreate{'notify'}) eq 'HASH') {
12373: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
12374: }
1.236 raeburn 12375: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
12376: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
12377: }
1.303 raeburn 12378: if (ref($cancreate{'emailverified'}) eq 'HASH') {
12379: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
12380: }
1.305 raeburn 12381: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
12382: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
12383: }
1.303 raeburn 12384: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
12385: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
12386: }
1.224 raeburn 12387: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
12388: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
12389: }
1.240 raeburn 12390: if (ref($cancreate{'shibenv'}) eq 'HASH') {
12391: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
12392: }
1.224 raeburn 12393: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 12394: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 12395:
12396: my %userconfig_hash = (
12397: usercreation => \%save_usercreate,
12398: usermodification => \%save_usermodify,
1.305 raeburn 12399: inststatus => \%save_inststatus,
1.224 raeburn 12400: );
1.305 raeburn 12401:
1.224 raeburn 12402: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
12403: $dom);
12404: #
1.305 raeburn 12405: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 12406: #
1.27 raeburn 12407: if ($putresult eq 'ok') {
12408: if (keys(%changes) > 0) {
12409: $resulttext = &mt('Changes made:').'<ul>';
12410: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 12411: my %lt = &selfcreation_types();
1.34 raeburn 12412: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 12413: my $chgtext = '';
1.45 raeburn 12414: if ($type eq 'selfcreate') {
1.50 raeburn 12415: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 12416: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 12417: } else {
1.224 raeburn 12418: $chgtext .= &mt('Self-creation of a new account is permitted for:').
12419: '<ul>';
1.50 raeburn 12420: foreach my $case (@{$cancreate{$type}}) {
12421: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
12422: }
12423: $chgtext .= '</ul>';
1.100 raeburn 12424: if (ref($cancreate{$type}) eq 'ARRAY') {
12425: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
12426: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
12427: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 12428: $chgtext .= '<span class="LC_warning">'.
12429: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
12430: '</span><br />';
12431: }
12432: }
12433: }
12434: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 12435: if (!@statuses) {
12436: $chgtext .= '<span class="LC_warning">'.
12437: &mt("However, e-mail verification is currently set to 'unavailable' for all user types (including 'other'), so self-creation of accounts is not possible for non-institutional log-in.").
12438: '</span><br />';
1.303 raeburn 12439:
1.100 raeburn 12440: }
12441: }
12442: }
1.43 raeburn 12443: }
1.240 raeburn 12444: } elsif ($type eq 'shibenv') {
12445: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 12446: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 12447: } else {
12448: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
12449: '<ul>';
12450: foreach my $field (@shibfields) {
12451: next if ($cancreate{$type}{$field} eq '');
12452: if ($field eq 'inststatus') {
12453: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
12454: } else {
12455: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
12456: }
12457: }
12458: $chgtext .= '</ul>';
1.303 raeburn 12459: }
1.93 raeburn 12460: } elsif ($type eq 'statustocreate') {
1.96 raeburn 12461: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
12462: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
12463: if (@{$cancreate{'selfcreate'}} > 0) {
12464: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 12465: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 12466: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 12467: $chgtext .= '<br />'.
12468: '<span class="LC_warning">'.
12469: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
12470: '</span>';
12471: }
1.303 raeburn 12472: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 12473: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 12474: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
12475: } else {
12476: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
12477: }
12478: $chgtext .= '<ul>';
12479: foreach my $case (@{$cancreate{$type}}) {
12480: if ($case eq 'default') {
12481: $chgtext .= '<li>'.$othertitle.'</li>';
12482: } else {
1.303 raeburn 12483: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 12484: }
12485: }
1.100 raeburn 12486: $chgtext .= '</ul>';
12487: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 12488: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 12489: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
12490: '</span>';
1.100 raeburn 12491: }
12492: }
12493: } else {
12494: if (@{$cancreate{$type}} == 0) {
12495: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
12496: } else {
12497: $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 12498: }
12499: }
1.303 raeburn 12500: $chgtext .= '<br />';
1.93 raeburn 12501: }
1.236 raeburn 12502: } elsif ($type eq 'selfcreateprocessing') {
12503: my %choices = &Apache::lonlocal::texthash (
12504: automatic => 'Automatic approval',
12505: approval => 'Queued for approval',
12506: );
1.305 raeburn 12507: if (@types) {
12508: if (@statuses) {
1.303 raeburn 12509: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 12510: '<ul>';
1.305 raeburn 12511: foreach my $status (@statuses) {
12512: if ($status eq 'default') {
12513: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 12514: } else {
1.305 raeburn 12515: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 12516: }
12517: }
12518: $chgtext .= '</ul>';
12519: }
12520: } else {
12521: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
12522: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
12523: }
12524: } elsif ($type eq 'emailverified') {
12525: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 12526: all => 'Same as e-mail',
12527: first => 'Omit @domain',
12528: free => 'Free to choose',
1.303 raeburn 12529: );
1.305 raeburn 12530: if (@types) {
12531: if (@statuses) {
1.303 raeburn 12532: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
12533: '<ul>';
1.305 raeburn 12534: foreach my $status (@statuses) {
1.303 raeburn 12535: if ($type eq 'default') {
1.305 raeburn 12536: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 12537: } else {
1.305 raeburn 12538: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 12539: }
12540: }
12541: $chgtext .= '</ul>';
12542: }
12543: } else {
1.305 raeburn 12544: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 12545: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 12546: }
1.305 raeburn 12547: } elsif ($type eq 'emailoptions') {
12548: my %options = &Apache::lonlocal::texthash (
12549: any => 'Any e-mail',
12550: inst => 'Institutional only',
12551: noninst => 'Non-institutional only',
12552: custom => 'Custom restrictions',
12553: );
12554: if (@types) {
12555: if (@statuses) {
12556: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
12557: '<ul>';
12558: foreach my $status (@statuses) {
12559: if ($type eq 'default') {
12560: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
12561: } else {
12562: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 12563: }
12564: }
1.305 raeburn 12565: $chgtext .= '</ul>';
12566: }
12567: } else {
12568: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
12569: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
12570: } else {
12571: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
12572: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 12573: }
1.305 raeburn 12574: }
12575: } elsif ($type eq 'emaildomain') {
12576: my $output;
12577: if (@statuses) {
12578: foreach my $type (@statuses) {
12579: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
12580: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
12581: if ($type eq 'default') {
12582: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12583: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
12584: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
12585: } else {
12586: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
12587: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
12588: }
1.303 raeburn 12589: } else {
1.305 raeburn 12590: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12591: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
12592: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
12593: } else {
12594: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
12595: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
12596: }
1.303 raeburn 12597: }
1.305 raeburn 12598: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
12599: if ($type eq 'default') {
12600: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12601: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
12602: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
12603: } else {
12604: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
12605: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
12606: }
1.303 raeburn 12607: } else {
1.305 raeburn 12608: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12609: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
12610: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
12611: } else {
12612: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
12613: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
12614: }
1.303 raeburn 12615: }
12616: }
12617: }
12618: }
1.305 raeburn 12619: }
12620: if ($output ne '') {
12621: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
12622: '<ul>'.$output.'</ul>';
1.236 raeburn 12623: }
1.165 raeburn 12624: } elsif ($type eq 'captcha') {
1.224 raeburn 12625: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 12626: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
12627: } else {
12628: my %captchas = &captcha_phrases();
1.224 raeburn 12629: if ($captchas{$savecaptcha{$type}}) {
12630: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 12631: } else {
1.210 raeburn 12632: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 12633: }
12634: }
12635: } elsif ($type eq 'recaptchakeys') {
12636: my ($privkey,$pubkey);
1.224 raeburn 12637: if (ref($savecaptcha{$type}) eq 'HASH') {
12638: $pubkey = $savecaptcha{$type}{'public'};
12639: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 12640: }
12641: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
12642: if (!$pubkey) {
12643: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
12644: } else {
12645: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12646: }
12647: if (!$privkey) {
12648: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
12649: } else {
12650: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
12651: }
12652: $chgtext .= '</ul>';
1.269 raeburn 12653: } elsif ($type eq 'recaptchaversion') {
12654: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 12655: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 12656: }
1.224 raeburn 12657: } elsif ($type eq 'emailusername') {
12658: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 12659: if (@statuses) {
12660: foreach my $type (@statuses) {
1.228 raeburn 12661: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
12662: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 12663: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 12664: '<ul>';
12665: foreach my $field (@{$infofields}) {
12666: if ($cancreate{'emailusername'}{$type}{$field}) {
12667: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
12668: }
12669: }
1.245 raeburn 12670: $chgtext .= '</ul>';
12671: } else {
1.303 raeburn 12672: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.228 raeburn 12673: }
12674: } else {
1.303 raeburn 12675: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.224 raeburn 12676: }
12677: }
12678: }
12679: }
12680: } elsif ($type eq 'notify') {
1.303 raeburn 12681: my $numapprove = 0;
1.224 raeburn 12682: if (ref($changes{'cancreate'}) eq 'ARRAY') {
12683: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
12684: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 12685: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
12686: $numapprove ++;
1.224 raeburn 12687: }
12688: }
1.43 raeburn 12689: }
1.303 raeburn 12690: unless ($numapprove) {
12691: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
12692: }
1.34 raeburn 12693: }
1.224 raeburn 12694: if ($chgtext) {
12695: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 12696: }
12697: }
12698: }
1.305 raeburn 12699: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 12700: my ($emailrules,$emailruleorder) =
12701: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 12702: foreach my $type (@{$changes{'email_rule'}}) {
12703: if (ref($email_rule{$type}) eq 'ARRAY') {
12704: my $chgtext = '<ul>';
12705: foreach my $rule (@{$email_rule{$type}}) {
12706: if (ref($emailrules->{$rule}) eq 'HASH') {
12707: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
12708: }
12709: }
12710: $chgtext .= '</ul>';
1.310 raeburn 12711: my $typename;
1.305 raeburn 12712: if (@types) {
12713: if ($type eq 'default') {
12714: $typename = $othertitle;
12715: } else {
12716: $typename = $usertypes{$type};
12717: }
12718: $chgtext .= &mt('(Affiliation: [_1])',$typename);
12719: }
12720: if (@{$email_rule{$type}} > 0) {
12721: $resulttext .= '<li>'.
12722: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
12723: $usertypes{$type}).
12724: $chgtext.
12725: '</li>';
12726: } else {
12727: $resulttext .= '<li>'.
1.310 raeburn 12728: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
1.305 raeburn 12729: '</li>'.
1.310 raeburn 12730: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 12731: }
1.43 raeburn 12732: }
12733: }
1.305 raeburn 12734: }
12735: if (ref($changes{'inststatus'}) eq 'ARRAY') {
12736: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
12737: if (@{$save_inststatus{'inststatusguest'}} > 0) {
12738: my $chgtext = '<ul>';
12739: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
12740: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
12741: }
12742: $chgtext .= '</ul>';
12743: $resulttext .= '<li>'.
12744: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
12745: $chgtext.
12746: '</li>';
12747: } else {
12748: $resulttext .= '<li>'.
12749: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
12750: '</li>';
12751: }
1.43 raeburn 12752: }
12753: }
1.224 raeburn 12754: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
12755: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
12756: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12757: foreach my $type (@{$changes{'selfcreate'}}) {
12758: my $typename = $type;
1.303 raeburn 12759: if (keys(%usertypes) > 0) {
12760: if ($usertypes{$type} ne '') {
12761: $typename = $usertypes{$type};
1.224 raeburn 12762: }
12763: }
12764: my @modifiable;
12765: $resulttext .= '<li>'.
12766: &mt('Self-creation of account by users with status: [_1]',
12767: '<span class="LC_cusr_emph">'.$typename.'</span>').
12768: ' - '.&mt('modifiable fields (if institutional data blank): ');
12769: foreach my $field (@fields) {
12770: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
12771: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 12772: }
12773: }
1.224 raeburn 12774: if (@modifiable > 0) {
12775: $resulttext .= join(', ',@modifiable);
1.43 raeburn 12776: } else {
1.224 raeburn 12777: $resulttext .= &mt('none');
1.43 raeburn 12778: }
1.224 raeburn 12779: $resulttext .= '</li>';
1.28 raeburn 12780: }
1.224 raeburn 12781: $resulttext .= '</ul></li>';
1.28 raeburn 12782: }
1.27 raeburn 12783: $resulttext .= '</ul>';
1.305 raeburn 12784: my $cachetime = 24*60*60;
12785: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
12786: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12787: if (ref($lastactref) eq 'HASH') {
12788: $lastactref->{'domdefaults'} = 1;
12789: }
1.27 raeburn 12790: } else {
1.224 raeburn 12791: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 12792: }
12793: } else {
12794: $resulttext = '<span class="LC_error">'.
1.23 raeburn 12795: &mt('An error occurred: [_1]',$putresult).'</span>';
12796: }
1.43 raeburn 12797: if ($warningmsg ne '') {
12798: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
12799: }
1.23 raeburn 12800: return $resulttext;
12801: }
12802:
1.165 raeburn 12803: sub process_captcha {
12804: my ($container,$changes,$newsettings,$current) = @_;
12805: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
12806: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
12807: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
12808: $newsettings->{'captcha'} = 'original';
12809: }
12810: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 12811: if ($container eq 'cancreate') {
1.169 raeburn 12812: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12813: push(@{$changes->{'cancreate'}},'captcha');
12814: } elsif (!defined($changes->{'cancreate'})) {
12815: $changes->{'cancreate'} = ['captcha'];
12816: }
12817: } else {
12818: $changes->{'captcha'} = 1;
1.165 raeburn 12819: }
12820: }
1.269 raeburn 12821: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 12822: if ($newsettings->{'captcha'} eq 'recaptcha') {
12823: $newpub = $env{'form.'.$container.'_recaptchapub'};
12824: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 12825: $newpub =~ s/[^\w\-]//g;
12826: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 12827: $newsettings->{'recaptchakeys'} = {
12828: public => $newpub,
12829: private => $newpriv,
12830: };
1.269 raeburn 12831: $newversion = $env{'form.'.$container.'_recaptchaversion'};
12832: $newversion =~ s/\D//g;
12833: if ($newversion ne '2') {
12834: $newversion = 1;
12835: }
12836: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 12837: }
12838: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
12839: $currpub = $current->{'recaptchakeys'}{'public'};
12840: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 12841: unless ($newsettings->{'captcha'} eq 'recaptcha') {
12842: $newsettings->{'recaptchakeys'} = {
12843: public => '',
12844: private => '',
12845: }
12846: }
1.165 raeburn 12847: }
1.269 raeburn 12848: if ($current->{'captcha'} eq 'recaptcha') {
12849: $currversion = $current->{'recaptchaversion'};
12850: if ($currversion ne '2') {
12851: $currversion = 1;
12852: }
12853: }
12854: if ($currversion ne $newversion) {
12855: if ($container eq 'cancreate') {
12856: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12857: push(@{$changes->{'cancreate'}},'recaptchaversion');
12858: } elsif (!defined($changes->{'cancreate'})) {
12859: $changes->{'cancreate'} = ['recaptchaversion'];
12860: }
12861: } else {
12862: $changes->{'recaptchaversion'} = 1;
12863: }
12864: }
1.165 raeburn 12865: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 12866: if ($container eq 'cancreate') {
12867: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12868: push(@{$changes->{'cancreate'}},'recaptchakeys');
12869: } elsif (!defined($changes->{'cancreate'})) {
12870: $changes->{'cancreate'} = ['recaptchakeys'];
12871: }
12872: } else {
1.210 raeburn 12873: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 12874: }
12875: }
12876: return;
12877: }
12878:
1.33 raeburn 12879: sub modify_usermodification {
12880: my ($dom,%domconfig) = @_;
1.224 raeburn 12881: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 12882: if (ref($domconfig{'usermodification'}) eq 'HASH') {
12883: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 12884: if ($key eq 'selfcreate') {
12885: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
12886: } else {
12887: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
12888: }
1.33 raeburn 12889: }
12890: }
1.224 raeburn 12891: my @contexts = ('author','course');
1.33 raeburn 12892: my %context_title = (
12893: author => 'In author context',
12894: course => 'In course context',
12895: );
12896: my @fields = ('lastname','firstname','middlename','generation',
12897: 'permanentemail','id');
12898: my %roles = (
12899: author => ['ca','aa'],
12900: course => ['st','ep','ta','in','cr'],
12901: );
12902: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12903: foreach my $context (@contexts) {
12904: foreach my $role (@{$roles{$context}}) {
12905: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
12906: foreach my $item (@fields) {
12907: if (grep(/^\Q$item\E$/,@modifiable)) {
12908: $modifyhash{$context}{$role}{$item} = 1;
12909: } else {
12910: $modifyhash{$context}{$role}{$item} = 0;
12911: }
12912: }
12913: }
12914: if (ref($curr_usermodification{$context}) eq 'HASH') {
12915: foreach my $role (@{$roles{$context}}) {
12916: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
12917: foreach my $field (@fields) {
12918: if ($modifyhash{$context}{$role}{$field} ne
12919: $curr_usermodification{$context}{$role}{$field}) {
12920: push(@{$changes{$context}},$role);
12921: last;
12922: }
12923: }
12924: }
12925: }
12926: } else {
12927: foreach my $context (@contexts) {
12928: foreach my $role (@{$roles{$context}}) {
12929: push(@{$changes{$context}},$role);
12930: }
12931: }
12932: }
12933: }
12934: my %usermodification_hash = (
12935: usermodification => \%modifyhash,
12936: );
12937: my $putresult = &Apache::lonnet::put_dom('configuration',
12938: \%usermodification_hash,$dom);
12939: if ($putresult eq 'ok') {
12940: if (keys(%changes) > 0) {
12941: $resulttext = &mt('Changes made: ').'<ul>';
12942: foreach my $context (@contexts) {
12943: if (ref($changes{$context}) eq 'ARRAY') {
12944: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
12945: if (ref($changes{$context}) eq 'ARRAY') {
12946: foreach my $role (@{$changes{$context}}) {
12947: my $rolename;
1.224 raeburn 12948: if ($role eq 'cr') {
12949: $rolename = &mt('Custom');
1.33 raeburn 12950: } else {
1.224 raeburn 12951: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 12952: }
12953: my @modifiable;
1.224 raeburn 12954: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 12955: foreach my $field (@fields) {
12956: if ($modifyhash{$context}{$role}{$field}) {
12957: push(@modifiable,$fieldtitles{$field});
12958: }
12959: }
12960: if (@modifiable > 0) {
12961: $resulttext .= join(', ',@modifiable);
12962: } else {
12963: $resulttext .= &mt('none');
12964: }
12965: $resulttext .= '</li>';
12966: }
12967: $resulttext .= '</ul></li>';
12968: }
12969: }
12970: }
12971: $resulttext .= '</ul>';
12972: } else {
12973: $resulttext = &mt('No changes made to user modification settings');
12974: }
12975: } else {
12976: $resulttext = '<span class="LC_error">'.
12977: &mt('An error occurred: [_1]',$putresult).'</span>';
12978: }
12979: return $resulttext;
12980: }
12981:
1.43 raeburn 12982: sub modify_defaults {
1.212 raeburn 12983: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 12984: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 12985: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 12986: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
12987: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 12988: my @authtypes = ('internal','krb4','krb5','localauth');
12989: foreach my $item (@items) {
12990: $newvalues{$item} = $env{'form.'.$item};
12991: if ($item eq 'auth_def') {
12992: if ($newvalues{$item} ne '') {
12993: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
12994: push(@errors,$item);
12995: }
12996: }
12997: } elsif ($item eq 'lang_def') {
12998: if ($newvalues{$item} ne '') {
12999: if ($newvalues{$item} =~ /^(\w+)/) {
13000: my $langcode = $1;
1.103 raeburn 13001: if ($langcode ne 'x_chef') {
13002: if (code2language($langcode) eq '') {
13003: push(@errors,$item);
13004: }
1.43 raeburn 13005: }
13006: } else {
13007: push(@errors,$item);
13008: }
13009: }
1.54 raeburn 13010: } elsif ($item eq 'timezone_def') {
13011: if ($newvalues{$item} ne '') {
1.62 raeburn 13012: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 13013: push(@errors,$item);
13014: }
13015: }
1.68 raeburn 13016: } elsif ($item eq 'datelocale_def') {
13017: if ($newvalues{$item} ne '') {
13018: my @datelocale_ids = DateTime::Locale->ids();
13019: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
13020: push(@errors,$item);
13021: }
13022: }
1.141 raeburn 13023: } elsif ($item eq 'portal_def') {
13024: if ($newvalues{$item} ne '') {
13025: 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])\/?$/) {
13026: push(@errors,$item);
13027: }
13028: }
1.294 raeburn 13029: } elsif ($item eq 'intauth_cost') {
13030: if ($newvalues{$item} ne '') {
13031: if ($newvalues{$item} =~ /\D/) {
13032: push(@errors,$item);
13033: }
13034: }
13035: } elsif ($item eq 'intauth_check') {
13036: if ($newvalues{$item} ne '') {
13037: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
13038: push(@errors,$item);
13039: }
13040: }
13041: } elsif ($item eq 'intauth_switch') {
13042: if ($newvalues{$item} ne '') {
13043: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
13044: push(@errors,$item);
13045: }
13046: }
1.43 raeburn 13047: }
13048: if (grep(/^\Q$item\E$/,@errors)) {
13049: $newvalues{$item} = $domdefaults{$item};
13050: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
13051: $changes{$item} = 1;
13052: }
1.72 raeburn 13053: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 13054: }
13055: my %defaults_hash = (
1.72 raeburn 13056: defaults => \%newvalues,
13057: );
1.43 raeburn 13058: my $title = &defaults_titles();
1.236 raeburn 13059:
13060: my $currinststatus;
13061: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13062: $currinststatus = $domconfig{'inststatus'};
13063: } else {
13064: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13065: $currinststatus = {
13066: inststatustypes => $usertypes,
13067: inststatusorder => $types,
13068: inststatusguest => [],
13069: };
13070: }
13071: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
13072: my @allpos;
13073: my %alltypes;
1.305 raeburn 13074: my @inststatusguest;
13075: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
13076: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
13077: unless (grep(/^\Q$type\E$/,@todelete)) {
13078: push(@inststatusguest,$type);
13079: }
13080: }
13081: }
13082: my ($currtitles,$currorder);
1.236 raeburn 13083: if (ref($currinststatus) eq 'HASH') {
13084: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
13085: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
13086: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
13087: if ($currinststatus->{inststatustypes}->{$type} ne '') {
13088: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
13089: }
13090: }
13091: unless (grep(/^\Q$type\E$/,@todelete)) {
13092: my $position = $env{'form.inststatus_pos_'.$type};
13093: $position =~ s/\D+//g;
13094: $allpos[$position] = $type;
13095: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
13096: $alltypes{$type} =~ s/`//g;
13097: }
13098: }
13099: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
13100: $currtitles =~ s/,$//;
13101: }
13102: }
13103: if ($env{'form.addinststatus'}) {
13104: my $newtype = $env{'form.addinststatus'};
13105: $newtype =~ s/\W//g;
13106: unless (exists($alltypes{$newtype})) {
13107: $alltypes{$newtype} = $env{'form.addinststatus_title'};
13108: $alltypes{$newtype} =~ s/`//g;
13109: my $position = $env{'form.addinststatus_pos'};
13110: $position =~ s/\D+//g;
13111: if ($position ne '') {
13112: $allpos[$position] = $newtype;
13113: }
13114: }
13115: }
1.305 raeburn 13116: my @orderedstatus;
1.236 raeburn 13117: foreach my $type (@allpos) {
13118: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
13119: push(@orderedstatus,$type);
13120: }
13121: }
13122: foreach my $type (keys(%alltypes)) {
13123: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
13124: delete($alltypes{$type});
13125: }
13126: }
13127: $defaults_hash{'inststatus'} = {
13128: inststatustypes => \%alltypes,
13129: inststatusorder => \@orderedstatus,
1.305 raeburn 13130: inststatusguest => \@inststatusguest,
1.236 raeburn 13131: };
13132: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
13133: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
13134: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
13135: }
13136: }
13137: if ($currorder ne join(',',@orderedstatus)) {
13138: $changes{'inststatus'}{'inststatusorder'} = 1;
13139: }
13140: my $newtitles;
13141: foreach my $item (@orderedstatus) {
13142: $newtitles .= $alltypes{$item}.',';
13143: }
13144: $newtitles =~ s/,$//;
13145: if ($currtitles ne $newtitles) {
13146: $changes{'inststatus'}{'inststatustypes'} = 1;
13147: }
1.43 raeburn 13148: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
13149: $dom);
13150: if ($putresult eq 'ok') {
13151: if (keys(%changes) > 0) {
13152: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 13153: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 13154: 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";
13155: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 13156: if ($item eq 'inststatus') {
13157: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 13158: if (@orderedstatus) {
1.236 raeburn 13159: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
13160: foreach my $type (@orderedstatus) {
13161: $resulttext .= $alltypes{$type}.', ';
13162: }
13163: $resulttext =~ s/, $//;
13164: $resulttext .= '</li>';
1.305 raeburn 13165: } else {
13166: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 13167: }
13168: }
13169: } else {
13170: my $value = $env{'form.'.$item};
13171: if ($value eq '') {
13172: $value = &mt('none');
13173: } elsif ($item eq 'auth_def') {
13174: my %authnames = &authtype_names();
13175: my %shortauth = (
13176: internal => 'int',
13177: krb4 => 'krb4',
13178: krb5 => 'krb5',
13179: localauth => 'loc',
13180: );
13181: $value = $authnames{$shortauth{$value}};
1.294 raeburn 13182: } elsif ($item eq 'intauth_switch') {
13183: my %optiondesc = &Apache::lonlocal::texthash (
13184: 0 => 'No',
13185: 1 => 'Yes',
13186: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
13187: );
13188: if ($value =~ /^(0|1|2)$/) {
13189: $value = $optiondesc{$value};
13190: } else {
13191: $value = &mt('none -- defaults to No');
13192: }
13193: } elsif ($item eq 'intauth_check') {
13194: my %optiondesc = &Apache::lonlocal::texthash (
13195: 0 => 'No',
13196: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
13197: 2 => 'Yes, disallow login if stored cost is less than domain default',
13198: );
13199: if ($value =~ /^(0|1|2)$/) {
13200: $value = $optiondesc{$value};
13201: } else {
13202: $value = &mt('none -- defaults to No');
13203: }
1.236 raeburn 13204: }
13205: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
13206: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 13207: }
13208: }
13209: $resulttext .= '</ul>';
13210: $mailmsgtext .= "\n";
13211: my $cachetime = 24*60*60;
1.72 raeburn 13212: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13213: if (ref($lastactref) eq 'HASH') {
13214: $lastactref->{'domdefaults'} = 1;
13215: }
1.68 raeburn 13216: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 13217: my $notify = 1;
13218: if (ref($domconfig{'contacts'}) eq 'HASH') {
13219: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
13220: $notify = 0;
13221: }
13222: }
13223: if ($notify) {
13224: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
13225: "LON-CAPA Domain Settings Change - $dom",
13226: $mailmsgtext);
13227: }
1.54 raeburn 13228: }
1.43 raeburn 13229: } else {
1.54 raeburn 13230: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 13231: }
13232: } else {
13233: $resulttext = '<span class="LC_error">'.
13234: &mt('An error occurred: [_1]',$putresult).'</span>';
13235: }
13236: if (@errors > 0) {
13237: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
13238: foreach my $item (@errors) {
13239: $resulttext .= ' "'.$title->{$item}.'",';
13240: }
13241: $resulttext =~ s/,$//;
13242: }
13243: return $resulttext;
13244: }
13245:
1.46 raeburn 13246: sub modify_scantron {
1.205 raeburn 13247: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 13248: my ($resulttext,%confhash,%changes,$errors);
13249: my $custom = 'custom.tab';
13250: my $default = 'default.tab';
13251: my $servadm = $r->dir_config('lonAdmEMail');
13252: my ($configuserok,$author_ok,$switchserver) =
13253: &config_check($dom,$confname,$servadm);
13254: if ($env{'form.scantronformat.filename'} ne '') {
13255: my $error;
13256: if ($configuserok eq 'ok') {
13257: if ($switchserver) {
1.130 raeburn 13258: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 13259: } else {
13260: if ($author_ok eq 'ok') {
13261: my ($result,$scantronurl) =
13262: &publishlogo($r,'upload','scantronformat',$dom,
13263: $confname,'scantron','','',$custom);
13264: if ($result eq 'ok') {
13265: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 13266: $changes{'scantronformat'} = 1;
1.46 raeburn 13267: } else {
13268: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
13269: }
13270: } else {
13271: $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);
13272: }
13273: }
13274: } else {
13275: $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);
13276: }
13277: if ($error) {
13278: &Apache::lonnet::logthis($error);
13279: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13280: }
13281: }
1.48 raeburn 13282: if (ref($domconfig{'scantron'}) eq 'HASH') {
13283: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
13284: if ($env{'form.scantronformat_del'}) {
13285: $confhash{'scantron'}{'scantronformat'} = '';
13286: $changes{'scantronformat'} = 1;
1.46 raeburn 13287: }
13288: }
13289: }
13290: if (keys(%confhash) > 0) {
13291: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
13292: $dom);
13293: if ($putresult eq 'ok') {
13294: if (keys(%changes) > 0) {
1.48 raeburn 13295: if (ref($confhash{'scantron'}) eq 'HASH') {
13296: $resulttext = &mt('Changes made:').'<ul>';
13297: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 13298: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 13299: } else {
1.130 raeburn 13300: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 13301: }
1.48 raeburn 13302: $resulttext .= '</ul>';
13303: } else {
1.130 raeburn 13304: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 13305: }
13306: $resulttext .= '</ul>';
13307: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13308: if (ref($lastactref) eq 'HASH') {
13309: $lastactref->{'domainconfig'} = 1;
13310: }
1.46 raeburn 13311: } else {
1.130 raeburn 13312: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 13313: }
13314: } else {
13315: $resulttext = '<span class="LC_error">'.
13316: &mt('An error occurred: [_1]',$putresult).'</span>';
13317: }
13318: } else {
1.130 raeburn 13319: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 13320: }
13321: if ($errors) {
13322: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13323: $errors.'</ul>';
13324: }
13325: return $resulttext;
13326: }
13327:
1.48 raeburn 13328: sub modify_coursecategories {
1.239 raeburn 13329: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 13330: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
13331: $cathash);
1.48 raeburn 13332: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 13333: my @catitems = ('unauth','auth');
13334: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 13335: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 13336: $cathash = $domconfig{'coursecategories'}{'cats'};
13337: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
13338: $changes{'togglecats'} = 1;
13339: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
13340: }
13341: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
13342: $changes{'categorize'} = 1;
13343: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
13344: }
1.120 raeburn 13345: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
13346: $changes{'togglecatscomm'} = 1;
13347: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
13348: }
13349: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
13350: $changes{'categorizecomm'} = 1;
13351: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 13352:
13353: }
13354: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
13355: $changes{'togglecatsplace'} = 1;
13356: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
13357: }
13358: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
13359: $changes{'categorizeplace'} = 1;
13360: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 13361: }
1.238 raeburn 13362: foreach my $item (@catitems) {
13363: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
13364: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
13365: $changes{$item} = 1;
13366: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
13367: }
13368: }
13369: }
1.57 raeburn 13370: } else {
13371: $changes{'togglecats'} = 1;
13372: $changes{'categorize'} = 1;
1.124 raeburn 13373: $changes{'togglecatscomm'} = 1;
13374: $changes{'categorizecomm'} = 1;
1.272 raeburn 13375: $changes{'togglecatsplace'} = 1;
13376: $changes{'categorizeplace'} = 1;
1.87 raeburn 13377: $domconfig{'coursecategories'} = {
13378: togglecats => $env{'form.togglecats'},
13379: categorize => $env{'form.categorize'},
1.124 raeburn 13380: togglecatscomm => $env{'form.togglecatscomm'},
13381: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 13382: togglecatsplace => $env{'form.togglecatsplace'},
13383: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 13384: };
1.238 raeburn 13385: foreach my $item (@catitems) {
13386: if ($env{'form.coursecat_'.$item} ne 'std') {
13387: $changes{$item} = 1;
13388: }
13389: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
13390: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
13391: }
13392: }
1.57 raeburn 13393: }
13394: if (ref($cathash) eq 'HASH') {
13395: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 13396: push (@deletecategory,'instcode::0');
13397: }
1.120 raeburn 13398: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
13399: push(@deletecategory,'communities::0');
13400: }
1.272 raeburn 13401: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
13402: push(@deletecategory,'placement::0');
13403: }
1.48 raeburn 13404: }
1.57 raeburn 13405: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
13406: if (ref($cathash) eq 'HASH') {
1.48 raeburn 13407: if (@deletecategory > 0) {
13408: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 13409: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 13410: foreach my $item (@deletecategory) {
1.57 raeburn 13411: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
13412: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 13413: $deletions{$item} = 1;
1.57 raeburn 13414: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 13415: }
13416: }
13417: }
1.57 raeburn 13418: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 13419: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 13420: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 13421: $reorderings{$item} = 1;
1.57 raeburn 13422: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 13423: }
13424: if ($env{'form.addcategory_name_'.$item} ne '') {
13425: my $newcat = $env{'form.addcategory_name_'.$item};
13426: my $newdepth = $depth+1;
13427: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 13428: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 13429: $adds{$newitem} = 1;
13430: }
13431: if ($env{'form.subcat_'.$item} ne '') {
13432: my $newcat = $env{'form.subcat_'.$item};
13433: my $newdepth = $depth+1;
13434: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 13435: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 13436: $adds{$newitem} = 1;
13437: }
13438: }
13439: }
13440: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 13441: if (ref($cathash) eq 'HASH') {
1.48 raeburn 13442: my $newitem = 'instcode::0';
1.57 raeburn 13443: if ($cathash->{$newitem} eq '') {
13444: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 13445: $adds{$newitem} = 1;
13446: }
13447: } else {
13448: my $newitem = 'instcode::0';
1.57 raeburn 13449: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 13450: $adds{$newitem} = 1;
13451: }
13452: }
1.120 raeburn 13453: if ($env{'form.communities'} eq '1') {
13454: if (ref($cathash) eq 'HASH') {
13455: my $newitem = 'communities::0';
13456: if ($cathash->{$newitem} eq '') {
13457: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
13458: $adds{$newitem} = 1;
13459: }
13460: } else {
13461: my $newitem = 'communities::0';
13462: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
13463: $adds{$newitem} = 1;
13464: }
13465: }
1.272 raeburn 13466: if ($env{'form.placement'} eq '1') {
13467: if (ref($cathash) eq 'HASH') {
13468: my $newitem = 'placement::0';
13469: if ($cathash->{$newitem} eq '') {
13470: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
13471: $adds{$newitem} = 1;
13472: }
13473: } else {
13474: my $newitem = 'placement::0';
13475: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
13476: $adds{$newitem} = 1;
13477: }
13478: }
1.48 raeburn 13479: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 13480: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 13481: ($env{'form.addcategory_name'} ne 'communities') &&
13482: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 13483: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
13484: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
13485: $adds{$newitem} = 1;
13486: }
1.48 raeburn 13487: }
1.57 raeburn 13488: my $putresult;
1.48 raeburn 13489: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13490: if (keys(%deletions) > 0) {
13491: foreach my $key (keys(%deletions)) {
13492: if ($predelallitems{$key} ne '') {
13493: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
13494: }
13495: }
13496: }
13497: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 13498: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 13499: if (ref($chkcats[0]) eq 'ARRAY') {
13500: my $depth = 0;
13501: my $chg = 0;
13502: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
13503: my $name = $chkcats[0][$i];
13504: my $item;
13505: if ($name eq '') {
13506: $chg ++;
13507: } else {
13508: $item = &escape($name).'::0';
13509: if ($chg) {
1.57 raeburn 13510: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 13511: }
13512: $depth ++;
1.57 raeburn 13513: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 13514: $depth --;
13515: }
13516: }
13517: }
1.57 raeburn 13518: }
13519: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13520: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 13521: if ($putresult eq 'ok') {
1.57 raeburn 13522: my %title = (
1.120 raeburn 13523: togglecats => 'Show/Hide a course in catalog',
13524: categorize => 'Assign a category to a course',
13525: togglecatscomm => 'Show/Hide a community in catalog',
13526: categorizecomm => 'Assign a category to a community',
1.57 raeburn 13527: );
13528: my %level = (
1.120 raeburn 13529: dom => 'set in Domain ("Modify Course/Community")',
13530: crs => 'set in Course ("Course Configuration")',
13531: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 13532: none => 'No catalog',
13533: std => 'Standard catalog',
13534: domonly => 'Domain-only catalog',
13535: codesrch => 'Code search form',
1.57 raeburn 13536: );
1.48 raeburn 13537: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 13538: if ($changes{'togglecats'}) {
13539: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
13540: }
13541: if ($changes{'categorize'}) {
13542: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 13543: }
1.120 raeburn 13544: if ($changes{'togglecatscomm'}) {
13545: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
13546: }
13547: if ($changes{'categorizecomm'}) {
13548: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
13549: }
1.238 raeburn 13550: if ($changes{'unauth'}) {
13551: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
13552: }
13553: if ($changes{'auth'}) {
13554: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
13555: }
1.57 raeburn 13556: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13557: my $cathash;
13558: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
13559: $cathash = $domconfig{'coursecategories'}{'cats'};
13560: } else {
13561: $cathash = {};
13562: }
13563: my (@cats,@trails,%allitems);
13564: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
13565: if (keys(%deletions) > 0) {
13566: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
13567: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
13568: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
13569: }
13570: $resulttext .= '</ul></li>';
13571: }
13572: if (keys(%reorderings) > 0) {
13573: my %sort_by_trail;
13574: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
13575: foreach my $key (keys(%reorderings)) {
13576: if ($allitems{$key} ne '') {
13577: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
13578: }
1.48 raeburn 13579: }
1.57 raeburn 13580: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
13581: $resulttext .= '<li>'.$trails[$trail].'</li>';
13582: }
13583: $resulttext .= '</ul></li>';
1.48 raeburn 13584: }
1.57 raeburn 13585: if (keys(%adds) > 0) {
13586: my %sort_by_trail;
13587: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
13588: foreach my $key (keys(%adds)) {
13589: if ($allitems{$key} ne '') {
13590: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
13591: }
13592: }
13593: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
13594: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 13595: }
1.57 raeburn 13596: $resulttext .= '</ul></li>';
1.48 raeburn 13597: }
13598: }
13599: $resulttext .= '</ul>';
1.239 raeburn 13600: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 13601: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
13602: if ($changes{'auth'}) {
13603: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
13604: }
13605: if ($changes{'unauth'}) {
13606: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
13607: }
13608: my $cachetime = 24*60*60;
13609: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 13610: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 13611: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 13612: }
13613: }
1.48 raeburn 13614: } else {
13615: $resulttext = '<span class="LC_error">'.
1.57 raeburn 13616: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 13617: }
13618: } else {
1.120 raeburn 13619: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 13620: }
13621: return $resulttext;
13622: }
13623:
1.69 raeburn 13624: sub modify_serverstatuses {
13625: my ($dom,%domconfig) = @_;
13626: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
13627: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
13628: %currserverstatus = %{$domconfig{'serverstatuses'}};
13629: }
13630: my @pages = &serverstatus_pages();
13631: foreach my $type (@pages) {
13632: $newserverstatus{$type}{'namedusers'} = '';
13633: $newserverstatus{$type}{'machines'} = '';
13634: if (defined($env{'form.'.$type.'_namedusers'})) {
13635: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
13636: my @okusers;
13637: foreach my $user (@users) {
13638: my ($uname,$udom) = split(/:/,$user);
13639: if (($udom =~ /^$match_domain$/) &&
13640: (&Apache::lonnet::domain($udom)) &&
13641: ($uname =~ /^$match_username$/)) {
13642: if (!grep(/^\Q$user\E/,@okusers)) {
13643: push(@okusers,$user);
13644: }
13645: }
13646: }
13647: if (@okusers > 0) {
13648: @okusers = sort(@okusers);
13649: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
13650: }
13651: }
13652: if (defined($env{'form.'.$type.'_machines'})) {
13653: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
13654: my @okmachines;
13655: foreach my $ip (@machines) {
13656: my @parts = split(/\./,$ip);
13657: next if (@parts < 4);
13658: my $badip = 0;
13659: for (my $i=0; $i<4; $i++) {
13660: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
13661: $badip = 1;
13662: last;
13663: }
13664: }
13665: if (!$badip) {
13666: push(@okmachines,$ip);
13667: }
13668: }
13669: @okmachines = sort(@okmachines);
13670: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
13671: }
13672: }
13673: my %serverstatushash = (
13674: serverstatuses => \%newserverstatus,
13675: );
13676: foreach my $type (@pages) {
1.83 raeburn 13677: foreach my $setting ('namedusers','machines') {
1.84 raeburn 13678: my (@current,@new);
1.83 raeburn 13679: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 13680: if ($currserverstatus{$type}{$setting} ne '') {
13681: @current = split(/,/,$currserverstatus{$type}{$setting});
13682: }
13683: }
13684: if ($newserverstatus{$type}{$setting} ne '') {
13685: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 13686: }
13687: if (@current > 0) {
13688: if (@new > 0) {
13689: foreach my $item (@current) {
13690: if (!grep(/^\Q$item\E$/,@new)) {
13691: $changes{$type}{$setting} = 1;
1.82 raeburn 13692: last;
13693: }
13694: }
1.84 raeburn 13695: foreach my $item (@new) {
13696: if (!grep(/^\Q$item\E$/,@current)) {
13697: $changes{$type}{$setting} = 1;
13698: last;
1.82 raeburn 13699: }
13700: }
13701: } else {
1.83 raeburn 13702: $changes{$type}{$setting} = 1;
1.69 raeburn 13703: }
1.83 raeburn 13704: } elsif (@new > 0) {
13705: $changes{$type}{$setting} = 1;
1.69 raeburn 13706: }
13707: }
13708: }
13709: if (keys(%changes) > 0) {
1.81 raeburn 13710: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 13711: my $putresult = &Apache::lonnet::put_dom('configuration',
13712: \%serverstatushash,$dom);
13713: if ($putresult eq 'ok') {
13714: $resulttext .= &mt('Changes made:').'<ul>';
13715: foreach my $type (@pages) {
1.84 raeburn 13716: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 13717: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 13718: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 13719: if ($newserverstatus{$type}{'namedusers'} eq '') {
13720: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
13721: } else {
13722: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
13723: }
1.84 raeburn 13724: }
13725: if ($changes{$type}{'machines'}) {
1.69 raeburn 13726: if ($newserverstatus{$type}{'machines'} eq '') {
13727: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
13728: } else {
13729: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
13730: }
13731:
13732: }
13733: $resulttext .= '</ul></li>';
13734: }
13735: }
13736: $resulttext .= '</ul>';
13737: } else {
13738: $resulttext = '<span class="LC_error">'.
13739: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
13740:
13741: }
13742: } else {
13743: $resulttext = &mt('No changes made to access to server status pages');
13744: }
13745: return $resulttext;
13746: }
13747:
1.118 jms 13748: sub modify_helpsettings {
1.285 raeburn 13749: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 13750: my ($resulttext,$errors,%changes,%helphash);
13751: my %defaultchecked = ('submitbugs' => 'on');
13752: my @offon = ('off','on');
1.118 jms 13753: my @toggles = ('submitbugs');
1.285 raeburn 13754: my %current = ('submitbugs' => '',
13755: 'adhoc' => {},
13756: );
1.118 jms 13757: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 13758: %current = %{$domconfig{'helpsettings'}};
13759: }
1.285 raeburn 13760: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 13761: foreach my $item (@toggles) {
13762: if ($defaultchecked{$item} eq 'on') {
13763: if ($current{$item} eq '') {
13764: if ($env{'form.'.$item} eq '0') {
13765: $changes{$item} = 1;
13766: }
13767: } elsif ($current{$item} ne $env{'form.'.$item}) {
13768: $changes{$item} = 1;
13769: }
13770: } elsif ($defaultchecked{$item} eq 'off') {
13771: if ($current{$item} eq '') {
13772: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 13773: $changes{$item} = 1;
13774: }
1.282 raeburn 13775: } elsif ($current{$item} ne $env{'form.'.$item}) {
13776: $changes{$item} = 1;
13777: }
13778: }
13779: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
13780: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
13781: }
13782: }
1.285 raeburn 13783: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 13784: my $confname = $dom.'-domainconfig';
13785: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 13786: my (@allpos,%newsettings,%changedprivs,$newrole);
13787: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 13788: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 13789: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 13790: my %lt = &Apache::lonlocal::texthash(
13791: s => 'system',
13792: d => 'domain',
13793: order => 'Display order',
13794: access => 'Role usage',
1.291 raeburn 13795: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 13796: dh => 'All with domain helpdesk role',
13797: da => 'All with domain helpdesk assistant role',
1.285 raeburn 13798: none => 'None',
13799: status => 'Determined based on institutional status',
13800: inc => 'Include all, but exclude specific personnel',
13801: exc => 'Exclude all, but include specific personnel',
13802: );
13803: for (my $num=0; $num<=$maxnum; $num++) {
13804: my ($prefix,$identifier,$rolename,%curr);
13805: if ($num == $maxnum) {
13806: next unless ($env{'form.newcusthelp'} == $maxnum);
13807: $identifier = 'custhelp'.$num;
13808: $prefix = 'helproles_'.$num;
13809: $rolename = $env{'form.custhelpname'.$num};
13810: $rolename=~s/[^A-Za-z0-9]//gs;
13811: next if ($rolename eq '');
13812: next if (exists($existing{'rolesdef_'.$rolename}));
13813: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13814: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13815: $newprivs{'c'},$confname,$dom);
13816: if ($result ne 'ok') {
13817: $errors .= '<li><span class="LC_error">'.
13818: &mt('An error occurred storing the new custom role: [_1]',
13819: $result).'</span></li>';
13820: next;
13821: } else {
13822: $changedprivs{$rolename} = \%newprivs;
13823: $newrole = $rolename;
13824: }
13825: } else {
13826: $prefix = 'helproles_'.$num;
13827: $rolename = $env{'form.'.$prefix};
13828: next if ($rolename eq '');
13829: next unless (exists($existing{'rolesdef_'.$rolename}));
13830: $identifier = 'custhelp'.$num;
13831: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13832: my %currprivs;
1.289 raeburn 13833: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 13834: split(/\_/,$existing{'rolesdef_'.$rolename});
13835: foreach my $level ('c','d','s') {
13836: if ($newprivs{$level} ne $currprivs{$level}) {
13837: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13838: $newprivs{'c'},$confname,$dom);
13839: if ($result ne 'ok') {
13840: $errors .= '<li><span class="LC_error">'.
13841: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
13842: $rolename,$result).'</span></li>';
13843: } else {
13844: $changedprivs{$rolename} = \%newprivs;
13845: }
13846: last;
13847: }
13848: }
13849: if (ref($current{'adhoc'}) eq 'HASH') {
13850: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13851: %curr = %{$current{'adhoc'}{$rolename}};
13852: }
13853: }
13854: }
13855: my $newpos = $env{'form.'.$prefix.'_pos'};
13856: $newpos =~ s/\D+//g;
13857: $allpos[$newpos] = $rolename;
13858: my $newdesc = $env{'form.'.$prefix.'_desc'};
13859: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
13860: if ($curr{'desc'}) {
13861: if ($curr{'desc'} ne $newdesc) {
13862: $changes{'customrole'}{$rolename}{'desc'} = 1;
13863: $newsettings{$rolename}{'desc'} = $newdesc;
13864: }
13865: } elsif ($newdesc ne '') {
13866: $changes{'customrole'}{$rolename}{'desc'} = 1;
13867: $newsettings{$rolename}{'desc'} = $newdesc;
13868: }
13869: my $access = $env{'form.'.$prefix.'_access'};
13870: if (grep(/^\Q$access\E$/,@accesstypes)) {
13871: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
13872: if ($access eq 'status') {
13873: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
13874: if (scalar(@statuses) == 0) {
1.289 raeburn 13875: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 13876: } else {
13877: my (@shownstatus,$numtypes);
13878: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13879: if (ref($types) eq 'ARRAY') {
13880: $numtypes = scalar(@{$types});
13881: foreach my $type (sort(@statuses)) {
13882: if ($type eq 'default') {
13883: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13884: } elsif (grep(/^\Q$type\E$/,@{$types})) {
13885: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13886: push(@shownstatus,$usertypes->{$type});
13887: }
13888: }
13889: }
13890: if (grep(/^default$/,@statuses)) {
13891: push(@shownstatus,$othertitle);
13892: }
13893: if (scalar(@shownstatus) == 1+$numtypes) {
13894: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
13895: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
13896: } else {
13897: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
13898: if (ref($curr{'status'}) eq 'ARRAY') {
13899: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13900: if (@diffs) {
13901: $changes{'customrole'}{$rolename}{$access} = 1;
13902: }
13903: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13904: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 13905: }
1.166 raeburn 13906: }
13907: }
1.285 raeburn 13908: } elsif (($access eq 'inc') || ($access eq 'exc')) {
13909: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
13910: my @newspecstaff;
13911: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13912: foreach my $person (sort(@personnel)) {
13913: if ($domhelpdesk{$person}) {
13914: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
13915: }
13916: }
13917: if (ref($curr{$access}) eq 'ARRAY') {
13918: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13919: if (@diffs) {
13920: $changes{'customrole'}{$rolename}{$access} = 1;
13921: }
13922: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13923: $changes{'customrole'}{$rolename}{$access} = 1;
13924: }
13925: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13926: my ($uname,$udom) = split(/:/,$person);
13927: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
13928: }
13929: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 13930: }
1.285 raeburn 13931: } else {
13932: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
13933: }
13934: unless ($curr{'access'} eq $access) {
13935: $changes{'customrole'}{$rolename}{'access'} = 1;
13936: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 13937: }
13938: }
1.285 raeburn 13939: if (@allpos > 0) {
13940: my $idx = 0;
13941: foreach my $rolename (@allpos) {
13942: if ($rolename ne '') {
13943: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
13944: if (ref($current{'adhoc'}) eq 'HASH') {
13945: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13946: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
13947: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 13948: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 13949: }
13950: }
1.282 raeburn 13951: }
1.285 raeburn 13952: $idx ++;
1.166 raeburn 13953: }
13954: }
1.118 jms 13955: }
1.123 jms 13956: my $putresult;
13957: if (keys(%changes) > 0) {
1.166 raeburn 13958: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 13959: if ($putresult eq 'ok') {
1.285 raeburn 13960: if (ref($helphash{'helpsettings'}) eq 'HASH') {
13961: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
13962: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
13963: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
13964: }
13965: }
13966: my $cachetime = 24*60*60;
13967: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13968: if (ref($lastactref) eq 'HASH') {
13969: $lastactref->{'domdefaults'} = 1;
13970: }
13971: } else {
13972: $errors .= '<li><span class="LC_error">'.
13973: &mt('An error occurred storing the settings: [_1]',
13974: $putresult).'</span></li>';
13975: }
13976: }
13977: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
13978: $resulttext = &mt('Changes made:').'<ul>';
13979: my (%shownprivs,@levelorder);
13980: @levelorder = ('c','d','s');
13981: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 13982: foreach my $item (sort(keys(%changes))) {
13983: if ($item eq 'submitbugs') {
13984: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
13985: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
13986: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 13987: } elsif ($item eq 'customrole') {
13988: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 13989: my @keyorder = ('order','desc','access','status','exc','inc');
13990: my %keytext = &Apache::lonlocal::texthash(
13991: order => 'Order',
13992: desc => 'Role description',
13993: access => 'Role usage',
1.300 droeschl 13994: status => 'Allowed institutional types',
1.285 raeburn 13995: exc => 'Allowed personnel',
13996: inc => 'Disallowed personnel',
13997: );
1.282 raeburn 13998: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 13999: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
14000: if ($role eq $newrole) {
14001: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
14002: $role).'<ul>';
14003: } else {
14004: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
14005: $role).'<ul>';
14006: }
14007: foreach my $key (@keyorder) {
14008: if ($changes{'customrole'}{$role}{$key}) {
14009: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
14010: $keytext{$key},$newsettings{$role}{$key}).
14011: '</li>';
14012: }
14013: }
14014: if (ref($changedprivs{$role}) eq 'HASH') {
14015: $shownprivs{$role} = 1;
14016: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
14017: foreach my $level (@levelorder) {
14018: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
14019: next if ($item eq '');
14020: my ($priv) = split(/\&/,$item,2);
14021: if (&Apache::lonnet::plaintext($priv)) {
14022: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
14023: unless ($level eq 'c') {
14024: $resulttext .= ' ('.$lt{$level}.')';
14025: }
14026: $resulttext .= '</li>';
14027: }
14028: }
14029: }
14030: $resulttext .= '</ul>';
14031: }
14032: $resulttext .= '</ul></li>';
14033: }
14034: }
14035: }
14036: }
14037: }
14038: }
14039: if (keys(%changedprivs)) {
14040: foreach my $role (sort(keys(%changedprivs))) {
14041: unless ($shownprivs{$role}) {
14042: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
14043: $role).'<ul>'.
14044: '<li>'.&mt('Privileges set to :').'<ul>';
14045: foreach my $level (@levelorder) {
14046: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
14047: next if ($item eq '');
14048: my ($priv) = split(/\&/,$item,2);
14049: if (&Apache::lonnet::plaintext($priv)) {
14050: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
14051: unless ($level eq 'c') {
14052: $resulttext .= ' ('.$lt{$level}.')';
14053: }
14054: $resulttext .= '</li>';
14055: }
1.282 raeburn 14056: }
14057: }
1.285 raeburn 14058: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 14059: }
14060: }
14061: }
1.285 raeburn 14062: $resulttext .= '</ul>';
14063: } else {
14064: $resulttext = &mt('No changes made to help settings');
1.118 jms 14065: }
14066: if ($errors) {
1.168 raeburn 14067: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 14068: $errors.'</ul>';
1.118 jms 14069: }
14070: return $resulttext;
14071: }
14072:
1.121 raeburn 14073: sub modify_coursedefaults {
1.212 raeburn 14074: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 14075: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 14076: my %defaultchecked = (
14077: 'canuse_pdfforms' => 'off',
14078: 'uselcmath' => 'on',
14079: 'usejsme' => 'on'
14080: );
14081: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 14082: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 14083: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
14084: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
14085: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 14086: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 14087: my %staticdefaults = (
14088: anonsurvey_threshold => 10,
14089: uploadquota => 500,
1.257 raeburn 14090: postsubmit => 60,
1.276 raeburn 14091: mysqltables => 172800,
1.198 raeburn 14092: );
1.314 raeburn 14093: my %texoptions = (
14094: MathJax => 'MathJax',
14095: mimetex => &mt('Convert to Images'),
14096: tth => &mt('TeX to HTML'),
14097: );
1.121 raeburn 14098: $defaultshash{'coursedefaults'} = {};
14099:
14100: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
14101: if ($domconfig{'coursedefaults'} eq '') {
14102: $domconfig{'coursedefaults'} = {};
14103: }
14104: }
14105:
14106: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
14107: foreach my $item (@toggles) {
14108: if ($defaultchecked{$item} eq 'on') {
14109: if (($domconfig{'coursedefaults'}{$item} eq '') &&
14110: ($env{'form.'.$item} eq '0')) {
14111: $changes{$item} = 1;
1.192 raeburn 14112: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 14113: $changes{$item} = 1;
14114: }
14115: } elsif ($defaultchecked{$item} eq 'off') {
14116: if (($domconfig{'coursedefaults'}{$item} eq '') &&
14117: ($env{'form.'.$item} eq '1')) {
14118: $changes{$item} = 1;
14119: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
14120: $changes{$item} = 1;
14121: }
14122: }
14123: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
14124: }
1.198 raeburn 14125: foreach my $item (@numbers) {
14126: my ($currdef,$newdef);
1.208 raeburn 14127: $newdef = $env{'form.'.$item};
1.198 raeburn 14128: if ($item eq 'anonsurvey_threshold') {
14129: $currdef = $domconfig{'coursedefaults'}{$item};
14130: $newdef =~ s/\D//g;
14131: if ($newdef eq '' || $newdef < 1) {
14132: $newdef = 1;
14133: }
14134: $defaultshash{'coursedefaults'}{$item} = $newdef;
14135: } else {
1.276 raeburn 14136: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
14137: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
14138: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 14139: }
14140: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 14141: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 14142: }
14143: if ($currdef ne $newdef) {
14144: my $staticdef;
14145: if ($item eq 'anonsurvey_threshold') {
14146: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
14147: $changes{$item} = 1;
14148: }
1.276 raeburn 14149: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 14150: my $setting = $1;
1.276 raeburn 14151: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
14152: $changes{$setting} = 1;
1.198 raeburn 14153: }
14154: }
1.139 raeburn 14155: }
14156: }
1.314 raeburn 14157: my $texengine;
14158: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
14159: $texengine = $env{'form.texengine'};
14160: if ($defaultshash{'coursedefaults'}{'texengine'} eq '') {
14161: unless ($texengine eq 'MathJax') {
14162: $changes{'texengine'} = 1;
14163: }
14164: } elsif ($defaultshash{'coursedefaults'}{'texengine'} ne $texengine) {
14165: $changes{'texengine'} = 1;
14166: }
14167: }
14168: if ($texengine ne '') {
14169: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
14170: }
1.264 raeburn 14171: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
14172: my @currclonecode;
14173: if (ref($currclone) eq 'HASH') {
14174: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
14175: @currclonecode = @{$currclone->{'instcode'}};
14176: }
14177: }
14178: my $newclone;
1.289 raeburn 14179: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 14180: $newclone = $env{'form.canclone'};
14181: }
14182: if ($newclone eq 'instcode') {
14183: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
14184: my (%codedefaults,@code_order,@clonecode);
14185: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
14186: \@code_order);
14187: foreach my $item (@code_order) {
14188: if (grep(/^\Q$item\E$/,@newcodes)) {
14189: push(@clonecode,$item);
14190: }
14191: }
14192: if (@clonecode) {
14193: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
14194: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
14195: if (@diffs) {
14196: $changes{'canclone'} = 1;
14197: }
14198: } else {
14199: $newclone eq '';
14200: }
14201: } elsif ($newclone ne '') {
1.289 raeburn 14202: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
14203: }
1.264 raeburn 14204: if ($newclone ne $currclone) {
14205: $changes{'canclone'} = 1;
14206: }
1.257 raeburn 14207: my %credits;
14208: foreach my $type (@types) {
14209: unless ($type eq 'community') {
14210: $credits{$type} = $env{'form.'.$type.'_credits'};
14211: $credits{$type} =~ s/[^\d.]+//g;
14212: }
14213: }
14214: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
14215: ($env{'form.coursecredits'} eq '1')) {
14216: $changes{'coursecredits'} = 1;
14217: foreach my $type (keys(%credits)) {
14218: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
14219: }
14220: } else {
1.289 raeburn 14221: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 14222: foreach my $type (@types) {
14223: unless ($type eq 'community') {
1.289 raeburn 14224: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 14225: $changes{'coursecredits'} = 1;
14226: }
14227: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
14228: }
14229: }
14230: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
14231: foreach my $type (@types) {
14232: unless ($type eq 'community') {
14233: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
14234: $changes{'coursecredits'} = 1;
14235: last;
14236: }
14237: }
14238: }
14239: }
14240: }
14241: if ($env{'form.postsubmit'} eq '1') {
14242: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
14243: my %currtimeout;
14244: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
14245: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
14246: $changes{'postsubmit'} = 1;
14247: }
14248: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
14249: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
14250: }
14251: } else {
14252: $changes{'postsubmit'} = 1;
14253: }
14254: foreach my $type (@types) {
14255: my $timeout = $env{'form.'.$type.'_timeout'};
14256: $timeout =~ s/\D//g;
14257: if ($timeout == $staticdefaults{'postsubmit'}) {
14258: $timeout = '';
14259: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
14260: $timeout = '0';
14261: }
14262: unless ($timeout eq '') {
14263: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
14264: }
14265: if (exists($currtimeout{$type})) {
14266: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 14267: $changes{'postsubmit'} = 1;
1.257 raeburn 14268: }
14269: } elsif ($timeout ne '') {
14270: $changes{'postsubmit'} = 1;
14271: }
14272: }
14273: } else {
14274: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
14275: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
14276: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
14277: $changes{'postsubmit'} = 1;
14278: }
14279: } else {
14280: $changes{'postsubmit'} = 1;
14281: }
1.192 raeburn 14282: }
1.121 raeburn 14283: }
14284: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14285: $dom);
14286: if ($putresult eq 'ok') {
14287: if (keys(%changes) > 0) {
1.213 raeburn 14288: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 14289: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 14290: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 14291: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
14292: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 14293: if ($changes{$item}) {
14294: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
14295: }
1.289 raeburn 14296: }
1.192 raeburn 14297: if ($changes{'coursecredits'}) {
14298: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 14299: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
14300: $domdefaults{$type.'credits'} =
14301: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
14302: }
14303: }
14304: }
14305: if ($changes{'postsubmit'}) {
14306: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
14307: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
14308: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
14309: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
14310: $domdefaults{$type.'postsubtimeout'} =
14311: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
14312: }
14313: }
1.192 raeburn 14314: }
14315: }
1.198 raeburn 14316: if ($changes{'uploadquota'}) {
14317: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
14318: foreach my $type (@types) {
14319: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
14320: }
14321: }
14322: }
1.264 raeburn 14323: if ($changes{'canclone'}) {
14324: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
14325: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
14326: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
14327: if (@clonecodes) {
14328: $domdefaults{'canclone'} = join('+',@clonecodes);
14329: }
14330: }
14331: } else {
14332: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
14333: }
14334: }
1.121 raeburn 14335: my $cachetime = 24*60*60;
14336: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14337: if (ref($lastactref) eq 'HASH') {
14338: $lastactref->{'domdefaults'} = 1;
14339: }
1.121 raeburn 14340: }
14341: $resulttext = &mt('Changes made:').'<ul>';
14342: foreach my $item (sort(keys(%changes))) {
14343: if ($item eq 'canuse_pdfforms') {
14344: if ($env{'form.'.$item} eq '1') {
14345: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
14346: } else {
14347: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
14348: }
1.257 raeburn 14349: } elsif ($item eq 'uselcmath') {
14350: if ($env{'form.'.$item} eq '1') {
14351: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
14352: } else {
14353: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
14354: }
14355: } elsif ($item eq 'usejsme') {
14356: if ($env{'form.'.$item} eq '1') {
14357: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
14358: } else {
1.289 raeburn 14359: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 14360: }
1.314 raeburn 14361: } elsif ($item eq 'texengine') {
14362: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
14363: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
14364: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
14365: }
1.139 raeburn 14366: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 14367: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 14368: } elsif ($item eq 'uploadquota') {
14369: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
14370: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
14371: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
14372: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 14373: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 14374: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 14375: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
14376: '</ul>'.
14377: '</li>';
14378: } else {
14379: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
14380: }
1.276 raeburn 14381: } elsif ($item eq 'mysqltables') {
14382: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
14383: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
14384: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
14385: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
14386: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
14387: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
14388: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
14389: '</ul>'.
14390: '</li>';
14391: } else {
14392: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
14393: }
1.257 raeburn 14394: } elsif ($item eq 'postsubmit') {
14395: if ($domdefaults{'postsubmit'} eq 'off') {
14396: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
14397: } else {
14398: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 14399: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 14400: $resulttext .= &mt('durations:').'<ul>';
14401: foreach my $type (@types) {
14402: $resulttext .= '<li>';
14403: my $timeout;
14404: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
14405: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
14406: }
14407: my $display;
14408: if ($timeout eq '0') {
14409: $display = &mt('unlimited');
14410: } elsif ($timeout eq '') {
14411: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
14412: } else {
14413: $display = &mt('[quant,_1,second]',$timeout);
14414: }
14415: if ($type eq 'community') {
14416: $resulttext .= &mt('Communities');
14417: } elsif ($type eq 'official') {
14418: $resulttext .= &mt('Official courses');
14419: } elsif ($type eq 'unofficial') {
14420: $resulttext .= &mt('Unofficial courses');
14421: } elsif ($type eq 'textbook') {
14422: $resulttext .= &mt('Textbook courses');
1.271 raeburn 14423: } elsif ($type eq 'placement') {
14424: $resulttext .= &mt('Placement tests');
1.257 raeburn 14425: }
14426: $resulttext .= ' -- '.$display.'</li>';
14427: }
14428: $resulttext .= '</ul>';
14429: }
1.289 raeburn 14430: $resulttext .= '</li>';
1.257 raeburn 14431: }
1.192 raeburn 14432: } elsif ($item eq 'coursecredits') {
14433: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
14434: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 14435: ($domdefaults{'unofficialcredits'} eq '') &&
14436: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 14437: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
14438: } else {
14439: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
14440: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
14441: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 14442: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 14443: '</ul>'.
14444: '</li>';
14445: }
14446: } else {
14447: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
14448: }
1.264 raeburn 14449: } elsif ($item eq 'canclone') {
14450: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
14451: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
14452: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
14453: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
14454: }
14455: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
14456: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
14457: } else {
1.289 raeburn 14458: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 14459: }
1.140 raeburn 14460: }
1.121 raeburn 14461: }
14462: $resulttext .= '</ul>';
14463: } else {
14464: $resulttext = &mt('No changes made to course defaults');
14465: }
14466: } else {
14467: $resulttext = '<span class="LC_error">'.
14468: &mt('An error occurred: [_1]',$putresult).'</span>';
14469: }
14470: return $resulttext;
14471: }
14472:
1.231 raeburn 14473: sub modify_selfenrollment {
14474: my ($dom,$lastactref,%domconfig) = @_;
14475: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 14476: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 14477: my %titles = &tool_titles();
1.232 raeburn 14478: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
14479: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 14480: $ordered{'default'} = ['types','registered','approval','limit'];
14481:
14482: my (%roles,%shown,%toplevel);
14483: $roles{'0'} = &Apache::lonnet::plaintext('dc');
14484:
14485: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
14486: if ($domconfig{'selfenrollment'} eq '') {
14487: $domconfig{'selfenrollment'} = {};
14488: }
14489: }
14490: %toplevel = (
14491: admin => 'Configuration Rights',
14492: default => 'Default settings',
14493: validation => 'Validation of self-enrollment requests',
14494: );
1.233 raeburn 14495: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 14496:
14497: if (ref($ordered{'admin'}) eq 'ARRAY') {
14498: foreach my $item (@{$ordered{'admin'}}) {
14499: foreach my $type (@types) {
14500: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
14501: $selfenrollhash{'admin'}{$type}{$item} = 1;
14502: } else {
14503: $selfenrollhash{'admin'}{$type}{$item} = 0;
14504: }
14505: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
14506: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
14507: if ($selfenrollhash{'admin'}{$type}{$item} ne
14508: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
14509: push(@{$changes{'admin'}{$type}},$item);
14510: }
14511: } else {
14512: if (!$selfenrollhash{'admin'}{$type}{$item}) {
14513: push(@{$changes{'admin'}{$type}},$item);
14514: }
14515: }
14516: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
14517: push(@{$changes{'admin'}{$type}},$item);
14518: }
14519: }
14520: }
14521: }
14522:
14523: foreach my $item (@{$ordered{'default'}}) {
14524: foreach my $type (@types) {
14525: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
14526: if ($item eq 'types') {
14527: unless (($value eq 'all') || ($value eq 'dom')) {
14528: $value = '';
14529: }
14530: } elsif ($item eq 'registered') {
14531: unless ($value eq '1') {
14532: $value = 0;
14533: }
14534: } elsif ($item eq 'approval') {
14535: unless ($value =~ /^[012]$/) {
14536: $value = 0;
14537: }
14538: } else {
14539: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
14540: $value = 'none';
14541: }
14542: }
14543: $selfenrollhash{'default'}{$type}{$item} = $value;
14544: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
14545: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
14546: if ($selfenrollhash{'default'}{$type}{$item} ne
14547: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
14548: push(@{$changes{'default'}{$type}},$item);
14549: }
14550: } else {
14551: push(@{$changes{'default'}{$type}},$item);
14552: }
14553: } else {
14554: push(@{$changes{'default'}{$type}},$item);
14555: }
14556: if ($item eq 'limit') {
14557: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
14558: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
14559: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
14560: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
14561: }
14562: } else {
14563: $selfenrollhash{'default'}{$type}{'cap'} = '';
14564: }
14565: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
14566: if ($selfenrollhash{'default'}{$type}{'cap'} ne
14567: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
14568: push(@{$changes{'default'}{$type}},'cap');
14569: }
14570: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
14571: push(@{$changes{'default'}{$type}},'cap');
14572: }
14573: }
14574: }
14575: }
14576:
14577: foreach my $item (@{$itemsref}) {
14578: if ($item eq 'fields') {
14579: my @changed;
14580: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
14581: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
14582: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
14583: }
14584: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
14585: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
14586: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
14587: $domconfig{'selfenrollment'}{'validation'}{$item});
14588: } else {
14589: @changed = @{$selfenrollhash{'validation'}{$item}};
14590: }
14591: } else {
14592: @changed = @{$selfenrollhash{'validation'}{$item}};
14593: }
14594: if (@changed) {
14595: if ($selfenrollhash{'validation'}{$item}) {
14596: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
14597: } else {
14598: $changes{'validation'}{$item} = &mt('None');
14599: }
14600: }
14601: } else {
14602: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
14603: if ($item eq 'markup') {
14604: if ($env{'form.selfenroll_validation_'.$item}) {
14605: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14606: }
14607: }
14608: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
14609: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
14610: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
14611: }
14612: }
14613: }
14614: }
14615:
14616: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
14617: $dom);
14618: if ($putresult eq 'ok') {
14619: if (keys(%changes) > 0) {
14620: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14621: $resulttext = &mt('Changes made:').'<ul>';
14622: foreach my $key ('admin','default','validation') {
14623: if (ref($changes{$key}) eq 'HASH') {
14624: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
14625: if ($key eq 'validation') {
14626: foreach my $item (@{$itemsref}) {
14627: if (exists($changes{$key}{$item})) {
14628: if ($item eq 'markup') {
14629: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
14630: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
14631: } else {
14632: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
14633: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
14634: }
14635: }
14636: }
14637: } else {
14638: foreach my $type (@types) {
14639: if ($type eq 'community') {
14640: $roles{'1'} = &mt('Community personnel');
14641: } else {
14642: $roles{'1'} = &mt('Course personnel');
14643: }
14644: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 14645: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
14646: if ($key eq 'admin') {
14647: my @mgrdc = ();
14648: if (ref($ordered{$key}) eq 'ARRAY') {
14649: foreach my $item (@{$ordered{'admin'}}) {
14650: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
14651: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
14652: push(@mgrdc,$item);
14653: }
14654: }
14655: }
14656: if (@mgrdc) {
14657: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
14658: } else {
14659: delete($domdefaults{$type.'selfenrolladmdc'});
14660: }
14661: }
14662: } else {
14663: if (ref($ordered{$key}) eq 'ARRAY') {
14664: foreach my $item (@{$ordered{$key}}) {
14665: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
14666: $domdefaults{$type.'selfenroll'.$item} =
14667: $selfenrollhash{$key}{$type}{$item};
14668: }
14669: }
14670: }
14671: }
14672: }
1.231 raeburn 14673: $resulttext .= '<li>'.$titles{$type}.'<ul>';
14674: foreach my $item (@{$ordered{$key}}) {
14675: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
14676: $resulttext .= '<li>';
14677: if ($key eq 'admin') {
14678: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
14679: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
14680: } else {
14681: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
14682: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
14683: }
14684: $resulttext .= '</li>';
14685: }
14686: }
14687: $resulttext .= '</ul></li>';
14688: }
14689: }
14690: $resulttext .= '</ul></li>';
14691: }
14692: }
1.305 raeburn 14693: }
14694: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
14695: my $cachetime = 24*60*60;
14696: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14697: if (ref($lastactref) eq 'HASH') {
14698: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 14699: }
1.231 raeburn 14700: }
14701: $resulttext .= '</ul>';
14702: } else {
14703: $resulttext = &mt('No changes made to self-enrollment settings');
14704: }
14705: } else {
14706: $resulttext = '<span class="LC_error">'.
14707: &mt('An error occurred: [_1]',$putresult).'</span>';
14708: }
14709: return $resulttext;
14710: }
14711:
1.137 raeburn 14712: sub modify_usersessions {
1.212 raeburn 14713: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 14714: my @hostingtypes = ('version','excludedomain','includedomain');
14715: my @offloadtypes = ('primary','default');
14716: my %types = (
14717: remote => \@hostingtypes,
14718: hosted => \@hostingtypes,
14719: spares => \@offloadtypes,
14720: );
14721: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 14722: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 14723: my (%by_ip,%by_location,@intdoms,@instdoms);
14724: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 14725: my @locations = sort(keys(%by_location));
1.137 raeburn 14726: my (%defaultshash,%changes);
14727: foreach my $prefix (@prefixes) {
14728: $defaultshash{'usersessions'}{$prefix} = {};
14729: }
1.212 raeburn 14730: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 14731: my $resulttext;
1.138 raeburn 14732: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 14733: foreach my $prefix (@prefixes) {
1.145 raeburn 14734: next if ($prefix eq 'spares');
14735: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 14736: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14737: if ($type eq 'version') {
14738: my $value = $env{'form.'.$prefix.'_'.$type};
14739: my $okvalue;
14740: if ($value ne '') {
14741: if (grep(/^\Q$value\E$/,@lcversions)) {
14742: $okvalue = $value;
14743: }
14744: }
14745: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14746: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
14747: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
14748: if ($inuse == 0) {
14749: $changes{$prefix}{$type} = 1;
14750: } else {
14751: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
14752: $changes{$prefix}{$type} = 1;
14753: }
14754: if ($okvalue ne '') {
14755: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14756: }
14757: }
14758: } else {
14759: if (($inuse == 1) && ($okvalue ne '')) {
14760: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14761: $changes{$prefix}{$type} = 1;
14762: }
14763: }
14764: } else {
14765: if (($inuse == 1) && ($okvalue ne '')) {
14766: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14767: $changes{$prefix}{$type} = 1;
14768: }
14769: }
14770: } else {
14771: if (($inuse == 1) && ($okvalue ne '')) {
14772: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14773: $changes{$prefix}{$type} = 1;
14774: }
14775: }
14776: } else {
14777: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14778: my @okvals;
14779: foreach my $val (@vals) {
1.138 raeburn 14780: if ($val =~ /:/) {
14781: my @items = split(/:/,$val);
14782: foreach my $item (@items) {
14783: if (ref($by_location{$item}) eq 'ARRAY') {
14784: push(@okvals,$item);
14785: }
14786: }
14787: } else {
14788: if (ref($by_location{$val}) eq 'ARRAY') {
14789: push(@okvals,$val);
14790: }
1.137 raeburn 14791: }
14792: }
14793: @okvals = sort(@okvals);
14794: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14795: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
14796: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14797: if ($inuse == 0) {
14798: $changes{$prefix}{$type} = 1;
14799: } else {
14800: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14801: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
14802: if (@changed > 0) {
14803: $changes{$prefix}{$type} = 1;
14804: }
14805: }
14806: } else {
14807: if ($inuse == 1) {
14808: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14809: $changes{$prefix}{$type} = 1;
14810: }
14811: }
14812: } else {
14813: if ($inuse == 1) {
14814: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14815: $changes{$prefix}{$type} = 1;
14816: }
14817: }
14818: } else {
14819: if ($inuse == 1) {
14820: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14821: $changes{$prefix}{$type} = 1;
14822: }
14823: }
14824: }
14825: }
14826: }
1.145 raeburn 14827:
14828: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 14829: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 14830: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
14831: my $savespares;
14832:
14833: foreach my $lonhost (sort(keys(%servers))) {
14834: my $serverhomeID =
14835: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 14836: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 14837: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
14838: my %spareschg;
14839: foreach my $type (@{$types{'spares'}}) {
14840: my @okspares;
14841: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
14842: foreach my $server (@checked) {
1.152 raeburn 14843: if (&Apache::lonnet::hostname($server) ne '') {
14844: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
14845: unless (grep(/^\Q$server\E$/,@okspares)) {
14846: push(@okspares,$server);
14847: }
1.145 raeburn 14848: }
14849: }
14850: }
14851: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
14852: my $newspare;
1.152 raeburn 14853: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
14854: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 14855: $newspare = $new;
14856: }
14857: }
1.152 raeburn 14858: my @spares;
14859: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
14860: @spares = sort(@okspares,$newspare);
14861: } else {
14862: @spares = sort(@okspares);
14863: }
14864: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 14865: if (ref($spareid{$lonhost}) eq 'HASH') {
14866: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 14867: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 14868: if (@diffs > 0) {
14869: $spareschg{$type} = 1;
14870: }
14871: }
14872: }
14873: }
14874: if (keys(%spareschg) > 0) {
14875: $changes{'spares'}{$lonhost} = \%spareschg;
14876: }
14877: }
1.261 raeburn 14878: $defaultshash{'usersessions'}{'offloadnow'} = {};
14879: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
14880: my @okoffload;
14881: if (@offloadnow) {
14882: foreach my $server (@offloadnow) {
14883: if (&Apache::lonnet::hostname($server) ne '') {
14884: unless (grep(/^\Q$server\E$/,@okoffload)) {
14885: push(@okoffload,$server);
14886: }
14887: }
14888: }
14889: if (@okoffload) {
14890: foreach my $lonhost (@okoffload) {
14891: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
14892: }
14893: }
14894: }
1.145 raeburn 14895: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14896: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
14897: if (ref($changes{'spares'}) eq 'HASH') {
14898: if (keys(%{$changes{'spares'}}) > 0) {
14899: $savespares = 1;
14900: }
14901: }
14902: } else {
14903: $savespares = 1;
14904: }
1.261 raeburn 14905: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
14906: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
14907: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
14908: $changes{'offloadnow'} = 1;
14909: last;
14910: }
14911: }
14912: unless ($changes{'offloadnow'}) {
1.289 raeburn 14913: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 14914: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
14915: $changes{'offloadnow'} = 1;
14916: last;
14917: }
14918: }
14919: }
14920: } elsif (@okoffload) {
14921: $changes{'offloadnow'} = 1;
14922: }
14923: } elsif (@okoffload) {
14924: $changes{'offloadnow'} = 1;
1.145 raeburn 14925: }
1.147 raeburn 14926: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
14927: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 14928: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14929: $dom);
14930: if ($putresult eq 'ok') {
14931: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14932: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
14933: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
14934: }
14935: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
14936: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
14937: }
1.261 raeburn 14938: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
14939: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
14940: }
1.137 raeburn 14941: }
14942: my $cachetime = 24*60*60;
14943: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 14944: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 14945: if (ref($lastactref) eq 'HASH') {
14946: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 14947: $lastactref->{'usersessions'} = 1;
1.212 raeburn 14948: }
1.147 raeburn 14949: if (keys(%changes) > 0) {
14950: my %lt = &usersession_titles();
14951: $resulttext = &mt('Changes made:').'<ul>';
14952: foreach my $prefix (@prefixes) {
14953: if (ref($changes{$prefix}) eq 'HASH') {
14954: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14955: if ($prefix eq 'spares') {
14956: if (ref($changes{$prefix}) eq 'HASH') {
14957: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
14958: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 14959: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 14960: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
14961: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 14962: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
14963: foreach my $type (@{$types{$prefix}}) {
14964: if ($changes{$prefix}{$lonhost}{$type}) {
14965: my $offloadto = &mt('None');
14966: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
14967: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
14968: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
14969: }
1.145 raeburn 14970: }
1.147 raeburn 14971: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 14972: }
1.137 raeburn 14973: }
14974: }
1.147 raeburn 14975: $resulttext .= '</li>';
1.137 raeburn 14976: }
14977: }
1.147 raeburn 14978: } else {
14979: foreach my $type (@{$types{$prefix}}) {
14980: if (defined($changes{$prefix}{$type})) {
14981: my $newvalue;
14982: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14983: if (ref($defaultshash{'usersessions'}{$prefix})) {
14984: if ($type eq 'version') {
14985: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
14986: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14987: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
14988: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
14989: }
1.145 raeburn 14990: }
14991: }
14992: }
1.147 raeburn 14993: if ($newvalue eq '') {
14994: if ($type eq 'version') {
14995: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
14996: } else {
14997: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14998: }
1.145 raeburn 14999: } else {
1.147 raeburn 15000: if ($type eq 'version') {
15001: $newvalue .= ' '.&mt('(or later)');
15002: }
15003: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 15004: }
1.137 raeburn 15005: }
15006: }
15007: }
1.147 raeburn 15008: $resulttext .= '</ul>';
1.137 raeburn 15009: }
15010: }
1.261 raeburn 15011: if ($changes{'offloadnow'}) {
15012: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
15013: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
15014: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
15015: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
15016: $resulttext .= '<li>'.$lonhost.'</li>';
15017: }
15018: $resulttext .= '</ul>';
15019: } else {
15020: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
15021: }
15022: } else {
15023: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
15024: }
15025: }
1.147 raeburn 15026: $resulttext .= '</ul>';
15027: } else {
15028: $resulttext = $nochgmsg;
1.137 raeburn 15029: }
15030: } else {
15031: $resulttext = '<span class="LC_error">'.
15032: &mt('An error occurred: [_1]',$putresult).'</span>';
15033: }
15034: } else {
1.147 raeburn 15035: $resulttext = $nochgmsg;
1.137 raeburn 15036: }
15037: return $resulttext;
15038: }
15039:
1.275 raeburn 15040: sub modify_ssl {
15041: my ($dom,$lastactref,%domconfig) = @_;
15042: my (%by_ip,%by_location,@intdoms,@instdoms);
15043: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
15044: my @locations = sort(keys(%by_location));
15045: my %servers = &Apache::lonnet::internet_dom_servers($dom);
15046: my (%defaultshash,%changes);
15047: my $action = 'ssl';
1.293 raeburn 15048: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 15049: foreach my $prefix (@prefixes) {
15050: $defaultshash{$action}{$prefix} = {};
15051: }
15052: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15053: my $resulttext;
15054: my %iphost = &Apache::lonnet::get_iphost();
15055: my @reptypes = ('certreq','nocertreq');
15056: my @connecttypes = ('dom','intdom','other');
15057: my %types = (
1.293 raeburn 15058: connto => \@connecttypes,
15059: connfrom => \@connecttypes,
15060: replication => \@reptypes,
1.275 raeburn 15061: );
15062: foreach my $prefix (sort(keys(%types))) {
15063: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 15064: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 15065: my $value = 'yes';
15066: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
15067: $value = $env{'form.'.$prefix.'_'.$type};
15068: }
15069: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
15070: if ($domconfig{$action}{$prefix}{$type} ne '') {
15071: if ($value ne $domconfig{$action}{$prefix}{$type}) {
15072: $changes{$prefix}{$type} = 1;
15073: }
15074: $defaultshash{$action}{$prefix}{$type} = $value;
15075: } else {
15076: $defaultshash{$action}{$prefix}{$type} = $value;
15077: $changes{$prefix}{$type} = 1;
15078: }
15079: } else {
15080: $defaultshash{$action}{$prefix}{$type} = $value;
15081: $changes{$prefix}{$type} = 1;
15082: }
15083: if (($type eq 'dom') && (keys(%servers) == 1)) {
15084: delete($changes{$prefix}{$type});
15085: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
15086: delete($changes{$prefix}{$type});
15087: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
15088: delete($changes{$prefix}{$type});
15089: }
15090: } elsif ($prefix eq 'replication') {
15091: if (@locations > 0) {
15092: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
15093: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
15094: my @okvals;
15095: foreach my $val (@vals) {
15096: if ($val =~ /:/) {
15097: my @items = split(/:/,$val);
15098: foreach my $item (@items) {
15099: if (ref($by_location{$item}) eq 'ARRAY') {
15100: push(@okvals,$item);
15101: }
15102: }
15103: } else {
15104: if (ref($by_location{$val}) eq 'ARRAY') {
15105: push(@okvals,$val);
15106: }
15107: }
15108: }
15109: @okvals = sort(@okvals);
15110: if (ref($domconfig{$action}) eq 'HASH') {
15111: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
15112: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
15113: if ($inuse == 0) {
15114: $changes{$prefix}{$type} = 1;
15115: } else {
15116: $defaultshash{$action}{$prefix}{$type} = \@okvals;
15117: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
15118: if (@changed > 0) {
15119: $changes{$prefix}{$type} = 1;
15120: }
15121: }
15122: } else {
15123: if ($inuse == 1) {
15124: $defaultshash{$action}{$prefix}{$type} = \@okvals;
15125: $changes{$prefix}{$type} = 1;
15126: }
15127: }
15128: } else {
15129: if ($inuse == 1) {
15130: $defaultshash{$action}{$prefix}{$type} = \@okvals;
15131: $changes{$prefix}{$type} = 1;
15132: }
15133: }
15134: } else {
15135: if ($inuse == 1) {
15136: $defaultshash{$action}{$prefix}{$type} = \@okvals;
15137: $changes{$prefix}{$type} = 1;
15138: }
15139: }
15140: }
15141: }
15142: }
15143: }
15144: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
15145: if (keys(%changes) > 0) {
15146: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15147: $dom);
15148: if ($putresult eq 'ok') {
15149: if (ref($defaultshash{$action}) eq 'HASH') {
15150: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
15151: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
15152: }
1.293 raeburn 15153: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
15154: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
15155: }
15156: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
15157: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275 raeburn 15158: }
15159: }
15160: my $cachetime = 24*60*60;
15161: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15162: if (ref($lastactref) eq 'HASH') {
15163: $lastactref->{'domdefaults'} = 1;
15164: }
15165: if (keys(%changes) > 0) {
15166: my %titles = &ssl_titles();
15167: $resulttext = &mt('Changes made:').'<ul>';
15168: foreach my $prefix (@prefixes) {
15169: if (ref($changes{$prefix}) eq 'HASH') {
15170: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
15171: foreach my $type (@{$types{$prefix}}) {
15172: if (defined($changes{$prefix}{$type})) {
15173: my $newvalue;
15174: if (ref($defaultshash{$action}) eq 'HASH') {
15175: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 15176: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 15177: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
15178: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
15179: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
15180: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
15181: }
15182: }
15183: }
15184: if ($newvalue eq '') {
15185: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
15186: } else {
15187: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
15188: }
15189: }
15190: }
15191: }
15192: $resulttext .= '</ul>';
15193: }
15194: }
15195: } else {
15196: $resulttext = $nochgmsg;
15197: }
15198: } else {
15199: $resulttext = '<span class="LC_error">'.
15200: &mt('An error occurred: [_1]',$putresult).'</span>';
15201: }
15202: } else {
15203: $resulttext = $nochgmsg;
15204: }
15205: return $resulttext;
15206: }
15207:
1.279 raeburn 15208: sub modify_trust {
15209: my ($dom,$lastactref,%domconfig) = @_;
15210: my (%by_ip,%by_location,@intdoms,@instdoms);
15211: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
15212: my @locations = sort(keys(%by_location));
15213: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
15214: my @types = ('exc','inc');
15215: my (%defaultshash,%changes);
15216: foreach my $prefix (@prefixes) {
15217: $defaultshash{'trust'}{$prefix} = {};
15218: }
15219: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15220: my $resulttext;
15221: foreach my $prefix (@prefixes) {
15222: foreach my $type (@types) {
15223: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
15224: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
15225: my @okvals;
15226: foreach my $val (@vals) {
15227: if ($val =~ /:/) {
15228: my @items = split(/:/,$val);
15229: foreach my $item (@items) {
15230: if (ref($by_location{$item}) eq 'ARRAY') {
15231: push(@okvals,$item);
15232: }
15233: }
15234: } else {
15235: if (ref($by_location{$val}) eq 'ARRAY') {
15236: push(@okvals,$val);
15237: }
15238: }
15239: }
15240: @okvals = sort(@okvals);
15241: if (ref($domconfig{'trust'}) eq 'HASH') {
15242: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
15243: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
15244: if ($inuse == 0) {
15245: $changes{$prefix}{$type} = 1;
15246: } else {
15247: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
15248: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
15249: if (@changed > 0) {
15250: $changes{$prefix}{$type} = 1;
15251: }
15252: }
15253: } else {
15254: if ($inuse == 1) {
15255: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
15256: $changes{$prefix}{$type} = 1;
15257: }
15258: }
15259: } else {
15260: if ($inuse == 1) {
15261: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
15262: $changes{$prefix}{$type} = 1;
15263: }
15264: }
15265: } else {
15266: if ($inuse == 1) {
15267: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
15268: $changes{$prefix}{$type} = 1;
15269: }
15270: }
15271: }
15272: }
15273: my $nochgmsg = &mt('No changes made to trust settings.');
15274: if (keys(%changes) > 0) {
15275: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15276: $dom);
15277: if ($putresult eq 'ok') {
15278: if (ref($defaultshash{'trust'}) eq 'HASH') {
15279: foreach my $prefix (@prefixes) {
15280: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
15281: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
15282: }
15283: }
15284: }
15285: my $cachetime = 24*60*60;
15286: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15287: if (ref($lastactref) eq 'HASH') {
15288: $lastactref->{'domdefaults'} = 1;
15289: }
15290: if (keys(%changes) > 0) {
15291: my %lt = &trust_titles();
15292: $resulttext = &mt('Changes made:').'<ul>';
15293: foreach my $prefix (@prefixes) {
15294: if (ref($changes{$prefix}) eq 'HASH') {
15295: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
15296: foreach my $type (@types) {
15297: if (defined($changes{$prefix}{$type})) {
15298: my $newvalue;
15299: if (ref($defaultshash{'trust'}) eq 'HASH') {
15300: if (ref($defaultshash{'trust'}{$prefix})) {
15301: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
15302: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
15303: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
15304: }
15305: }
15306: }
15307: }
15308: if ($newvalue eq '') {
15309: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
15310: } else {
15311: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
15312: }
15313: }
15314: }
15315: $resulttext .= '</ul>';
15316: }
15317: }
15318: $resulttext .= '</ul>';
15319: } else {
15320: $resulttext = $nochgmsg;
15321: }
15322: } else {
15323: $resulttext = '<span class="LC_error">'.
15324: &mt('An error occurred: [_1]',$putresult).'</span>';
15325: }
15326: } else {
15327: $resulttext = $nochgmsg;
15328: }
15329: return $resulttext;
15330: }
15331:
1.150 raeburn 15332: sub modify_loadbalancing {
15333: my ($dom,%domconfig) = @_;
15334: my $primary_id = &Apache::lonnet::domain($dom,'primary');
15335: my $intdom = &Apache::lonnet::internet_dom($primary_id);
15336: my ($othertitle,$usertypes,$types) =
15337: &Apache::loncommon::sorted_inst_types($dom);
15338: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 15339: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 15340: my @sparestypes = ('primary','default');
15341: my %typetitles = &sparestype_titles();
15342: my $resulttext;
1.171 raeburn 15343: my (%currbalancer,%currtargets,%currrules,%existing);
15344: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
15345: %existing = %{$domconfig{'loadbalancing'}};
15346: }
15347: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
15348: \%currtargets,\%currrules);
15349: my ($saveloadbalancing,%defaultshash,%changes);
15350: my ($alltypes,$othertypes,$titles) =
15351: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
15352: my %ruletitles = &offloadtype_text();
15353: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
15354: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
15355: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
15356: if ($balancer eq '') {
15357: next;
15358: }
1.210 raeburn 15359: if (!exists($servers{$balancer})) {
1.171 raeburn 15360: if (exists($currbalancer{$balancer})) {
15361: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 15362: }
1.171 raeburn 15363: next;
15364: }
15365: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
15366: push(@{$changes{'delete'}},$balancer);
15367: next;
15368: }
15369: if (!exists($currbalancer{$balancer})) {
15370: push(@{$changes{'add'}},$balancer);
15371: }
15372: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
15373: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
15374: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
15375: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
15376: $saveloadbalancing = 1;
15377: }
15378: foreach my $sparetype (@sparestypes) {
15379: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
15380: my @offloadto;
15381: foreach my $target (@targets) {
15382: if (($servers{$target}) && ($target ne $balancer)) {
15383: if ($sparetype eq 'default') {
15384: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
15385: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 15386: }
15387: }
1.171 raeburn 15388: unless(grep(/^\Q$target\E$/,@offloadto)) {
15389: push(@offloadto,$target);
15390: }
1.150 raeburn 15391: }
15392: }
1.284 raeburn 15393: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
15394: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
15395: push(@offloadto,$balancer);
15396: }
15397: }
15398: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 15399: }
1.171 raeburn 15400: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 15401: foreach my $sparetype (@sparestypes) {
1.171 raeburn 15402: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
15403: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 15404: if (@targetdiffs > 0) {
1.171 raeburn 15405: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 15406: }
1.171 raeburn 15407: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15408: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
15409: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 15410: }
15411: }
15412: }
15413: } else {
1.171 raeburn 15414: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 15415: foreach my $sparetype (@sparestypes) {
1.171 raeburn 15416: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15417: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
15418: $changes{'curr'}{$balancer}{'targets'} = 1;
15419: }
1.150 raeburn 15420: }
15421: }
1.210 raeburn 15422: }
1.150 raeburn 15423: }
15424: my $ishomedom;
1.171 raeburn 15425: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
15426: $ishomedom = 1;
1.150 raeburn 15427: }
15428: if (ref($alltypes) eq 'ARRAY') {
15429: foreach my $type (@{$alltypes}) {
15430: my $rule;
1.210 raeburn 15431: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 15432: (!$ishomedom)) {
1.171 raeburn 15433: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
15434: }
15435: if ($rule eq 'specific') {
1.255 raeburn 15436: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 15437: if (exists($servers{$specifiedhost})) {
1.255 raeburn 15438: $rule = $specifiedhost;
15439: }
1.150 raeburn 15440: }
1.171 raeburn 15441: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
15442: if (ref($currrules{$balancer}) eq 'HASH') {
15443: if ($rule ne $currrules{$balancer}{$type}) {
15444: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 15445: }
15446: } elsif ($rule ne '') {
1.171 raeburn 15447: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 15448: }
15449: }
15450: }
1.171 raeburn 15451: }
15452: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
15453: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
15454: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
15455: $defaultshash{'loadbalancing'} = {};
15456: }
15457: my $putresult = &Apache::lonnet::put_dom('configuration',
15458: \%defaultshash,$dom);
15459: if ($putresult eq 'ok') {
15460: if (keys(%changes) > 0) {
1.252 raeburn 15461: my %toupdate;
1.171 raeburn 15462: if (ref($changes{'delete'}) eq 'ARRAY') {
15463: foreach my $balancer (sort(@{$changes{'delete'}})) {
15464: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 15465: $toupdate{$balancer} = 1;
1.150 raeburn 15466: }
1.171 raeburn 15467: }
15468: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 15469: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 15470: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 15471: $toupdate{$balancer} = 1;
1.171 raeburn 15472: }
15473: }
15474: if (ref($changes{'curr'}) eq 'HASH') {
15475: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 15476: $toupdate{$balancer} = 1;
1.171 raeburn 15477: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
15478: if ($changes{'curr'}{$balancer}{'targets'}) {
15479: my %offloadstr;
15480: foreach my $sparetype (@sparestypes) {
15481: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15482: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
15483: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
15484: }
15485: }
1.150 raeburn 15486: }
1.171 raeburn 15487: if (keys(%offloadstr) == 0) {
15488: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 15489: } else {
1.171 raeburn 15490: my $showoffload;
15491: foreach my $sparetype (@sparestypes) {
15492: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
15493: if (defined($offloadstr{$sparetype})) {
15494: $showoffload .= $offloadstr{$sparetype};
15495: } else {
15496: $showoffload .= &mt('None');
15497: }
15498: $showoffload .= (' 'x3);
15499: }
15500: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 15501: }
15502: }
15503: }
1.171 raeburn 15504: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
15505: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
15506: foreach my $type (@{$alltypes}) {
15507: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
15508: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
15509: my $balancetext;
15510: if ($rule eq '') {
15511: $balancetext = $ruletitles{'default'};
1.209 raeburn 15512: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 15513: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 15514: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 15515: foreach my $sparetype (@sparestypes) {
15516: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15517: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
15518: }
15519: }
1.253 raeburn 15520: foreach my $item (@{$alltypes}) {
15521: next if ($item =~ /^_LC_ipchange/);
15522: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
15523: if ($hasrule eq 'homeserver') {
15524: map { $toupdate{$_} = 1; } (keys(%libraryservers));
15525: } else {
15526: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
15527: if ($servers{$hasrule}) {
15528: $toupdate{$hasrule} = 1;
15529: }
15530: }
15531: }
15532: }
1.254 raeburn 15533: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
15534: $balancetext = $ruletitles{$rule};
15535: } else {
15536: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
15537: $balancetext = $ruletitles{'particular'}.' '.$receiver;
15538: if ($receiver) {
15539: $toupdate{$receiver};
15540: }
15541: }
15542: } else {
15543: $balancetext = $ruletitles{$rule};
1.252 raeburn 15544: }
1.171 raeburn 15545: } else {
15546: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
15547: }
1.210 raeburn 15548: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 15549: }
15550: }
15551: }
15552: }
1.252 raeburn 15553: if (keys(%toupdate)) {
15554: my %thismachine;
15555: my $updatedhere;
15556: my $cachetime = 60*60*24;
15557: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
15558: foreach my $lonhost (keys(%toupdate)) {
15559: if ($thismachine{$lonhost}) {
15560: unless ($updatedhere) {
15561: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
15562: $defaultshash{'loadbalancing'},
15563: $cachetime);
15564: $updatedhere = 1;
15565: }
15566: } else {
15567: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
15568: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
15569: }
15570: }
15571: }
1.150 raeburn 15572: }
1.171 raeburn 15573: }
15574: if ($resulttext ne '') {
15575: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 15576: } else {
15577: $resulttext = $nochgmsg;
15578: }
15579: } else {
1.171 raeburn 15580: $resulttext = $nochgmsg;
1.150 raeburn 15581: }
15582: } else {
1.171 raeburn 15583: $resulttext = '<span class="LC_error">'.
15584: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 15585: }
15586: } else {
1.171 raeburn 15587: $resulttext = $nochgmsg;
1.150 raeburn 15588: }
15589: return $resulttext;
15590: }
15591:
1.48 raeburn 15592: sub recurse_check {
15593: my ($chkcats,$categories,$depth,$name) = @_;
15594: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
15595: my $chg = 0;
15596: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
15597: my $category = $chkcats->[$depth]{$name}[$j];
15598: my $item;
15599: if ($category eq '') {
15600: $chg ++;
15601: } else {
15602: my $deeper = $depth + 1;
15603: $item = &escape($category).':'.&escape($name).':'.$depth;
15604: if ($chg) {
15605: $categories->{$item} -= $chg;
15606: }
15607: &recurse_check($chkcats,$categories,$deeper,$category);
15608: $deeper --;
15609: }
15610: }
15611: }
15612: return;
15613: }
15614:
15615: sub recurse_cat_deletes {
15616: my ($item,$coursecategories,$deletions) = @_;
15617: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15618: my $subdepth = $depth + 1;
15619: if (ref($coursecategories) eq 'HASH') {
15620: foreach my $subitem (keys(%{$coursecategories})) {
15621: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
15622: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
15623: delete($coursecategories->{$subitem});
15624: $deletions->{$subitem} = 1;
15625: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 15626: }
1.48 raeburn 15627: }
15628: }
15629: return;
15630: }
15631:
1.125 raeburn 15632: sub active_dc_picker {
1.191 raeburn 15633: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 15634: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 15635: my @domcoord = keys(%domcoords);
15636: if (keys(%currhash)) {
15637: foreach my $dc (keys(%currhash)) {
15638: unless (exists($domcoords{$dc})) {
15639: push(@domcoord,$dc);
15640: }
15641: }
15642: }
15643: @domcoord = sort(@domcoord);
1.210 raeburn 15644: my $numdcs = scalar(@domcoord);
1.191 raeburn 15645: my $rows = 0;
15646: my $table;
1.125 raeburn 15647: if ($numdcs > 1) {
1.191 raeburn 15648: $table = '<table>';
15649: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 15650: my $rem = $i%($numinrow);
15651: if ($rem == 0) {
15652: if ($i > 0) {
1.191 raeburn 15653: $table .= '</tr>';
1.125 raeburn 15654: }
1.191 raeburn 15655: $table .= '<tr>';
15656: $rows ++;
1.125 raeburn 15657: }
1.191 raeburn 15658: my $check = '';
15659: if ($inputtype eq 'radio') {
15660: if (keys(%currhash) == 0) {
15661: if (!$i) {
15662: $check = ' checked="checked"';
15663: }
15664: } elsif (exists($currhash{$domcoord[$i]})) {
15665: $check = ' checked="checked"';
15666: }
15667: } else {
15668: if (exists($currhash{$domcoord[$i]})) {
15669: $check = ' checked="checked"';
1.125 raeburn 15670: }
15671: }
1.191 raeburn 15672: if ($i == @domcoord - 1) {
1.125 raeburn 15673: my $colsleft = $numinrow - $rem;
15674: if ($colsleft > 1) {
1.191 raeburn 15675: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 15676: } else {
1.191 raeburn 15677: $table .= '<td class="LC_left_item">';
1.125 raeburn 15678: }
15679: } else {
1.191 raeburn 15680: $table .= '<td class="LC_left_item">';
15681: }
15682: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
15683: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
15684: $table .= '<span class="LC_nobreak"><label>'.
15685: '<input type="'.$inputtype.'" name="'.$name.'"'.
15686: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
15687: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 15688: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 15689: }
1.219 raeburn 15690: $table .= '</label></span></td>';
1.191 raeburn 15691: }
15692: $table .= '</tr></table>';
15693: } elsif ($numdcs == 1) {
1.219 raeburn 15694: my ($dcname,$dcdom) = split(':',$domcoord[0]);
15695: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 15696: if ($inputtype eq 'radio') {
1.247 raeburn 15697: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 15698: if ($user ne $dcname.':'.$dcdom) {
15699: $table .= ' ('.$dcname.':'.$dcdom.')';
15700: }
1.191 raeburn 15701: } else {
15702: my $check;
15703: if (exists($currhash{$domcoord[0]})) {
15704: $check = ' checked="checked"';
1.125 raeburn 15705: }
1.247 raeburn 15706: $table = '<span class="LC_nobreak"><label>'.
15707: '<input type="checkbox" name="'.$name.'" '.
15708: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 15709: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 15710: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 15711: }
1.220 raeburn 15712: $table .= '</label></span>';
1.191 raeburn 15713: $rows ++;
1.125 raeburn 15714: }
15715: }
1.191 raeburn 15716: return ($numdcs,$table,$rows);
1.125 raeburn 15717: }
15718:
1.137 raeburn 15719: sub usersession_titles {
15720: return &Apache::lonlocal::texthash(
15721: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
15722: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 15723: spares => 'Servers offloaded to, when busy',
1.137 raeburn 15724: version => 'LON-CAPA version requirement',
1.138 raeburn 15725: excludedomain => 'Allow all, but exclude specific domains',
15726: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 15727: primary => 'Primary (checked first)',
1.154 raeburn 15728: default => 'Default',
1.137 raeburn 15729: );
15730: }
15731:
1.152 raeburn 15732: sub id_for_thisdom {
15733: my (%servers) = @_;
15734: my %altids;
15735: foreach my $server (keys(%servers)) {
15736: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
15737: if ($serverhome ne $server) {
15738: $altids{$serverhome} = $server;
15739: }
15740: }
15741: return %altids;
15742: }
15743:
1.150 raeburn 15744: sub count_servers {
15745: my ($currbalancer,%servers) = @_;
15746: my (@spares,$numspares);
15747: foreach my $lonhost (sort(keys(%servers))) {
15748: next if ($currbalancer eq $lonhost);
15749: push(@spares,$lonhost);
15750: }
15751: if ($currbalancer) {
15752: $numspares = scalar(@spares);
15753: } else {
15754: $numspares = scalar(@spares) - 1;
15755: }
15756: return ($numspares,@spares);
15757: }
15758:
15759: sub lonbalance_targets_js {
1.171 raeburn 15760: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 15761: my $select = &mt('Select');
15762: my ($alltargets,$allishome,$allinsttypes,@alltypes);
15763: if (ref($servers) eq 'HASH') {
15764: $alltargets = join("','",sort(keys(%{$servers})));
15765: my @homedoms;
15766: foreach my $server (sort(keys(%{$servers}))) {
15767: if (&Apache::lonnet::host_domain($server) eq $dom) {
15768: push(@homedoms,'1');
15769: } else {
15770: push(@homedoms,'0');
15771: }
15772: }
15773: $allishome = join("','",@homedoms);
15774: }
15775: if (ref($types) eq 'ARRAY') {
15776: if (@{$types} > 0) {
15777: @alltypes = @{$types};
15778: }
15779: }
15780: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
15781: $allinsttypes = join("','",@alltypes);
1.171 raeburn 15782: my (%currbalancer,%currtargets,%currrules,%existing);
15783: if (ref($settings) eq 'HASH') {
15784: %existing = %{$settings};
15785: }
15786: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
15787: \%currtargets,\%currrules);
1.210 raeburn 15788: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 15789: return <<"END";
15790:
15791: <script type="text/javascript">
15792: // <![CDATA[
15793:
1.171 raeburn 15794: currBalancers = new Array('$balancers');
15795:
15796: function toggleTargets(balnum) {
15797: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
15798: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
15799: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
15800: var prevbalancer = prevhostitem.value;
15801: var baltotal = document.getElementById('loadbalancing_total').value;
15802: prevhostitem.value = balancer;
15803: if (prevbalancer != '') {
15804: var prevIdx = currBalancers.indexOf(prevbalancer);
15805: if (prevIdx != -1) {
15806: currBalancers.splice(prevIdx,1);
15807: }
15808: }
1.150 raeburn 15809: if (balancer == '') {
1.171 raeburn 15810: hideSpares(balnum);
1.150 raeburn 15811: } else {
1.171 raeburn 15812: var currIdx = currBalancers.indexOf(balancer);
15813: if (currIdx == -1) {
15814: currBalancers.push(balancer);
15815: }
1.150 raeburn 15816: var homedoms = new Array('$allishome');
1.171 raeburn 15817: var ishomedom = homedoms[lonhostitem.selectedIndex];
15818: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 15819: }
1.171 raeburn 15820: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 15821: return;
15822: }
15823:
1.171 raeburn 15824: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 15825: var alltargets = new Array('$alltargets');
15826: var insttypes = new Array('$allinsttypes');
1.151 raeburn 15827: var offloadtypes = new Array('primary','default');
15828:
1.171 raeburn 15829: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
15830: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 15831:
1.151 raeburn 15832: for (var i=0; i<offloadtypes.length; i++) {
15833: var count = 0;
15834: for (var j=0; j<alltargets.length; j++) {
15835: if (alltargets[j] != balancer) {
1.171 raeburn 15836: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
15837: item.value = alltargets[j];
15838: item.style.textAlign='left';
15839: item.style.textFace='normal';
15840: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
15841: if (currBalancers.indexOf(alltargets[j]) == -1) {
15842: item.disabled = '';
15843: } else {
15844: item.disabled = 'disabled';
15845: item.checked = false;
15846: }
1.151 raeburn 15847: count ++;
15848: }
1.150 raeburn 15849: }
15850: }
1.151 raeburn 15851: for (var k=0; k<insttypes.length; k++) {
15852: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 15853: if (ishomedom == 1) {
1.171 raeburn 15854: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
15855: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 15856: } else {
1.171 raeburn 15857: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
15858: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 15859: }
15860: } else {
1.171 raeburn 15861: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
15862: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 15863: }
1.151 raeburn 15864: if ((insttypes[k] != '_LC_external') &&
15865: ((insttypes[k] != '_LC_internetdom') ||
15866: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 15867: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
15868: item.options.length = 0;
15869: item.options[0] = new Option("","",true,true);
1.210 raeburn 15870: var idx = 0;
1.151 raeburn 15871: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 15872: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
15873: idx ++;
15874: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 15875: }
15876: }
15877: }
15878: }
15879: return;
15880: }
15881:
1.171 raeburn 15882: function hideSpares(balnum) {
1.150 raeburn 15883: var alltargets = new Array('$alltargets');
15884: var insttypes = new Array('$allinsttypes');
15885: var offloadtypes = new Array('primary','default');
15886:
1.171 raeburn 15887: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
15888: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 15889:
15890: var total = alltargets.length - 1;
15891: for (var i=0; i<offloadtypes; i++) {
15892: for (var j=0; j<total; j++) {
1.171 raeburn 15893: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
15894: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
15895: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 15896: }
1.150 raeburn 15897: }
15898: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 15899: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
15900: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 15901: if (insttypes[k] != '_LC_external') {
1.171 raeburn 15902: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
15903: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 15904: }
15905: }
15906: return;
15907: }
15908:
1.171 raeburn 15909: function checkOffloads(item,balnum,type) {
1.150 raeburn 15910: var alltargets = new Array('$alltargets');
15911: var offloadtypes = new Array('primary','default');
15912: if (item.checked) {
15913: var total = alltargets.length - 1;
15914: var other;
15915: if (type == offloadtypes[0]) {
1.151 raeburn 15916: other = offloadtypes[1];
1.150 raeburn 15917: } else {
1.151 raeburn 15918: other = offloadtypes[0];
1.150 raeburn 15919: }
15920: for (var i=0; i<total; i++) {
1.171 raeburn 15921: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 15922: if (server == item.value) {
1.171 raeburn 15923: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
15924: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 15925: }
15926: }
15927: }
15928: }
15929: return;
15930: }
15931:
1.171 raeburn 15932: function singleServerToggle(balnum,type) {
15933: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 15934: if (offloadtoSelIdx == 0) {
1.171 raeburn 15935: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
15936: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 15937:
15938: } else {
1.171 raeburn 15939: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
15940: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 15941: }
15942: return;
15943: }
15944:
1.171 raeburn 15945: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 15946: if (type == '_LC_external') {
1.171 raeburn 15947: return;
1.150 raeburn 15948: }
1.171 raeburn 15949: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 15950: for (var i=0; i<typesRules.length; i++) {
15951: if (formname.elements[typesRules[i]].checked) {
15952: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 15953: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
15954: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 15955: } else {
1.171 raeburn 15956: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
15957: }
15958: }
15959: }
15960: return;
15961: }
15962:
15963: function balancerDeleteChange(balnum) {
15964: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
15965: var baltotal = document.getElementById('loadbalancing_total').value;
15966: var addtarget;
15967: var removetarget;
15968: var action = 'delete';
15969: if (document.getElementById('loadbalancing_delete_'+balnum)) {
15970: var lonhost = hostitem.value;
15971: var currIdx = currBalancers.indexOf(lonhost);
15972: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
15973: if (currIdx != -1) {
15974: currBalancers.splice(currIdx,1);
15975: }
15976: addtarget = lonhost;
15977: } else {
15978: if (currIdx == -1) {
15979: currBalancers.push(lonhost);
15980: }
15981: removetarget = lonhost;
15982: action = 'undelete';
15983: }
15984: balancerChange(balnum,baltotal,action,addtarget,removetarget);
15985: }
15986: return;
15987: }
15988:
15989: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
15990: if (baltotal > 1) {
15991: var offloadtypes = new Array('primary','default');
15992: var alltargets = new Array('$alltargets');
15993: var insttypes = new Array('$allinsttypes');
15994: for (var i=0; i<baltotal; i++) {
15995: if (i != balnum) {
15996: for (var j=0; j<offloadtypes.length; j++) {
15997: var total = alltargets.length - 1;
15998: for (var k=0; k<total; k++) {
15999: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
16000: var server = serveritem.value;
16001: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
16002: if (server == addtarget) {
16003: serveritem.disabled = '';
16004: }
16005: }
16006: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
16007: if (server == removetarget) {
16008: serveritem.disabled = 'disabled';
16009: serveritem.checked = false;
16010: }
16011: }
16012: }
16013: }
16014: for (var j=0; j<insttypes.length; j++) {
16015: if (insttypes[j] != '_LC_external') {
16016: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
16017: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
16018: var currSel = singleserver.selectedIndex;
16019: var currVal = singleserver.options[currSel].value;
16020: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
16021: var numoptions = singleserver.options.length;
16022: var needsnew = 1;
16023: for (var k=0; k<numoptions; k++) {
16024: if (singleserver.options[k] == addtarget) {
16025: needsnew = 0;
16026: break;
16027: }
16028: }
16029: if (needsnew == 1) {
16030: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
16031: }
16032: }
16033: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
16034: singleserver.options.length = 0;
16035: if ((currVal) && (currVal != removetarget)) {
16036: singleserver.options[0] = new Option("","",false,false);
16037: } else {
16038: singleserver.options[0] = new Option("","",true,true);
16039: }
16040: var idx = 0;
16041: for (var m=0; m<alltargets.length; m++) {
16042: if (currBalancers.indexOf(alltargets[m]) == -1) {
16043: idx ++;
16044: if (currVal == alltargets[m]) {
16045: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
16046: } else {
16047: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
16048: }
16049: }
16050: }
16051: }
16052: }
16053: }
16054: }
1.150 raeburn 16055: }
16056: }
16057: }
16058: return;
16059: }
16060:
1.152 raeburn 16061: // ]]>
16062: </script>
16063:
16064: END
16065: }
16066:
16067: sub new_spares_js {
16068: my @sparestypes = ('primary','default');
16069: my $types = join("','",@sparestypes);
16070: my $select = &mt('Select');
16071: return <<"END";
16072:
16073: <script type="text/javascript">
16074: // <![CDATA[
16075:
16076: function updateNewSpares(formname,lonhost) {
16077: var types = new Array('$types');
16078: var include = new Array();
16079: var exclude = new Array();
16080: for (var i=0; i<types.length; i++) {
16081: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
16082: for (var j=0; j<spareboxes.length; j++) {
16083: if (formname.elements[spareboxes[j]].checked) {
16084: exclude.push(formname.elements[spareboxes[j]].value);
16085: } else {
16086: include.push(formname.elements[spareboxes[j]].value);
16087: }
16088: }
16089: }
16090: for (var i=0; i<types.length; i++) {
16091: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
16092: var selIdx = newSpare.selectedIndex;
16093: var currnew = newSpare.options[selIdx].value;
16094: var okSpares = new Array();
16095: for (var j=0; j<newSpare.options.length; j++) {
16096: var possible = newSpare.options[j].value;
16097: if (possible != '') {
16098: if (exclude.indexOf(possible) == -1) {
16099: okSpares.push(possible);
16100: } else {
16101: if (currnew == possible) {
16102: selIdx = 0;
16103: }
16104: }
16105: }
16106: }
16107: for (var k=0; k<include.length; k++) {
16108: if (okSpares.indexOf(include[k]) == -1) {
16109: okSpares.push(include[k]);
16110: }
16111: }
16112: okSpares.sort();
16113: newSpare.options.length = 0;
16114: if (selIdx == 0) {
16115: newSpare.options[0] = new Option("$select","",true,true);
16116: } else {
16117: newSpare.options[0] = new Option("$select","",false,false);
16118: }
16119: for (var m=0; m<okSpares.length; m++) {
16120: var idx = m+1;
16121: var selThis = 0;
16122: if (selIdx != 0) {
16123: if (okSpares[m] == currnew) {
16124: selThis = 1;
16125: }
16126: }
16127: if (selThis == 1) {
16128: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
16129: } else {
16130: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
16131: }
16132: }
16133: }
16134: return;
16135: }
16136:
16137: function checkNewSpares(lonhost,type) {
16138: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
16139: var chosen = newSpare.options[newSpare.selectedIndex].value;
16140: if (chosen != '') {
16141: var othertype;
16142: var othernewSpare;
16143: if (type == 'primary') {
16144: othernewSpare = document.getElementById('newspare_default_'+lonhost);
16145: }
16146: if (type == 'default') {
16147: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
16148: }
16149: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
16150: othernewSpare.selectedIndex = 0;
16151: }
16152: }
16153: return;
16154: }
16155:
16156: // ]]>
16157: </script>
16158:
16159: END
16160:
16161: }
16162:
16163: sub common_domprefs_js {
16164: return <<"END";
16165:
16166: <script type="text/javascript">
16167: // <![CDATA[
16168:
1.150 raeburn 16169: function getIndicesByName(formname,item) {
1.152 raeburn 16170: var group = new Array();
1.150 raeburn 16171: for (var i=0;i<formname.elements.length;i++) {
16172: if (formname.elements[i].name == item) {
1.152 raeburn 16173: group.push(formname.elements[i].id);
1.150 raeburn 16174: }
16175: }
1.152 raeburn 16176: return group;
1.150 raeburn 16177: }
16178:
16179: // ]]>
16180: </script>
16181:
16182: END
1.152 raeburn 16183:
1.150 raeburn 16184: }
16185:
1.165 raeburn 16186: sub recaptcha_js {
16187: my %lt = &captcha_phrases();
16188: return <<"END";
16189:
16190: <script type="text/javascript">
16191: // <![CDATA[
16192:
16193: function updateCaptcha(caller,context) {
16194: var privitem;
16195: var pubitem;
16196: var privtext;
16197: var pubtext;
1.269 raeburn 16198: var versionitem;
16199: var versiontext;
1.165 raeburn 16200: if (document.getElementById(context+'_recaptchapub')) {
16201: pubitem = document.getElementById(context+'_recaptchapub');
16202: } else {
16203: return;
16204: }
16205: if (document.getElementById(context+'_recaptchapriv')) {
16206: privitem = document.getElementById(context+'_recaptchapriv');
16207: } else {
16208: return;
16209: }
16210: if (document.getElementById(context+'_recaptchapubtxt')) {
16211: pubtext = document.getElementById(context+'_recaptchapubtxt');
16212: } else {
16213: return;
16214: }
16215: if (document.getElementById(context+'_recaptchaprivtxt')) {
16216: privtext = document.getElementById(context+'_recaptchaprivtxt');
16217: } else {
16218: return;
16219: }
1.269 raeburn 16220: if (document.getElementById(context+'_recaptchaversion')) {
16221: versionitem = document.getElementById(context+'_recaptchaversion');
16222: } else {
16223: return;
16224: }
16225: if (document.getElementById(context+'_recaptchavertxt')) {
16226: versiontext = document.getElementById(context+'_recaptchavertxt');
16227: } else {
16228: return;
16229: }
1.165 raeburn 16230: if (caller.checked) {
16231: if (caller.value == 'recaptcha') {
16232: pubitem.type = 'text';
16233: privitem.type = 'text';
16234: pubitem.size = '40';
16235: privitem.size = '40';
16236: pubtext.innerHTML = "$lt{'pub'}";
16237: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 16238: versionitem.type = 'text';
16239: versionitem.size = '3';
1.289 raeburn 16240: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 16241: } else {
16242: pubitem.type = 'hidden';
16243: privitem.type = 'hidden';
1.269 raeburn 16244: versionitem.type = 'hidden';
1.165 raeburn 16245: pubtext.innerHTML = '';
16246: privtext.innerHTML = '';
1.269 raeburn 16247: versiontext.innerHTML = '';
1.165 raeburn 16248: }
16249: }
16250: return;
16251: }
16252:
16253: // ]]>
16254: </script>
16255:
16256: END
16257:
16258: }
16259:
1.236 raeburn 16260: sub toggle_display_js {
1.192 raeburn 16261: return <<"END";
16262:
16263: <script type="text/javascript">
16264: // <![CDATA[
16265:
1.236 raeburn 16266: function toggleDisplay(domForm,caller) {
16267: if (document.getElementById(caller)) {
16268: var divitem = document.getElementById(caller);
16269: var optionsElement = domForm.coursecredits;
1.264 raeburn 16270: var checkval = 1;
16271: var dispval = 'block';
1.303 raeburn 16272: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 16273: if (caller == 'emailoptions') {
16274: optionsElement = domForm.cancreate_email;
16275: }
1.257 raeburn 16276: if (caller == 'studentsubmission') {
16277: optionsElement = domForm.postsubmit;
16278: }
1.264 raeburn 16279: if (caller == 'cloneinstcode') {
16280: optionsElement = domForm.canclone;
16281: checkval = 'instcode';
16282: }
1.303 raeburn 16283: if (selfcreateRegExp.test(caller)) {
16284: optionsElement = domForm.elements[caller];
16285: checkval = 'other';
16286: dispval = 'inline'
16287: }
1.236 raeburn 16288: if (optionsElement.length) {
1.192 raeburn 16289: var currval;
1.236 raeburn 16290: for (var i=0; i<optionsElement.length; i++) {
16291: if (optionsElement[i].checked) {
16292: currval = optionsElement[i].value;
1.192 raeburn 16293: }
16294: }
1.264 raeburn 16295: if (currval == checkval) {
16296: divitem.style.display = dispval;
1.192 raeburn 16297: } else {
1.236 raeburn 16298: divitem.style.display = 'none';
1.192 raeburn 16299: }
16300: }
16301: }
16302: return;
16303: }
16304:
16305: // ]]>
16306: </script>
16307:
16308: END
16309:
16310: }
16311:
1.165 raeburn 16312: sub captcha_phrases {
16313: return &Apache::lonlocal::texthash (
16314: priv => 'Private key',
16315: pub => 'Public key',
16316: original => 'original (CAPTCHA)',
16317: recaptcha => 'successor (ReCAPTCHA)',
16318: notused => 'unused',
1.289 raeburn 16319: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 16320: );
16321: }
16322:
1.205 raeburn 16323: sub devalidate_remote_domconfs {
1.212 raeburn 16324: my ($dom,$cachekeys) = @_;
16325: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 16326: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16327: my %thismachine;
16328: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 16329: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 16330: if (keys(%servers)) {
1.205 raeburn 16331: foreach my $server (keys(%servers)) {
16332: next if ($thismachine{$server});
1.212 raeburn 16333: my @cached;
16334: foreach my $name (@posscached) {
16335: if ($cachekeys->{$name}) {
16336: push(@cached,&escape($name).':'.&escape($dom));
16337: }
16338: }
16339: if (@cached) {
16340: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
16341: }
1.205 raeburn 16342: }
16343: }
16344: return;
16345: }
16346:
1.3 raeburn 16347: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>