Annotation of loncom/interface/domainprefs.pm, revision 1.288
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.288 ! raeburn 4: # $Id: domainprefs.pm,v 1.287 2017/01/22 13:26:32 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: ###############################################################
30: ##############################################################
31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.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.43 raeburn 223: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 224: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 225: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 226: 'requestcourses','requestauthor','coursecategories',
1.267 raeburn 227: 'serverstatuses','helpsettings','coursedefaults',
1.279 raeburn 228: 'ltitools','selfenrollment','usersessions','ssl','trust');
1.171 raeburn 229: my %existing;
230: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
231: %existing = %{$domconfig{'loadbalancing'}};
232: }
233: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 234: push(@prefs_order,'loadbalancing');
235: }
1.30 raeburn 236: my %prefs = (
237: 'rolecolors' =>
238: { text => 'Default color schemes',
1.67 raeburn 239: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 240: header => [{col1 => 'Student Settings',
241: col2 => '',},
242: {col1 => 'Coordinator Settings',
243: col2 => '',},
244: {col1 => 'Author Settings',
245: col2 => '',},
246: {col1 => 'Administrator Settings',
247: col2 => '',}],
1.230 raeburn 248: print => \&print_rolecolors,
249: modify => \&modify_rolecolors,
1.30 raeburn 250: },
1.110 raeburn 251: 'login' =>
1.30 raeburn 252: { text => 'Log-in page options',
1.67 raeburn 253: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 254: header => [{col1 => 'Log-in Page Items',
255: col2 => '',},
256: {col1 => 'Log-in Help',
1.256 raeburn 257: col2 => 'Value'},
258: {col1 => 'Custom HTML in document head',
1.168 raeburn 259: col2 => 'Value'}],
1.230 raeburn 260: print => \&print_login,
261: modify => \&modify_login,
1.30 raeburn 262: },
1.43 raeburn 263: 'defaults' =>
1.236 raeburn 264: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 265: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 266: header => [{col1 => 'Setting',
1.236 raeburn 267: col2 => 'Value'},
268: {col1 => 'Institutional user types',
269: col2 => 'Assignable to e-mail usernames'}],
1.230 raeburn 270: print => \&print_defaults,
271: modify => \&modify_defaults,
1.43 raeburn 272: },
1.30 raeburn 273: 'quotas' =>
1.197 raeburn 274: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 275: help => 'Domain_Configuration_Quotas',
1.77 raeburn 276: header => [{col1 => 'User affiliation',
1.72 raeburn 277: col2 => 'Available tools',
1.213 raeburn 278: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 279: print => \&print_quotas,
280: modify => \&modify_quotas,
1.30 raeburn 281: },
282: 'autoenroll' =>
283: { text => 'Auto-enrollment settings',
1.67 raeburn 284: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 285: header => [{col1 => 'Configuration setting',
286: col2 => 'Value(s)'}],
1.230 raeburn 287: print => \&print_autoenroll,
288: modify => \&modify_autoenroll,
1.30 raeburn 289: },
290: 'autoupdate' =>
291: { text => 'Auto-update settings',
1.67 raeburn 292: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 293: header => [{col1 => 'Setting',
294: col2 => 'Value',},
1.131 raeburn 295: {col1 => 'Setting',
296: col2 => 'Affiliation'},
1.43 raeburn 297: {col1 => 'User population',
1.227 bisitz 298: col2 => 'Updatable user data'}],
1.230 raeburn 299: print => \&print_autoupdate,
300: modify => \&modify_autoupdate,
1.30 raeburn 301: },
1.125 raeburn 302: 'autocreate' =>
303: { text => 'Auto-course creation settings',
304: help => 'Domain_Configuration_Auto_Creation',
305: header => [{col1 => 'Configuration Setting',
306: col2 => 'Value',}],
1.230 raeburn 307: print => \&print_autocreate,
308: modify => \&modify_autocreate,
1.125 raeburn 309: },
1.30 raeburn 310: 'directorysrch' =>
1.277 raeburn 311: { text => 'Directory searches',
1.67 raeburn 312: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 313: header => [{col1 => 'Institutional Directory Setting',
314: col2 => 'Value',},
315: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 316: col2 => 'Value',}],
1.230 raeburn 317: print => \&print_directorysrch,
318: modify => \&modify_directorysrch,
1.30 raeburn 319: },
320: 'contacts' =>
1.286 raeburn 321: { text => 'E-mail addresses and helpform',
1.67 raeburn 322: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 323: header => [{col1 => 'Default e-mail addresses',
324: col2 => 'Value',},
325: {col1 => 'Recipient(s) for notifications',
326: col2 => 'Value',},
327: {col1 => 'Ask helpdesk form settings',
328: col2 => 'Value',},],
1.230 raeburn 329: print => \&print_contacts,
330: modify => \&modify_contacts,
1.30 raeburn 331: },
332: 'usercreation' =>
333: { text => 'User creation',
1.67 raeburn 334: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 335: header => [{col1 => 'Format rule type',
336: col2 => 'Format rules in force'},
1.34 raeburn 337: {col1 => 'User account creation',
338: col2 => 'Usernames which may be created',},
1.30 raeburn 339: {col1 => 'Context',
1.43 raeburn 340: col2 => 'Assignable authentication types'}],
1.230 raeburn 341: print => \&print_usercreation,
342: modify => \&modify_usercreation,
1.30 raeburn 343: },
1.224 raeburn 344: 'selfcreation' =>
345: { text => 'Users self-creating accounts',
346: help => 'Domain_Configuration_Self_Creation',
347: header => [{col1 => 'Self-creation with institutional username',
348: col2 => 'Enabled?'},
349: {col1 => 'Institutional user type (login/SSO self-creation)',
350: col2 => 'Information user can enter'},
351: {col1 => 'Self-creation with e-mail as username',
352: col2 => 'Settings'}],
1.230 raeburn 353: print => \&print_selfcreation,
354: modify => \&modify_selfcreation,
1.224 raeburn 355: },
1.69 raeburn 356: 'usermodification' =>
1.33 raeburn 357: { text => 'User modification',
1.67 raeburn 358: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 359: header => [{col1 => 'Target user has role',
1.227 bisitz 360: col2 => 'User information updatable in author context'},
1.33 raeburn 361: {col1 => 'Target user has role',
1.227 bisitz 362: col2 => 'User information updatable in course context'}],
1.230 raeburn 363: print => \&print_usermodification,
364: modify => \&modify_usermodification,
1.33 raeburn 365: },
1.69 raeburn 366: 'scantron' =>
1.95 www 367: { text => 'Bubblesheet format file',
1.67 raeburn 368: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 369: header => [ {col1 => 'Item',
370: col2 => '',
371: }],
1.230 raeburn 372: print => \&print_scantron,
373: modify => \&modify_scantron,
1.46 raeburn 374: },
1.86 raeburn 375: 'requestcourses' =>
376: {text => 'Request creation of courses',
377: help => 'Domain_Configuration_Request_Courses',
378: header => [{col1 => 'User affiliation',
1.102 raeburn 379: col2 => 'Availability/Processing of requests',},
380: {col1 => 'Setting',
1.216 raeburn 381: col2 => 'Value'},
382: {col1 => 'Available textbooks',
1.235 raeburn 383: col2 => ''},
1.242 raeburn 384: {col1 => 'Available templates',
385: col2 => ''},
1.235 raeburn 386: {col1 => 'Validation (not official courses)',
387: col2 => 'Value'},],
1.230 raeburn 388: print => \&print_quotas,
389: modify => \&modify_quotas,
1.86 raeburn 390: },
1.163 raeburn 391: 'requestauthor' =>
1.223 bisitz 392: {text => 'Request Authoring Space',
1.163 raeburn 393: help => 'Domain_Configuration_Request_Author',
394: header => [{col1 => 'User affiliation',
395: col2 => 'Availability/Processing of requests',},
396: {col1 => 'Setting',
397: col2 => 'Value'}],
1.230 raeburn 398: print => \&print_quotas,
399: modify => \&modify_quotas,
1.163 raeburn 400: },
1.69 raeburn 401: 'coursecategories' =>
1.120 raeburn 402: { text => 'Cataloging of courses/communities',
1.67 raeburn 403: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 404: header => [{col1 => 'Catalog type/availability',
405: col2 => '',},
406: {col1 => 'Category settings for standard catalog',
1.57 raeburn 407: col2 => '',},
408: {col1 => 'Categories',
409: col2 => '',
410: }],
1.230 raeburn 411: print => \&print_coursecategories,
412: modify => \&modify_coursecategories,
1.69 raeburn 413: },
414: 'serverstatuses' =>
1.77 raeburn 415: {text => 'Access to server status pages',
1.69 raeburn 416: help => 'Domain_Configuration_Server_Status',
417: header => [{col1 => 'Status Page',
418: col2 => 'Other named users',
419: col3 => 'Specific IPs',
420: }],
1.230 raeburn 421: print => \&print_serverstatuses,
422: modify => \&modify_serverstatuses,
1.69 raeburn 423: },
1.118 jms 424: 'helpsettings' =>
1.282 raeburn 425: {text => 'Support settings',
1.118 jms 426: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 427: header => [{col1 => 'Help Page Settings (logged-in users)',
428: col2 => 'Value'},
429: {col1 => 'Helpdesk Roles',
430: col2 => 'Settings'},],
1.230 raeburn 431: print => \&print_helpsettings,
432: modify => \&modify_helpsettings,
1.118 jms 433: },
1.121 raeburn 434: 'coursedefaults' =>
435: {text => 'Course/Community defaults',
436: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 437: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
438: col2 => 'Value',},
439: {col1 => 'Defaults which can be overridden for each course by a DC',
440: col2 => 'Value',},],
1.230 raeburn 441: print => \&print_coursedefaults,
442: modify => \&modify_coursedefaults,
1.121 raeburn 443: },
1.231 raeburn 444: 'selfenrollment' =>
445: {text => 'Self-enrollment in Course/Community',
446: help => 'Domain_Configuration_Selfenrollment',
447: header => [{col1 => 'Configuration Rights',
448: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
449: {col1 => 'Defaults',
450: col2 => 'Value'},
451: {col1 => 'Self-enrollment validation (optional)',
452: col2 => 'Value'},],
453: print => \&print_selfenrollment,
454: modify => \&modify_selfenrollment,
455: },
1.120 raeburn 456: 'privacy' =>
457: {text => 'User Privacy',
458: help => 'Domain_Configuration_User_Privacy',
459: header => [{col1 => 'Setting',
460: col2 => 'Value',}],
1.230 raeburn 461: print => \&print_privacy,
462: modify => \&modify_privacy,
1.120 raeburn 463: },
1.141 raeburn 464: 'usersessions' =>
1.145 raeburn 465: {text => 'User session hosting/offloading',
1.137 raeburn 466: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 467: header => [{col1 => 'Domain server',
468: col2 => 'Servers to offload sessions to when busy'},
469: {col1 => 'Hosting of users from other domains',
1.137 raeburn 470: col2 => 'Rules'},
471: {col1 => "Hosting domain's own users elsewhere",
472: col2 => 'Rules'}],
1.230 raeburn 473: print => \&print_usersessions,
474: modify => \&modify_usersessions,
1.137 raeburn 475: },
1.279 raeburn 476: 'loadbalancing' =>
1.185 raeburn 477: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 478: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 479: header => [{col1 => 'Balancers',
1.150 raeburn 480: col2 => 'Default destinations',
1.183 bisitz 481: col3 => 'User affiliation',
1.150 raeburn 482: col4 => 'Overrides'},
483: ],
1.230 raeburn 484: print => \&print_loadbalancing,
485: modify => \&modify_loadbalancing,
1.150 raeburn 486: },
1.279 raeburn 487: 'ltitools' =>
1.267 raeburn 488: {text => 'External Tools (LTI)',
489: help => 'Domain_configuration_LTI_Tools',
490: header => [{col1 => 'Setting',
491: col2 => 'Value',}],
492: print => \&print_ltitools,
493: modify => \&modify_ltitools,
494: },
1.279 raeburn 495: 'ssl' =>
1.275 raeburn 496: {text => 'LON-CAPA Network (SSL)',
497: help => 'Domain_Configuration_Network_SSL',
498: header => [{col1 => 'Server',
499: col2 => 'Certificate Status'},
500: {col1 => 'Connections to other servers',
501: col2 => 'Rules'},
502: {col1 => "Replicating domain's published content",
503: col2 => 'Rules'}],
504: print => \&print_ssl,
505: modify => \&modify_ssl,
506: },
1.279 raeburn 507: 'trust' =>
508: {text => 'Trust Settings',
509: help => 'Domain_Configuration_Trust',
510: header => [{col1 => "Access to this domain's content by others",
511: col2 => 'Rules'},
512: {col1 => "Access to other domain's content by this domain",
513: col2 => 'Rules'},
514: {col1 => "Enrollment in this domain's courses by others",
515: col2 => 'Rules',},
516: {col1 => "Co-author roles in this domain for others",
517: col2 => 'Rules',},
518: {col1 => "Co-author roles for this domain's users elsewhere",
519: col2 => 'Rules',},
520: {col1 => "Domain roles in this domain assignable to others",
521: col2 => 'Rules'},
522: {col1 => "Course catalog for this domain displayed elsewhere",
523: col2 => 'Rules'},
524: {col1 => "Requests for creation of courses in this domain by others",
525: col2 => 'Rules'},
526: {col1 => "Users in other domains can send messages to this domain",
527: col2 => 'Rules'},],
528: print => \&print_trust,
529: modify => \&modify_trust,
530: },
1.3 raeburn 531: );
1.110 raeburn 532: if (keys(%servers) > 1) {
533: $prefs{'login'} = { text => 'Log-in page options',
534: help => 'Domain_Configuration_Login_Page',
535: header => [{col1 => 'Log-in Service',
536: col2 => 'Server Setting',},
537: {col1 => 'Log-in Page Items',
1.168 raeburn 538: col2 => ''},
539: {col1 => 'Log-in Help',
1.256 raeburn 540: col2 => 'Value'},
541: {col1 => 'Custom HTML in document head',
1.168 raeburn 542: col2 => 'Value'}],
1.230 raeburn 543: print => \&print_login,
544: modify => \&modify_login,
1.110 raeburn 545: };
546: }
1.174 foxr 547:
1.6 raeburn 548: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 549: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 550: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 551: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 552: text=>"Settings to display/modify"});
1.9 raeburn 553: my $confname = $dom.'-domainconfig';
1.174 foxr 554:
1.3 raeburn 555: if ($phase eq 'process') {
1.212 raeburn 556: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
557: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 558: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 559: $r->rflush();
1.212 raeburn 560: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 561: }
1.30 raeburn 562: } elsif ($phase eq 'display') {
1.192 raeburn 563: my $js = &recaptcha_js().
1.236 raeburn 564: &toggle_display_js();
1.171 raeburn 565: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 566: my ($othertitle,$usertypes,$types) =
567: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 568: $js .= &lonbalance_targets_js($dom,$types,\%servers,
569: $domconfig{'loadbalancing'}).
1.170 raeburn 570: &new_spares_js().
571: &common_domprefs_js().
572: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 573: }
1.216 raeburn 574: if (grep(/^requestcourses$/,@actions)) {
575: my $javascript_validations;
576: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
577: $js .= <<END;
578: <script type="text/javascript">
579: $javascript_validations
580: </script>
581: $coursebrowserjs
582: END
583: }
1.286 raeburn 584: if (grep(/^contacts$/,@actions)) {
585: $js .= &contacts_javascript();
586: }
1.150 raeburn 587: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 588: } else {
1.180 raeburn 589: # check if domconfig user exists for the domain.
590: my $servadm = $r->dir_config('lonAdmEMail');
591: my ($configuserok,$author_ok,$switchserver) =
592: &config_check($dom,$confname,$servadm);
593: unless ($configuserok eq 'ok') {
1.181 raeburn 594: &Apache::lonconfigsettings::print_header($r,$phase,$context);
595: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 596: $confname).
1.181 raeburn 597: '<br />'
598: );
1.180 raeburn 599: if ($switchserver) {
1.181 raeburn 600: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
601: '<br />'.
602: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
603: '<br />'.
604: &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).
605: '<br />'.
606: &mt('To do that now, use the following link: [_1]',$switchserver)
607: );
608: } else {
609: $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.').
610: '<br />'.
611: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
612: );
1.180 raeburn 613: }
614: $r->print(&Apache::loncommon::end_page());
615: return OK;
616: }
1.21 raeburn 617: if (keys(%domconfig) == 0) {
618: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 619: my @ids=&Apache::lonnet::current_machine_ids();
620: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 621: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 622: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 623: my $custom_img_count = 0;
624: foreach my $img (@loginimages) {
625: if ($designhash{$dom.'.login.'.$img} ne '') {
626: $custom_img_count ++;
627: }
628: }
629: foreach my $role (@roles) {
630: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
631: $custom_img_count ++;
632: }
633: }
634: if ($custom_img_count > 0) {
1.94 raeburn 635: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 636: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 637: $r->print(
638: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
639: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
640: &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 />'.
641: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
642: if ($switch_server) {
1.30 raeburn 643: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 644: }
1.91 raeburn 645: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 646: return OK;
647: }
648: }
649: }
1.91 raeburn 650: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 651: }
652: return OK;
653: }
654:
655: sub process_changes {
1.205 raeburn 656: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 657: my %domconfig;
658: if (ref($values) eq 'HASH') {
659: %domconfig = %{$values};
660: }
1.3 raeburn 661: my $output;
662: if ($action eq 'login') {
1.205 raeburn 663: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 664: } elsif ($action eq 'rolecolors') {
1.9 raeburn 665: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 666: $lastactref,%domconfig);
1.3 raeburn 667: } elsif ($action eq 'quotas') {
1.216 raeburn 668: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 669: } elsif ($action eq 'autoenroll') {
1.205 raeburn 670: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 671: } elsif ($action eq 'autoupdate') {
672: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 673: } elsif ($action eq 'autocreate') {
674: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 675: } elsif ($action eq 'directorysrch') {
676: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 677: } elsif ($action eq 'usercreation') {
1.28 raeburn 678: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 679: } elsif ($action eq 'selfcreation') {
680: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 681: } elsif ($action eq 'usermodification') {
682: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 683: } elsif ($action eq 'contacts') {
1.205 raeburn 684: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 685: } elsif ($action eq 'defaults') {
1.212 raeburn 686: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 687: } elsif ($action eq 'scantron') {
1.205 raeburn 688: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 689: } elsif ($action eq 'coursecategories') {
1.239 raeburn 690: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 691: } elsif ($action eq 'serverstatuses') {
692: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 693: } elsif ($action eq 'requestcourses') {
1.216 raeburn 694: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 695: } elsif ($action eq 'requestauthor') {
1.216 raeburn 696: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 697: } elsif ($action eq 'helpsettings') {
1.285 raeburn 698: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 699: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 700: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 701: } elsif ($action eq 'selfenrollment') {
702: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 703: } elsif ($action eq 'usersessions') {
1.212 raeburn 704: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 705: } elsif ($action eq 'loadbalancing') {
706: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 707: } elsif ($action eq 'ltitools') {
708: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 709: } elsif ($action eq 'ssl') {
710: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 711: } elsif ($action eq 'trust') {
712: $output = &modify_trust($dom,$lastactref,%domconfig);
1.3 raeburn 713: }
714: return $output;
715: }
716:
717: sub print_config_box {
1.9 raeburn 718: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 719: my $rowtotal = 0;
1.49 raeburn 720: my $output;
721: if ($action eq 'coursecategories') {
722: $output = &coursecategories_javascript($settings);
1.236 raeburn 723: } elsif ($action eq 'defaults') {
724: $output = &defaults_javascript($settings);
1.282 raeburn 725: } elsif ($action eq 'helpsettings') {
726: my (%privs,%levelscurrent);
727: my %full=();
728: my %levels=(
729: course => {},
730: domain => {},
731: system => {},
732: );
733: my $context = 'domain';
734: my $crstype = 'Course';
735: my $formname = 'display';
736: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
737: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
738: $output =
739: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
740: \@templateroles);
1.91 raeburn 741: }
1.236 raeburn 742: $output .=
1.30 raeburn 743: '<table class="LC_nested_outer">
1.3 raeburn 744: <tr>
1.66 raeburn 745: <th align="left" valign="middle"><span class="LC_nobreak">'.
746: &mt($item->{text}).' '.
747: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
748: '</tr>';
1.30 raeburn 749: $rowtotal ++;
1.110 raeburn 750: my $numheaders = 1;
751: if (ref($item->{'header'}) eq 'ARRAY') {
752: $numheaders = scalar(@{$item->{'header'}});
753: }
754: if ($numheaders > 1) {
1.64 raeburn 755: my $colspan = '';
1.145 raeburn 756: my $rightcolspan = '';
1.238 raeburn 757: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 758: ($action eq 'directorysrch') ||
1.256 raeburn 759: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 760: $colspan = ' colspan="2"';
761: }
1.145 raeburn 762: if ($action eq 'usersessions') {
763: $rightcolspan = ' colspan="3"';
764: }
1.30 raeburn 765: $output .= '
1.3 raeburn 766: <tr>
767: <td>
768: <table class="LC_nested">
769: <tr class="LC_info_row">
1.59 bisitz 770: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 771: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 772: </tr>';
1.69 raeburn 773: $rowtotal ++;
1.230 raeburn 774: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 775: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 776: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 777: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
778: ($action eq 'contacts')) {
1.230 raeburn 779: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 780: } elsif ($action eq 'coursecategories') {
1.230 raeburn 781: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 782: } elsif ($action eq 'login') {
1.256 raeburn 783: if ($numheaders == 4) {
1.168 raeburn 784: $colspan = ' colspan="2"';
785: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
786: } else {
787: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
788: }
1.230 raeburn 789: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 790: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 791: } elsif ($action eq 'rolecolors') {
1.30 raeburn 792: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 793: }
1.30 raeburn 794: $output .= '
1.6 raeburn 795: </table>
796: </td>
797: </tr>
798: <tr>
799: <td>
800: <table class="LC_nested">
801: <tr class="LC_info_row">
1.230 raeburn 802: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 803: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 804: </tr>';
805: $rowtotal ++;
1.230 raeburn 806: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
807: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 808: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.286 raeburn 809: ($action eq 'ssl') || ($action eq 'trust') || ($action eq 'contacts')) {
1.238 raeburn 810: if ($action eq 'coursecategories') {
811: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
812: $colspan = ' colspan="2"';
1.279 raeburn 813: } elsif ($action eq 'trust') {
814: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.238 raeburn 815: } else {
816: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
817: }
1.279 raeburn 818: if ($action eq 'trust') {
819: $output .= '
820: </table>
821: </td>
822: </tr>';
823: my @trusthdrs = qw(2 3 4 5 6 7);
824: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
825: for (my $i=0; $i<@trusthdrs; $i++) {
826: $output .= '
827: <tr>
828: <td>
829: <table class="LC_nested">
830: <tr class="LC_info_row">
831: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
832: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
833: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
834: </table>
835: </td>
836: </tr>';
837: }
838: $output .= '
839: <tr>
840: <td>
841: <table class="LC_nested">
842: <tr class="LC_info_row">
843: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
844: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
845: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
846: } else {
847: $output .= '
1.63 raeburn 848: </table>
849: </td>
850: </tr>
851: <tr>
852: <td>
853: <table class="LC_nested">
854: <tr class="LC_info_row">
855: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 856: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 857: </tr>'."\n";
1.279 raeburn 858: if ($action eq 'coursecategories') {
859: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
860: } else {
861: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
862: }
1.238 raeburn 863: }
1.63 raeburn 864: $rowtotal ++;
1.236 raeburn 865: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 866: ($action eq 'defaults') || ($action eq 'directorysrch') ||
867: ($action eq 'helpsettings')) {
1.230 raeburn 868: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 869: } elsif ($action eq 'login') {
1.256 raeburn 870: if ($numheaders == 4) {
1.168 raeburn 871: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
872: </table>
873: </td>
874: </tr>
875: <tr>
876: <td>
877: <table class="LC_nested">
878: <tr class="LC_info_row">
879: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 880: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 881: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
882: $rowtotal ++;
883: } else {
884: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
885: }
1.256 raeburn 886: $output .= '
887: </table>
888: </td>
889: </tr>
890: <tr>
891: <td>
892: <table class="LC_nested">
893: <tr class="LC_info_row">';
894: if ($numheaders == 4) {
895: $output .= '
896: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
897: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
898: </tr>';
899: } else {
900: $output .= '
901: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
902: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
903: </tr>';
904: }
905: $rowtotal ++;
906: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 907: } elsif ($action eq 'requestcourses') {
1.247 raeburn 908: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
909: $rowtotal ++;
910: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 911: </table>
912: </td>
913: </tr>
914: <tr>
915: <td>
916: <table class="LC_nested">
917: <tr class="LC_info_row">
918: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
919: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 920: &textbookcourses_javascript($settings).
921: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
922: </table>
923: </td>
924: </tr>
925: <tr>
926: <td>
927: <table class="LC_nested">
928: <tr class="LC_info_row">
929: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
930: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
931: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 932: </table>
933: </td>
934: </tr>
935: <tr>
936: <td>
937: <table class="LC_nested">
938: <tr class="LC_info_row">
1.242 raeburn 939: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
940: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 941: </tr>'.
942: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 943: } elsif ($action eq 'requestauthor') {
944: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 945: $rowtotal ++;
1.122 jms 946: } elsif ($action eq 'rolecolors') {
1.30 raeburn 947: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 948: </table>
949: </td>
950: </tr>
951: <tr>
952: <td>
953: <table class="LC_nested">
954: <tr class="LC_info_row">
1.69 raeburn 955: <td class="LC_left_item"'.$colspan.' valign="top">'.
956: &mt($item->{'header'}->[2]->{'col1'}).'</td>
957: <td class="LC_right_item" valign="top">'.
958: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 959: </tr>'.
1.30 raeburn 960: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 961: </table>
962: </td>
963: </tr>
964: <tr>
965: <td>
966: <table class="LC_nested">
967: <tr class="LC_info_row">
1.59 bisitz 968: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
969: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 970: </tr>'.
1.30 raeburn 971: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
972: $rowtotal += 2;
1.6 raeburn 973: }
1.3 raeburn 974: } else {
1.30 raeburn 975: $output .= '
1.3 raeburn 976: <tr>
977: <td>
978: <table class="LC_nested">
1.30 raeburn 979: <tr class="LC_info_row">';
1.277 raeburn 980: if ($action eq 'login') {
1.30 raeburn 981: $output .= '
1.59 bisitz 982: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 983: } elsif ($action eq 'serverstatuses') {
984: $output .= '
985: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
986: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
987:
1.6 raeburn 988: } else {
1.30 raeburn 989: $output .= '
1.69 raeburn 990: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
991: }
1.72 raeburn 992: if (defined($item->{'header'}->[0]->{'col3'})) {
993: $output .= '<td class="LC_left_item" valign="top">'.
994: &mt($item->{'header'}->[0]->{'col2'});
995: if ($action eq 'serverstatuses') {
996: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
997: }
1.69 raeburn 998: } else {
999: $output .= '<td class="LC_right_item" valign="top">'.
1000: &mt($item->{'header'}->[0]->{'col2'});
1001: }
1002: $output .= '</td>';
1003: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1004: if (defined($item->{'header'}->[0]->{'col4'})) {
1005: $output .= '<td class="LC_left_item" valign="top">'.
1006: &mt($item->{'header'}->[0]->{'col3'});
1007: } else {
1008: $output .= '<td class="LC_right_item" valign="top">'.
1009: &mt($item->{'header'}->[0]->{'col3'});
1010: }
1.69 raeburn 1011: if ($action eq 'serverstatuses') {
1012: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1013: }
1014: $output .= '</td>';
1.6 raeburn 1015: }
1.150 raeburn 1016: if ($item->{'header'}->[0]->{'col4'}) {
1017: $output .= '<td class="LC_right_item" valign="top">'.
1018: &mt($item->{'header'}->[0]->{'col4'});
1019: }
1.69 raeburn 1020: $output .= '</tr>';
1.48 raeburn 1021: $rowtotal ++;
1.168 raeburn 1022: if ($action eq 'quotas') {
1.86 raeburn 1023: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1024: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1025: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1026: ($action eq 'ltitools')) {
1.230 raeburn 1027: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 1028: } elsif ($action eq 'scantron') {
1029: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 1030: }
1.3 raeburn 1031: }
1.30 raeburn 1032: $output .= '
1.3 raeburn 1033: </table>
1034: </td>
1035: </tr>
1.30 raeburn 1036: </table><br />';
1037: return ($output,$rowtotal);
1.1 raeburn 1038: }
1039:
1.3 raeburn 1040: sub print_login {
1.168 raeburn 1041: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1042: my ($css_class,$datatable);
1.6 raeburn 1043: my %choices = &login_choices();
1.110 raeburn 1044:
1.168 raeburn 1045: if ($caller eq 'service') {
1.149 raeburn 1046: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1047: my $choice = $choices{'disallowlogin'};
1048: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1049: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1050: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1051: '<th>'.$choices{'server'}.'</th>'.
1052: '<th>'.$choices{'serverpath'}.'</th>'.
1053: '<th>'.$choices{'custompath'}.'</th>'.
1054: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1055: my %disallowed;
1056: if (ref($settings) eq 'HASH') {
1057: if (ref($settings->{'loginvia'}) eq 'HASH') {
1058: %disallowed = %{$settings->{'loginvia'}};
1059: }
1060: }
1061: foreach my $lonhost (sort(keys(%servers))) {
1062: my $direct = 'selected="selected"';
1.128 raeburn 1063: if (ref($disallowed{$lonhost}) eq 'HASH') {
1064: if ($disallowed{$lonhost}{'server'} ne '') {
1065: $direct = '';
1066: }
1.110 raeburn 1067: }
1.115 raeburn 1068: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1069: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1070: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1071: '</option>';
1.184 raeburn 1072: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1073: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1074: my $selected = '';
1.128 raeburn 1075: if (ref($disallowed{$lonhost}) eq 'HASH') {
1076: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1077: $selected = 'selected="selected"';
1078: }
1.110 raeburn 1079: }
1080: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1081: $servers{$hostid}.'</option>';
1082: }
1.128 raeburn 1083: $datatable .= '</select></td>'.
1084: '<td><select name="'.$lonhost.'_serverpath">';
1085: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1086: my $pathname = $path;
1087: if ($path eq 'custom') {
1088: $pathname = &mt('Custom Path').' ->';
1089: }
1090: my $selected = '';
1091: if (ref($disallowed{$lonhost}) eq 'HASH') {
1092: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1093: $selected = 'selected="selected"';
1094: }
1095: } elsif ($path eq '') {
1096: $selected = 'selected="selected"';
1097: }
1098: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1099: }
1100: $datatable .= '</select></td>';
1101: my ($custom,$exempt);
1102: if (ref($disallowed{$lonhost}) eq 'HASH') {
1103: $custom = $disallowed{$lonhost}{'custompath'};
1104: $exempt = $disallowed{$lonhost}{'exempt'};
1105: }
1106: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1107: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1108: '</tr>';
1.110 raeburn 1109: }
1110: $datatable .= '</table></td></tr>';
1111: return $datatable;
1.168 raeburn 1112: } elsif ($caller eq 'page') {
1113: my %defaultchecked = (
1114: 'coursecatalog' => 'on',
1.188 raeburn 1115: 'helpdesk' => 'on',
1.168 raeburn 1116: 'adminmail' => 'off',
1117: 'newuser' => 'off',
1118: );
1.188 raeburn 1119: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1120: my (%checkedon,%checkedoff);
1.42 raeburn 1121: foreach my $item (@toggles) {
1.168 raeburn 1122: if ($defaultchecked{$item} eq 'on') {
1123: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1124: $checkedoff{$item} = ' ';
1.168 raeburn 1125: } elsif ($defaultchecked{$item} eq 'off') {
1126: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1127: $checkedon{$item} = ' ';
1128: }
1.1 raeburn 1129: }
1.168 raeburn 1130: my @images = ('img','logo','domlogo','login');
1131: my @logintext = ('textcol','bgcol');
1132: my @bgs = ('pgbg','mainbg','sidebg');
1133: my @links = ('link','alink','vlink');
1134: my %designhash = &Apache::loncommon::get_domainconf($dom);
1135: my %defaultdesign = %Apache::loncommon::defaultdesign;
1136: my (%is_custom,%designs);
1137: my %defaults = (
1138: font => $defaultdesign{'login.font'},
1139: );
1.6 raeburn 1140: foreach my $item (@images) {
1.168 raeburn 1141: $defaults{$item} = $defaultdesign{'login.'.$item};
1142: $defaults{'showlogo'}{$item} = 1;
1143: }
1144: foreach my $item (@bgs) {
1145: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1146: }
1.41 raeburn 1147: foreach my $item (@logintext) {
1.168 raeburn 1148: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1149: }
1.168 raeburn 1150: foreach my $item (@links) {
1151: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1152: }
1.168 raeburn 1153: if (ref($settings) eq 'HASH') {
1154: foreach my $item (@toggles) {
1155: if ($settings->{$item} eq '1') {
1156: $checkedon{$item} = ' checked="checked" ';
1157: $checkedoff{$item} = ' ';
1158: } elsif ($settings->{$item} eq '0') {
1159: $checkedoff{$item} = ' checked="checked" ';
1160: $checkedon{$item} = ' ';
1161: }
1162: }
1163: foreach my $item (@images) {
1164: if (defined($settings->{$item})) {
1165: $designs{$item} = $settings->{$item};
1166: $is_custom{$item} = 1;
1167: }
1168: if (defined($settings->{'showlogo'}{$item})) {
1169: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1170: }
1171: }
1172: foreach my $item (@logintext) {
1173: if ($settings->{$item} ne '') {
1174: $designs{'logintext'}{$item} = $settings->{$item};
1175: $is_custom{$item} = 1;
1176: }
1177: }
1178: if ($settings->{'font'} ne '') {
1179: $designs{'font'} = $settings->{'font'};
1180: $is_custom{'font'} = 1;
1181: }
1182: foreach my $item (@bgs) {
1183: if ($settings->{$item} ne '') {
1184: $designs{'bgs'}{$item} = $settings->{$item};
1185: $is_custom{$item} = 1;
1186: }
1187: }
1188: foreach my $item (@links) {
1189: if ($settings->{$item} ne '') {
1190: $designs{'links'}{$item} = $settings->{$item};
1191: $is_custom{$item} = 1;
1192: }
1193: }
1194: } else {
1195: if ($designhash{$dom.'.login.font'} ne '') {
1196: $designs{'font'} = $designhash{$dom.'.login.font'};
1197: $is_custom{'font'} = 1;
1198: }
1199: foreach my $item (@images) {
1200: if ($designhash{$dom.'.login.'.$item} ne '') {
1201: $designs{$item} = $designhash{$dom.'.login.'.$item};
1202: $is_custom{$item} = 1;
1203: }
1204: }
1205: foreach my $item (@bgs) {
1206: if ($designhash{$dom.'.login.'.$item} ne '') {
1207: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1208: $is_custom{$item} = 1;
1209: }
1.6 raeburn 1210: }
1.168 raeburn 1211: foreach my $item (@links) {
1212: if ($designhash{$dom.'.login.'.$item} ne '') {
1213: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1214: $is_custom{$item} = 1;
1215: }
1.6 raeburn 1216: }
1217: }
1.168 raeburn 1218: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1219: logo => 'Institution Logo',
1220: domlogo => 'Domain Logo',
1221: login => 'Login box');
1222: my $itemcount = 1;
1223: foreach my $item (@toggles) {
1224: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1225: $datatable .=
1226: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1227: '</td><td>'.
1228: '<span class="LC_nobreak"><label><input type="radio" name="'.
1229: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1230: '</label> <label><input type="radio" name="'.$item.'"'.
1231: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1232: '</tr>';
1233: $itemcount ++;
1.6 raeburn 1234: }
1.168 raeburn 1235: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1236: $datatable .= '</tr></table></td></tr>';
1237: } elsif ($caller eq 'help') {
1238: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1239: my $switchserver = &check_switchserver($dom,$confname);
1240: my $itemcount = 1;
1241: $defaulturl = '/adm/loginproblems.html';
1242: $defaulttype = 'default';
1243: %lt = &Apache::lonlocal::texthash (
1244: del => 'Delete?',
1245: rep => 'Replace:',
1246: upl => 'Upload:',
1247: default => 'Default',
1248: custom => 'Custom',
1249: );
1250: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1251: my @currlangs;
1252: if (ref($settings) eq 'HASH') {
1253: if (ref($settings->{'helpurl'}) eq 'HASH') {
1254: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1255: next if ($settings->{'helpurl'}{$key} eq '');
1256: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1257: $type{$key} = 'custom';
1258: unless ($key eq 'nolang') {
1259: push(@currlangs,$key);
1260: }
1261: }
1262: } elsif ($settings->{'helpurl'} ne '') {
1263: $type{'nolang'} = 'custom';
1264: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1265: }
1266: }
1.168 raeburn 1267: foreach my $lang ('nolang',sort(@currlangs)) {
1268: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1269: $datatable .= '<tr'.$css_class.'>';
1270: if ($url{$lang} eq '') {
1271: $url{$lang} = $defaulturl;
1272: }
1273: if ($type{$lang} eq '') {
1274: $type{$lang} = $defaulttype;
1275: }
1276: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1277: if ($lang eq 'nolang') {
1278: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1279: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1280: } else {
1281: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1282: $langchoices{$lang},
1283: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1284: }
1285: $datatable .= '</span></td>'."\n".
1286: '<td class="LC_left_item">';
1287: if ($type{$lang} eq 'custom') {
1288: $datatable .= '<span class="LC_nobreak"><label>'.
1289: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1290: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1291: } else {
1292: $datatable .= $lt{'upl'};
1293: }
1294: $datatable .='<br />';
1295: if ($switchserver) {
1296: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1297: } else {
1298: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1299: }
1.168 raeburn 1300: $datatable .= '</td></tr>';
1301: $itemcount ++;
1.6 raeburn 1302: }
1.168 raeburn 1303: my @addlangs;
1304: foreach my $lang (sort(keys(%langchoices))) {
1305: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1306: push(@addlangs,$lang);
1307: }
1308: if (@addlangs > 0) {
1309: my %toadd;
1310: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1311: $toadd{''} = &mt('Select');
1312: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1313: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1314: &mt('Add log-in help page for a specific language:').' '.
1315: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1316: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1317: if ($switchserver) {
1318: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1319: } else {
1320: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1321: }
1.168 raeburn 1322: $datatable .= '</td></tr>';
1.169 raeburn 1323: $itemcount ++;
1.6 raeburn 1324: }
1.169 raeburn 1325: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1326: } elsif ($caller eq 'headtag') {
1327: my %domservers = &Apache::lonnet::get_servers($dom);
1328: my $choice = $choices{'headtag'};
1329: $css_class = ' class="LC_odd_row"';
1330: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1331: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1332: '<th>'.$choices{'current'}.'</th>'.
1333: '<th>'.$choices{'action'}.'</th>'.
1334: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1335: my (%currurls,%currexempt);
1336: if (ref($settings) eq 'HASH') {
1337: if (ref($settings->{'headtag'}) eq 'HASH') {
1338: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1339: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1340: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1341: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1342: }
1343: }
1344: }
1345: }
1346: my %lt = &Apache::lonlocal::texthash(
1347: del => 'Delete?',
1348: rep => 'Replace:',
1349: upl => 'Upload:',
1350: curr => 'View contents',
1351: none => 'None',
1352: );
1353: my $switchserver = &check_switchserver($dom,$confname);
1354: foreach my $lonhost (sort(keys(%domservers))) {
1355: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1356: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1357: if ($currurls{$lonhost}) {
1358: $datatable .= '<td class="LC_right_item"><a href="'.
1359: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1360: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1361: '">'.$lt{'curr'}.'</a></td>'.
1362: '<td><span class="LC_nobreak"><label>'.
1363: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1364: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1365: } else {
1366: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1367: }
1368: $datatable .='<br />';
1369: if ($switchserver) {
1370: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1371: } else {
1372: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1373: }
1374: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1375: }
1376: $datatable .= '</table></td></tr>';
1.1 raeburn 1377: }
1.6 raeburn 1378: return $datatable;
1379: }
1380:
1381: sub login_choices {
1382: my %choices =
1383: &Apache::lonlocal::texthash (
1.116 bisitz 1384: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1385: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1386: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1387: disallowlogin => "Login page requests redirected",
1388: hostid => "Server",
1.128 raeburn 1389: server => "Redirect to:",
1390: serverpath => "Path",
1391: custompath => "Custom",
1392: exempt => "Exempt IP(s)",
1.110 raeburn 1393: directlogin => "No redirect",
1394: newuser => "Link to create a user account",
1395: img => "Header",
1396: logo => "Main Logo",
1397: domlogo => "Domain Logo",
1398: login => "Log-in Header",
1399: textcol => "Text color",
1400: bgcol => "Box color",
1401: bgs => "Background colors",
1402: links => "Link colors",
1403: font => "Font color",
1404: pgbg => "Header",
1405: mainbg => "Page",
1406: sidebg => "Login box",
1407: link => "Link",
1408: alink => "Active link",
1409: vlink => "Visited link",
1.256 raeburn 1410: headtag => "Custom markup",
1411: action => "Action",
1412: current => "Current",
1.6 raeburn 1413: );
1414: return %choices;
1415: }
1416:
1417: sub print_rolecolors {
1.30 raeburn 1418: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1419: my %choices = &color_font_choices();
1420: my @bgs = ('pgbg','tabbg','sidebg');
1421: my @links = ('link','alink','vlink');
1422: my @images = ('img');
1423: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1424: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1425: my %defaultdesign = %Apache::loncommon::defaultdesign;
1426: my (%is_custom,%designs);
1.200 raeburn 1427: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1428: if (ref($settings) eq 'HASH') {
1429: if (ref($settings->{$role}) eq 'HASH') {
1430: if ($settings->{$role}->{'img'} ne '') {
1431: $designs{'img'} = $settings->{$role}->{'img'};
1432: $is_custom{'img'} = 1;
1433: }
1434: if ($settings->{$role}->{'font'} ne '') {
1435: $designs{'font'} = $settings->{$role}->{'font'};
1436: $is_custom{'font'} = 1;
1437: }
1.97 tempelho 1438: if ($settings->{$role}->{'fontmenu'} ne '') {
1439: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1440: $is_custom{'fontmenu'} = 1;
1441: }
1.6 raeburn 1442: foreach my $item (@bgs) {
1443: if ($settings->{$role}->{$item} ne '') {
1444: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1445: $is_custom{$item} = 1;
1446: }
1447: }
1448: foreach my $item (@links) {
1449: if ($settings->{$role}->{$item} ne '') {
1450: $designs{'links'}{$item} = $settings->{$role}->{$item};
1451: $is_custom{$item} = 1;
1452: }
1453: }
1454: }
1455: } else {
1456: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1457: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1458: $is_custom{'img'} = 1;
1459: }
1.97 tempelho 1460: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1461: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1462: $is_custom{'fontmenu'} = 1;
1463: }
1.6 raeburn 1464: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1465: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1466: $is_custom{'font'} = 1;
1467: }
1468: foreach my $item (@bgs) {
1469: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1470: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1471: $is_custom{$item} = 1;
1472:
1473: }
1474: }
1475: foreach my $item (@links) {
1476: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1477: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1478: $is_custom{$item} = 1;
1479: }
1480: }
1481: }
1482: my $itemcount = 1;
1.30 raeburn 1483: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1484: $datatable .= '</tr></table></td></tr>';
1485: return $datatable;
1486: }
1487:
1.200 raeburn 1488: sub role_defaults {
1489: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1490: my %defaults;
1491: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1492: return %defaults;
1493: }
1494: my %defaultdesign = %Apache::loncommon::defaultdesign;
1495: if ($role eq 'login') {
1496: %defaults = (
1497: font => $defaultdesign{$role.'.font'},
1498: );
1499: if (ref($logintext) eq 'ARRAY') {
1500: foreach my $item (@{$logintext}) {
1501: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1502: }
1503: }
1504: foreach my $item (@{$images}) {
1505: $defaults{'showlogo'}{$item} = 1;
1506: }
1507: } else {
1508: %defaults = (
1509: img => $defaultdesign{$role.'.img'},
1510: font => $defaultdesign{$role.'.font'},
1511: fontmenu => $defaultdesign{$role.'.fontmenu'},
1512: );
1513: }
1514: foreach my $item (@{$bgs}) {
1515: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1516: }
1517: foreach my $item (@{$links}) {
1518: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1519: }
1520: foreach my $item (@{$images}) {
1521: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1522: }
1523: return %defaults;
1524: }
1525:
1.6 raeburn 1526: sub display_color_options {
1.9 raeburn 1527: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1528: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1529: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1530: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1531: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1532: '<td>'.$choices->{'font'}.'</td>';
1533: if (!$is_custom->{'font'}) {
1.30 raeburn 1534: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1535: } else {
1536: $datatable .= '<td> </td>';
1537: }
1.174 foxr 1538: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1539:
1.8 raeburn 1540: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1541: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1542: ' value="'.$current_color.'" /> '.
1.174 foxr 1543: ' </td></tr>';
1.107 raeburn 1544: unless ($role eq 'login') {
1545: $datatable .= '<tr'.$css_class.'>'.
1546: '<td>'.$choices->{'fontmenu'}.'</td>';
1547: if (!$is_custom->{'fontmenu'}) {
1548: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1549: } else {
1550: $datatable .= '<td> </td>';
1551: }
1.202 raeburn 1552: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1553: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1554: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1555: '<input class="colorchooser" type="text" size="10" name="'
1556: .$role.'_fontmenu"'.
1557: ' value="'.$current_color.'" /> '.
1558: ' </td></tr>';
1.97 tempelho 1559: }
1.9 raeburn 1560: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1561: foreach my $img (@{$images}) {
1.18 albertel 1562: $itemcount ++;
1.6 raeburn 1563: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1564: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1565: '<td>'.$choices->{$img};
1.41 raeburn 1566: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1567: if ($role eq 'login') {
1568: if ($img eq 'login') {
1569: $login_hdr_pick =
1.135 bisitz 1570: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1571: $logincolors =
1572: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1573: $designs,$defaults);
1.70 raeburn 1574: } elsif ($img ne 'domlogo') {
1575: $datatable.= &logo_display_options($img,$defaults,$designs);
1576: }
1577: }
1578: $datatable .= '</td>';
1.6 raeburn 1579: if ($designs->{$img} ne '') {
1580: $imgfile = $designs->{$img};
1.18 albertel 1581: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1582: } else {
1583: $imgfile = $defaults->{$img};
1584: }
1585: if ($imgfile) {
1.9 raeburn 1586: my ($showfile,$fullsize);
1587: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1588: my $urldir = $1;
1589: my $filename = $2;
1590: my @info = &Apache::lonnet::stat_file($designs->{$img});
1591: if (@info) {
1592: my $thumbfile = 'tn-'.$filename;
1593: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1594: if (@thumb) {
1595: $showfile = $urldir.'/'.$thumbfile;
1596: } else {
1597: $showfile = $imgfile;
1598: }
1599: } else {
1600: $showfile = '';
1601: }
1602: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1603: $showfile = $imgfile;
1.6 raeburn 1604: my $imgdir = $1;
1605: my $filename = $2;
1.159 raeburn 1606: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1607: $showfile = "/$imgdir/tn-".$filename;
1608: } else {
1.159 raeburn 1609: my $input = $londocroot.$imgfile;
1610: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1611: if (!-e $output) {
1.9 raeburn 1612: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1613: my ($fullwidth,$fullheight) = &check_dimensions($input);
1614: if ($fullwidth ne '' && $fullheight ne '') {
1615: if ($fullwidth > $width && $fullheight > $height) {
1616: my $size = $width.'x'.$height;
1617: system("convert -sample $size $input $output");
1.159 raeburn 1618: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1619: }
1620: }
1.6 raeburn 1621: }
1622: }
1.16 raeburn 1623: }
1.6 raeburn 1624: if ($showfile) {
1.40 raeburn 1625: if ($showfile =~ m{^/(adm|res)/}) {
1626: if ($showfile =~ m{^/res/}) {
1627: my $local_showfile =
1628: &Apache::lonnet::filelocation('',$showfile);
1629: &Apache::lonnet::repcopy($local_showfile);
1630: }
1631: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1632: }
1633: if ($imgfile) {
1634: if ($imgfile =~ m{^/(adm|res)/}) {
1635: if ($imgfile =~ m{^/res/}) {
1636: my $local_imgfile =
1637: &Apache::lonnet::filelocation('',$imgfile);
1638: &Apache::lonnet::repcopy($local_imgfile);
1639: }
1640: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1641: } else {
1642: $fullsize = $imgfile;
1643: }
1644: }
1.41 raeburn 1645: $datatable .= '<td>';
1646: if ($img eq 'login') {
1.135 bisitz 1647: $datatable .= $login_hdr_pick;
1648: }
1.41 raeburn 1649: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1650: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1651: } else {
1.201 raeburn 1652: $datatable .= '<td> </td><td class="LC_left_item">'.
1653: &mt('Upload:').'<br />';
1.6 raeburn 1654: }
1655: } else {
1.201 raeburn 1656: $datatable .= '<td> </td><td class="LC_left_item">'.
1657: &mt('Upload:').'<br />';
1.6 raeburn 1658: }
1.9 raeburn 1659: if ($switchserver) {
1660: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1661: } else {
1.135 bisitz 1662: if ($img ne 'login') { # suppress file selection for Log-in header
1663: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1664: }
1.9 raeburn 1665: }
1666: $datatable .= '</td></tr>';
1.6 raeburn 1667: }
1668: $itemcount ++;
1669: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1670: $datatable .= '<tr'.$css_class.'>'.
1671: '<td>'.$choices->{'bgs'}.'</td>';
1672: my $bgs_def;
1673: foreach my $item (@{$bgs}) {
1674: if (!$is_custom->{$item}) {
1.70 raeburn 1675: $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 1676: }
1677: }
1678: if ($bgs_def) {
1.8 raeburn 1679: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1680: } else {
1681: $datatable .= '<td> </td>';
1682: }
1683: $datatable .= '<td class="LC_right_item">'.
1684: '<table border="0"><tr>';
1.174 foxr 1685:
1.6 raeburn 1686: foreach my $item (@{$bgs}) {
1.201 raeburn 1687: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1688: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1689: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1690: $datatable .= ' ';
1.6 raeburn 1691: }
1.174 foxr 1692: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1693: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1694: }
1695: $datatable .= '</tr></table></td></tr>';
1696: $itemcount ++;
1697: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1698: $datatable .= '<tr'.$css_class.'>'.
1699: '<td>'.$choices->{'links'}.'</td>';
1700: my $links_def;
1701: foreach my $item (@{$links}) {
1702: if (!$is_custom->{$item}) {
1.30 raeburn 1703: $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 1704: }
1705: }
1706: if ($links_def) {
1.8 raeburn 1707: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1708: } else {
1709: $datatable .= '<td> </td>';
1710: }
1711: $datatable .= '<td class="LC_right_item">'.
1712: '<table border="0"><tr>';
1713: foreach my $item (@{$links}) {
1.234 raeburn 1714: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1715: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1716: if ($designs->{'links'}{$item}) {
1.174 foxr 1717: $datatable.=' ';
1.6 raeburn 1718: }
1.174 foxr 1719: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1720: '" /></td>';
1721: }
1.30 raeburn 1722: $$rowtotal += $itemcount;
1.3 raeburn 1723: return $datatable;
1724: }
1725:
1.70 raeburn 1726: sub logo_display_options {
1727: my ($img,$defaults,$designs) = @_;
1728: my $checkedon;
1729: if (ref($defaults) eq 'HASH') {
1730: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1731: if ($defaults->{'showlogo'}{$img}) {
1732: $checkedon = 'checked="checked" ';
1733: }
1734: }
1735: }
1736: if (ref($designs) eq 'HASH') {
1737: if (ref($designs->{'showlogo'}) eq 'HASH') {
1738: if (defined($designs->{'showlogo'}{$img})) {
1739: if ($designs->{'showlogo'}{$img} == 0) {
1740: $checkedon = '';
1741: } elsif ($designs->{'showlogo'}{$img} == 1) {
1742: $checkedon = 'checked="checked" ';
1743: }
1744: }
1745: }
1746: }
1747: return '<br /><label> <input type="checkbox" name="'.
1748: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1749: &mt('show').'</label>'."\n";
1750: }
1751:
1.41 raeburn 1752: sub login_header_options {
1.135 bisitz 1753: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1754: my $output = '';
1.41 raeburn 1755: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1756: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1757: if (!$is_custom->{'textcol'}) {
1758: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1759: ' ';
1760: }
1761: if (!$is_custom->{'bgcol'}) {
1762: $output .= $choices->{'bgcol'}.': '.
1763: '<span id="css_'.$role.'_font" style="background-color: '.
1764: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1765: }
1766: $output .= '<br />';
1767: }
1768: $output .='<br />';
1769: return $output;
1770: }
1771:
1772: sub login_text_colors {
1.201 raeburn 1773: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1774: my $color_menu = '<table border="0"><tr>';
1775: foreach my $item (@{$logintext}) {
1.201 raeburn 1776: $color_menu .= '<td align="center">'.$choices->{$item};
1777: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1778: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1779: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1780: }
1781: $color_menu .= '</tr></table><br />';
1782: return $color_menu;
1783: }
1784:
1785: sub image_changes {
1786: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1787: my $output;
1.135 bisitz 1788: if ($img eq 'login') {
1789: # suppress image for Log-in header
1790: } elsif (!$is_custom) {
1.70 raeburn 1791: if ($img ne 'domlogo') {
1.41 raeburn 1792: $output .= &mt('Default image:').'<br />';
1793: } else {
1794: $output .= &mt('Default in use:').'<br />';
1795: }
1796: }
1.135 bisitz 1797: if ($img eq 'login') { # suppress image for Log-in header
1798: $output .= '<td>'.$logincolors;
1.41 raeburn 1799: } else {
1.135 bisitz 1800: if ($img_import) {
1801: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1802: }
1803: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1804: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1805: if ($is_custom) {
1806: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1807: '<input type="checkbox" name="'.
1808: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1809: '</label> '.&mt('Replace:').'</span><br />';
1810: } else {
1.201 raeburn 1811: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1812: }
1.41 raeburn 1813: }
1814: return $output;
1815: }
1816:
1.3 raeburn 1817: sub print_quotas {
1.86 raeburn 1818: my ($dom,$settings,$rowtotal,$action) = @_;
1819: my $context;
1820: if ($action eq 'quotas') {
1821: $context = 'tools';
1822: } else {
1823: $context = $action;
1824: }
1.197 raeburn 1825: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1826: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1827: my $typecount = 0;
1.101 raeburn 1828: my ($css_class,%titles);
1.86 raeburn 1829: if ($context eq 'requestcourses') {
1.271 raeburn 1830: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 1831: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1832: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1833: %titles = &courserequest_titles();
1.163 raeburn 1834: } elsif ($context eq 'requestauthor') {
1835: @usertools = ('author');
1836: @options = ('norequest','approval','automatic');
1.210 raeburn 1837: %titles = &authorrequest_titles();
1.86 raeburn 1838: } else {
1.162 raeburn 1839: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1840: %titles = &tool_titles();
1.86 raeburn 1841: }
1.26 raeburn 1842: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1843: foreach my $type (@{$types}) {
1.197 raeburn 1844: my ($currdefquota,$currauthorquota);
1.163 raeburn 1845: unless (($context eq 'requestcourses') ||
1846: ($context eq 'requestauthor')) {
1.86 raeburn 1847: if (ref($settings) eq 'HASH') {
1848: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1849: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1850: } else {
1851: $currdefquota = $settings->{$type};
1852: }
1.197 raeburn 1853: if (ref($settings->{authorquota}) eq 'HASH') {
1854: $currauthorquota = $settings->{authorquota}->{$type};
1855: }
1.78 raeburn 1856: }
1.72 raeburn 1857: }
1.3 raeburn 1858: if (defined($usertypes->{$type})) {
1859: $typecount ++;
1860: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1861: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1862: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1863: '<td class="LC_left_item">';
1.101 raeburn 1864: if ($context eq 'requestcourses') {
1865: $datatable .= '<table><tr>';
1866: }
1867: my %cell;
1.72 raeburn 1868: foreach my $item (@usertools) {
1.101 raeburn 1869: if ($context eq 'requestcourses') {
1870: my ($curroption,$currlimit);
1871: if (ref($settings) eq 'HASH') {
1872: if (ref($settings->{$item}) eq 'HASH') {
1873: $curroption = $settings->{$item}->{$type};
1874: if ($curroption =~ /^autolimit=(\d*)$/) {
1875: $currlimit = $1;
1876: }
1877: }
1878: }
1879: if (!$curroption) {
1880: $curroption = 'norequest';
1881: }
1882: $datatable .= '<th>'.$titles{$item}.'</th>';
1883: foreach my $option (@options) {
1884: my $val = $option;
1885: if ($option eq 'norequest') {
1886: $val = 0;
1887: }
1888: if ($option eq 'validate') {
1889: my $canvalidate = 0;
1890: if (ref($validations{$item}) eq 'HASH') {
1891: if ($validations{$item}{$type}) {
1892: $canvalidate = 1;
1893: }
1894: }
1895: next if (!$canvalidate);
1896: }
1897: my $checked = '';
1898: if ($option eq $curroption) {
1899: $checked = ' checked="checked"';
1900: } elsif ($option eq 'autolimit') {
1901: if ($curroption =~ /^autolimit/) {
1902: $checked = ' checked="checked"';
1903: }
1904: }
1905: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1906: '<input type="radio" name="crsreq_'.$item.
1907: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1908: $titles{$option}.'</label>';
1.101 raeburn 1909: if ($option eq 'autolimit') {
1.127 raeburn 1910: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1911: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1912: 'value="'.$currlimit.'" />';
1.101 raeburn 1913: }
1.127 raeburn 1914: $cell{$item} .= '</span> ';
1.103 raeburn 1915: if ($option eq 'autolimit') {
1.127 raeburn 1916: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1917: }
1.101 raeburn 1918: }
1.163 raeburn 1919: } elsif ($context eq 'requestauthor') {
1920: my $curroption;
1921: if (ref($settings) eq 'HASH') {
1922: $curroption = $settings->{$type};
1923: }
1924: if (!$curroption) {
1925: $curroption = 'norequest';
1926: }
1927: foreach my $option (@options) {
1928: my $val = $option;
1929: if ($option eq 'norequest') {
1930: $val = 0;
1931: }
1932: my $checked = '';
1933: if ($option eq $curroption) {
1934: $checked = ' checked="checked"';
1935: }
1936: $datatable .= '<span class="LC_nobreak"><label>'.
1937: '<input type="radio" name="authorreq_'.$type.
1938: '" value="'.$val.'"'.$checked.' />'.
1939: $titles{$option}.'</label></span> ';
1940: }
1.101 raeburn 1941: } else {
1942: my $checked = 'checked="checked" ';
1943: if (ref($settings) eq 'HASH') {
1944: if (ref($settings->{$item}) eq 'HASH') {
1945: if ($settings->{$item}->{$type} == 0) {
1946: $checked = '';
1947: } elsif ($settings->{$item}->{$type} == 1) {
1948: $checked = 'checked="checked" ';
1949: }
1.78 raeburn 1950: }
1.72 raeburn 1951: }
1.101 raeburn 1952: $datatable .= '<span class="LC_nobreak"><label>'.
1953: '<input type="checkbox" name="'.$context.'_'.$item.
1954: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1955: '</label></span> ';
1.72 raeburn 1956: }
1.101 raeburn 1957: }
1958: if ($context eq 'requestcourses') {
1959: $datatable .= '</tr><tr>';
1960: foreach my $item (@usertools) {
1.106 raeburn 1961: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1962: }
1963: $datatable .= '</tr></table>';
1.72 raeburn 1964: }
1.86 raeburn 1965: $datatable .= '</td>';
1.163 raeburn 1966: unless (($context eq 'requestcourses') ||
1967: ($context eq 'requestauthor')) {
1.86 raeburn 1968: $datatable .=
1.197 raeburn 1969: '<td class="LC_right_item">'.
1970: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1971: '<input type="text" name="quota_'.$type.
1.72 raeburn 1972: '" value="'.$currdefquota.
1.197 raeburn 1973: '" size="5" /></span>'.(' ' x 2).
1974: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1975: '<input type="text" name="authorquota_'.$type.
1976: '" value="'.$currauthorquota.
1977: '" size="5" /></span></td>';
1.86 raeburn 1978: }
1979: $datatable .= '</tr>';
1.3 raeburn 1980: }
1981: }
1982: }
1.163 raeburn 1983: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1984: $defaultquota = '20';
1.197 raeburn 1985: $authorquota = '500';
1.86 raeburn 1986: if (ref($settings) eq 'HASH') {
1987: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1988: $defaultquota = $settings->{'defaultquota'}->{'default'};
1989: } elsif (defined($settings->{'default'})) {
1990: $defaultquota = $settings->{'default'};
1991: }
1.197 raeburn 1992: if (ref($settings->{'authorquota'}) eq 'HASH') {
1993: $authorquota = $settings->{'authorquota'}->{'default'};
1994: }
1.3 raeburn 1995: }
1996: }
1997: $typecount ++;
1998: $css_class = $typecount%2?' class="LC_odd_row"':'';
1999: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2000: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2001: '<td class="LC_left_item">';
1.101 raeburn 2002: if ($context eq 'requestcourses') {
2003: $datatable .= '<table><tr>';
2004: }
2005: my %defcell;
1.72 raeburn 2006: foreach my $item (@usertools) {
1.101 raeburn 2007: if ($context eq 'requestcourses') {
2008: my ($curroption,$currlimit);
2009: if (ref($settings) eq 'HASH') {
2010: if (ref($settings->{$item}) eq 'HASH') {
2011: $curroption = $settings->{$item}->{'default'};
2012: if ($curroption =~ /^autolimit=(\d*)$/) {
2013: $currlimit = $1;
2014: }
2015: }
2016: }
2017: if (!$curroption) {
2018: $curroption = 'norequest';
2019: }
2020: $datatable .= '<th>'.$titles{$item}.'</th>';
2021: foreach my $option (@options) {
2022: my $val = $option;
2023: if ($option eq 'norequest') {
2024: $val = 0;
2025: }
2026: if ($option eq 'validate') {
2027: my $canvalidate = 0;
2028: if (ref($validations{$item}) eq 'HASH') {
2029: if ($validations{$item}{'default'}) {
2030: $canvalidate = 1;
2031: }
2032: }
2033: next if (!$canvalidate);
2034: }
2035: my $checked = '';
2036: if ($option eq $curroption) {
2037: $checked = ' checked="checked"';
2038: } elsif ($option eq 'autolimit') {
2039: if ($curroption =~ /^autolimit/) {
2040: $checked = ' checked="checked"';
2041: }
2042: }
2043: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2044: '<input type="radio" name="crsreq_'.$item.
2045: '_default" value="'.$val.'"'.$checked.' />'.
2046: $titles{$option}.'</label>';
2047: if ($option eq 'autolimit') {
1.127 raeburn 2048: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2049: $item.'_limit_default" size="1" '.
2050: 'value="'.$currlimit.'" />';
2051: }
1.127 raeburn 2052: $defcell{$item} .= '</span> ';
1.104 raeburn 2053: if ($option eq 'autolimit') {
1.127 raeburn 2054: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2055: }
1.101 raeburn 2056: }
1.163 raeburn 2057: } elsif ($context eq 'requestauthor') {
2058: my $curroption;
2059: if (ref($settings) eq 'HASH') {
1.172 raeburn 2060: $curroption = $settings->{'default'};
1.163 raeburn 2061: }
2062: if (!$curroption) {
2063: $curroption = 'norequest';
2064: }
2065: foreach my $option (@options) {
2066: my $val = $option;
2067: if ($option eq 'norequest') {
2068: $val = 0;
2069: }
2070: my $checked = '';
2071: if ($option eq $curroption) {
2072: $checked = ' checked="checked"';
2073: }
2074: $datatable .= '<span class="LC_nobreak"><label>'.
2075: '<input type="radio" name="authorreq_default"'.
2076: ' value="'.$val.'"'.$checked.' />'.
2077: $titles{$option}.'</label></span> ';
2078: }
1.101 raeburn 2079: } else {
2080: my $checked = 'checked="checked" ';
2081: if (ref($settings) eq 'HASH') {
2082: if (ref($settings->{$item}) eq 'HASH') {
2083: if ($settings->{$item}->{'default'} == 0) {
2084: $checked = '';
2085: } elsif ($settings->{$item}->{'default'} == 1) {
2086: $checked = 'checked="checked" ';
2087: }
1.78 raeburn 2088: }
1.72 raeburn 2089: }
1.101 raeburn 2090: $datatable .= '<span class="LC_nobreak"><label>'.
2091: '<input type="checkbox" name="'.$context.'_'.$item.
2092: '" value="default" '.$checked.'/>'.$titles{$item}.
2093: '</label></span> ';
2094: }
2095: }
2096: if ($context eq 'requestcourses') {
2097: $datatable .= '</tr><tr>';
2098: foreach my $item (@usertools) {
1.106 raeburn 2099: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2100: }
1.101 raeburn 2101: $datatable .= '</tr></table>';
1.72 raeburn 2102: }
1.86 raeburn 2103: $datatable .= '</td>';
1.163 raeburn 2104: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2105: $datatable .= '<td class="LC_right_item">'.
2106: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2107: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2108: $defaultquota.'" size="5" /></span>'.(' ' x2).
2109: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2110: '<input type="text" name="authorquota" value="'.
2111: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2112: }
2113: $datatable .= '</tr>';
1.72 raeburn 2114: $typecount ++;
2115: $css_class = $typecount%2?' class="LC_odd_row"':'';
2116: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2117: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2118: if ($context eq 'requestcourses') {
1.109 raeburn 2119: $datatable .= &mt('(overrides affiliation, if set)').
2120: '</td>'.
2121: '<td class="LC_left_item">'.
2122: '<table><tr>';
1.101 raeburn 2123: } else {
1.109 raeburn 2124: $datatable .= &mt('(overrides affiliation, if checked)').
2125: '</td>'.
2126: '<td class="LC_left_item" colspan="2">'.
2127: '<br />';
1.101 raeburn 2128: }
2129: my %advcell;
1.72 raeburn 2130: foreach my $item (@usertools) {
1.101 raeburn 2131: if ($context eq 'requestcourses') {
2132: my ($curroption,$currlimit);
2133: if (ref($settings) eq 'HASH') {
2134: if (ref($settings->{$item}) eq 'HASH') {
2135: $curroption = $settings->{$item}->{'_LC_adv'};
2136: if ($curroption =~ /^autolimit=(\d*)$/) {
2137: $currlimit = $1;
2138: }
2139: }
2140: }
2141: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2142: my $checked = '';
2143: if ($curroption eq '') {
2144: $checked = ' checked="checked"';
2145: }
2146: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2147: '<input type="radio" name="crsreq_'.$item.
2148: '__LC_adv" value=""'.$checked.' />'.
2149: &mt('No override set').'</label></span> ';
1.101 raeburn 2150: foreach my $option (@options) {
2151: my $val = $option;
2152: if ($option eq 'norequest') {
2153: $val = 0;
2154: }
2155: if ($option eq 'validate') {
2156: my $canvalidate = 0;
2157: if (ref($validations{$item}) eq 'HASH') {
2158: if ($validations{$item}{'_LC_adv'}) {
2159: $canvalidate = 1;
2160: }
2161: }
2162: next if (!$canvalidate);
2163: }
2164: my $checked = '';
1.104 raeburn 2165: if ($val eq $curroption) {
1.101 raeburn 2166: $checked = ' checked="checked"';
2167: } elsif ($option eq 'autolimit') {
2168: if ($curroption =~ /^autolimit/) {
2169: $checked = ' checked="checked"';
2170: }
2171: }
2172: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2173: '<input type="radio" name="crsreq_'.$item.
2174: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2175: $titles{$option}.'</label>';
2176: if ($option eq 'autolimit') {
1.127 raeburn 2177: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2178: $item.'_limit__LC_adv" size="1" '.
2179: 'value="'.$currlimit.'" />';
2180: }
1.127 raeburn 2181: $advcell{$item} .= '</span> ';
1.104 raeburn 2182: if ($option eq 'autolimit') {
1.127 raeburn 2183: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2184: }
1.101 raeburn 2185: }
1.163 raeburn 2186: } elsif ($context eq 'requestauthor') {
2187: my $curroption;
2188: if (ref($settings) eq 'HASH') {
2189: $curroption = $settings->{'_LC_adv'};
2190: }
2191: my $checked = '';
2192: if ($curroption eq '') {
2193: $checked = ' checked="checked"';
2194: }
2195: $datatable .= '<span class="LC_nobreak"><label>'.
2196: '<input type="radio" name="authorreq__LC_adv"'.
2197: ' value=""'.$checked.' />'.
2198: &mt('No override set').'</label></span> ';
2199: foreach my $option (@options) {
2200: my $val = $option;
2201: if ($option eq 'norequest') {
2202: $val = 0;
2203: }
2204: my $checked = '';
2205: if ($val eq $curroption) {
2206: $checked = ' checked="checked"';
2207: }
2208: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2209: '<input type="radio" name="authorreq__LC_adv"'.
2210: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2211: $titles{$option}.'</label></span> ';
2212: }
1.101 raeburn 2213: } else {
2214: my $checked = 'checked="checked" ';
2215: if (ref($settings) eq 'HASH') {
2216: if (ref($settings->{$item}) eq 'HASH') {
2217: if ($settings->{$item}->{'_LC_adv'} == 0) {
2218: $checked = '';
2219: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2220: $checked = 'checked="checked" ';
2221: }
1.79 raeburn 2222: }
1.72 raeburn 2223: }
1.101 raeburn 2224: $datatable .= '<span class="LC_nobreak"><label>'.
2225: '<input type="checkbox" name="'.$context.'_'.$item.
2226: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2227: '</label></span> ';
2228: }
2229: }
2230: if ($context eq 'requestcourses') {
2231: $datatable .= '</tr><tr>';
2232: foreach my $item (@usertools) {
1.106 raeburn 2233: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2234: }
1.101 raeburn 2235: $datatable .= '</tr></table>';
1.72 raeburn 2236: }
1.98 raeburn 2237: $datatable .= '</td></tr>';
1.30 raeburn 2238: $$rowtotal += $typecount;
1.3 raeburn 2239: return $datatable;
2240: }
2241:
1.163 raeburn 2242: sub print_requestmail {
2243: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2244: my ($now,$datatable,%currapp);
1.102 raeburn 2245: $now = time;
2246: if (ref($settings) eq 'HASH') {
2247: if (ref($settings->{'notify'}) eq 'HASH') {
2248: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2249: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2250: }
2251: }
2252: }
1.191 raeburn 2253: my $numinrow = 2;
1.224 raeburn 2254: my $css_class;
2255: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2256: my $text;
2257: if ($action eq 'requestcourses') {
2258: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2259: } elsif ($action eq 'requestauthor') {
2260: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2261: } else {
1.224 raeburn 2262: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2263: }
1.224 raeburn 2264: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2265: ' <td>'.$text.'</td>'.
1.102 raeburn 2266: ' <td class="LC_left_item">';
1.191 raeburn 2267: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2268: $action.'notifyapproval',%currapp);
1.191 raeburn 2269: if ($numdc > 0) {
2270: $datatable .= $table;
1.102 raeburn 2271: } else {
2272: $datatable .= &mt('There are no active Domain Coordinators');
2273: }
2274: $datatable .='</td></tr>';
2275: return $datatable;
2276: }
2277:
1.216 raeburn 2278: sub print_studentcode {
2279: my ($settings,$rowtotal) = @_;
2280: my $rownum = 0;
1.218 raeburn 2281: my ($output,%current);
1.271 raeburn 2282: my @crstypes = ('official','unofficial','community','textbook','placement');
1.248 raeburn 2283: if (ref($settings) eq 'HASH') {
2284: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2285: foreach my $type (@crstypes) {
2286: $current{$type} = $settings->{'uniquecode'}{$type};
2287: }
1.218 raeburn 2288: }
2289: }
2290: $output .= '<tr>'.
2291: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2292: '<td class="LC_left_item">';
2293: foreach my $type (@crstypes) {
2294: my $check = ' ';
2295: if ($current{$type}) {
2296: $check = ' checked="checked" ';
2297: }
2298: $output .= '<span class="LC_nobreak"><label>'.
2299: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2300: &mt($type).'</label></span>'.(' 'x2).' ';
2301: }
2302: $output .= '</td></tr>';
2303: $$rowtotal ++;
2304: return $output;
1.216 raeburn 2305: }
2306:
2307: sub print_textbookcourses {
1.242 raeburn 2308: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2309: my $rownum = 0;
2310: my $css_class;
2311: my $itemcount = 1;
2312: my $maxnum = 0;
2313: my $bookshash;
2314: if (ref($settings) eq 'HASH') {
1.242 raeburn 2315: $bookshash = $settings->{$type};
1.216 raeburn 2316: }
2317: my %ordered;
2318: if (ref($bookshash) eq 'HASH') {
2319: foreach my $item (keys(%{$bookshash})) {
2320: if (ref($bookshash->{$item}) eq 'HASH') {
2321: my $num = $bookshash->{$item}{'order'};
2322: $ordered{$num} = $item;
2323: }
2324: }
2325: }
2326: my $confname = $dom.'-domainconfig';
2327: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2328: my $maxnum = scalar(keys(%ordered));
2329: my $datatable;
1.216 raeburn 2330: if (keys(%ordered)) {
2331: my @items = sort { $a <=> $b } keys(%ordered);
2332: for (my $i=0; $i<@items; $i++) {
2333: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2334: my $key = $ordered{$items[$i]};
2335: my %coursehash=&Apache::lonnet::coursedescription($key);
2336: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2337: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2338: if (ref($bookshash->{$key}) eq 'HASH') {
2339: $subject = $bookshash->{$key}->{'subject'};
2340: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2341: if ($type eq 'textbooks') {
1.243 raeburn 2342: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2343: $author = $bookshash->{$key}->{'author'};
2344: $image = $bookshash->{$key}->{'image'};
2345: if ($image ne '') {
2346: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2347: my $imagethumb = "$path/tn-".$imagefile;
2348: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2349: }
1.216 raeburn 2350: }
2351: }
1.242 raeburn 2352: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2353: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2354: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2355: for (my $k=0; $k<=$maxnum; $k++) {
2356: my $vpos = $k+1;
2357: my $selstr;
2358: if ($k == $i) {
2359: $selstr = ' selected="selected" ';
2360: }
2361: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2362: }
2363: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2364: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2365: &mt('Delete?').'</label></span></td>'.
2366: '<td colspan="2">'.
1.242 raeburn 2367: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2368: (' 'x2).
1.242 raeburn 2369: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2370: if ($type eq 'textbooks') {
2371: $datatable .= (' 'x2).
1.243 raeburn 2372: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2373: (' 'x2).
1.242 raeburn 2374: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2375: (' 'x2).
2376: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2377: if ($image) {
1.267 raeburn 2378: $datatable .= $imgsrc.
1.242 raeburn 2379: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2380: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2381: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2382: }
2383: if ($switchserver) {
2384: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2385: } else {
2386: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2387: }
1.216 raeburn 2388: }
1.242 raeburn 2389: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2390: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2391: $coursetitle.'</span></td></tr>'."\n";
2392: $itemcount ++;
2393: }
2394: }
2395: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2396: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2397: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2398: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2399: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2400: for (my $k=0; $k<$maxnum+1; $k++) {
2401: my $vpos = $k+1;
2402: my $selstr;
2403: if ($k == $maxnum) {
2404: $selstr = ' selected="selected" ';
2405: }
2406: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2407: }
2408: $datatable .= '</select> '."\n".
1.242 raeburn 2409: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2410: '<td colspan="2">'.
1.242 raeburn 2411: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2412: (' 'x2).
1.242 raeburn 2413: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2414: (' 'x2);
2415: if ($type eq 'textbooks') {
1.243 raeburn 2416: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2417: (' 'x2).
2418: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2419: (' 'x2).
2420: '<span class="LC_nobreak">'.&mt('Image:').' ';
2421: if ($switchserver) {
2422: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2423: } else {
2424: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2425: }
1.216 raeburn 2426: }
2427: $datatable .= '</span>'."\n".
2428: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2429: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2430: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2431: &Apache::loncommon::selectcourse_link
1.242 raeburn 2432: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2433: '</span></td>'."\n".
2434: '</tr>'."\n";
2435: $itemcount ++;
2436: return $datatable;
2437: }
2438:
1.217 raeburn 2439: sub textbookcourses_javascript {
1.242 raeburn 2440: my ($settings) = @_;
2441: return unless(ref($settings) eq 'HASH');
2442: my (%ordered,%total,%jstext);
2443: foreach my $type ('textbooks','templates') {
2444: $total{$type} = 0;
2445: if (ref($settings->{$type}) eq 'HASH') {
2446: foreach my $item (keys(%{$settings->{$type}})) {
2447: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2448: my $num = $settings->{$type}->{$item}{'order'};
2449: $ordered{$type}{$num} = $item;
2450: }
2451: }
2452: $total{$type} = scalar(keys(%{$settings->{$type}}));
2453: }
2454: my @jsarray = ();
2455: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2456: push(@jsarray,$ordered{$type}{$item});
2457: }
2458: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2459: }
2460: return <<"ENDSCRIPT";
2461: <script type="text/javascript">
2462: // <![CDATA[
1.242 raeburn 2463: function reorderBooks(form,item,caller) {
1.217 raeburn 2464: var changedVal;
1.242 raeburn 2465: $jstext{'textbooks'};
2466: $jstext{'templates'};
2467: var newpos;
2468: var maxh;
2469: if (caller == 'textbooks') {
2470: newpos = 'textbooks_addbook_pos';
2471: maxh = 1 + $total{'textbooks'};
2472: } else {
2473: newpos = 'templates_addbook_pos';
2474: maxh = 1 + $total{'templates'};
2475: }
1.217 raeburn 2476: var current = new Array;
2477: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2478: if (item == newpos) {
2479: changedVal = newitemVal;
2480: } else {
2481: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2482: current[newitemVal] = newpos;
2483: }
1.242 raeburn 2484: if (caller == 'textbooks') {
2485: for (var i=0; i<textbooks.length; i++) {
2486: var elementName = 'textbooks_'+textbooks[i];
2487: if (elementName != item) {
2488: if (form.elements[elementName]) {
2489: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2490: current[currVal] = elementName;
2491: }
2492: }
2493: }
2494: }
2495: if (caller == 'templates') {
2496: for (var i=0; i<templates.length; i++) {
2497: var elementName = 'templates_'+templates[i];
2498: if (elementName != item) {
2499: if (form.elements[elementName]) {
2500: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2501: current[currVal] = elementName;
2502: }
1.217 raeburn 2503: }
2504: }
2505: }
2506: var oldVal;
2507: for (var j=0; j<maxh; j++) {
2508: if (current[j] == undefined) {
2509: oldVal = j;
2510: }
2511: }
2512: if (oldVal < changedVal) {
2513: for (var k=oldVal+1; k<=changedVal ; k++) {
2514: var elementName = current[k];
2515: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2516: }
2517: } else {
2518: for (var k=changedVal; k<oldVal; k++) {
2519: var elementName = current[k];
2520: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2521: }
2522: }
2523: return;
2524: }
2525:
2526: // ]]>
2527: </script>
2528:
2529: ENDSCRIPT
2530: }
2531:
1.267 raeburn 2532: sub ltitools_javascript {
2533: my ($settings) = @_;
2534: return unless(ref($settings) eq 'HASH');
2535: my (%ordered,$total,%jstext);
2536: $total = 0;
2537: foreach my $item (keys(%{$settings})) {
2538: if (ref($settings->{$item}) eq 'HASH') {
2539: my $num = $settings->{$item}{'order'};
2540: $ordered{$num} = $item;
2541: }
2542: }
2543: $total = scalar(keys(%{$settings}));
2544: my @jsarray = ();
2545: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2546: push(@jsarray,$ordered{$item});
2547: }
2548: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2549: return <<"ENDSCRIPT";
2550: <script type="text/javascript">
2551: // <![CDATA[
2552: function reorderLTI(form,item) {
2553: var changedVal;
2554: $jstext
2555: var newpos = 'ltitools_add_pos';
2556: var maxh = 1 + $total;
2557: var current = new Array;
2558: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2559: if (item == newpos) {
2560: changedVal = newitemVal;
2561: } else {
2562: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2563: current[newitemVal] = newpos;
2564: }
2565: for (var i=0; i<ltitools.length; i++) {
2566: var elementName = 'ltitools_'+ltitools[i];
2567: if (elementName != item) {
2568: if (form.elements[elementName]) {
2569: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2570: current[currVal] = elementName;
2571: }
2572: }
2573: }
2574: var oldVal;
2575: for (var j=0; j<maxh; j++) {
2576: if (current[j] == undefined) {
2577: oldVal = j;
2578: }
2579: }
2580: if (oldVal < changedVal) {
2581: for (var k=oldVal+1; k<=changedVal ; k++) {
2582: var elementName = current[k];
2583: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2584: }
2585: } else {
2586: for (var k=changedVal; k<oldVal; k++) {
2587: var elementName = current[k];
2588: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2589: }
2590: }
2591: return;
2592: }
2593:
2594: // ]]>
2595: </script>
2596:
2597: ENDSCRIPT
2598: }
2599:
1.3 raeburn 2600: sub print_autoenroll {
1.30 raeburn 2601: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2602: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2603: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2604: if (ref($settings) eq 'HASH') {
2605: if (exists($settings->{'run'})) {
2606: if ($settings->{'run'} eq '0') {
2607: $runoff = ' checked="checked" ';
2608: $runon = ' ';
2609: } else {
2610: $runon = ' checked="checked" ';
2611: $runoff = ' ';
2612: }
2613: } else {
2614: if ($autorun) {
2615: $runon = ' checked="checked" ';
2616: $runoff = ' ';
2617: } else {
2618: $runoff = ' checked="checked" ';
2619: $runon = ' ';
2620: }
2621: }
1.129 raeburn 2622: if (exists($settings->{'co-owners'})) {
2623: if ($settings->{'co-owners'} eq '0') {
2624: $coownersoff = ' checked="checked" ';
2625: $coownerson = ' ';
2626: } else {
2627: $coownerson = ' checked="checked" ';
2628: $coownersoff = ' ';
2629: }
2630: } else {
2631: $coownersoff = ' checked="checked" ';
2632: $coownerson = ' ';
2633: }
1.3 raeburn 2634: if (exists($settings->{'sender_domain'})) {
2635: $defdom = $settings->{'sender_domain'};
2636: }
1.274 raeburn 2637: if (exists($settings->{'autofailsafe'})) {
2638: $failsafe = $settings->{'autofailsafe'};
2639: }
1.14 raeburn 2640: } else {
2641: if ($autorun) {
2642: $runon = ' checked="checked" ';
2643: $runoff = ' ';
2644: } else {
2645: $runoff = ' checked="checked" ';
2646: $runon = ' ';
2647: }
1.3 raeburn 2648: }
2649: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2650: my $notif_sender;
2651: if (ref($settings) eq 'HASH') {
2652: $notif_sender = $settings->{'sender_uname'};
2653: }
1.3 raeburn 2654: my $datatable='<tr class="LC_odd_row">'.
2655: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2656: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2657: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2658: $runon.' value="1" />'.&mt('Yes').'</label> '.
2659: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2660: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2661: '</tr><tr>'.
2662: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2663: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2664: &mt('username').': '.
2665: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2666: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2667: ': '.$domform.'</span></td></tr>'.
2668: '<tr class="LC_odd_row">'.
2669: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2670: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2671: '<input type="radio" name="autoassign_coowners"'.
2672: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2673: '<label><input type="radio" name="autoassign_coowners"'.
2674: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 2675: '</tr><tr>'.
2676: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2677: '<td class="LC_right_item"><span class="LC_nobreak">'.
2678: '<input type="text" name="autoenroll_failsafe"'.
2679: ' value="'.$failsafe.'" size="4" /></td></tr>';
2680: $$rowtotal += 4;
1.3 raeburn 2681: return $datatable;
2682: }
2683:
2684: sub print_autoupdate {
1.30 raeburn 2685: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2686: my $datatable;
2687: if ($position eq 'top') {
2688: my $updateon = ' ';
2689: my $updateoff = ' checked="checked" ';
2690: my $classlistson = ' ';
2691: my $classlistsoff = ' checked="checked" ';
2692: if (ref($settings) eq 'HASH') {
2693: if ($settings->{'run'} eq '1') {
2694: $updateon = $updateoff;
2695: $updateoff = ' ';
2696: }
2697: if ($settings->{'classlists'} eq '1') {
2698: $classlistson = $classlistsoff;
2699: $classlistsoff = ' ';
2700: }
2701: }
2702: my %title = (
2703: run => 'Auto-update active?',
2704: classlists => 'Update information in classlists?',
2705: );
2706: $datatable = '<tr class="LC_odd_row">'.
2707: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2708: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2709: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2710: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2711: '<label><input type="radio" name="autoupdate_run"'.
2712: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2713: '</tr><tr>'.
2714: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2715: '<td class="LC_right_item"><span class="LC_nobreak">'.
2716: '<label><input type="radio" name="classlists"'.
2717: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2718: '<label><input type="radio" name="classlists"'.
2719: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2720: '</tr>';
1.30 raeburn 2721: $$rowtotal += 2;
1.131 raeburn 2722: } elsif ($position eq 'middle') {
2723: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2724: my $numinrow = 3;
2725: my $locknamesettings;
2726: $datatable .= &insttypes_row($settings,$types,$usertypes,
2727: $dom,$numinrow,$othertitle,
2728: 'lockablenames');
2729: $$rowtotal ++;
1.3 raeburn 2730: } else {
1.44 raeburn 2731: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2732: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2733: 'permanentemail','id');
1.33 raeburn 2734: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2735: my $numrows = 0;
1.26 raeburn 2736: if (ref($types) eq 'ARRAY') {
2737: if (@{$types} > 0) {
2738: $datatable =
2739: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2740: \@fields,$types,\$numrows);
1.30 raeburn 2741: $$rowtotal += @{$types};
1.26 raeburn 2742: }
1.3 raeburn 2743: }
2744: $datatable .=
2745: &usertype_update_row($settings,{'default' => $othertitle},
2746: \%fieldtitles,\@fields,['default'],
2747: \$numrows);
1.30 raeburn 2748: $$rowtotal ++;
1.3 raeburn 2749: }
2750: return $datatable;
2751: }
2752:
1.125 raeburn 2753: sub print_autocreate {
2754: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2755: my (%createon,%createoff,%currhash);
1.125 raeburn 2756: my @types = ('xml','req');
2757: if (ref($settings) eq 'HASH') {
2758: foreach my $item (@types) {
2759: $createoff{$item} = ' checked="checked" ';
2760: $createon{$item} = ' ';
2761: if (exists($settings->{$item})) {
2762: if ($settings->{$item}) {
2763: $createon{$item} = ' checked="checked" ';
2764: $createoff{$item} = ' ';
2765: }
2766: }
2767: }
1.210 raeburn 2768: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2769: $currhash{$settings->{'xmldc'}} = 1;
2770: }
1.125 raeburn 2771: } else {
2772: foreach my $item (@types) {
2773: $createoff{$item} = ' checked="checked" ';
2774: $createon{$item} = ' ';
2775: }
2776: }
2777: $$rowtotal += 2;
1.191 raeburn 2778: my $numinrow = 2;
1.125 raeburn 2779: my $datatable='<tr class="LC_odd_row">'.
2780: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2781: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2782: '<input type="radio" name="autocreate_xml"'.
2783: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2784: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2785: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2786: '</td></tr><tr>'.
2787: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2788: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2789: '<input type="radio" name="autocreate_req"'.
2790: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2791: '<label><input type="radio" name="autocreate_req"'.
2792: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2793: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2794: 'autocreate_xmldc',%currhash);
1.247 raeburn 2795: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2796: if ($numdc > 1) {
1.247 raeburn 2797: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2798: '</td><td class="LC_left_item">';
1.125 raeburn 2799: } else {
1.247 raeburn 2800: $datatable .= &mt('Course creation processed as:').
2801: '</td><td class="LC_right_item">';
1.125 raeburn 2802: }
1.247 raeburn 2803: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 2804: $$rowtotal += $rows;
1.125 raeburn 2805: return $datatable;
2806: }
2807:
1.23 raeburn 2808: sub print_directorysrch {
1.277 raeburn 2809: my ($position,$dom,$settings,$rowtotal) = @_;
2810: my $datatable;
2811: if ($position eq 'top') {
2812: my $instsrchon = ' ';
2813: my $instsrchoff = ' checked="checked" ';
2814: my ($exacton,$containson,$beginson);
2815: my $instlocalon = ' ';
2816: my $instlocaloff = ' checked="checked" ';
2817: if (ref($settings) eq 'HASH') {
2818: if ($settings->{'available'} eq '1') {
2819: $instsrchon = $instsrchoff;
2820: $instsrchoff = ' ';
2821: }
2822: if ($settings->{'localonly'} eq '1') {
2823: $instlocalon = $instlocaloff;
2824: $instlocaloff = ' ';
2825: }
2826: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2827: foreach my $type (@{$settings->{'searchtypes'}}) {
2828: if ($type eq 'exact') {
2829: $exacton = ' checked="checked" ';
2830: } elsif ($type eq 'contains') {
2831: $containson = ' checked="checked" ';
2832: } elsif ($type eq 'begins') {
2833: $beginson = ' checked="checked" ';
2834: }
2835: }
2836: } else {
2837: if ($settings->{'searchtypes'} eq 'exact') {
2838: $exacton = ' checked="checked" ';
2839: } elsif ($settings->{'searchtypes'} eq 'contains') {
2840: $containson = ' checked="checked" ';
2841: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2842: $exacton = ' checked="checked" ';
2843: $containson = ' checked="checked" ';
2844: }
2845: }
1.277 raeburn 2846: }
2847: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2848: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2849:
2850: my $numinrow = 4;
2851: my $cansrchrow = 0;
2852: $datatable='<tr class="LC_odd_row">'.
2853: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2854: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2855: '<input type="radio" name="dirsrch_available"'.
2856: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2857: '<label><input type="radio" name="dirsrch_available"'.
2858: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2859: '</tr><tr>'.
2860: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2861: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2862: '<input type="radio" name="dirsrch_instlocalonly"'.
2863: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2864: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2865: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2866: '</tr>';
2867: $$rowtotal += 2;
2868: if (ref($usertypes) eq 'HASH') {
2869: if (keys(%{$usertypes}) > 0) {
2870: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2871: $numinrow,$othertitle,'cansearch');
2872: $cansrchrow = 1;
1.25 raeburn 2873: }
1.23 raeburn 2874: }
1.277 raeburn 2875: if ($cansrchrow) {
2876: $$rowtotal ++;
2877: $datatable .= '<tr>';
2878: } else {
2879: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 2880: }
1.277 raeburn 2881: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2882: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2883: foreach my $title (@{$titleorder}) {
2884: if (defined($searchtitles->{$title})) {
2885: my $check = ' ';
2886: if (ref($settings) eq 'HASH') {
2887: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2888: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2889: $check = ' checked="checked" ';
2890: }
1.39 raeburn 2891: }
1.25 raeburn 2892: }
1.277 raeburn 2893: $datatable .= '<td class="LC_left_item">'.
2894: '<span class="LC_nobreak"><label>'.
2895: '<input type="checkbox" name="searchby" '.
2896: 'value="'.$title.'"'.$check.'/>'.
2897: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2898: }
2899: }
1.277 raeburn 2900: $datatable .= '</tr></table></td></tr>';
2901: $$rowtotal ++;
2902: if ($cansrchrow) {
2903: $datatable .= '<tr class="LC_odd_row">';
2904: } else {
2905: $datatable .= '<tr>';
2906: }
2907: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2908: '<td class="LC_left_item" colspan="2">'.
2909: '<span class="LC_nobreak"><label>'.
2910: '<input type="checkbox" name="searchtypes" '.
2911: $exacton.' value="exact" />'.&mt('Exact match').
2912: '</label> '.
2913: '<label><input type="checkbox" name="searchtypes" '.
2914: $beginson.' value="begins" />'.&mt('Begins with').
2915: '</label> '.
2916: '<label><input type="checkbox" name="searchtypes" '.
2917: $containson.' value="contains" />'.&mt('Contains').
2918: '</label></span></td></tr>';
2919: $$rowtotal ++;
1.26 raeburn 2920: } else {
1.277 raeburn 2921: my $domsrchon = ' checked="checked" ';
2922: my $domsrchoff = ' ';
2923: my $domlocalon = ' ';
2924: my $domlocaloff = ' checked="checked" ';
2925: if (ref($settings) eq 'HASH') {
2926: if ($settings->{'lclocalonly'} eq '1') {
2927: $domlocalon = $domlocaloff;
2928: $domlocaloff = ' ';
2929: }
2930: if ($settings->{'lcavailable'} eq '0') {
2931: $domsrchoff = $domsrchon;
2932: $domsrchon = ' ';
2933: }
2934: }
2935: $datatable='<tr class="LC_odd_row">'.
2936: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2937: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2938: '<input type="radio" name="dirsrch_domavailable"'.
2939: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2940: '<label><input type="radio" name="dirsrch_domavailable"'.
2941: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2942: '</tr><tr>'.
2943: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2944: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2945: '<input type="radio" name="dirsrch_domlocalonly"'.
2946: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2947: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2948: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2949: '</tr>';
2950: $$rowtotal += 2;
1.26 raeburn 2951: }
1.25 raeburn 2952: return $datatable;
2953: }
2954:
1.28 raeburn 2955: sub print_contacts {
1.286 raeburn 2956: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 2957: my $datatable;
2958: my @contacts = ('adminemail','supportemail');
1.286 raeburn 2959: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
2960: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
2961: if ($position eq 'top') {
2962: if (ref($settings) eq 'HASH') {
2963: foreach my $item (@contacts) {
2964: if (exists($settings->{$item})) {
2965: $to{$item} = $settings->{$item};
2966: }
2967: }
2968: }
2969: } elsif ($position eq 'middle') {
2970: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
2971: 'updatesmail','idconflictsmail');
1.288 ! raeburn 2972: foreach my $type (@mailings) {
! 2973: $otheremails{$type} = '';
! 2974: }
1.286 raeburn 2975: } else {
2976: @mailings = ('helpdeskmail','otherdomsmail');
1.288 ! raeburn 2977: foreach my $type (@mailings) {
! 2978: $otheremails{$type} = '';
! 2979: }
1.286 raeburn 2980: $bccemails{'helpdeskmail'} = '';
2981: $bccemails{'otherdomsmail'} = '';
2982: $includestr{'helpdeskmail'} = '';
2983: $includestr{'otherdomsmail'} = '';
2984: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
2985: }
1.28 raeburn 2986: if (ref($settings) eq 'HASH') {
1.286 raeburn 2987: unless ($position eq 'top') {
2988: foreach my $type (@mailings) {
2989: if (exists($settings->{$type})) {
2990: if (ref($settings->{$type}) eq 'HASH') {
2991: foreach my $item (@contacts) {
2992: if ($settings->{$type}{$item}) {
2993: $checked{$type}{$item} = ' checked="checked" ';
2994: }
2995: }
2996: $otheremails{$type} = $settings->{$type}{'others'};
2997: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2998: $bccemails{$type} = $settings->{$type}{'bcc'};
2999: if ($settings->{$type}{'include'} ne '') {
3000: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3001: $includestr{$type} = &unescape($includestr{$type});
3002: }
3003: }
3004: }
3005: } elsif ($type eq 'lonstatusmail') {
3006: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3007: }
1.28 raeburn 3008: }
3009: }
1.286 raeburn 3010: if ($position eq 'bottom') {
3011: foreach my $type (@mailings) {
3012: $bccemails{$type} = $settings->{$type}{'bcc'};
3013: if ($settings->{$type}{'include'} ne '') {
3014: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3015: $includestr{$type} = &unescape($includestr{$type});
3016: }
3017: }
3018: if (ref($settings->{'helpform'}) eq 'HASH') {
3019: if (ref($fields) eq 'ARRAY') {
3020: foreach my $field (@{$fields}) {
3021: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3022: }
1.286 raeburn 3023: }
3024: if (exists($settings->{'helpform'}{'maxsize'})) {
3025: $maxsize = $settings->{'helpform'}{'maxsize'};
3026: } else {
3027: $maxsize = '1.0';
3028: }
3029: } else {
3030: if (ref($fields) eq 'ARRAY') {
3031: foreach my $field (@{$fields}) {
3032: $currfield{$field} = 'yes';
1.134 raeburn 3033: }
1.28 raeburn 3034: }
1.286 raeburn 3035: $maxsize = '1.0';
1.28 raeburn 3036: }
3037: }
3038: } else {
1.286 raeburn 3039: if ($position eq 'top') {
3040: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3041: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3042: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3043: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
3044: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3045: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3046: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3047: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3048: } elsif ($position eq 'bottom') {
3049: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3050: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3051: if (ref($fields) eq 'ARRAY') {
3052: foreach my $field (@{$fields}) {
3053: $currfield{$field} = 'yes';
3054: }
3055: }
3056: $maxsize = '1.0';
3057: }
1.28 raeburn 3058: }
3059: my ($titles,$short_titles) = &contact_titles();
3060: my $rownum = 0;
3061: my $css_class;
1.286 raeburn 3062: if ($position eq 'top') {
3063: foreach my $item (@contacts) {
3064: $css_class = $rownum%2?' class="LC_odd_row"':'';
3065: $datatable .= '<tr'.$css_class.'>'.
3066: '<td><span class="LC_nobreak">'.$titles->{$item}.
3067: '</span></td><td class="LC_right_item">'.
3068: '<input type="text" name="'.$item.'" value="'.
3069: $to{$item}.'" /></td></tr>';
3070: $rownum ++;
3071: }
3072: } else {
3073: foreach my $type (@mailings) {
3074: $css_class = $rownum%2?' class="LC_odd_row"':'';
3075: $datatable .= '<tr'.$css_class.'>'.
3076: '<td><span class="LC_nobreak">'.
3077: $titles->{$type}.': </span></td>'.
3078: '<td class="LC_left_item">';
3079: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3080: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3081: }
3082: $datatable .= '<span class="LC_nobreak">';
3083: foreach my $item (@contacts) {
3084: $datatable .= '<label>'.
3085: '<input type="checkbox" name="'.$type.'"'.
3086: $checked{$type}{$item}.
3087: ' value="'.$item.'" />'.$short_titles->{$item}.
3088: '</label> ';
3089: }
3090: $datatable .= '</span><br />'.&mt('Others').': '.
3091: '<input type="text" name="'.$type.'_others" '.
3092: 'value="'.$otheremails{$type}.'" />';
3093: my %locchecked;
3094: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3095: foreach my $loc ('s','b') {
3096: if ($includeloc{$type} eq $loc) {
3097: $locchecked{$loc} = ' checked="checked"';
3098: last;
3099: }
3100: }
3101: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3102: '<input type="text" name="'.$type.'_bcc" '.
3103: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3104: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3105: &mt('Text automatically added to e-mail:').' '.
3106: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
3107: '<span class="LC_nobreak">'.&mt('Location:').' '.
3108: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3109: (' 'x2).
3110: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3111: '</span></fieldset>';
3112: }
3113: $datatable .= '</td></tr>'."\n";
3114: $rownum ++;
3115: }
1.28 raeburn 3116: }
1.286 raeburn 3117: if ($position eq 'middle') {
3118: my %choices;
3119: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
3120: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3121: &mt('LON-CAPA core group - MSU'),600,500));
3122: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3123: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3124: &mt('LON-CAPA core group - MSU'),600,500));
3125: my @toggles = ('reporterrors','reportupdates');
3126: my %defaultchecked = ('reporterrors' => 'on',
3127: 'reportupdates' => 'on');
3128: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3129: \%choices,$rownum);
3130: $datatable .= $reports;
3131: } elsif ($position eq 'bottom') {
1.69 raeburn 3132: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 3133: $datatable .= '<tr'.$css_class.'>'.
1.286 raeburn 3134: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3135: &mt('(e-mail, subject, and description always shown)').
3136: '</td><td class="LC_left_item">';
3137: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3138: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3139: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3140: foreach my $field (@{$fields}) {
3141: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3142: if (($field eq 'screenshot') || ($field eq 'cc')) {
3143: $datatable .= ' '.&mt('(logged-in users)');
3144: }
3145: $datatable .='</td><td>';
3146: my $clickaction;
3147: if ($field eq 'screenshot') {
3148: $clickaction = ' onclick="screenshotSize(this);"';
3149: }
3150: if (ref($possoptions->{$field}) eq 'ARRAY') {
3151: foreach my $option (@{$possoptions->{$field}}) {
3152: my $checked;
3153: if ($currfield{$field} eq $option) {
3154: $checked = ' checked="checked"';
3155: }
3156: $datatable .= '<span class="LC_nobreak"><label>'.
3157: '<input type="radio" name="helpform_'.$field.'" '.
3158: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3159: '</label></span>'.(' 'x2);
3160: }
3161: }
3162: if ($field eq 'screenshot') {
3163: my $display;
3164: if ($currfield{$field} eq 'no') {
3165: $display = ' style="display:none"';
3166: }
3167: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
3168: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3169: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3170: }
3171: $datatable .= '</td></tr>';
3172: }
3173: $datatable .= '</table>';
1.134 raeburn 3174: }
3175: $datatable .= '</td></tr>'."\n";
1.203 raeburn 3176: $rownum ++;
1.28 raeburn 3177: }
1.30 raeburn 3178: $$rowtotal += $rownum;
1.28 raeburn 3179: return $datatable;
3180: }
3181:
1.286 raeburn 3182: sub contacts_javascript {
3183: return <<"ENDSCRIPT";
3184:
3185: <script type="text/javascript">
3186: // <![CDATA[
3187:
3188: function screenshotSize(field) {
3189: if (document.getElementById('help_screenshotsize')) {
3190: if (field.value == 'no') {
3191: document.getElementById('help_screenshotsize').style.display="none";
3192: } else {
3193: document.getElementById('help_screenshotsize').style.display="";
3194: }
3195: }
3196: return;
3197: }
3198:
3199: // ]]>
3200: </script>
3201:
3202: ENDSCRIPT
3203: }
3204:
1.118 jms 3205: sub print_helpsettings {
1.282 raeburn 3206: my ($position,$dom,$settings,$rowtotal) = @_;
3207: my $confname = $dom.'-domainconfig';
1.285 raeburn 3208: my $formname = 'display';
1.168 raeburn 3209: my ($datatable,$itemcount);
1.282 raeburn 3210: if ($position eq 'top') {
3211: $itemcount = 1;
3212: my (%choices,%defaultchecked,@toggles);
3213: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3214: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3215: &mt('LON-CAPA bug tracker'),600,500));
3216: %defaultchecked = ('submitbugs' => 'on');
3217: @toggles = ('submitbugs');
3218: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3219: \%choices,$itemcount);
3220: $$rowtotal ++;
3221: } else {
3222: my $css_class;
3223: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3224: my (%customroles,%ordered,%current);
3225: if (ref($settings->{'adhoc'}) eq 'HASH') {
3226: %current = %{$settings->{'adhoc'}};
3227: }
3228: my $count = 0;
3229: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3230: if ($key=~/^rolesdef\_(\w+)$/) {
3231: my $rolename = $1;
1.285 raeburn 3232: my (%privs,$order);
1.282 raeburn 3233: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3234: $customroles{$rolename} = \%privs;
1.285 raeburn 3235: if (ref($current{$rolename}) eq 'HASH') {
3236: $order = $current{$rolename}{'order'};
3237: }
3238: if ($order eq '') {
3239: $order = $count;
3240: }
3241: $ordered{$order} = $rolename;
3242: $count++;
3243: }
3244: }
3245: my $maxnum = scalar(keys(%ordered));
3246: my @roles_by_num = ();
3247: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3248: push(@roles_by_num,$item);
3249: }
3250: my $context = 'domprefs';
3251: my $crstype = 'Course';
3252: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3253: my @accesstypes = ('all','none');
3254: my ($numstatustypes,@jsarray);
3255: if (ref($types) eq 'ARRAY') {
3256: if (@{$types} > 0) {
3257: $numstatustypes = scalar(@{$types});
3258: push(@accesstypes,'status');
3259: @jsarray = ('bystatus');
1.282 raeburn 3260: }
3261: }
1.285 raeburn 3262: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh']);
3263: if (keys(%domhelpdesk)) {
3264: push(@accesstypes,('inc','exc'));
3265: push(@jsarray,('notinc','notexc'));
3266: }
3267: my $hiddenstr = join("','",@jsarray);
3268: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.282 raeburn 3269: my $context = 'domprefs';
3270: my $crstype = 'Course';
1.285 raeburn 3271: my $prefix = 'helproles_';
3272: my $add_class = 'LC_hidden';
3273: foreach my $num (@roles_by_num) {
3274: my $role = $ordered{$num};
3275: my ($desc,$access,@statuses);
3276: if (ref($current{$role}) eq 'HASH') {
3277: $desc = $current{$role}{'desc'};
3278: $access = $current{$role}{'access'};
3279: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3280: @statuses = @{$current{$role}{'insttypes'}};
3281: }
3282: }
3283: if ($desc eq '') {
3284: $desc = $role;
3285: }
3286: my $identifier = 'custhelp'.$num;
1.282 raeburn 3287: my %full=();
3288: my %levels= (
3289: course => {},
3290: domain => {},
3291: system => {},
3292: );
3293: my %levelscurrent=(
3294: course => {},
3295: domain => {},
3296: system => {},
3297: );
3298: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3299: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3300: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 3301: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3302: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3303: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3304: for (my $k=0; $k<=$maxnum; $k++) {
3305: my $vpos = $k+1;
3306: my $selstr;
3307: if ($k == $num) {
3308: $selstr = ' selected="selected" ';
3309: }
3310: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3311: }
3312: $datatable .= '</select>'.(' 'x2).
3313: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3314: '</td>'.
3315: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3316: &mt('Name shown to users:').
3317: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3318: '</fieldset>'.
3319: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3320: $othertitle,$usertypes,$types,\%domhelpdesk).
3321: '<fieldset>'.
3322: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 3323: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 3324: \%levelscurrent,$identifier,
3325: 'LC_hidden',$prefix.$num.'_privs').
3326: '</fieldset></td>';
1.282 raeburn 3327: $itemcount ++;
3328: }
3329: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3330: my $newcust = 'custhelp'.$count;
3331: my (%privs,%levelscurrent);
3332: my %full=();
3333: my %levels= (
3334: course => {},
3335: domain => {},
3336: system => {},
3337: );
3338: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3339: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 3340: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3341: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3342: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3343: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3344: for (my $k=0; $k<$maxnum+1; $k++) {
3345: my $vpos = $k+1;
3346: my $selstr;
3347: if ($k == $maxnum) {
3348: $selstr = ' selected="selected" ';
3349: }
3350: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3351: }
3352: $datatable .= '</select> '."\n".
1.282 raeburn 3353: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3354: '</label></span></td>'.
1.285 raeburn 3355: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3356: '<span class="LC_nobreak">'.
3357: &mt('Internal name:').
3358: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3359: '</span>'.(' 'x4).
3360: '<span class="LC_nobreak">'.
3361: &mt('Name shown to users:').
3362: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3363: '</span></fieldset>'.
3364: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3365: $usertypes,$types,\%domhelpdesk).
3366: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 3367: &Apache::lonuserutils::custom_role_header($context,$crstype,
3368: \@templateroles,$newcust).
3369: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3370: \%levelscurrent,$newcust).
1.285 raeburn 3371: '</fieldset></td></tr>';
1.282 raeburn 3372: $count ++;
3373: $$rowtotal += $count;
3374: }
1.166 raeburn 3375: return $datatable;
1.121 raeburn 3376: }
3377:
1.285 raeburn 3378: sub adhocbutton {
3379: my ($prefix,$num,$field,$visibility) = @_;
3380: my %lt = &Apache::lonlocal::texthash(
3381: show => 'Show details',
3382: hide => 'Hide details',
3383: );
3384: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3385: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3386: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3387: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3388: }
3389:
3390: sub helpsettings_javascript {
3391: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3392: return unless(ref($roles_by_num) eq 'ARRAY');
3393: my %html_js_lt = &Apache::lonlocal::texthash(
3394: show => 'Show details',
3395: hide => 'Hide details',
3396: );
3397: &html_escape(\%html_js_lt);
3398: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3399: return <<"ENDSCRIPT";
3400: <script type="text/javascript">
3401: // <![CDATA[
3402:
3403: function reorderHelpRoles(form,item) {
3404: var changedVal;
3405: $jstext
3406: var newpos = 'helproles_${total}_pos';
3407: var maxh = 1 + $total;
3408: var current = new Array();
3409: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3410: if (item == newpos) {
3411: changedVal = newitemVal;
3412: } else {
3413: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3414: current[newitemVal] = newpos;
3415: }
3416: for (var i=0; i<helproles.length; i++) {
3417: var elementName = 'helproles_'+helproles[i]+'_pos';
3418: if (elementName != item) {
3419: if (form.elements[elementName]) {
3420: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3421: current[currVal] = elementName;
3422: }
3423: }
3424: }
3425: var oldVal;
3426: for (var j=0; j<maxh; j++) {
3427: if (current[j] == undefined) {
3428: oldVal = j;
3429: }
3430: }
3431: if (oldVal < changedVal) {
3432: for (var k=oldVal+1; k<=changedVal ; k++) {
3433: var elementName = current[k];
3434: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3435: }
3436: } else {
3437: for (var k=changedVal; k<oldVal; k++) {
3438: var elementName = current[k];
3439: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3440: }
3441: }
3442: return;
3443: }
3444:
3445: function helpdeskAccess(num) {
3446: var curraccess = null;
3447: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3448: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3449: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3450: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3451: }
3452: }
3453: }
3454: var shown = Array();
3455: var hidden = Array();
3456: if (curraccess == 'none') {
3457: hidden = Array('$hiddenstr');
3458: } else {
3459: if (curraccess == 'status') {
3460: shown = Array('bystatus');
3461: hidden = Array('notinc','notexc');
3462: } else {
3463: if (curraccess == 'exc') {
3464: shown = Array('notexc');
3465: hidden = Array('notinc','bystatus');
3466: }
3467: if (curraccess == 'inc') {
3468: shown = Array('notinc');
3469: hidden = Array('notexc','bystatus');
3470: }
3471: if (curraccess == 'all') {
3472: hidden = Array('notinc','notexc','bystatus');
3473: }
3474: }
3475: }
3476: if (hidden.length > 0) {
3477: for (var i=0; i<hidden.length; i++) {
3478: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3479: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3480: }
3481: }
3482: }
3483: if (shown.length > 0) {
3484: for (var i=0; i<shown.length; i++) {
3485: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3486: if (shown[i] == 'privs') {
3487: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3488: } else {
3489: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3490: }
3491: }
3492: }
3493: }
3494: return;
3495: }
3496:
3497: function toggleHelpdeskItem(num,field) {
3498: if (document.getElementById('helproles_'+num+'_'+field)) {
3499: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3500: document.getElementById('helproles_'+num+'_'+field).className =
3501: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3502: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3503: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3504: }
3505: } else {
3506: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3507: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3508: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3509: }
3510: }
3511: }
3512: return;
3513: }
3514:
3515: // ]]>
3516: </script>
3517:
3518: ENDSCRIPT
3519: }
3520:
3521: sub helpdeskroles_access {
3522: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3523: $usertypes,$types,$domhelpdesk) = @_;
3524: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3525: my %lt = &Apache::lonlocal::texthash(
3526: 'rou' => 'Role usage',
3527: 'whi' => 'Which helpdesk personnel may use this role?',
3528: 'all' => 'All',
3529: 'none' => 'None',
3530: 'status' => 'Determined based on institutional status',
3531: 'inc' => 'Include all, but exclude specific personnel',
3532: 'exc' => 'Exclude all, but include specific personnel',
3533: );
3534: my %usecheck = (
3535: all => ' checked="checked"',
3536: );
3537: my %displaydiv = (
3538: status => 'none',
3539: inc => 'none',
3540: exc => 'none',
3541: priv => 'block',
3542: );
3543: my $output;
3544: if (ref($current) eq 'HASH') {
3545: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3546: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3547: $usecheck{$current->{access}} = $usecheck{'all'};
3548: delete($usecheck{'all'});
3549: if ($current->{access} =~ /^(status|inc|exc)$/) {
3550: my $access = $1;
3551: $displaydiv{$access} = 'inline';
3552: } elsif ($current->{access} eq 'none') {
3553: $displaydiv{'priv'} = 'none';
3554: }
3555: }
3556: }
3557: }
3558: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3559: '<p>'.$lt{'whi'}.'</p>';
3560: foreach my $access (@{$accesstypes}) {
3561: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3562: ' onclick="helpdeskAccess('."'$num'".');" />'.
3563: $lt{$access}.'</label>';
3564: if ($access eq 'status') {
3565: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3566: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3567: $othertitle,$usertypes,$types).
3568: '</div>';
3569: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3570: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3571: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3572: '</div>';
3573: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3574: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3575: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3576: '</div>';
3577: }
3578: $output .= '</p>';
3579: }
3580: $output .= '</fieldset>';
3581: return $output;
3582: }
3583:
1.121 raeburn 3584: sub radiobutton_prefs {
1.192 raeburn 3585: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 3586: $additional,$align) = @_;
1.121 raeburn 3587: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3588: (ref($choices) eq 'HASH'));
3589:
1.170 raeburn 3590: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 3591:
3592: foreach my $item (@{$toggles}) {
3593: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3594: $checkedon{$item} = ' checked="checked" ';
3595: $checkedoff{$item} = ' ';
1.121 raeburn 3596: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3597: $checkedoff{$item} = ' checked="checked" ';
3598: $checkedon{$item} = ' ';
3599: }
3600: }
3601: if (ref($settings) eq 'HASH') {
1.121 raeburn 3602: foreach my $item (@{$toggles}) {
1.118 jms 3603: if ($settings->{$item} eq '1') {
3604: $checkedon{$item} = ' checked="checked" ';
3605: $checkedoff{$item} = ' ';
3606: } elsif ($settings->{$item} eq '0') {
3607: $checkedoff{$item} = ' checked="checked" ';
3608: $checkedon{$item} = ' ';
3609: }
3610: }
1.121 raeburn 3611: }
1.192 raeburn 3612: if ($onclick) {
3613: $onclick = ' onclick="'.$onclick.'"';
3614: }
1.121 raeburn 3615: foreach my $item (@{$toggles}) {
1.118 jms 3616: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3617: $datatable .=
1.192 raeburn 3618: '<tr'.$css_class.'><td valign="top">'.
3619: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 3620: '</span></td>';
3621: if ($align eq 'left') {
3622: $datatable .= '<td class="LC_left_item">';
3623: } else {
3624: $datatable .= '<td class="LC_right_item">';
3625: }
3626: $datatable .=
3627: '<span class="LC_nobreak">'.
1.118 jms 3628: '<label><input type="radio" name="'.
1.192 raeburn 3629: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3630: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 3631: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3632: '</span>'.$additional.
3633: '</td>'.
1.118 jms 3634: '</tr>';
3635: $itemcount ++;
1.121 raeburn 3636: }
3637: return ($datatable,$itemcount);
3638: }
3639:
1.267 raeburn 3640: sub print_ltitools {
3641: my ($dom,$settings,$rowtotal) = @_;
3642: my $rownum = 0;
3643: my $css_class;
3644: my $itemcount = 1;
3645: my $maxnum = 0;
3646: my %ordered;
3647: if (ref($settings) eq 'HASH') {
3648: foreach my $item (keys(%{$settings})) {
3649: if (ref($settings->{$item}) eq 'HASH') {
3650: my $num = $settings->{$item}{'order'};
3651: $ordered{$num} = $item;
3652: }
3653: }
3654: }
3655: my $confname = $dom.'-domainconfig';
3656: my $switchserver = &check_switchserver($dom,$confname);
3657: my $maxnum = scalar(keys(%ordered));
3658: my $datatable = <itools_javascript($settings);
3659: my %lt = <itools_names();
3660: my @courseroles = ('cc','in','ta','ep','st');
3661: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3662: my @fields = ('fullname','firstname','lastname','email','user','roles');
3663: if (keys(%ordered)) {
3664: my @items = sort { $a <=> $b } keys(%ordered);
3665: for (my $i=0; $i<@items; $i++) {
3666: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3667: my $item = $ordered{$items[$i]};
3668: my ($title,$key,$secret,$url,$imgsrc,$version);
3669: if (ref($settings->{$item}) eq 'HASH') {
3670: $title = $settings->{$item}->{'title'};
3671: $url = $settings->{$item}->{'url'};
3672: $key = $settings->{$item}->{'key'};
3673: $secret = $settings->{$item}->{'secret'};
3674: my $image = $settings->{$item}->{'image'};
3675: if ($image ne '') {
3676: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3677: }
3678: }
3679: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3680: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3681: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3682: for (my $k=0; $k<=$maxnum; $k++) {
3683: my $vpos = $k+1;
3684: my $selstr;
3685: if ($k == $i) {
3686: $selstr = ' selected="selected" ';
3687: }
3688: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3689: }
3690: $datatable .= '</select>'.(' 'x2).
3691: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3692: &mt('Delete?').'</label></span></td>'.
3693: '<td colspan="2">'.
3694: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3695: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3696: (' 'x2).
3697: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3698: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3699: (' 'x2).
3700: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3701: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3702: '<br /><br />'.
3703: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3704: ' value="'.$url.'" /></span>'.
3705: (' 'x2).
3706: '<span class="LC_nobreak">'.$lt{'key'}.
3707: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3708: (' 'x2).
3709: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3710: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3711: '<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>'.
3712: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3713: '</fieldset>'.
3714: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3715: '<span class="LC_nobreak">'.&mt('Display target:');
3716: my %currdisp;
3717: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3718: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3719: $currdisp{'window'} = ' checked="checked"';
3720: } else {
3721: $currdisp{'iframe'} = ' checked="checked"';
3722: }
3723: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3724: $currdisp{'width'} = $1;
3725: }
3726: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3727: $currdisp{'height'} = $1;
3728: }
3729: } else {
3730: $currdisp{'iframe'} = ' checked="checked"';
3731: }
3732: foreach my $disp ('iframe','window') {
3733: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3734: $lt{$disp}.'</label>'.(' 'x2);
3735: }
3736: $datatable .= (' 'x4);
3737: foreach my $dimen ('width','height') {
3738: $datatable .= '<label>'.$lt{$dimen}.' '.
3739: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3740: (' 'x2);
3741: }
3742: $datatable .= '<br />';
3743: foreach my $extra ('passback','roster') {
3744: my $checkedon = '';
3745: my $checkedoff = ' checked="checked"';
3746: if ($settings->{$item}->{$extra}) {
3747: $checkedon = $checkedoff;
3748: $checkedoff = '';
3749: }
3750: $datatable .= $lt{$extra}.' '.
3751: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3752: &mt('Yes').'</label>'.(' 'x2).
3753: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3754: &mt('No').'</label>'.(' 'x4);
3755: }
3756: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3757: if ($imgsrc) {
3758: $datatable .= $imgsrc.
3759: '<label><input type="checkbox" name="ltitools_image_del"'.
3760: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3761: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3762: } else {
3763: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3764: }
3765: if ($switchserver) {
3766: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3767: } else {
3768: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3769: }
3770: $datatable .= '</span></fieldset>';
3771: my (%checkedfields,%rolemaps);
3772: if (ref($settings->{$item}) eq 'HASH') {
3773: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3774: %checkedfields = %{$settings->{$item}->{'fields'}};
3775: }
3776: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3777: %rolemaps = %{$settings->{$item}->{'roles'}};
3778: $checkedfields{'roles'} = 1;
3779: }
3780: }
3781: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3782: '<span class="LC_nobreak">';
3783: foreach my $field (@fields) {
3784: my $checked;
3785: if ($checkedfields{$field}) {
3786: $checked = ' checked="checked"';
3787: }
3788: $datatable .= '<label>'.
3789: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3790: $lt{$field}.'</label>'.(' ' x2);
3791: }
3792: $datatable .= '</span></fieldset>'.
3793: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3794: foreach my $role (@courseroles) {
3795: my ($selected,$selectnone);
3796: if (!$rolemaps{$role}) {
3797: $selectnone = ' selected="selected"';
3798: }
3799: $datatable .= '<td align="center">'.
3800: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3801: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3802: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3803: foreach my $ltirole (@ltiroles) {
3804: unless ($selectnone) {
3805: if ($rolemaps{$role} eq $ltirole) {
3806: $selected = ' selected="selected"';
3807: } else {
3808: $selected = '';
3809: }
3810: }
3811: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3812: }
3813: $datatable .= '</select></td>';
3814: }
1.273 raeburn 3815: $datatable .= '</tr></table></fieldset>';
3816: my %courseconfig;
3817: if (ref($settings->{$item}) eq 'HASH') {
3818: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3819: %courseconfig = %{$settings->{$item}->{'crsconf'}};
3820: }
3821: }
3822: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3823: foreach my $item ('label','title','target') {
3824: my $checked;
3825: if ($courseconfig{$item}) {
3826: $checked = ' checked="checked"';
3827: }
3828: $datatable .= '<label>'.
3829: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3830: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3831: }
3832: $datatable .= '</span></fieldset>'.
1.267 raeburn 3833: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3834: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3835: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3836: my %custom = %{$settings->{$item}->{'custom'}};
3837: if (keys(%custom) > 0) {
3838: foreach my $key (sort(keys(%custom))) {
3839: $datatable .= '<tr><td><span class="LC_nobreak">'.
3840: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3841: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3842: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3843: ' value="'.$custom{$key}.'" /></td></tr>';
3844: }
3845: }
3846: }
3847: $datatable .= '<tr><td><span class="LC_nobreak">'.
3848: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3849: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3850: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3851: $datatable .= '</table></fieldset></td></tr>'."\n";
3852: $itemcount ++;
3853: }
3854: }
3855: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3856: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3857: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3858: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3859: '<select name="ltitools_add_pos"'.$chgstr.'>';
3860: for (my $k=0; $k<$maxnum+1; $k++) {
3861: my $vpos = $k+1;
3862: my $selstr;
3863: if ($k == $maxnum) {
3864: $selstr = ' selected="selected" ';
3865: }
3866: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3867: }
3868: $datatable .= '</select> '."\n".
3869: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3870: '<td colspan="2">'.
3871: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3872: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3873: (' 'x2).
3874: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3875: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3876: (' 'x2).
3877: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3878: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3879: '<br />'.
3880: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3881: (' 'x2).
3882: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3883: (' 'x2).
3884: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3885: '<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".
3886: '</fieldset>'.
3887: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3888: '<span class="LC_nobreak">'.&mt('Display target:');
3889: my %defaultdisp;
3890: $defaultdisp{'iframe'} = ' checked="checked"';
3891: foreach my $disp ('iframe','window') {
3892: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3893: $lt{$disp}.'</label>'.(' 'x2);
3894: }
3895: $datatable .= (' 'x4);
3896: foreach my $dimen ('width','height') {
3897: $datatable .= '<label>'.$lt{$dimen}.' '.
3898: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3899: (' 'x2);
3900: }
3901: $datatable .= '<br />';
3902: foreach my $extra ('passback','roster') {
3903: $datatable .= $lt{$extra}.' '.
3904: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
3905: &mt('Yes').'</label>'.(' 'x2).
3906: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
3907: &mt('No').'</label>'.(' 'x4);
3908: }
3909: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
3910: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3911: if ($switchserver) {
3912: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3913: } else {
3914: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3915: }
3916: $datatable .= '</span></fieldset>'.
3917: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3918: '<span class="LC_nobreak">';
3919: foreach my $field (@fields) {
3920: $datatable .= '<label>'.
3921: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
3922: $lt{$field}.'</label>'.(' ' x2);
3923: }
3924: $datatable .= '</span></fieldset>'.
3925: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3926: foreach my $role (@courseroles) {
3927: my ($checked,$checkednone);
3928: $datatable .= '<td align="center">'.
3929: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3930: '<select name="ltitools_add_roles_'.$role.'">'.
3931: '<option value="" selected="selected">'.&mt('Select').'</option>';
3932: foreach my $ltirole (@ltiroles) {
3933: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
3934: }
3935: $datatable .= '</select></td>';
3936: }
3937: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 3938: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3939: foreach my $item ('label','title','target') {
3940: $datatable .= '<label>'.
3941: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
3942: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3943: }
3944: $datatable .= '</span></fieldset>'.
1.267 raeburn 3945: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3946: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
3947: '<tr><td><span class="LC_nobreak">'.
3948: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
3949: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
3950: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
3951: '</table></fieldset></td></tr>'."\n".
3952: '</td>'."\n".
3953: '</tr>'."\n";
3954: $itemcount ++;
3955: return $datatable;
3956: }
3957:
3958: sub ltitools_names {
3959: my %lt = &Apache::lonlocal::texthash(
3960: 'title' => 'Title',
3961: 'version' => 'Version',
3962: 'msgtype' => 'Message Type',
3963: 'url' => 'URL',
3964: 'key' => 'Key',
3965: 'secret' => 'Secret',
3966: 'icon' => 'Icon',
3967: 'user' => 'Username:domain',
3968: 'fullname' => 'Full Name',
3969: 'firstname' => 'First Name',
3970: 'lastname' => 'Last Name',
3971: 'email' => 'E-mail',
3972: 'roles' => 'Role',
3973: 'window' => 'Window/Tab',
3974: 'iframe' => 'iFrame',
3975: 'height' => 'Height',
3976: 'width' => 'Width',
3977: 'passback' => 'Tool can return grades:',
3978: 'roster' => 'Tool can retrieve roster:',
1.273 raeburn 3979: 'crstarget' => 'Display target',
3980: 'crslabel' => 'Course label',
3981: 'crstitle' => 'Course title',
1.267 raeburn 3982: );
3983: return %lt;
3984: }
3985:
1.121 raeburn 3986: sub print_coursedefaults {
1.139 raeburn 3987: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 3988: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3989: my $itemcount = 1;
1.192 raeburn 3990: my %choices = &Apache::lonlocal::texthash (
3991: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 3992: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 3993: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3994: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 3995: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3996: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
3997: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 3998: canclone => "People who may clone a course (besides course's owner and coordinators)",
3999: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 4000: );
1.198 raeburn 4001: my %staticdefaults = (
4002: anonsurvey_threshold => 10,
4003: uploadquota => 500,
1.257 raeburn 4004: postsubmit => 60,
1.276 raeburn 4005: mysqltables => 172800,
1.198 raeburn 4006: );
1.139 raeburn 4007: if ($position eq 'top') {
1.257 raeburn 4008: %defaultchecked = (
4009: 'canuse_pdfforms' => 'off',
4010: 'uselcmath' => 'on',
4011: 'usejsme' => 'on',
1.264 raeburn 4012: 'canclone' => 'none',
1.257 raeburn 4013: );
4014: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139 raeburn 4015: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 4016: \%choices,$itemcount);
1.264 raeburn 4017: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4018: $datatable .=
4019: '<tr'.$css_class.'><td valign="top">'.
4020: '<span class="LC_nobreak">'.$choices{'canclone'}.
4021: '</span></td><td class="LC_left_item">';
4022: my $currcanclone = 'none';
4023: my $onclick;
4024: my @cloneoptions = ('none','domain');
4025: my %clonetitles = (
4026: none => 'No additional course requesters',
4027: domain => "Any course requester in course's domain",
4028: instcode => 'Course requests for official courses ...',
4029: );
4030: my (%codedefaults,@code_order,@posscodes);
4031: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4032: \@code_order) eq 'ok') {
4033: if (@code_order > 0) {
4034: push(@cloneoptions,'instcode');
4035: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4036: }
4037: }
4038: if (ref($settings) eq 'HASH') {
4039: if ($settings->{'canclone'}) {
4040: if (ref($settings->{'canclone'}) eq 'HASH') {
4041: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4042: if (@code_order > 0) {
4043: $currcanclone = 'instcode';
4044: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4045: }
4046: }
4047: } elsif ($settings->{'canclone'} eq 'domain') {
4048: $currcanclone = $settings->{'canclone'};
4049: }
4050: }
4051: }
4052: foreach my $option (@cloneoptions) {
4053: my ($checked,$additional);
4054: if ($currcanclone eq $option) {
4055: $checked = ' checked="checked"';
4056: }
4057: if ($option eq 'instcode') {
4058: if (@code_order) {
4059: my $show = 'none';
4060: if ($checked) {
4061: $show = 'block';
4062: }
4063: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4064: &mt('Institutional codes for new and cloned course have identical:').
4065: '<br />';
4066: foreach my $item (@code_order) {
4067: my $codechk;
4068: if ($checked) {
4069: if (grep(/^\Q$item\E$/,@posscodes)) {
4070: $codechk = ' checked="checked"';
4071: }
4072: }
4073: $additional .= '<label>'.
4074: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4075: $item.'</label>';
4076: }
4077: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4078: }
4079: }
4080: $datatable .=
4081: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4082: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4083: '</label> '.$additional.'</span><br />';
4084: }
4085: $datatable .= '</td>'.
4086: '</tr>';
4087: $itemcount ++;
1.139 raeburn 4088: } else {
4089: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 4090: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 4091: my $currusecredits = 0;
1.257 raeburn 4092: my $postsubmitclient = 1;
1.271 raeburn 4093: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 4094: if (ref($settings) eq 'HASH') {
4095: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 4096: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4097: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4098: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4099: }
4100: }
1.192 raeburn 4101: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 4102: foreach my $type (@types) {
4103: next if ($type eq 'community');
4104: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4105: if ($defcredits{$type} ne '') {
4106: $currusecredits = 1;
4107: }
4108: }
4109: }
4110: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4111: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4112: $postsubmitclient = 0;
4113: foreach my $type (@types) {
4114: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4115: }
4116: } else {
4117: foreach my $type (@types) {
4118: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4119: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
4120: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
4121: } else {
4122: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4123: }
4124: } else {
4125: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4126: }
4127: }
4128: }
4129: } else {
4130: foreach my $type (@types) {
4131: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 4132: }
4133: }
1.276 raeburn 4134: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4135: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4136: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4137: }
4138: } else {
4139: foreach my $type (@types) {
4140: $currmysql{$type} = $staticdefaults{'mysqltables'};
4141: }
4142: }
1.258 raeburn 4143: } else {
4144: foreach my $type (@types) {
4145: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4146: }
1.139 raeburn 4147: }
4148: if (!$currdefresponder) {
1.198 raeburn 4149: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4150: } elsif ($currdefresponder < 1) {
4151: $currdefresponder = 1;
4152: }
1.198 raeburn 4153: foreach my $type (@types) {
4154: if ($curruploadquota{$type} eq '') {
4155: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4156: }
4157: }
1.139 raeburn 4158: $datatable .=
1.192 raeburn 4159: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4160: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4161: '</span></td>'.
4162: '<td class="LC_right_item"><span class="LC_nobreak">'.
4163: '<input type="text" name="anonsurvey_threshold"'.
4164: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 4165: '</td></tr>'."\n";
4166: $itemcount ++;
4167: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4168: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4169: $choices{'uploadquota'}.
4170: '</span></td>'.
4171: '<td align="right" class="LC_right_item">'.
4172: '<table><tr>';
1.198 raeburn 4173: foreach my $type (@types) {
4174: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4175: '<input type="text" name="uploadquota_'.$type.'"'.
4176: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4177: }
4178: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 4179: $itemcount ++;
1.236 raeburn 4180: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 4181: my $display = 'none';
1.192 raeburn 4182: if ($currusecredits) {
4183: $display = 'block';
4184: }
4185: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 4186: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4187: foreach my $type (@types) {
4188: next if ($type eq 'community');
4189: $additional .= '<td align="center">'.&mt($type).'<br />'.
4190: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 4191: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 4192: }
4193: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 4194: %defaultchecked = ('coursecredits' => 'off');
4195: @toggles = ('coursecredits');
4196: my $current = {
4197: 'coursecredits' => $currusecredits,
4198: };
4199: (my $table,$itemcount) =
4200: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 4201: \%choices,$itemcount,$onclick,$additional,'left');
4202: $datatable .= $table;
4203: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4204: my $display = 'none';
4205: if ($postsubmitclient) {
4206: $display = 'block';
4207: }
4208: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 4209: &mt('Number of seconds submit is disabled').'<br />'.
4210: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4211: '<table><tr>';
1.257 raeburn 4212: foreach my $type (@types) {
4213: $additional .= '<td align="center">'.&mt($type).'<br />'.
4214: '<input type="text" name="'.$type.'_timeout" value="'.
4215: $deftimeout{$type}.'" size="5" /></td>';
4216: }
4217: $additional .= '</tr></table></div>'."\n";
4218: %defaultchecked = ('postsubmit' => 'on');
4219: @toggles = ('postsubmit');
1.280 raeburn 4220: $current = {
4221: 'postsubmit' => $postsubmitclient,
4222: };
1.257 raeburn 4223: ($table,$itemcount) =
4224: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4225: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 4226: $datatable .= $table;
1.276 raeburn 4227: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4228: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4229: $choices{'mysqltables'}.
4230: '</span></td>'.
4231: '<td align="right" class="LC_right_item">'.
4232: '<table><tr>';
4233: foreach my $type (@types) {
4234: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4235: '<input type="text" name="mysqltables_'.$type.'"'.
4236: ' value="'.$currmysql{$type}.'" size="5" /></td>';
4237: }
4238: $datatable .= '</tr></table></td></tr>'."\n";
4239: $itemcount ++;
4240:
1.139 raeburn 4241: }
1.192 raeburn 4242: $$rowtotal += $itemcount;
1.121 raeburn 4243: return $datatable;
1.118 jms 4244: }
4245:
1.231 raeburn 4246: sub print_selfenrollment {
4247: my ($position,$dom,$settings,$rowtotal) = @_;
4248: my ($css_class,$datatable);
4249: my $itemcount = 1;
1.271 raeburn 4250: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 4251: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 4252: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4253: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 4254: my @rows;
4255: my $key;
4256: if ($position eq 'top') {
4257: $key = 'admin';
4258: if (ref($rowsref) eq 'ARRAY') {
4259: @rows = @{$rowsref};
4260: }
4261: } elsif ($position eq 'middle') {
4262: $key = 'default';
4263: @rows = ('types','registered','approval','limit');
4264: }
4265: foreach my $row (@rows) {
4266: if (defined($titlesref->{$row})) {
4267: $itemcount ++;
4268: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4269: $datatable .= '<tr'.$css_class.'>'.
4270: '<td>'.$titlesref->{$row}.'</td>'.
4271: '<td class="LC_left_item">'.
4272: '<table><tr>';
4273: my (%current,%currentcap);
4274: if (ref($settings) eq 'HASH') {
4275: if (ref($settings->{$key}) eq 'HASH') {
4276: foreach my $type (@types) {
4277: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4278: $current{$type} = $settings->{$key}->{$type}->{$row};
4279: }
4280: if (($row eq 'limit') && ($key eq 'default')) {
4281: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4282: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4283: }
4284: }
4285: }
4286: }
4287: }
4288: my %roles = (
4289: '0' => &Apache::lonnet::plaintext('dc'),
4290: );
4291:
4292: foreach my $type (@types) {
4293: unless (($row eq 'registered') && ($key eq 'default')) {
4294: $datatable .= '<th>'.&mt($type).'</th>';
4295: }
4296: }
4297: unless (($row eq 'registered') && ($key eq 'default')) {
4298: $datatable .= '</tr><tr>';
4299: }
4300: foreach my $type (@types) {
4301: if ($type eq 'community') {
4302: $roles{'1'} = &mt('Community personnel');
4303: } else {
4304: $roles{'1'} = &mt('Course personnel');
4305: }
4306: $datatable .= '<td style="vertical-align: top">';
4307: if ($position eq 'top') {
4308: my %checked;
4309: if ($current{$type} eq '0') {
4310: $checked{'0'} = ' checked="checked"';
4311: } else {
4312: $checked{'1'} = ' checked="checked"';
4313: }
4314: foreach my $role ('1','0') {
4315: $datatable .= '<span class="LC_nobreak"><label>'.
4316: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4317: 'value="'.$role.'"'.$checked{$role}.' />'.
4318: $roles{$role}.'</label></span> ';
4319: }
4320: } else {
4321: if ($row eq 'types') {
4322: my %checked;
4323: if ($current{$type} =~ /^(all|dom)$/) {
4324: $checked{$1} = ' checked="checked"';
4325: } else {
4326: $checked{''} = ' checked="checked"';
4327: }
4328: foreach my $val ('','dom','all') {
4329: $datatable .= '<span class="LC_nobreak"><label>'.
4330: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4331: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4332: }
4333: } elsif ($row eq 'registered') {
4334: my %checked;
4335: if ($current{$type} eq '1') {
4336: $checked{'1'} = ' checked="checked"';
4337: } else {
4338: $checked{'0'} = ' checked="checked"';
4339: }
4340: foreach my $val ('0','1') {
4341: $datatable .= '<span class="LC_nobreak"><label>'.
4342: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4343: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4344: }
4345: } elsif ($row eq 'approval') {
4346: my %checked;
4347: if ($current{$type} =~ /^([12])$/) {
4348: $checked{$1} = ' checked="checked"';
4349: } else {
4350: $checked{'0'} = ' checked="checked"';
4351: }
4352: for my $val (0..2) {
4353: $datatable .= '<span class="LC_nobreak"><label>'.
4354: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4355: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4356: }
4357: } elsif ($row eq 'limit') {
4358: my %checked;
4359: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4360: $checked{$1} = ' checked="checked"';
4361: } else {
4362: $checked{'none'} = ' checked="checked"';
4363: }
4364: my $cap;
4365: if ($currentcap{$type} =~ /^\d+$/) {
4366: $cap = $currentcap{$type};
4367: }
4368: foreach my $val ('none','allstudents','selfenrolled') {
4369: $datatable .= '<span class="LC_nobreak"><label>'.
4370: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4371: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4372: }
4373: $datatable .= '<br />'.
4374: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4375: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4376: '</span>';
4377: }
4378: }
4379: $datatable .= '</td>';
4380: }
4381: $datatable .= '</tr>';
4382: }
4383: $datatable .= '</table></td></tr>';
4384: }
4385: } elsif ($position eq 'bottom') {
1.235 raeburn 4386: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4387: }
4388: $$rowtotal += $itemcount;
4389: return $datatable;
4390: }
4391:
4392: sub print_validation_rows {
4393: my ($caller,$dom,$settings,$rowtotal) = @_;
4394: my ($itemsref,$namesref,$fieldsref);
4395: if ($caller eq 'selfenroll') {
4396: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4397: } elsif ($caller eq 'requestcourses') {
4398: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4399: }
4400: my %currvalidation;
4401: if (ref($settings) eq 'HASH') {
4402: if (ref($settings->{'validation'}) eq 'HASH') {
4403: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 4404: }
1.235 raeburn 4405: }
4406: my $datatable;
4407: my $itemcount = 0;
4408: foreach my $item (@{$itemsref}) {
4409: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4410: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4411: $namesref->{$item}.
4412: '</span></td>'.
4413: '<td class="LC_left_item">';
4414: if (($item eq 'url') || ($item eq 'button')) {
4415: $datatable .= '<span class="LC_nobreak">'.
4416: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4417: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4418: } elsif ($item eq 'fields') {
4419: my @currfields;
4420: if (ref($currvalidation{$item}) eq 'ARRAY') {
4421: @currfields = @{$currvalidation{$item}};
4422: }
4423: foreach my $field (@{$fieldsref}) {
4424: my $check = '';
4425: if (grep(/^\Q$field\E$/,@currfields)) {
4426: $check = ' checked="checked"';
4427: }
4428: $datatable .= '<span class="LC_nobreak"><label>'.
4429: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4430: ' value="'.$field.'"'.$check.' />'.$field.
4431: '</label></span> ';
4432: }
4433: } elsif ($item eq 'markup') {
4434: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
4435: $currvalidation{$item}.
1.231 raeburn 4436: '</textarea>';
1.235 raeburn 4437: }
4438: $datatable .= '</td></tr>'."\n";
4439: if (ref($rowtotal)) {
1.231 raeburn 4440: $itemcount ++;
4441: }
4442: }
1.235 raeburn 4443: if ($caller eq 'requestcourses') {
4444: my %currhash;
1.248 raeburn 4445: if (ref($settings) eq 'HASH') {
4446: if (ref($settings->{'validation'}) eq 'HASH') {
4447: if ($settings->{'validation'}{'dc'} ne '') {
4448: $currhash{$settings->{'validation'}{'dc'}} = 1;
4449: }
1.235 raeburn 4450: }
4451: }
4452: my $numinrow = 2;
4453: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4454: 'validationdc',%currhash);
1.247 raeburn 4455: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4456: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 4457: if ($numdc > 1) {
1.247 raeburn 4458: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 4459: } else {
1.247 raeburn 4460: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 4461: }
1.247 raeburn 4462: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 4463: $itemcount ++;
4464: }
4465: if (ref($rowtotal)) {
4466: $$rowtotal += $itemcount;
4467: }
1.231 raeburn 4468: return $datatable;
4469: }
4470:
1.137 raeburn 4471: sub print_usersessions {
4472: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 4473: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 4474: my (%by_ip,%by_location,@intdoms,@instdoms);
4475: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 4476:
4477: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4478: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4479: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4480: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4481: if ($position eq 'top') {
1.152 raeburn 4482: if (keys(%serverhomes) > 1) {
1.145 raeburn 4483: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 4484: my $curroffloadnow;
4485: if (ref($settings) eq 'HASH') {
4486: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4487: $curroffloadnow = $settings->{'offloadnow'};
4488: }
4489: }
4490: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4491: } else {
1.140 raeburn 4492: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 4493: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
4494: '</td></tr>';
1.140 raeburn 4495: }
1.137 raeburn 4496: } else {
1.279 raeburn 4497: my %titles = &usersession_titles();
4498: my ($prefix,@types);
4499: if ($position eq 'bottom') {
4500: $prefix = 'remote';
4501: @types = ('version','excludedomain','includedomain');
1.145 raeburn 4502: } else {
1.279 raeburn 4503: $prefix = 'hosted';
4504: @types = ('excludedomain','includedomain');
4505: }
4506: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4507: }
4508: $$rowtotal += $itemcount;
4509: return $datatable;
4510: }
4511:
4512: sub rules_by_location {
4513: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
4514: my ($datatable,$itemcount,$css_class);
4515: if (keys(%{$by_location}) == 0) {
4516: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4517: $datatable = '<tr'.$css_class.'><td colspan="2">'.
4518: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
4519: '</td></tr>';
4520: $itemcount = 1;
4521: } else {
4522: $itemcount = 0;
4523: my $numinrow = 5;
4524: my (%current,%checkedon,%checkedoff);
4525: my @locations = sort(keys(%{$by_location}));
4526: foreach my $type (@{$types}) {
4527: $checkedon{$type} = '';
4528: $checkedoff{$type} = ' checked="checked"';
4529: }
4530: if (ref($settings) eq 'HASH') {
4531: if (ref($settings->{$prefix}) eq 'HASH') {
4532: foreach my $key (keys(%{$settings->{$prefix}})) {
4533: $current{$key} = $settings->{$prefix}{$key};
4534: if ($key eq 'version') {
4535: if ($current{$key} ne '') {
1.145 raeburn 4536: $checkedon{$key} = ' checked="checked"';
4537: $checkedoff{$key} = '';
4538: }
1.279 raeburn 4539: } elsif (ref($current{$key}) eq 'ARRAY') {
4540: $checkedon{$key} = ' checked="checked"';
4541: $checkedoff{$key} = '';
1.137 raeburn 4542: }
4543: }
4544: }
1.279 raeburn 4545: }
4546: foreach my $type (@{$types}) {
4547: next if ($type ne 'version' && !@locations);
4548: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4549: $datatable .= '<tr'.$css_class.'>
4550: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
4551: <span class="LC_nobreak">
4552: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4553: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4554: if ($type eq 'version') {
4555: my @lcversions = &Apache::lonnet::all_loncaparevs();
4556: my $selector = '<select name="'.$prefix.'_version">';
4557: foreach my $version (@lcversions) {
4558: my $selected = '';
4559: if ($current{'version'} eq $version) {
4560: $selected = ' selected="selected"';
1.145 raeburn 4561: }
1.279 raeburn 4562: $selector .= ' <option value="'.$version.'"'.
4563: $selected.'>'.$version.'</option>';
4564: }
4565: $selector .= '</select> ';
4566: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4567: } else {
4568: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4569: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4570: ' />'.(' 'x2).
4571: '<input type="button" value="'.&mt('uncheck all').'" '.
4572: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4573: "\n".
4574: '</div><div><table>';
4575: my $rem;
4576: for (my $i=0; $i<@locations; $i++) {
4577: my ($showloc,$value,$checkedtype);
4578: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
4579: my $ip = $by_location->{$locations[$i]}->[0];
4580: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4581: $value = join(':',@{$by_ip->{$ip}});
4582: $showloc = join(', ',@{$by_ip->{$ip}});
4583: if (ref($current{$type}) eq 'ARRAY') {
4584: foreach my $loc (@{$by_ip->{$ip}}) {
4585: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4586: $checkedtype = ' checked="checked"';
4587: last;
1.145 raeburn 4588: }
1.138 raeburn 4589: }
4590: }
4591: }
1.137 raeburn 4592: }
1.279 raeburn 4593: $rem = $i%($numinrow);
4594: if ($rem == 0) {
4595: if ($i > 0) {
4596: $datatable .= '</tr>';
4597: }
4598: $datatable .= '<tr>';
4599: }
4600: $datatable .= '<td class="LC_left_item">'.
4601: '<span class="LC_nobreak"><label>'.
4602: '<input type="checkbox" name="'.$prefix.'_'.$type.
4603: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4604: '</label></span></td>';
4605: }
4606: $rem = @locations%($numinrow);
4607: my $colsleft = $numinrow - $rem;
4608: if ($colsleft > 1 ) {
4609: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4610: ' </td>';
4611: } elsif ($colsleft == 1) {
4612: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4613: }
1.279 raeburn 4614: $datatable .= '</tr></table>';
1.137 raeburn 4615: }
1.279 raeburn 4616: $datatable .= '</td></tr>';
4617: $itemcount ++;
1.137 raeburn 4618: }
4619: }
1.279 raeburn 4620: return ($datatable,$itemcount);
1.137 raeburn 4621: }
4622:
1.275 raeburn 4623: sub print_ssl {
4624: my ($position,$dom,$settings,$rowtotal) = @_;
4625: my ($css_class,$datatable);
4626: my $itemcount = 1;
4627: if ($position eq 'top') {
1.281 raeburn 4628: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4629: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4630: my $same_institution;
4631: if ($intdom ne '') {
4632: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
4633: if (ref($internet_names) eq 'ARRAY') {
4634: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4635: $same_institution = 1;
4636: }
4637: }
4638: }
1.275 raeburn 4639: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 4640: $datatable = '<tr'.$css_class.'><td colspan="2">';
4641: if ($same_institution) {
4642: my %domservers = &Apache::lonnet::get_servers($dom);
4643: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
4644: } else {
4645: $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.");
4646: }
4647: $datatable .= '</td></tr>';
1.275 raeburn 4648: $itemcount ++;
4649: } else {
4650: my %titles = &ssl_titles();
4651: my (%by_ip,%by_location,@intdoms,@instdoms);
4652: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4653: my @alldoms = &Apache::lonnet::all_domains();
4654: my %serverhomes = %Apache::lonnet::serverhomeIDs;
4655: my @domservers = &Apache::lonnet::get_servers($dom);
4656: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4657: my %altids = &id_for_thisdom(%servers);
4658: if ($position eq 'middle') {
4659: foreach my $type ('dom','intdom','other') {
4660: my %checked;
4661: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4662: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
4663: '<td class="LC_right_item">';
4664: my $skip;
4665: if ($type eq 'dom') {
4666: unless (keys(%servers) > 1) {
4667: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
4668: $skip = 1;
4669: }
4670: }
4671: if ($type eq 'intdom') {
4672: unless (@instdoms > 1) {
4673: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
4674: $skip = 1;
4675: }
4676: } elsif ($type eq 'other') {
4677: if (keys(%by_location) == 0) {
4678: $datatable .= &mt('Nothing to set here, as there are no other institutions');
4679: $skip = 1;
4680: }
4681: }
4682: unless ($skip) {
4683: $checked{'yes'} = ' checked="checked"';
4684: if (ref($settings) eq 'HASH') {
4685: if (ref($settings->{'connect'}) eq 'HASH') {
4686: if ($settings->{'connect'}->{$type} =~ /^(no|req)$/) {
4687: $checked{$1} = $checked{'yes'};
4688: delete($checked{'yes'});
4689: }
4690: }
4691: }
4692: foreach my $option ('no','yes','req') {
4693: $datatable .= '<span class="LC_nobreak"><label>'.
4694: '<input type="radio" name="connect_'.$type.'" '.
4695: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
4696: '</label></span>'.(' 'x2);
4697: }
4698: }
4699: $datatable .= '</td></tr>';
4700: $itemcount ++;
4701: }
4702: } else {
4703: my $prefix = 'replication';
4704: my @types = ('certreq','nocertreq');
1.279 raeburn 4705: if (keys(%by_location) == 0) {
4706: $datatable .= '<tr'.$css_class.'><td>'.
4707: &mt('Nothing to set here, as there are no other institutions').
4708: '</td></tr>';
4709: $itemcount ++;
1.275 raeburn 4710: } else {
1.279 raeburn 4711: ($datatable,$itemcount) =
4712: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 4713: }
4714: }
4715: }
4716: $$rowtotal += $itemcount;
4717: return $datatable;
4718: }
4719:
4720: sub ssl_titles {
4721: return &Apache::lonlocal::texthash (
4722: dom => 'LON-CAPA servers/VMs from same domain',
4723: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
4724: other => 'External LON-CAPA servers/VMs',
4725: connect => 'Connections to other servers',
4726: replication => 'Replicating content to other institutions',
4727: certreq => 'Client certificate required, but specific domains exempt',
4728: nocertreq => 'No client certificate required, except for specific domains',
4729: no => 'SSL not used',
4730: yes => 'SSL Optional (used if available)',
4731: req => 'SSL Required',
4732: );
1.279 raeburn 4733: }
4734:
4735: sub print_trust {
4736: my ($prefix,$dom,$settings,$rowtotal) = @_;
4737: my ($css_class,$datatable,%checked,%choices);
4738: my (%by_ip,%by_location,@intdoms,@instdoms);
4739: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4740: my $itemcount = 1;
4741: my %titles = &trust_titles();
4742: my @types = ('exc','inc');
4743: if ($prefix eq 'top') {
4744: $prefix = 'content';
4745: } elsif ($prefix eq 'bottom') {
4746: $prefix = 'msg';
4747: }
4748: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4749: $$rowtotal += $itemcount;
4750: return $datatable;
4751: }
4752:
4753: sub trust_titles {
4754: return &Apache::lonlocal::texthash(
4755: content => "Access to this domain's content by others",
4756: shared => "Access to other domain's content by this domain",
4757: enroll => "Enrollment in this domain's courses by others",
4758: othcoau => "Co-author roles in this domain for others",
4759: coaurem => "Co-author roles for this domain's users elsewhere",
4760: domroles => "Domain roles in this domain assignable to others",
4761: catalog => "Course Catalog for this domain displayed elsewhere",
4762: reqcrs => "Requests for creation of courses in this domain by others",
4763: msg => "Users in other domains can send messages to this domain",
4764: exc => "Allow all, but exclude specific domains",
4765: inc => "Deny all, but include specific domains",
4766: );
1.275 raeburn 4767: }
4768:
1.138 raeburn 4769: sub build_location_hashes {
1.275 raeburn 4770: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 4771: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 4772: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 4773: my %iphost = &Apache::lonnet::get_iphost();
4774: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4775: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4776: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4777: foreach my $id (@{$iphost{$primary_ip}}) {
4778: my $intdom = &Apache::lonnet::internet_dom($id);
4779: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4780: push(@{$intdoms},$intdom);
4781: }
4782: }
4783: }
4784: foreach my $ip (keys(%iphost)) {
4785: if (ref($iphost{$ip}) eq 'ARRAY') {
4786: foreach my $id (@{$iphost{$ip}}) {
4787: my $location = &Apache::lonnet::internet_dom($id);
4788: if ($location) {
1.275 raeburn 4789: if (grep(/^\Q$location\E$/,@{$intdoms})) {
4790: my $dom = &Apache::lonnet::host_domain($id);
4791: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
4792: push(@{$instdoms},$dom);
4793: }
4794: next;
4795: }
1.138 raeburn 4796: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4797: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4798: push(@{$by_ip->{$ip}},$location);
4799: }
4800: } else {
4801: $by_ip->{$ip} = [$location];
4802: }
4803: }
4804: }
4805: }
4806: }
4807: foreach my $ip (sort(keys(%{$by_ip}))) {
4808: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4809: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4810: my $first = $by_ip->{$ip}->[0];
4811: if (ref($by_location->{$first}) eq 'ARRAY') {
4812: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4813: push(@{$by_location->{$first}},$ip);
4814: }
4815: } else {
4816: $by_location->{$first} = [$ip];
4817: }
4818: }
4819: }
4820: return;
4821: }
4822:
1.145 raeburn 4823: sub current_offloads_to {
4824: my ($dom,$settings,$servers) = @_;
4825: my (%spareid,%otherdomconfigs);
1.152 raeburn 4826: if (ref($servers) eq 'HASH') {
1.145 raeburn 4827: foreach my $lonhost (sort(keys(%{$servers}))) {
4828: my $gotspares;
1.152 raeburn 4829: if (ref($settings) eq 'HASH') {
4830: if (ref($settings->{'spares'}) eq 'HASH') {
4831: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4832: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4833: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4834: $gotspares = 1;
4835: }
1.145 raeburn 4836: }
4837: }
4838: unless ($gotspares) {
4839: my $gotspares;
4840: my $serverhomeID =
4841: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4842: my $serverhomedom =
4843: &Apache::lonnet::host_domain($serverhomeID);
4844: if ($serverhomedom ne $dom) {
4845: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4846: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4847: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4848: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4849: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4850: $gotspares = 1;
4851: }
4852: }
4853: } else {
4854: $otherdomconfigs{$serverhomedom} =
4855: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4856: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4857: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4858: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4859: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4860: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4861: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4862: $gotspares = 1;
4863: }
4864: }
4865: }
4866: }
4867: }
4868: }
4869: }
4870: unless ($gotspares) {
4871: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4872: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4873: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4874: } else {
4875: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4876: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4877: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4878: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4879: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4880: } else {
1.150 raeburn 4881: my %what = (
4882: spareid => 1,
4883: );
4884: my ($result,$returnhash) =
4885: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4886: if ($result eq 'ok') {
4887: if (ref($returnhash) eq 'HASH') {
4888: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4889: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4890: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4891: }
4892: }
1.145 raeburn 4893: }
4894: }
4895: }
4896: }
4897: }
4898: }
4899: return %spareid;
4900: }
4901:
4902: sub spares_row {
1.261 raeburn 4903: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4904: my $css_class;
4905: my $numinrow = 4;
4906: my $itemcount = 1;
4907: my $datatable;
1.152 raeburn 4908: my %typetitles = &sparestype_titles();
4909: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4910: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4911: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4912: my ($othercontrol,$serverdom);
4913: if ($serverhome ne $server) {
4914: $serverdom = &Apache::lonnet::host_domain($serverhome);
4915: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4916: } else {
4917: $serverdom = &Apache::lonnet::host_domain($server);
4918: if ($serverdom ne $dom) {
4919: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4920: }
4921: }
4922: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 4923: my $checkednow;
4924: if (ref($curroffloadnow) eq 'HASH') {
4925: if ($curroffloadnow->{$server}) {
4926: $checkednow = ' checked="checked"';
4927: }
4928: }
1.145 raeburn 4929: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4930: $datatable .= '<tr'.$css_class.'>
4931: <td rowspan="2">
1.183 bisitz 4932: <span class="LC_nobreak">'.
4933: &mt('[_1] when busy, offloads to:'
1.261 raeburn 4934: ,'<b>'.$server.'</b>').'</span><br />'.
4935: '<span class="LC_nobreak">'."\n".
4936: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4937: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 4938: "\n";
1.145 raeburn 4939: my (%current,%canselect);
1.152 raeburn 4940: my @choices =
4941: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4942: foreach my $type ('primary','default') {
4943: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4944: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4945: my @spares = @{$spareid->{$server}{$type}};
4946: if (@spares > 0) {
1.152 raeburn 4947: if ($othercontrol) {
4948: $current{$type} = join(', ',@spares);
4949: } else {
4950: $current{$type} .= '<table>';
4951: my $numspares = scalar(@spares);
4952: for (my $i=0; $i<@spares; $i++) {
4953: my $rem = $i%($numinrow);
4954: if ($rem == 0) {
4955: if ($i > 0) {
4956: $current{$type} .= '</tr>';
4957: }
4958: $current{$type} .= '<tr>';
1.145 raeburn 4959: }
1.152 raeburn 4960: $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'".');" /> '.
4961: $spareid->{$server}{$type}[$i].
4962: '</label></td>'."\n";
4963: }
4964: my $rem = @spares%($numinrow);
4965: my $colsleft = $numinrow - $rem;
4966: if ($colsleft > 1 ) {
4967: $current{$type} .= '<td colspan="'.$colsleft.
4968: '" class="LC_left_item">'.
4969: ' </td>';
4970: } elsif ($colsleft == 1) {
4971: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4972: }
1.152 raeburn 4973: $current{$type} .= '</tr></table>';
1.150 raeburn 4974: }
1.145 raeburn 4975: }
4976: }
4977: if ($current{$type} eq '') {
4978: $current{$type} = &mt('None specified');
4979: }
1.152 raeburn 4980: if ($othercontrol) {
4981: if ($type eq 'primary') {
4982: $canselect{$type} = $othercontrol;
4983: }
4984: } else {
4985: $canselect{$type} =
4986: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4987: '<select name="newspare_'.$type.'_'.$server.'" '.
4988: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4989: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4990: if (@choices > 0) {
4991: foreach my $lonhost (@choices) {
4992: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4993: }
4994: }
4995: $canselect{$type} .= '</select>'."\n";
4996: }
4997: } else {
4998: $current{$type} = &mt('Could not be determined');
4999: if ($type eq 'primary') {
5000: $canselect{$type} = $othercontrol;
5001: }
1.145 raeburn 5002: }
1.152 raeburn 5003: if ($type eq 'default') {
5004: $datatable .= '<tr'.$css_class.'>';
5005: }
5006: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5007: '<td>'.$current{$type}.'</td>'."\n".
5008: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 5009: }
5010: $itemcount ++;
5011: }
5012: }
5013: $$rowtotal += $itemcount;
5014: return $datatable;
5015: }
5016:
1.152 raeburn 5017: sub possible_newspares {
5018: my ($server,$currspares,$serverhomes,$altids) = @_;
5019: my $serverhostname = &Apache::lonnet::hostname($server);
5020: my %excluded;
5021: if ($serverhostname ne '') {
5022: %excluded = (
5023: $serverhostname => 1,
5024: );
5025: }
5026: if (ref($currspares) eq 'HASH') {
5027: foreach my $type (keys(%{$currspares})) {
5028: if (ref($currspares->{$type}) eq 'ARRAY') {
5029: if (@{$currspares->{$type}} > 0) {
5030: foreach my $curr (@{$currspares->{$type}}) {
5031: my $hostname = &Apache::lonnet::hostname($curr);
5032: $excluded{$hostname} = 1;
5033: }
5034: }
5035: }
5036: }
5037: }
5038: my @choices;
5039: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5040: if (keys(%{$serverhomes}) > 1) {
5041: foreach my $name (sort(keys(%{$serverhomes}))) {
5042: unless ($excluded{$name}) {
5043: if (exists($altids->{$serverhomes->{$name}})) {
5044: push(@choices,$altids->{$serverhomes->{$name}});
5045: } else {
5046: push(@choices,$serverhomes->{$name});
1.145 raeburn 5047: }
5048: }
5049: }
5050: }
5051: }
1.152 raeburn 5052: return sort(@choices);
1.145 raeburn 5053: }
5054:
1.150 raeburn 5055: sub print_loadbalancing {
5056: my ($dom,$settings,$rowtotal) = @_;
5057: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5058: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5059: my $numinrow = 1;
5060: my $datatable;
5061: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 5062: my (%currbalancer,%currtargets,%currrules,%existing);
5063: if (ref($settings) eq 'HASH') {
5064: %existing = %{$settings};
5065: }
5066: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5067: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
5068: \%currtargets,\%currrules);
1.150 raeburn 5069: } else {
5070: return;
5071: }
5072: my ($othertitle,$usertypes,$types) =
5073: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 5074: my $rownum = 8;
1.150 raeburn 5075: if (ref($types) eq 'ARRAY') {
5076: $rownum += scalar(@{$types});
5077: }
1.171 raeburn 5078: my @css_class = ('LC_odd_row','LC_even_row');
5079: my $balnum = 0;
5080: my $islast;
5081: my (@toshow,$disabledtext);
5082: if (keys(%currbalancer) > 0) {
5083: @toshow = sort(keys(%currbalancer));
5084: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5085: push(@toshow,'');
5086: }
5087: } else {
5088: @toshow = ('');
5089: $disabledtext = &mt('No existing load balancer');
5090: }
5091: foreach my $lonhost (@toshow) {
5092: if ($balnum == scalar(@toshow)-1) {
5093: $islast = 1;
5094: } else {
5095: $islast = 0;
5096: }
5097: my $cssidx = $balnum%2;
5098: my $targets_div_style = 'display: none';
5099: my $disabled_div_style = 'display: block';
5100: my $homedom_div_style = 'display: none';
5101: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
5102: '<td rowspan="'.$rownum.'" valign="top">'.
5103: '<p>';
5104: if ($lonhost eq '') {
1.210 raeburn 5105: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 5106: if (keys(%currbalancer) > 0) {
5107: $datatable .= &mt('Add balancer:');
5108: } else {
5109: $datatable .= &mt('Enable balancer:');
5110: }
5111: $datatable .= ' '.
5112: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5113: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5114: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5115: '<option value="" selected="selected">'.&mt('None').
5116: '</option>'."\n";
5117: foreach my $server (sort(keys(%servers))) {
5118: next if ($currbalancer{$server});
5119: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5120: }
1.210 raeburn 5121: $datatable .=
1.171 raeburn 5122: '</select>'."\n".
5123: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5124: } else {
5125: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5126: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5127: &mt('Stop balancing').'</label>'.
5128: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5129: $targets_div_style = 'display: block';
5130: $disabled_div_style = 'display: none';
5131: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5132: $homedom_div_style = 'display: block';
5133: }
5134: }
5135: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
5136: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5137: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5138: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5139: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5140: my @sparestypes = ('primary','default');
5141: my %typetitles = &sparestype_titles();
1.284 raeburn 5142: my %hostherechecked = (
5143: no => ' checked="checked"',
5144: );
1.171 raeburn 5145: foreach my $sparetype (@sparestypes) {
5146: my $targettable;
5147: for (my $i=0; $i<$numspares; $i++) {
5148: my $checked;
5149: if (ref($currtargets{$lonhost}) eq 'HASH') {
5150: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5151: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5152: $checked = ' checked="checked"';
5153: }
5154: }
5155: }
5156: my ($chkboxval,$disabled);
5157: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5158: $chkboxval = $spares[$i];
5159: }
5160: if (exists($currbalancer{$spares[$i]})) {
5161: $disabled = ' disabled="disabled"';
5162: }
1.210 raeburn 5163: $targettable .=
1.253 raeburn 5164: '<td><span class="LC_nobreak"><label>'.
5165: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 5166: $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 5167: '</span></label></span></td>';
1.171 raeburn 5168: my $rem = $i%($numinrow);
5169: if ($rem == 0) {
5170: if (($i > 0) && ($i < $numspares-1)) {
5171: $targettable .= '</tr>';
5172: }
5173: if ($i < $numspares-1) {
5174: $targettable .= '<tr>';
1.150 raeburn 5175: }
5176: }
5177: }
1.171 raeburn 5178: if ($targettable ne '') {
5179: my $rem = $numspares%($numinrow);
5180: my $colsleft = $numinrow - $rem;
5181: if ($colsleft > 1 ) {
5182: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5183: ' </td>';
5184: } elsif ($colsleft == 1) {
5185: $targettable .= '<td class="LC_left_item"> </td>';
5186: }
5187: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5188: '<table><tr>'.$targettable.'</tr></table><br />';
5189: }
1.284 raeburn 5190: $hostherechecked{$sparetype} = '';
5191: if (ref($currtargets{$lonhost}) eq 'HASH') {
5192: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5193: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5194: $hostherechecked{$sparetype} = ' checked="checked"';
5195: $hostherechecked{'no'} = '';
5196: }
5197: }
5198: }
5199: }
5200: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5201: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5202: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5203: foreach my $sparetype (@sparestypes) {
5204: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5205: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5206: '</i></label><br />';
1.171 raeburn 5207: }
5208: $datatable .= '</div></td></tr>'.
5209: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5210: $othertitle,$usertypes,$types,\%servers,
5211: \%currbalancer,$lonhost,
5212: $targets_div_style,$homedom_div_style,
5213: $css_class[$cssidx],$balnum,$islast);
5214: $$rowtotal += $rownum;
5215: $balnum ++;
5216: }
5217: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5218: return $datatable;
5219: }
5220:
5221: sub get_loadbalancers_config {
5222: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
5223: return unless ((ref($servers) eq 'HASH') &&
5224: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
5225: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
5226: if (keys(%{$existing}) > 0) {
5227: my $oldlonhost;
5228: foreach my $key (sort(keys(%{$existing}))) {
5229: if ($key eq 'lonhost') {
5230: $oldlonhost = $existing->{'lonhost'};
5231: $currbalancer->{$oldlonhost} = 1;
5232: } elsif ($key eq 'targets') {
5233: if ($oldlonhost) {
5234: $currtargets->{$oldlonhost} = $existing->{'targets'};
5235: }
5236: } elsif ($key eq 'rules') {
5237: if ($oldlonhost) {
5238: $currrules->{$oldlonhost} = $existing->{'rules'};
5239: }
5240: } elsif (ref($existing->{$key}) eq 'HASH') {
5241: $currbalancer->{$key} = 1;
5242: $currtargets->{$key} = $existing->{$key}{'targets'};
5243: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 5244: }
5245: }
1.171 raeburn 5246: } else {
5247: my ($balancerref,$targetsref) =
5248: &Apache::lonnet::get_lonbalancer_config($servers);
5249: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5250: foreach my $server (sort(keys(%{$balancerref}))) {
5251: $currbalancer->{$server} = 1;
5252: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5253: }
5254: }
5255: }
1.171 raeburn 5256: return;
1.150 raeburn 5257: }
5258:
5259: sub loadbalancing_rules {
5260: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 5261: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5262: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5263: my $output;
1.171 raeburn 5264: my $num = 0;
1.210 raeburn 5265: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5266: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5267: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5268: foreach my $type (@{$alltypes}) {
1.171 raeburn 5269: $num ++;
1.150 raeburn 5270: my $current;
5271: if (ref($currrules) eq 'HASH') {
5272: $current = $currrules->{$type};
5273: }
1.253 raeburn 5274: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 5275: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5276: $current = '';
5277: }
5278: }
5279: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 5280: $servers,$currbalancer,$lonhost,$dom,
5281: $targets_div_style,$homedom_div_style,
5282: $css_class,$balnum,$num,$islast);
1.150 raeburn 5283: }
5284: }
5285: return $output;
5286: }
5287:
5288: sub loadbalancing_titles {
5289: my ($dom,$intdom,$usertypes,$types) = @_;
5290: my %othertypes = (
5291: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5292: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5293: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5294: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 5295: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5296: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5297: );
1.209 raeburn 5298: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 5299: if (ref($types) eq 'ARRAY') {
5300: unshift(@alltypes,@{$types},'default');
5301: }
5302: my %titles;
5303: foreach my $type (@alltypes) {
5304: if ($type =~ /^_LC_/) {
5305: $titles{$type} = $othertypes{$type};
5306: } elsif ($type eq 'default') {
5307: $titles{$type} = &mt('All users from [_1]',$dom);
5308: if (ref($types) eq 'ARRAY') {
5309: if (@{$types} > 0) {
5310: $titles{$type} = &mt('Other users from [_1]',$dom);
5311: }
5312: }
5313: } elsif (ref($usertypes) eq 'HASH') {
5314: $titles{$type} = $usertypes->{$type};
5315: }
5316: }
5317: return (\@alltypes,\%othertypes,\%titles);
5318: }
5319:
5320: sub loadbalance_rule_row {
1.171 raeburn 5321: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5322: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 5323: my @rulenames;
1.150 raeburn 5324: my %ruletitles = &offloadtype_text();
1.209 raeburn 5325: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 5326: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 5327: } else {
1.209 raeburn 5328: @rulenames = ('default','homeserver');
5329: if ($type eq '_LC_external') {
5330: push(@rulenames,'externalbalancer');
5331: } else {
5332: push(@rulenames,'specific');
5333: }
5334: push(@rulenames,'none');
1.150 raeburn 5335: }
5336: my $style = $targets_div_style;
1.253 raeburn 5337: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 5338: $style = $homedom_div_style;
5339: }
1.171 raeburn 5340: my $space;
5341: if ($islast && $num == 1) {
5342: $space = '<div display="inline-block"> </div>';
5343: }
1.210 raeburn 5344: my $output =
1.171 raeburn 5345: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
5346: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5347: '<td valaign="top">'.$space.
5348: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 5349: for (my $i=0; $i<@rulenames; $i++) {
5350: my $rule = $rulenames[$i];
5351: my ($checked,$extra);
5352: if ($rulenames[$i] eq 'default') {
5353: $rule = '';
5354: }
5355: if ($rulenames[$i] eq 'specific') {
5356: if (ref($servers) eq 'HASH') {
5357: my $default;
5358: if (($current ne '') && (exists($servers->{$current}))) {
5359: $checked = ' checked="checked"';
5360: }
5361: unless ($checked) {
5362: $default = ' selected="selected"';
5363: }
1.210 raeburn 5364: $extra =
1.171 raeburn 5365: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5366: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5367: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5368: '<option value=""'.$default.'></option>'."\n";
5369: foreach my $server (sort(keys(%{$servers}))) {
5370: if (ref($currbalancer) eq 'HASH') {
5371: next if (exists($currbalancer->{$server}));
5372: }
1.150 raeburn 5373: my $selected;
1.171 raeburn 5374: if ($server eq $current) {
1.150 raeburn 5375: $selected = ' selected="selected"';
5376: }
1.171 raeburn 5377: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 5378: }
5379: $extra .= '</select>';
5380: }
5381: } elsif ($rule eq $current) {
5382: $checked = ' checked="checked"';
5383: }
5384: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 5385: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5386: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5387: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 5388: ')"'.$checked.' /> ';
5389: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
5390: $output .= $ruletitles{'particular'};
5391: } else {
5392: $output .= $ruletitles{$rulenames[$i]};
5393: }
5394: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 5395: }
5396: $output .= '</div></td></tr>'."\n";
5397: return $output;
5398: }
5399:
5400: sub offloadtype_text {
5401: my %ruletitles = &Apache::lonlocal::texthash (
5402: 'default' => 'Offloads to default destinations',
5403: 'homeserver' => "Offloads to user's home server",
5404: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5405: 'specific' => 'Offloads to specific server',
1.161 raeburn 5406: 'none' => 'No offload',
1.209 raeburn 5407: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5408: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 5409: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 5410: );
5411: return %ruletitles;
5412: }
5413:
5414: sub sparestype_titles {
5415: my %typestitles = &Apache::lonlocal::texthash (
5416: 'primary' => 'primary',
5417: 'default' => 'default',
5418: );
5419: return %typestitles;
5420: }
5421:
1.28 raeburn 5422: sub contact_titles {
5423: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 5424: 'supportemail' => 'Support E-mail address',
5425: 'adminemail' => 'Default Server Admin E-mail address',
5426: 'errormail' => 'Error reports to be e-mailed to',
5427: 'packagesmail' => 'Package update alerts to be e-mailed to',
5428: 'helpdeskmail' => "Helpdesk requests for this domain's users",
5429: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
5430: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5431: 'requestsmail' => 'E-mail from course requests requiring approval',
5432: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 5433: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 5434: );
5435: my %short_titles = &Apache::lonlocal::texthash (
5436: adminemail => 'Admin E-mail address',
5437: supportemail => 'Support E-mail',
5438: );
5439: return (\%titles,\%short_titles);
5440: }
5441:
1.286 raeburn 5442: sub helpform_fields {
5443: my %titles = &Apache::lonlocal::texthash (
5444: 'username' => 'Name',
5445: 'user' => 'Username/domain',
5446: 'phone' => 'Phone',
5447: 'cc' => 'Cc e-mail',
5448: 'course' => 'Course Details',
5449: 'section' => 'Sections',
5450: 'screenshot' => 'File upload',
5451: );
5452: my @fields = ('username','phone','user','course','section','cc','screenshot');
5453: my %possoptions = (
5454: username => ['yes','no','req'],
5455: phone => ['yes','no','req'],
5456: user => ['yes','no'],
5457: cc => ['yes','no'],
5458: course => ['yes','no'],
5459: section => ['yes','no'],
5460: screenshot => ['yes','no'],
5461: );
5462: my %fieldoptions = &Apache::lonlocal::texthash (
5463: 'yes' => 'Optional',
5464: 'req' => 'Required',
5465: 'no' => "Not shown",
5466: );
5467: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5468: }
5469:
1.72 raeburn 5470: sub tool_titles {
5471: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 5472: aboutme => 'Personal web page',
1.86 raeburn 5473: blog => 'Blog',
1.162 raeburn 5474: webdav => 'WebDAV',
1.86 raeburn 5475: portfolio => 'Portfolio',
1.88 bisitz 5476: official => 'Official courses (with institutional codes)',
5477: unofficial => 'Unofficial courses',
1.98 raeburn 5478: community => 'Communities',
1.216 raeburn 5479: textbook => 'Textbook courses',
1.271 raeburn 5480: placement => 'Placement tests',
1.86 raeburn 5481: );
1.72 raeburn 5482: return %titles;
5483: }
5484:
1.101 raeburn 5485: sub courserequest_titles {
5486: my %titles = &Apache::lonlocal::texthash (
5487: official => 'Official',
5488: unofficial => 'Unofficial',
5489: community => 'Communities',
1.216 raeburn 5490: textbook => 'Textbook',
1.271 raeburn 5491: placement => 'Placement tests',
1.101 raeburn 5492: norequest => 'Not allowed',
1.104 raeburn 5493: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5494: validate => 'With validation',
5495: autolimit => 'Numerical limit',
1.103 raeburn 5496: unlimited => '(blank for unlimited)',
1.101 raeburn 5497: );
5498: return %titles;
5499: }
5500:
1.163 raeburn 5501: sub authorrequest_titles {
5502: my %titles = &Apache::lonlocal::texthash (
5503: norequest => 'Not allowed',
5504: approval => 'Approval by Dom. Coord.',
5505: automatic => 'Automatic approval',
5506: );
5507: return %titles;
1.210 raeburn 5508: }
1.163 raeburn 5509:
1.101 raeburn 5510: sub courserequest_conditions {
5511: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5512: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 5513: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 5514: );
5515: return %conditions;
5516: }
5517:
5518:
1.27 raeburn 5519: sub print_usercreation {
1.30 raeburn 5520: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 5521: my $numinrow = 4;
1.28 raeburn 5522: my $datatable;
5523: if ($position eq 'top') {
1.30 raeburn 5524: $$rowtotal ++;
1.34 raeburn 5525: my $rowcount = 0;
1.32 raeburn 5526: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 5527: if (ref($rules) eq 'HASH') {
5528: if (keys(%{$rules}) > 0) {
1.32 raeburn 5529: $datatable .= &user_formats_row('username',$settings,$rules,
5530: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 5531: $$rowtotal ++;
1.32 raeburn 5532: $rowcount ++;
5533: }
5534: }
5535: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5536: if (ref($idrules) eq 'HASH') {
5537: if (keys(%{$idrules}) > 0) {
5538: $datatable .= &user_formats_row('id',$settings,$idrules,
5539: $idruleorder,$numinrow,$rowcount);
5540: $$rowtotal ++;
5541: $rowcount ++;
1.28 raeburn 5542: }
5543: }
1.39 raeburn 5544: if ($rowcount == 0) {
5545: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5546: $$rowtotal ++;
5547: $rowcount ++;
5548: }
1.34 raeburn 5549: } elsif ($position eq 'middle') {
1.224 raeburn 5550: my @creators = ('author','course','requestcrs');
1.37 raeburn 5551: my ($rules,$ruleorder) =
5552: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 5553: my %lt = &usercreation_types();
5554: my %checked;
5555: if (ref($settings) eq 'HASH') {
5556: if (ref($settings->{'cancreate'}) eq 'HASH') {
5557: foreach my $item (@creators) {
5558: $checked{$item} = $settings->{'cancreate'}{$item};
5559: }
5560: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5561: foreach my $item (@creators) {
5562: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5563: $checked{$item} = 'none';
5564: }
5565: }
5566: }
5567: }
5568: my $rownum = 0;
5569: foreach my $item (@creators) {
5570: $rownum ++;
1.224 raeburn 5571: if ($checked{$item} eq '') {
5572: $checked{$item} = 'any';
1.34 raeburn 5573: }
5574: my $css_class;
5575: if ($rownum%2) {
5576: $css_class = '';
5577: } else {
5578: $css_class = ' class="LC_odd_row" ';
5579: }
5580: $datatable .= '<tr'.$css_class.'>'.
5581: '<td><span class="LC_nobreak">'.$lt{$item}.
5582: '</span></td><td align="right">';
1.224 raeburn 5583: my @options = ('any');
5584: if (ref($rules) eq 'HASH') {
5585: if (keys(%{$rules}) > 0) {
5586: push(@options,('official','unofficial'));
1.37 raeburn 5587: }
5588: }
1.224 raeburn 5589: push(@options,'none');
1.37 raeburn 5590: foreach my $option (@options) {
1.50 raeburn 5591: my $type = 'radio';
1.34 raeburn 5592: my $check = ' ';
1.224 raeburn 5593: if ($checked{$item} eq $option) {
5594: $check = ' checked="checked" ';
1.34 raeburn 5595: }
5596: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5597: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5598: $item.'" value="'.$option.'"'.$check.'/> '.
5599: $lt{$option}.'</label> </span>';
5600: }
5601: $datatable .= '</td></tr>';
5602: }
1.28 raeburn 5603: } else {
5604: my @contexts = ('author','course','domain');
5605: my @authtypes = ('int','krb4','krb5','loc');
5606: my %checked;
5607: if (ref($settings) eq 'HASH') {
5608: if (ref($settings->{'authtypes'}) eq 'HASH') {
5609: foreach my $item (@contexts) {
5610: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5611: foreach my $auth (@authtypes) {
5612: if ($settings->{'authtypes'}{$item}{$auth}) {
5613: $checked{$item}{$auth} = ' checked="checked" ';
5614: }
5615: }
5616: }
5617: }
1.27 raeburn 5618: }
1.35 raeburn 5619: } else {
5620: foreach my $item (@contexts) {
1.36 raeburn 5621: foreach my $auth (@authtypes) {
1.35 raeburn 5622: $checked{$item}{$auth} = ' checked="checked" ';
5623: }
5624: }
1.27 raeburn 5625: }
1.28 raeburn 5626: my %title = &context_names();
5627: my %authname = &authtype_names();
5628: my $rownum = 0;
5629: my $css_class;
5630: foreach my $item (@contexts) {
5631: if ($rownum%2) {
5632: $css_class = '';
5633: } else {
5634: $css_class = ' class="LC_odd_row" ';
5635: }
1.30 raeburn 5636: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5637: '<td>'.$title{$item}.
5638: '</td><td class="LC_left_item">'.
5639: '<span class="LC_nobreak">';
5640: foreach my $auth (@authtypes) {
5641: $datatable .= '<label>'.
5642: '<input type="checkbox" name="'.$item.'_auth" '.
5643: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5644: $authname{$auth}.'</label> ';
5645: }
5646: $datatable .= '</span></td></tr>';
5647: $rownum ++;
1.27 raeburn 5648: }
1.30 raeburn 5649: $$rowtotal += $rownum;
1.27 raeburn 5650: }
5651: return $datatable;
5652: }
5653:
1.224 raeburn 5654: sub print_selfcreation {
5655: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 5656: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 5657: if (ref($settings) eq 'HASH') {
5658: if (ref($settings->{'cancreate'}) eq 'HASH') {
5659: $createsettings = $settings->{'cancreate'};
1.236 raeburn 5660: if (ref($createsettings) eq 'HASH') {
5661: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5662: @selfcreate = @{$createsettings->{'selfcreate'}};
5663: } elsif ($createsettings->{'selfcreate'} ne '') {
5664: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5665: @selfcreate = ('email','login','sso');
5666: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5667: @selfcreate = ($createsettings->{'selfcreate'});
5668: }
5669: }
5670: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5671: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 5672: }
5673: }
5674: }
5675: }
5676: my %radiohash;
5677: my $numinrow = 4;
5678: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5679: if ($position eq 'top') {
5680: my %choices = &Apache::lonlocal::texthash (
5681: cancreate_login => 'Institutional Login',
5682: cancreate_sso => 'Institutional Single Sign On',
5683: );
5684: my @toggles = sort(keys(%choices));
5685: my %defaultchecked = (
5686: 'cancreate_login' => 'off',
5687: 'cancreate_sso' => 'off',
5688: );
1.228 raeburn 5689: my ($onclick,$itemcount);
1.224 raeburn 5690: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5691: \%choices,$itemcount,$onclick);
1.228 raeburn 5692: $$rowtotal += $itemcount;
5693:
1.224 raeburn 5694: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5695:
5696: if (ref($usertypes) eq 'HASH') {
5697: if (keys(%{$usertypes}) > 0) {
5698: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5699: $dom,$numinrow,$othertitle,
1.228 raeburn 5700: 'statustocreate',$$rowtotal);
1.224 raeburn 5701: $$rowtotal ++;
5702: }
5703: }
1.240 raeburn 5704: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5705: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5706: $fieldtitles{'inststatus'} = &mt('Institutional status');
5707: my $rem;
5708: my $numperrow = 2;
5709: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5710: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 5711: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 5712: '<td class="LC_left_item">'."\n".
5713: '<table><tr><td>'."\n";
5714: for (my $i=0; $i<@fields; $i++) {
5715: $rem = $i%($numperrow);
5716: if ($rem == 0) {
5717: if ($i > 0) {
5718: $datatable .= '</tr>';
5719: }
5720: $datatable .= '<tr>';
5721: }
5722: my $currval;
1.248 raeburn 5723: if (ref($createsettings) eq 'HASH') {
5724: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5725: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5726: }
1.240 raeburn 5727: }
5728: $datatable .= '<td class="LC_left_item">'.
5729: '<span class="LC_nobreak">'.
5730: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5731: 'value="'.$currval.'" size="10" /> '.
5732: $fieldtitles{$fields[$i]}.'</span></td>';
5733: }
5734: my $colsleft = $numperrow - $rem;
5735: if ($colsleft > 1 ) {
5736: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5737: ' </td>';
5738: } elsif ($colsleft == 1) {
5739: $datatable .= '<td class="LC_left_item"> </td>';
5740: }
5741: $datatable .= '</tr></table></td></tr>';
5742: $$rowtotal ++;
1.224 raeburn 5743: } elsif ($position eq 'middle') {
5744: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5745: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5746: $usertypes->{'default'} = $othertitle;
5747: if (ref($types) eq 'ARRAY') {
5748: push(@{$types},'default');
5749: $usertypes->{'default'} = $othertitle;
5750: foreach my $status (@{$types}) {
5751: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 5752: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 5753: $$rowtotal ++;
1.224 raeburn 5754: }
5755: }
5756: } else {
1.236 raeburn 5757: my %choices = &Apache::lonlocal::texthash (
5758: cancreate_email => 'E-mail address as username',
5759: );
5760: my @toggles = sort(keys(%choices));
5761: my %defaultchecked = (
5762: 'cancreate_email' => 'off',
5763: );
5764: my $itemcount = 0;
5765: my $display = 'none';
5766: if (grep(/^\Qemail\E$/,@selfcreate)) {
5767: $display = 'block';
5768: }
5769: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5770: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5771: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5772: my $usertypes = {};
5773: my $order = [];
5774: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
5775: $usertypes = $domdefaults{'inststatustypes'};
5776: $order = $domdefaults{'inststatusguest'};
5777: }
5778: if (ref($order) eq 'ARRAY') {
5779: push(@{$order},'default');
5780: if (@{$order} > 1) {
5781: $usertypes->{'default'} = &mt('Other users');
5782: $additional .= '<table><tr>';
5783: foreach my $status (@{$order}) {
5784: $additional .= '<th>'.$usertypes->{$status}.'</th>';
5785: }
5786: $additional .= '</tr><tr>';
5787: foreach my $status (@{$order}) {
5788: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 5789: }
1.236 raeburn 5790: $additional .= '</tr></table>';
1.224 raeburn 5791: } else {
1.236 raeburn 5792: $usertypes->{'default'} = &mt('All users');
5793: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 5794: }
5795: }
1.236 raeburn 5796: $additional .= '</div>'."\n";
5797:
5798: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 5799: \%choices,$$rowtotal,$onclick,$additional);
5800: $$rowtotal ++;
1.236 raeburn 5801: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 5802: $$rowtotal ++;
1.224 raeburn 5803: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 5804: $numinrow = 1;
1.236 raeburn 5805: if (ref($order) eq 'ARRAY') {
5806: foreach my $status (@{$order}) {
1.228 raeburn 5807: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5808: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
5809: $$rowtotal ++;
5810: }
5811: }
1.224 raeburn 5812: my ($emailrules,$emailruleorder) =
5813: &Apache::lonnet::inst_userrules($dom,'email');
5814: if (ref($emailrules) eq 'HASH') {
5815: if (keys(%{$emailrules}) > 0) {
5816: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 5817: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 5818: $$rowtotal ++;
5819: }
5820: }
1.228 raeburn 5821: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 5822: }
5823: return $datatable;
5824: }
5825:
1.236 raeburn 5826: sub email_as_username {
5827: my ($rowtotal,$processing,$type) = @_;
5828: my %choices =
5829: &Apache::lonlocal::texthash (
5830: automatic => 'Automatic approval',
5831: approval => 'Queued for approval',
5832: );
5833: my $output;
5834: foreach my $option ('automatic','approval') {
5835: my $checked;
5836: if (ref($processing) eq 'HASH') {
5837: if ($type eq '') {
5838: if (!exists($processing->{'default'})) {
5839: if ($option eq 'automatic') {
5840: $checked = ' checked="checked"';
5841: }
5842: } else {
5843: if ($processing->{'default'} eq $option) {
5844: $checked = ' checked="checked"';
5845: }
5846: }
5847: } else {
5848: if (!exists($processing->{$type})) {
5849: if ($option eq 'automatic') {
5850: $checked = ' checked="checked"';
5851: }
5852: } else {
5853: if ($processing->{$type} eq $option) {
5854: $checked = ' checked="checked"';
5855: }
5856: }
5857: }
5858: } elsif ($option eq 'automatic') {
5859: $checked = ' checked="checked"';
5860: }
5861: my $name = 'cancreate_emailprocess';
5862: if (($type ne '') && ($type ne 'default')) {
5863: $name .= '_'.$type;
5864: }
5865: $output .= '<span class="LC_nobreak"><label>'.
5866: '<input type="radio" name="'.$name.'"'.
5867: $checked.' value="'.$option.'" />'.
5868: $choices{$option}.'</label></span>';
5869: if ($type eq '') {
5870: $output .= ' ';
5871: } else {
5872: $output .= '<br />';
5873: }
5874: }
5875: $$rowtotal ++;
5876: return $output;
5877: }
5878:
1.165 raeburn 5879: sub captcha_choice {
1.169 raeburn 5880: my ($context,$settings,$itemcount) = @_;
1.269 raeburn 5881: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5882: $vertext,$currver);
1.165 raeburn 5883: my %lt = &captcha_phrases();
5884: $keyentry = 'hidden';
5885: if ($context eq 'cancreate') {
1.224 raeburn 5886: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 5887: } elsif ($context eq 'login') {
5888: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 5889: }
5890: if (ref($settings) eq 'HASH') {
5891: if ($settings->{'captcha'}) {
5892: $checked{$settings->{'captcha'}} = ' checked="checked"';
5893: } else {
5894: $checked{'original'} = ' checked="checked"';
5895: }
5896: if ($settings->{'captcha'} eq 'recaptcha') {
5897: $pubtext = $lt{'pub'};
5898: $privtext = $lt{'priv'};
5899: $keyentry = 'text';
1.269 raeburn 5900: $vertext = $lt{'ver'};
5901: $currver = $settings->{'recaptchaversion'};
5902: if ($currver ne '2') {
5903: $currver = 1;
5904: }
1.165 raeburn 5905: }
5906: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5907: $currpub = $settings->{'recaptchakeys'}{'public'};
5908: $currpriv = $settings->{'recaptchakeys'}{'private'};
5909: }
5910: } else {
5911: $checked{'original'} = ' checked="checked"';
5912: }
1.169 raeburn 5913: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5914: my $output = '<tr'.$css_class.'>'.
5915: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 5916: '<table><tr><td>'."\n";
5917: foreach my $option ('original','recaptcha','notused') {
5918: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5919: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5920: $lt{$option}.'</label></span>';
5921: unless ($option eq 'notused') {
5922: $output .= (' 'x2)."\n";
5923: }
5924: }
5925: #
5926: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5927: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 5928: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 5929: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 5930: #
1.165 raeburn 5931: $output .= '</td></tr>'."\n".
5932: '<tr><td>'."\n".
5933: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5934: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5935: $currpub.'" size="40" /></span><br />'."\n".
5936: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5937: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 5938: $currpriv.'" size="40" /></span><br />'.
5939: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5940: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5941: $currver.'" size="3" /></span><br />'.
5942: '</td></tr></table>'."\n".
1.165 raeburn 5943: '</td></tr>';
5944: return $output;
5945: }
5946:
1.32 raeburn 5947: sub user_formats_row {
5948: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5949: my $output;
5950: my %text = (
5951: 'username' => 'new usernames',
5952: 'id' => 'IDs',
1.45 raeburn 5953: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5954: );
5955: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5956: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5957: '<td><span class="LC_nobreak">';
5958: if ($type eq 'email') {
5959: $output .= &mt("Formats disallowed for $text{$type}: ");
5960: } else {
5961: $output .= &mt("Format rules to check for $text{$type}: ");
5962: }
5963: $output .= '</span></td>'.
5964: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5965: my $rem;
5966: if (ref($ruleorder) eq 'ARRAY') {
5967: for (my $i=0; $i<@{$ruleorder}; $i++) {
5968: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5969: my $rem = $i%($numinrow);
5970: if ($rem == 0) {
5971: if ($i > 0) {
5972: $output .= '</tr>';
5973: }
5974: $output .= '<tr>';
5975: }
5976: my $check = ' ';
1.39 raeburn 5977: if (ref($settings) eq 'HASH') {
5978: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5979: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5980: $check = ' checked="checked" ';
5981: }
1.27 raeburn 5982: }
5983: }
5984: $output .= '<td class="LC_left_item">'.
5985: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5986: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5987: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5988: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5989: }
5990: }
5991: $rem = @{$ruleorder}%($numinrow);
5992: }
5993: my $colsleft = $numinrow - $rem;
5994: if ($colsleft > 1 ) {
5995: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5996: ' </td>';
5997: } elsif ($colsleft == 1) {
5998: $output .= '<td class="LC_left_item"> </td>';
5999: }
6000: $output .= '</tr></table></td></tr>';
6001: return $output;
6002: }
6003:
1.34 raeburn 6004: sub usercreation_types {
6005: my %lt = &Apache::lonlocal::texthash (
6006: author => 'When adding a co-author',
6007: course => 'When adding a user to a course',
1.100 raeburn 6008: requestcrs => 'When requesting a course',
1.34 raeburn 6009: any => 'Any',
6010: official => 'Institutional only ',
6011: unofficial => 'Non-institutional only',
6012: none => 'None',
6013: );
6014: return %lt;
1.48 raeburn 6015: }
1.34 raeburn 6016:
1.224 raeburn 6017: sub selfcreation_types {
6018: my %lt = &Apache::lonlocal::texthash (
6019: selfcreate => 'User creates own account',
6020: any => 'Any',
6021: official => 'Institutional only ',
6022: unofficial => 'Non-institutional only',
6023: email => 'E-mail address',
6024: login => 'Institutional Login',
6025: sso => 'SSO',
6026: );
6027: }
6028:
1.28 raeburn 6029: sub authtype_names {
6030: my %lt = &Apache::lonlocal::texthash(
6031: int => 'Internal',
6032: krb4 => 'Kerberos 4',
6033: krb5 => 'Kerberos 5',
6034: loc => 'Local',
6035: );
6036: return %lt;
6037: }
6038:
6039: sub context_names {
6040: my %context_title = &Apache::lonlocal::texthash(
6041: author => 'Creating users when an Author',
6042: course => 'Creating users when in a course',
6043: domain => 'Creating users when a Domain Coordinator',
6044: );
6045: return %context_title;
6046: }
6047:
1.33 raeburn 6048: sub print_usermodification {
6049: my ($position,$dom,$settings,$rowtotal) = @_;
6050: my $numinrow = 4;
6051: my ($context,$datatable,$rowcount);
6052: if ($position eq 'top') {
6053: $rowcount = 0;
6054: $context = 'author';
6055: foreach my $role ('ca','aa') {
6056: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6057: $numinrow,$rowcount);
6058: $$rowtotal ++;
6059: $rowcount ++;
6060: }
1.230 raeburn 6061: } elsif ($position eq 'bottom') {
1.33 raeburn 6062: $context = 'course';
6063: $rowcount = 0;
6064: foreach my $role ('st','ep','ta','in','cr') {
6065: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6066: $numinrow,$rowcount);
6067: $$rowtotal ++;
6068: $rowcount ++;
6069: }
6070: }
6071: return $datatable;
6072: }
6073:
1.43 raeburn 6074: sub print_defaults {
1.236 raeburn 6075: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 6076: my $rownum = 0;
6077: my ($datatable,$css_class);
1.236 raeburn 6078: if ($position eq 'top') {
6079: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6080: 'datelocale_def','portal_def');
6081: my %defaults;
6082: if (ref($settings) eq 'HASH') {
6083: %defaults = %{$settings};
1.43 raeburn 6084: } else {
1.236 raeburn 6085: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6086: foreach my $item (@items) {
6087: $defaults{$item} = $domdefaults{$item};
6088: }
1.43 raeburn 6089: }
1.236 raeburn 6090: my $titles = &defaults_titles($dom);
6091: foreach my $item (@items) {
6092: if ($rownum%2) {
6093: $css_class = '';
6094: } else {
6095: $css_class = ' class="LC_odd_row" ';
6096: }
6097: $datatable .= '<tr'.$css_class.'>'.
6098: '<td><span class="LC_nobreak">'.$titles->{$item}.
6099: '</span></td><td class="LC_right_item" colspan="3">';
6100: if ($item eq 'auth_def') {
6101: my @authtypes = ('internal','krb4','krb5','localauth');
6102: my %shortauth = (
6103: internal => 'int',
6104: krb4 => 'krb4',
6105: krb5 => 'krb5',
6106: localauth => 'loc'
6107: );
6108: my %authnames = &authtype_names();
6109: foreach my $auth (@authtypes) {
6110: my $checked = ' ';
6111: if ($defaults{$item} eq $auth) {
6112: $checked = ' checked="checked" ';
6113: }
6114: $datatable .= '<label><input type="radio" name="'.$item.
6115: '" value="'.$auth.'"'.$checked.'/>'.
6116: $authnames{$shortauth{$auth}}.'</label> ';
6117: }
6118: } elsif ($item eq 'timezone_def') {
6119: my $includeempty = 1;
6120: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6121: } elsif ($item eq 'datelocale_def') {
6122: my $includeempty = 1;
6123: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
6124: } elsif ($item eq 'lang_def') {
1.263 raeburn 6125: my $includeempty = 1;
6126: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 6127: } else {
6128: my $size;
6129: if ($item eq 'portal_def') {
6130: $size = ' size="25"';
6131: }
6132: $datatable .= '<input type="text" name="'.$item.'" value="'.
6133: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 6134: }
1.236 raeburn 6135: $datatable .= '</td></tr>';
6136: $rownum ++;
6137: }
6138: } else {
6139: my (%defaults);
6140: if (ref($settings) eq 'HASH') {
6141: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
6142: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
6143: my $maxnum = @{$settings->{'inststatusorder'}};
6144: for (my $i=0; $i<$maxnum; $i++) {
6145: $css_class = $rownum%2?' class="LC_odd_row"':'';
6146: my $item = $settings->{'inststatusorder'}->[$i];
6147: my $title = $settings->{'inststatustypes'}->{$item};
6148: my $guestok;
6149: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
6150: $guestok = 1;
6151: }
6152: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6153: $datatable .= '<tr'.$css_class.'>'.
6154: '<td><span class="LC_nobreak">'.
6155: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6156: for (my $k=0; $k<=$maxnum; $k++) {
6157: my $vpos = $k+1;
6158: my $selstr;
6159: if ($k == $i) {
6160: $selstr = ' selected="selected" ';
6161: }
6162: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6163: }
6164: my ($checkedon,$checkedoff);
6165: $checkedoff = ' checked="checked"';
6166: if ($guestok) {
6167: $checkedon = $checkedoff;
6168: $checkedoff = '';
6169: }
6170: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6171: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6172: &mt('delete').'</span></td>'.
6173: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
6174: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
6175: '</span></td>'.
6176: '<td class="LC_right_item"><span class="LC_nobreak">'.
6177: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
6178: &mt('Yes').'</label>'.(' 'x2).
6179: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
6180: &mt('No').'</label></span></td></tr>';
6181: }
6182: $css_class = $rownum%2?' class="LC_odd_row"':'';
6183: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6184: $datatable .= '<tr '.$css_class.'>'.
6185: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6186: for (my $k=0; $k<=$maxnum; $k++) {
6187: my $vpos = $k+1;
6188: my $selstr;
6189: if ($k == $maxnum) {
6190: $selstr = ' selected="selected" ';
6191: }
6192: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6193: }
6194: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 6195: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 6196: ' '.&mt('(new)').
6197: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
6198: &mt('Name displayed:').
6199: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6200: '<td class="LC_right_item"><span class="LC_nobreak">'.
6201: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
6202: &mt('Yes').'</label>'.(' 'x2).
6203: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
6204: &mt('No').'</label></span></td></tr>';
6205: '</tr>'."\n";
6206: $rownum ++;
1.141 raeburn 6207: }
1.43 raeburn 6208: }
6209: }
6210: $$rowtotal += $rownum;
6211: return $datatable;
6212: }
6213:
1.168 raeburn 6214: sub get_languages_hash {
6215: my %langchoices;
6216: foreach my $id (&Apache::loncommon::languageids()) {
6217: my $code = &Apache::loncommon::supportedlanguagecode($id);
6218: if ($code ne '') {
6219: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6220: }
6221: }
6222: return %langchoices;
6223: }
6224:
1.43 raeburn 6225: sub defaults_titles {
1.141 raeburn 6226: my ($dom) = @_;
1.43 raeburn 6227: my %titles = &Apache::lonlocal::texthash (
6228: 'auth_def' => 'Default authentication type',
6229: 'auth_arg_def' => 'Default authentication argument',
6230: 'lang_def' => 'Default language',
1.54 raeburn 6231: 'timezone_def' => 'Default timezone',
1.68 raeburn 6232: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6233: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 6234: );
1.141 raeburn 6235: if ($dom) {
6236: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6237: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6238: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6239: $protocol = 'http' if ($protocol ne 'https');
6240: if ($uint_dom) {
6241: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6242: $uint_dom);
6243: }
6244: }
1.43 raeburn 6245: return (\%titles);
6246: }
6247:
1.46 raeburn 6248: sub print_scantronformat {
6249: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6250: my $itemcount = 1;
1.60 raeburn 6251: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6252: %confhash);
1.46 raeburn 6253: my $switchserver = &check_switchserver($dom,$confname);
6254: my %lt = &Apache::lonlocal::texthash (
1.95 www 6255: default => 'Default bubblesheet format file error',
6256: custom => 'Custom bubblesheet format file error',
1.46 raeburn 6257: );
6258: my %scantronfiles = (
6259: default => 'default.tab',
6260: custom => 'custom.tab',
6261: );
6262: foreach my $key (keys(%scantronfiles)) {
6263: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6264: .$scantronfiles{$key};
6265: }
6266: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6267: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6268: if (!$switchserver) {
6269: my $servadm = $r->dir_config('lonAdmEMail');
6270: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6271: if ($configuserok eq 'ok') {
6272: if ($author_ok eq 'ok') {
6273: my %legacyfile = (
6274: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6275: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
6276: );
6277: my %md5chk;
6278: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6279: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6280: chomp($md5chk{$type});
1.46 raeburn 6281: }
6282: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6283: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6284: ($scantronurls{$type},my $error) =
1.46 raeburn 6285: &legacy_scantronformat($r,$dom,$confname,
6286: $type,$legacyfile{$type},
6287: $scantronurls{$type},
6288: $scantronfiles{$type});
1.60 raeburn 6289: if ($error ne '') {
6290: $error{$type} = $error;
6291: }
6292: }
6293: if (keys(%error) == 0) {
6294: $is_custom = 1;
6295: $confhash{'scantron'}{'scantronformat'} =
6296: $scantronurls{'custom'};
6297: my $putresult =
6298: &Apache::lonnet::put_dom('configuration',
6299: \%confhash,$dom);
6300: if ($putresult ne 'ok') {
6301: $error{'custom'} =
6302: '<span class="LC_error">'.
6303: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6304: }
1.46 raeburn 6305: }
6306: } else {
1.60 raeburn 6307: ($scantronurls{'default'},my $error) =
1.46 raeburn 6308: &legacy_scantronformat($r,$dom,$confname,
6309: 'default',$legacyfile{'default'},
6310: $scantronurls{'default'},
6311: $scantronfiles{'default'});
1.60 raeburn 6312: if ($error eq '') {
6313: $confhash{'scantron'}{'scantronformat'} = '';
6314: my $putresult =
6315: &Apache::lonnet::put_dom('configuration',
6316: \%confhash,$dom);
6317: if ($putresult ne 'ok') {
6318: $error{'default'} =
6319: '<span class="LC_error">'.
6320: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6321: }
6322: } else {
6323: $error{'default'} = $error;
6324: }
1.46 raeburn 6325: }
6326: }
6327: }
6328: } else {
1.95 www 6329: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 6330: }
6331: }
6332: if (ref($settings) eq 'HASH') {
6333: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6334: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
6335: if ((!@info) || ($info[0] eq 'no_such_dir')) {
6336: $scantronurl = '';
6337: } else {
6338: $scantronurl = $settings->{'scantronformat'};
6339: }
6340: $is_custom = 1;
6341: } else {
6342: $scantronurl = $scantronurls{'default'};
6343: }
6344: } else {
1.60 raeburn 6345: if ($is_custom) {
6346: $scantronurl = $scantronurls{'custom'};
6347: } else {
6348: $scantronurl = $scantronurls{'default'};
6349: }
1.46 raeburn 6350: }
6351: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6352: $datatable .= '<tr'.$css_class.'>';
6353: if (!$is_custom) {
1.65 raeburn 6354: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6355: '<span class="LC_nobreak">';
1.46 raeburn 6356: if ($scantronurl) {
1.199 raeburn 6357: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6358: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 6359: } else {
6360: $datatable = &mt('File unavailable for display');
6361: }
1.65 raeburn 6362: $datatable .= '</span></td>';
1.60 raeburn 6363: if (keys(%error) == 0) {
6364: $datatable .= '<td valign="bottom">';
6365: if (!$switchserver) {
6366: $datatable .= &mt('Upload:').'<br />';
6367: }
6368: } else {
6369: my $errorstr;
6370: foreach my $key (sort(keys(%error))) {
6371: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6372: }
6373: $datatable .= '<td>'.$errorstr;
6374: }
1.46 raeburn 6375: } else {
6376: if (keys(%error) > 0) {
6377: my $errorstr;
6378: foreach my $key (sort(keys(%error))) {
6379: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6380: }
1.60 raeburn 6381: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 6382: } elsif ($scantronurl) {
1.199 raeburn 6383: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
6384: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 6385: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 6386: $link.
6387: '<label><input type="checkbox" name="scantronformat_del"'.
6388: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 6389: '<td><span class="LC_nobreak"> '.
6390: &mt('Replace:').'</span><br />';
1.46 raeburn 6391: }
6392: }
6393: if (keys(%error) == 0) {
6394: if ($switchserver) {
6395: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6396: } else {
1.65 raeburn 6397: $datatable .='<span class="LC_nobreak"> '.
6398: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 6399: }
6400: }
6401: $datatable .= '</td></tr>';
6402: $$rowtotal ++;
6403: return $datatable;
6404: }
6405:
6406: sub legacy_scantronformat {
6407: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6408: my ($url,$error);
6409: my @statinfo = &Apache::lonnet::stat_file($newurl);
6410: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6411: (my $result,$url) =
6412: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6413: '','',$newfile);
6414: if ($result ne 'ok') {
1.130 raeburn 6415: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 6416: }
6417: }
6418: return ($url,$error);
6419: }
1.43 raeburn 6420:
1.49 raeburn 6421: sub print_coursecategories {
1.57 raeburn 6422: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6423: my $datatable;
6424: if ($position eq 'top') {
1.238 raeburn 6425: my (%checked);
6426: my @catitems = ('unauth','auth');
6427: my @cattypes = ('std','domonly','codesrch','none');
6428: $checked{'unauth'} = 'std';
6429: $checked{'auth'} = 'std';
6430: if (ref($settings) eq 'HASH') {
6431: foreach my $type (@cattypes) {
6432: if ($type eq $settings->{'unauth'}) {
6433: $checked{'unauth'} = $type;
6434: }
6435: if ($type eq $settings->{'auth'}) {
6436: $checked{'auth'} = $type;
6437: }
6438: }
6439: }
6440: my %lt = &Apache::lonlocal::texthash (
6441: unauth => 'Catalog type for unauthenticated users',
6442: auth => 'Catalog type for authenticated users',
6443: none => 'No catalog',
6444: std => 'Standard catalog',
6445: domonly => 'Domain-only catalog',
6446: codesrch => "Code search form",
6447: );
6448: my $itemcount = 0;
6449: foreach my $item (@catitems) {
6450: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6451: $datatable .= '<tr '.$css_class.'>'.
6452: '<td>'.$lt{$item}.'</td>'.
6453: '<td class="LC_right_item"><span class="LC_nobreak">';
6454: foreach my $type (@cattypes) {
6455: my $ischecked;
6456: if ($checked{$item} eq $type) {
6457: $ischecked=' checked="checked"';
6458: }
6459: $datatable .= '<label>'.
6460: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6461: ' />'.$lt{$type}.'</label> ';
6462: }
6463: $datatable .= '</td></tr>';
6464: $itemcount ++;
6465: }
6466: $$rowtotal += $itemcount;
6467: } elsif ($position eq 'middle') {
1.57 raeburn 6468: my $toggle_cats_crs = ' ';
6469: my $toggle_cats_dom = ' checked="checked" ';
6470: my $can_cat_crs = ' ';
6471: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 6472: my $toggle_catscomm_comm = ' ';
6473: my $toggle_catscomm_dom = ' checked="checked" ';
6474: my $can_catcomm_comm = ' ';
6475: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 6476: my $toggle_catsplace_place = ' ';
6477: my $toggle_catsplace_dom = ' checked="checked" ';
6478: my $can_catplace_place = ' ';
6479: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 6480:
1.57 raeburn 6481: if (ref($settings) eq 'HASH') {
6482: if ($settings->{'togglecats'} eq 'crs') {
6483: $toggle_cats_crs = $toggle_cats_dom;
6484: $toggle_cats_dom = ' ';
6485: }
6486: if ($settings->{'categorize'} eq 'crs') {
6487: $can_cat_crs = $can_cat_dom;
6488: $can_cat_dom = ' ';
6489: }
1.120 raeburn 6490: if ($settings->{'togglecatscomm'} eq 'comm') {
6491: $toggle_catscomm_comm = $toggle_catscomm_dom;
6492: $toggle_catscomm_dom = ' ';
6493: }
6494: if ($settings->{'categorizecomm'} eq 'comm') {
6495: $can_catcomm_comm = $can_catcomm_dom;
6496: $can_catcomm_dom = ' ';
6497: }
1.272 raeburn 6498: if ($settings->{'togglecatsplace'} eq 'place') {
6499: $toggle_catsplace_place = $toggle_catsplace_dom;
6500: $toggle_catsplace_dom = ' ';
6501: }
6502: if ($settings->{'categorizeplace'} eq 'place') {
6503: $can_catplace_place = $can_catplace_dom;
6504: $can_catplace_dom = ' ';
6505: }
1.57 raeburn 6506: }
6507: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 6508: togglecats => 'Show/Hide a course in catalog',
6509: togglecatscomm => 'Show/Hide a community in catalog',
6510: togglecatsplace => 'Show/Hide a placement test in catalog',
6511: categorize => 'Assign a category to a course',
6512: categorizecomm => 'Assign a category to a community',
6513: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 6514: );
6515: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 6516: dom => 'Set in Domain',
6517: crs => 'Set in Course',
6518: comm => 'Set in Community',
6519: place => 'Set in Placement Test',
1.57 raeburn 6520: );
6521: $datatable = '<tr class="LC_odd_row">'.
6522: '<td>'.$title{'togglecats'}.'</td>'.
6523: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6524: '<input type="radio" name="togglecats"'.
6525: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6526: '<label><input type="radio" name="togglecats"'.
6527: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
6528: '</tr><tr>'.
6529: '<td>'.$title{'categorize'}.'</td>'.
6530: '<td class="LC_right_item"><span class="LC_nobreak">'.
6531: '<label><input type="radio" name="categorize"'.
6532: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6533: '<label><input type="radio" name="categorize"'.
6534: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 6535: '</tr><tr class="LC_odd_row">'.
6536: '<td>'.$title{'togglecatscomm'}.'</td>'.
6537: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6538: '<input type="radio" name="togglecatscomm"'.
6539: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6540: '<label><input type="radio" name="togglecatscomm"'.
6541: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
6542: '</tr><tr>'.
6543: '<td>'.$title{'categorizecomm'}.'</td>'.
6544: '<td class="LC_right_item"><span class="LC_nobreak">'.
6545: '<label><input type="radio" name="categorizecomm"'.
6546: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6547: '<label><input type="radio" name="categorizecomm"'.
6548: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 6549: '</tr><tr>'.
6550: '<td>'.$title{'togglecatsplace'}.'</td>'.
6551: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6552: '<input type="radio" name="togglecatsplace"'.
6553: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6554: '<label><input type="radio" name="togglecatscomm"'.
6555: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
6556: '</tr><tr>'.
6557: '<td>'.$title{'categorizeplace'}.'</td>'.
6558: '<td class="LC_right_item"><span class="LC_nobreak">'.
6559: '<label><input type="radio" name="categorizeplace"'.
6560: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6561: '<label><input type="radio" name="categorizeplace"'.
6562: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 6563: '</tr>';
1.272 raeburn 6564: $$rowtotal += 6;
1.57 raeburn 6565: } else {
6566: my $css_class;
6567: my $itemcount = 1;
6568: my $cathash;
6569: if (ref($settings) eq 'HASH') {
6570: $cathash = $settings->{'cats'};
6571: }
6572: if (ref($cathash) eq 'HASH') {
6573: my (@cats,@trails,%allitems,%idx,@jsarray);
6574: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
6575: \%allitems,\%idx,\@jsarray);
6576: my $maxdepth = scalar(@cats);
6577: my $colattrib = '';
6578: if ($maxdepth > 2) {
6579: $colattrib = ' colspan="2" ';
6580: }
6581: my @path;
6582: if (@cats > 0) {
6583: if (ref($cats[0]) eq 'ARRAY') {
6584: my $numtop = @{$cats[0]};
6585: my $maxnum = $numtop;
1.120 raeburn 6586: my %default_names = (
6587: instcode => &mt('Official courses'),
6588: communities => &mt('Communities'),
1.272 raeburn 6589: placement => &mt('Placement Tests'),
1.120 raeburn 6590: );
6591:
6592: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6593: ($cathash->{'instcode::0'} eq '') ||
6594: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 6595: ($cathash->{'communities::0'} eq '') ||
6596: (!grep(/^placement$/,@{$cats[0]})) ||
6597: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 6598: $maxnum ++;
6599: }
6600: my $lastidx;
6601: for (my $i=0; $i<$numtop; $i++) {
6602: my $parent = $cats[0][$i];
6603: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6604: my $item = &escape($parent).'::0';
6605: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6606: $lastidx = $idx{$item};
6607: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6608: .'<select name="'.$item.'"'.$chgstr.'>';
6609: for (my $k=0; $k<=$maxnum; $k++) {
6610: my $vpos = $k+1;
6611: my $selstr;
6612: if ($k == $i) {
6613: $selstr = ' selected="selected" ';
6614: }
6615: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6616: }
1.214 raeburn 6617: $datatable .= '</select></span></td><td>';
1.272 raeburn 6618: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 6619: $datatable .= '<span class="LC_nobreak">'
6620: .$default_names{$parent}.'</span>';
6621: if ($parent eq 'instcode') {
6622: $datatable .= '<br /><span class="LC_nobreak">('
6623: .&mt('with institutional codes')
6624: .')</span></td><td'.$colattrib.'>';
6625: } else {
6626: $datatable .= '<table><tr><td>';
6627: }
6628: $datatable .= '<span class="LC_nobreak">'
6629: .'<label><input type="radio" name="'
6630: .$parent.'" value="1" checked="checked" />'
6631: .&mt('Display').'</label>';
6632: if ($parent eq 'instcode') {
6633: $datatable .= ' ';
6634: } else {
6635: $datatable .= '</span></td></tr><tr><td>'
6636: .'<span class="LC_nobreak">';
6637: }
6638: $datatable .= '<label><input type="radio" name="'
6639: .$parent.'" value="0" />'
6640: .&mt('Do not display').'</label></span>';
1.272 raeburn 6641: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 6642: $datatable .= '</td></tr></table>';
6643: }
6644: $datatable .= '</td>';
1.57 raeburn 6645: } else {
6646: $datatable .= $parent
1.214 raeburn 6647: .' <span class="LC_nobreak"><label>'
6648: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6649: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6650: }
6651: my $depth = 1;
6652: push(@path,$parent);
6653: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6654: pop(@path);
6655: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6656: $itemcount ++;
6657: }
1.48 raeburn 6658: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6659: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6660: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6661: for (my $k=0; $k<=$maxnum; $k++) {
6662: my $vpos = $k+1;
6663: my $selstr;
1.57 raeburn 6664: if ($k == $numtop) {
1.48 raeburn 6665: $selstr = ' selected="selected" ';
6666: }
6667: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6668: }
1.59 bisitz 6669: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6670: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6671: .'</tr>'."\n";
1.48 raeburn 6672: $itemcount ++;
1.272 raeburn 6673: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6674: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6675: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6676: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6677: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6678: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6679: for (my $k=0; $k<=$maxnum; $k++) {
6680: my $vpos = $k+1;
6681: my $selstr;
6682: if ($k == $maxnum) {
6683: $selstr = ' selected="selected" ';
6684: }
6685: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6686: }
1.120 raeburn 6687: $datatable .= '</select></span></td>'.
6688: '<td><span class="LC_nobreak">'.
6689: $default_names{$default}.'</span>';
6690: if ($default eq 'instcode') {
6691: $datatable .= '<br /><span class="LC_nobreak">('
6692: .&mt('with institutional codes').')</span>';
6693: }
6694: $datatable .= '</td>'
6695: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6696: .&mt('Display').'</label> '
6697: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6698: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6699: }
6700: }
6701: }
1.57 raeburn 6702: } else {
6703: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6704: }
6705: } else {
1.238 raeburn 6706: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6707: .&initialize_categories($itemcount);
1.48 raeburn 6708: }
1.57 raeburn 6709: $$rowtotal += $itemcount;
1.48 raeburn 6710: }
6711: return $datatable;
6712: }
6713:
1.69 raeburn 6714: sub print_serverstatuses {
6715: my ($dom,$settings,$rowtotal) = @_;
6716: my $datatable;
6717: my @pages = &serverstatus_pages();
6718: my (%namedaccess,%machineaccess);
6719: foreach my $type (@pages) {
6720: $namedaccess{$type} = '';
6721: $machineaccess{$type}= '';
6722: }
6723: if (ref($settings) eq 'HASH') {
6724: foreach my $type (@pages) {
6725: if (exists($settings->{$type})) {
6726: if (ref($settings->{$type}) eq 'HASH') {
6727: foreach my $key (keys(%{$settings->{$type}})) {
6728: if ($key eq 'namedusers') {
6729: $namedaccess{$type} = $settings->{$type}->{$key};
6730: } elsif ($key eq 'machines') {
6731: $machineaccess{$type} = $settings->{$type}->{$key};
6732: }
6733: }
6734: }
6735: }
6736: }
6737: }
1.81 raeburn 6738: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6739: my $rownum = 0;
6740: my $css_class;
6741: foreach my $type (@pages) {
6742: $rownum ++;
6743: $css_class = $rownum%2?' class="LC_odd_row"':'';
6744: $datatable .= '<tr'.$css_class.'>'.
6745: '<td><span class="LC_nobreak">'.
6746: $titles->{$type}.'</span></td>'.
6747: '<td class="LC_left_item">'.
6748: '<input type="text" name="'.$type.'_namedusers" '.
6749: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6750: '<td class="LC_right_item">'.
6751: '<span class="LC_nobreak">'.
6752: '<input type="text" name="'.$type.'_machines" '.
6753: 'value="'.$machineaccess{$type}.'" size="10" />'.
6754: '</td></tr>'."\n";
6755: }
6756: $$rowtotal += $rownum;
6757: return $datatable;
6758: }
6759:
6760: sub serverstatus_pages {
6761: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 6762: 'checksums','clusterstatus','certstatus','metadata_keywords',
6763: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
6764: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6765: }
6766:
1.236 raeburn 6767: sub defaults_javascript {
6768: my ($settings) = @_;
1.248 raeburn 6769: return unless (ref($settings) eq 'HASH');
1.236 raeburn 6770: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6771: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6772: if ($maxnum eq '') {
6773: $maxnum = 0;
6774: }
6775: $maxnum ++;
1.249 raeburn 6776: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 6777: return <<"ENDSCRIPT";
6778: <script type="text/javascript">
6779: // <![CDATA[
6780: function reorderTypes(form,caller) {
6781: var changedVal;
6782: $jstext
6783: var newpos = 'addinststatus_pos';
6784: var current = new Array;
6785: var maxh = $maxnum;
6786: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6787: var oldVal;
6788: if (caller == newpos) {
6789: changedVal = newitemVal;
6790: } else {
6791: var curritem = 'inststatus_pos_'+caller;
6792: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6793: current[newitemVal] = newpos;
6794: }
6795: for (var i=0; i<inststatuses.length; i++) {
6796: if (inststatuses[i] != caller) {
6797: var elementName = 'inststatus_pos_'+inststatuses[i];
6798: if (form.elements[elementName]) {
6799: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6800: current[currVal] = elementName;
6801: }
6802: }
6803: }
6804: for (var j=0; j<maxh; j++) {
6805: if (current[j] == undefined) {
6806: oldVal = j;
6807: }
6808: }
6809: if (oldVal < changedVal) {
6810: for (var k=oldVal+1; k<=changedVal ; k++) {
6811: var elementName = current[k];
6812: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6813: }
6814: } else {
6815: for (var k=changedVal; k<oldVal; k++) {
6816: var elementName = current[k];
6817: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6818: }
6819: }
6820: return;
6821: }
6822:
6823: // ]]>
6824: </script>
6825:
6826: ENDSCRIPT
6827: }
6828: }
6829:
1.49 raeburn 6830: sub coursecategories_javascript {
6831: my ($settings) = @_;
1.57 raeburn 6832: my ($output,$jstext,$cathash);
1.49 raeburn 6833: if (ref($settings) eq 'HASH') {
1.57 raeburn 6834: $cathash = $settings->{'cats'};
6835: }
6836: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6837: my (@cats,@jsarray,%idx);
1.57 raeburn 6838: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6839: if (@jsarray > 0) {
6840: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6841: for (my $i=0; $i<@jsarray; $i++) {
6842: if (ref($jsarray[$i]) eq 'ARRAY') {
6843: my $catstr = join('","',@{$jsarray[$i]});
6844: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6845: }
6846: }
6847: }
6848: } else {
6849: $jstext = ' var categories = Array(1);'."\n".
6850: ' categories[0] = Array("instcode_pos");'."\n";
6851: }
1.237 bisitz 6852: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6853: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 6854: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 6855: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6856: &js_escape(\$instcode_reserved);
6857: &js_escape(\$communities_reserved);
1.272 raeburn 6858: &js_escape(\$placement_reserved);
1.265 damieng 6859: &js_escape(\$choose_again);
1.49 raeburn 6860: $output = <<"ENDSCRIPT";
6861: <script type="text/javascript">
1.109 raeburn 6862: // <![CDATA[
1.49 raeburn 6863: function reorderCats(form,parent,item,idx) {
6864: var changedVal;
6865: $jstext
6866: var newpos = 'addcategory_pos';
6867: if (parent == '') {
6868: var has_instcode = 0;
6869: var maxtop = categories[idx].length;
6870: for (var j=0; j<maxtop; j++) {
6871: if (categories[idx][j] == 'instcode::0') {
6872: has_instcode == 1;
6873: }
6874: }
6875: if (has_instcode == 0) {
6876: categories[idx][maxtop] = 'instcode_pos';
6877: }
6878: } else {
6879: newpos += '_'+parent;
6880: }
6881: var maxh = 1 + categories[idx].length;
6882: var current = new Array;
6883: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6884: if (item == newpos) {
6885: changedVal = newitemVal;
6886: } else {
6887: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6888: current[newitemVal] = newpos;
6889: }
6890: for (var i=0; i<categories[idx].length; i++) {
6891: var elementName = categories[idx][i];
6892: if (elementName != item) {
6893: if (form.elements[elementName]) {
6894: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6895: current[currVal] = elementName;
6896: }
6897: }
6898: }
6899: var oldVal;
6900: for (var j=0; j<maxh; j++) {
6901: if (current[j] == undefined) {
6902: oldVal = j;
6903: }
6904: }
6905: if (oldVal < changedVal) {
6906: for (var k=oldVal+1; k<=changedVal ; k++) {
6907: var elementName = current[k];
6908: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6909: }
6910: } else {
6911: for (var k=changedVal; k<oldVal; k++) {
6912: var elementName = current[k];
6913: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6914: }
6915: }
6916: return;
6917: }
1.120 raeburn 6918:
6919: function categoryCheck(form) {
6920: if (form.elements['addcategory_name'].value == 'instcode') {
6921: alert('$instcode_reserved\\n$choose_again');
6922: return false;
6923: }
6924: if (form.elements['addcategory_name'].value == 'communities') {
6925: alert('$communities_reserved\\n$choose_again');
6926: return false;
6927: }
1.272 raeburn 6928: if (form.elements['addcategory_name'].value == 'placement') {
6929: alert('$placement_reserved\\n$choose_again');
6930: return false;
6931: }
1.120 raeburn 6932: return true;
6933: }
6934:
1.109 raeburn 6935: // ]]>
1.49 raeburn 6936: </script>
6937:
6938: ENDSCRIPT
6939: return $output;
6940: }
6941:
1.48 raeburn 6942: sub initialize_categories {
6943: my ($itemcount) = @_;
1.120 raeburn 6944: my ($datatable,$css_class,$chgstr);
6945: my %default_names = (
6946: instcode => 'Official courses (with institutional codes)',
6947: communities => 'Communities',
1.272 raeburn 6948: placement => 'Placement Tests',
1.120 raeburn 6949: );
6950: my $select0 = ' selected="selected"';
6951: my $select1 = '';
1.272 raeburn 6952: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6953: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6954: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 6955: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 6956: $select1 = $select0;
6957: $select0 = '';
6958: }
6959: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6960: .'<select name="'.$default.'_pos">'
6961: .'<option value="0"'.$select0.'>1</option>'
6962: .'<option value="1"'.$select1.'>2</option>'
6963: .'<option value="2">3</option></select> '
6964: .$default_names{$default}
6965: .'</span></td><td><span class="LC_nobreak">'
6966: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6967: .&mt('Display').'</label> <label>'
6968: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6969: .'</label></span></td></tr>';
1.120 raeburn 6970: $itemcount ++;
6971: }
1.48 raeburn 6972: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6973: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6974: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6975: .'<select name="addcategory_pos"'.$chgstr.'>'
6976: .'<option value="0">1</option>'
6977: .'<option value="1">2</option>'
6978: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 6979: .&mt('Add category').'</td><td>'.&mt('Name:')
6980: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
6981: return $datatable;
6982: }
6983:
6984: sub build_category_rows {
1.49 raeburn 6985: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6986: my ($text,$name,$item,$chgstr);
1.48 raeburn 6987: if (ref($cats) eq 'ARRAY') {
6988: my $maxdepth = scalar(@{$cats});
6989: if (ref($cats->[$depth]) eq 'HASH') {
6990: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6991: my $numchildren = @{$cats->[$depth]{$parent}};
6992: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 6993: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6994: my ($idxnum,$parent_name,$parent_item);
6995: my $higher = $depth - 1;
6996: if ($higher == 0) {
6997: $parent_name = &escape($parent).'::'.$higher;
6998: } else {
6999: if (ref($path) eq 'ARRAY') {
7000: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7001: }
7002: }
7003: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 7004: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 7005: if ($j < $numchildren) {
1.48 raeburn 7006: $name = $cats->[$depth]{$parent}[$j];
7007: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 7008: $idxnum = $idx->{$item};
7009: } else {
7010: $name = $parent_name;
7011: $item = $parent_item;
1.48 raeburn 7012: }
1.49 raeburn 7013: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
7014: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 7015: for (my $i=0; $i<=$numchildren; $i++) {
7016: my $vpos = $i+1;
7017: my $selstr;
7018: if ($j == $i) {
7019: $selstr = ' selected="selected" ';
7020: }
7021: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
7022: }
7023: $text .= '</select> ';
7024: if ($j < $numchildren) {
7025: my $deeper = $depth+1;
7026: $text .= $name.' '
7027: .'<label><input type="checkbox" name="deletecategory" value="'
7028: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
7029: if(ref($path) eq 'ARRAY') {
7030: push(@{$path},$name);
1.49 raeburn 7031: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 7032: pop(@{$path});
7033: }
7034: } else {
1.59 bisitz 7035: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 7036: if ($j == $numchildren) {
7037: $text .= $name;
7038: } else {
7039: $text .= $item;
7040: }
7041: $text .= '" value="" />';
7042: }
7043: $text .= '</td></tr>';
7044: }
7045: $text .= '</table></td>';
7046: } else {
7047: my $higher = $depth-1;
7048: if ($higher == 0) {
7049: $name = &escape($parent).'::'.$higher;
7050: } else {
7051: if (ref($path) eq 'ARRAY') {
7052: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7053: }
7054: }
7055: my $colspan;
7056: if ($parent ne 'instcode') {
7057: $colspan = $maxdepth - $depth - 1;
7058: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
7059: }
7060: }
7061: }
7062: }
7063: return $text;
7064: }
7065:
1.33 raeburn 7066: sub modifiable_userdata_row {
1.228 raeburn 7067: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
7068: my ($role,$rolename,$statustype);
7069: $role = $item;
1.224 raeburn 7070: if ($context eq 'cancreate') {
1.228 raeburn 7071: if ($item =~ /^emailusername_(.+)$/) {
7072: $statustype = $1;
7073: $role = 'emailusername';
7074: if (ref($usertypes) eq 'HASH') {
7075: if ($usertypes->{$statustype}) {
7076: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7077: } else {
7078: $rolename = &mt('Data provided by user');
7079: }
7080: }
1.224 raeburn 7081: }
7082: } elsif ($context eq 'selfcreate') {
1.63 raeburn 7083: if (ref($usertypes) eq 'HASH') {
7084: $rolename = $usertypes->{$role};
7085: } else {
7086: $rolename = $role;
7087: }
1.33 raeburn 7088: } else {
1.63 raeburn 7089: if ($role eq 'cr') {
7090: $rolename = &mt('Custom role');
7091: } else {
7092: $rolename = &Apache::lonnet::plaintext($role);
7093: }
1.33 raeburn 7094: }
1.224 raeburn 7095: my (@fields,%fieldtitles);
7096: if (ref($fieldsref) eq 'ARRAY') {
7097: @fields = @{$fieldsref};
7098: } else {
7099: @fields = ('lastname','firstname','middlename','generation',
7100: 'permanentemail','id');
7101: }
7102: if ((ref($titlesref) eq 'HASH')) {
7103: %fieldtitles = %{$titlesref};
7104: } else {
7105: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7106: }
1.33 raeburn 7107: my $output;
7108: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7109: $output = '<tr '.$css_class.'>'.
7110: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7111: '<td class="LC_left_item" colspan="2"><table>';
7112: my $rem;
7113: my %checks;
7114: if (ref($settings) eq 'HASH') {
7115: if (ref($settings->{$context}) eq 'HASH') {
7116: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 7117: my $hashref = $settings->{$context}->{$role};
7118: if ($role eq 'emailusername') {
7119: if ($statustype) {
7120: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7121: $hashref = $settings->{$context}->{$role}->{$statustype};
7122: if (ref($hashref) eq 'HASH') {
7123: foreach my $field (@fields) {
7124: if ($hashref->{$field}) {
7125: $checks{$field} = $hashref->{$field};
7126: }
7127: }
7128: }
7129: }
7130: }
7131: } else {
7132: if (ref($hashref) eq 'HASH') {
7133: foreach my $field (@fields) {
7134: if ($hashref->{$field}) {
7135: $checks{$field} = ' checked="checked" ';
7136: }
7137: }
1.33 raeburn 7138: }
7139: }
7140: }
7141: }
7142: }
1.228 raeburn 7143:
1.33 raeburn 7144: for (my $i=0; $i<@fields; $i++) {
7145: my $rem = $i%($numinrow);
7146: if ($rem == 0) {
7147: if ($i > 0) {
7148: $output .= '</tr>';
7149: }
7150: $output .= '<tr>';
7151: }
7152: my $check = ' ';
1.228 raeburn 7153: unless ($role eq 'emailusername') {
7154: if (exists($checks{$fields[$i]})) {
7155: $check = $checks{$fields[$i]}
7156: } else {
7157: if ($role eq 'st') {
7158: if (ref($settings) ne 'HASH') {
7159: $check = ' checked="checked" ';
7160: }
1.33 raeburn 7161: }
7162: }
7163: }
7164: $output .= '<td class="LC_left_item">'.
1.228 raeburn 7165: '<span class="LC_nobreak">';
7166: if ($role eq 'emailusername') {
7167: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7168: $checks{$fields[$i]} = 'omit';
7169: }
7170: foreach my $option ('required','optional','omit') {
7171: my $checked='';
7172: if ($checks{$fields[$i]} eq $option) {
7173: $checked='checked="checked" ';
7174: }
7175: $output .= '<label>'.
7176: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7177: &mt($option).'</label>'.(' ' x2);
7178: }
7179: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7180: } else {
7181: $output .= '<label>'.
7182: '<input type="checkbox" name="canmodify_'.$role.'" '.
7183: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7184: '</label>';
7185: }
7186: $output .= '</span></td>';
1.33 raeburn 7187: $rem = @fields%($numinrow);
7188: }
7189: my $colsleft = $numinrow - $rem;
7190: if ($colsleft > 1 ) {
7191: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7192: ' </td>';
7193: } elsif ($colsleft == 1) {
7194: $output .= '<td class="LC_left_item"> </td>';
7195: }
7196: $output .= '</tr></table></td></tr>';
7197: return $output;
7198: }
1.28 raeburn 7199:
1.93 raeburn 7200: sub insttypes_row {
1.224 raeburn 7201: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 7202: my %lt = &Apache::lonlocal::texthash (
7203: cansearch => 'Users allowed to search',
7204: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 7205: lockablenames => 'User preference to lock name',
1.93 raeburn 7206: );
7207: my $showdom;
7208: if ($context eq 'cansearch') {
7209: $showdom = ' ('.$dom.')';
7210: }
1.165 raeburn 7211: my $class = 'LC_left_item';
7212: if ($context eq 'statustocreate') {
7213: $class = 'LC_right_item';
7214: }
1.224 raeburn 7215: my $css_class = ' class="LC_odd_row"';
7216: if ($rownum ne '') {
7217: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
7218: }
7219: my $output = '<tr'.$css_class.'>'.
7220: '<td>'.$lt{$context}.$showdom.
7221: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7222: my $rem;
7223: if (ref($types) eq 'ARRAY') {
7224: for (my $i=0; $i<@{$types}; $i++) {
7225: if (defined($usertypes->{$types->[$i]})) {
7226: my $rem = $i%($numinrow);
7227: if ($rem == 0) {
7228: if ($i > 0) {
7229: $output .= '</tr>';
7230: }
7231: $output .= '<tr>';
1.23 raeburn 7232: }
1.26 raeburn 7233: my $check = ' ';
1.99 raeburn 7234: if (ref($settings) eq 'HASH') {
7235: if (ref($settings->{$context}) eq 'ARRAY') {
7236: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7237: $check = ' checked="checked" ';
7238: }
7239: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7240: $check = ' checked="checked" ';
7241: }
1.23 raeburn 7242: }
1.26 raeburn 7243: $output .= '<td class="LC_left_item">'.
7244: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7245: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 7246: 'value="'.$types->[$i].'"'.$check.'/>'.
7247: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7248: }
7249: }
1.26 raeburn 7250: $rem = @{$types}%($numinrow);
1.23 raeburn 7251: }
7252: my $colsleft = $numinrow - $rem;
1.131 raeburn 7253: if (($rem == 0) && (@{$types} > 0)) {
7254: $output .= '<tr>';
7255: }
1.23 raeburn 7256: if ($colsleft > 1) {
1.25 raeburn 7257: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 7258: } else {
1.25 raeburn 7259: $output .= '<td class="LC_left_item">';
1.23 raeburn 7260: }
7261: my $defcheck = ' ';
1.99 raeburn 7262: if (ref($settings) eq 'HASH') {
7263: if (ref($settings->{$context}) eq 'ARRAY') {
7264: if (grep(/^default$/,@{$settings->{$context}})) {
7265: $defcheck = ' checked="checked" ';
7266: }
7267: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7268: $defcheck = ' checked="checked" ';
7269: }
1.23 raeburn 7270: }
1.25 raeburn 7271: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 7272: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 7273: 'value="default"'.$defcheck.'/>'.
7274: $othertitle.'</label></span></td>'.
7275: '</tr></table></td></tr>';
7276: return $output;
1.23 raeburn 7277: }
7278:
7279: sub sorted_searchtitles {
7280: my %searchtitles = &Apache::lonlocal::texthash(
7281: 'uname' => 'username',
7282: 'lastname' => 'last name',
7283: 'lastfirst' => 'last name, first name',
7284: );
7285: my @titleorder = ('uname','lastname','lastfirst');
7286: return (\%searchtitles,\@titleorder);
7287: }
7288:
1.25 raeburn 7289: sub sorted_searchtypes {
7290: my %srchtypes_desc = (
7291: exact => 'is exact match',
7292: contains => 'contains ..',
7293: begins => 'begins with ..',
7294: );
7295: my @srchtypeorder = ('exact','begins','contains');
7296: return (\%srchtypes_desc,\@srchtypeorder);
7297: }
7298:
1.3 raeburn 7299: sub usertype_update_row {
7300: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7301: my $datatable;
7302: my $numinrow = 4;
7303: foreach my $type (@{$types}) {
7304: if (defined($usertypes->{$type})) {
7305: $$rownums ++;
7306: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7307: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7308: '</td><td class="LC_left_item"><table>';
7309: for (my $i=0; $i<@{$fields}; $i++) {
7310: my $rem = $i%($numinrow);
7311: if ($rem == 0) {
7312: if ($i > 0) {
7313: $datatable .= '</tr>';
7314: }
7315: $datatable .= '<tr>';
7316: }
7317: my $check = ' ';
1.39 raeburn 7318: if (ref($settings) eq 'HASH') {
7319: if (ref($settings->{'fields'}) eq 'HASH') {
7320: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7321: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7322: $check = ' checked="checked" ';
7323: }
1.3 raeburn 7324: }
7325: }
7326: }
7327:
7328: if ($i == @{$fields}-1) {
7329: my $colsleft = $numinrow - $rem;
7330: if ($colsleft > 1) {
7331: $datatable .= '<td colspan="'.$colsleft.'">';
7332: } else {
7333: $datatable .= '<td>';
7334: }
7335: } else {
7336: $datatable .= '<td>';
7337: }
1.8 raeburn 7338: $datatable .= '<span class="LC_nobreak"><label>'.
7339: '<input type="checkbox" name="updateable_'.$type.
7340: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7341: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 7342: }
7343: $datatable .= '</tr></table></td></tr>';
7344: }
7345: }
7346: return $datatable;
1.1 raeburn 7347: }
7348:
7349: sub modify_login {
1.205 raeburn 7350: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 7351: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7352: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7353: %title = ( coursecatalog => 'Display course catalog',
7354: adminmail => 'Display administrator E-mail address',
1.188 raeburn 7355: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 7356: newuser => 'Link for visitors to create a user account',
7357: loginheader => 'Log-in box header');
7358: @offon = ('off','on');
1.112 raeburn 7359: if (ref($domconfig{login}) eq 'HASH') {
7360: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7361: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7362: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7363: }
7364: }
7365: }
1.9 raeburn 7366: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7367: \%domconfig,\%loginhash);
1.188 raeburn 7368: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7369: foreach my $item (@toggles) {
7370: $loginhash{login}{$item} = $env{'form.'.$item};
7371: }
1.41 raeburn 7372: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 7373: if (ref($colchanges{'login'}) eq 'HASH') {
7374: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7375: \%loginhash);
7376: }
1.110 raeburn 7377:
1.149 raeburn 7378: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 7379: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 7380: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 7381: if (keys(%servers) > 1) {
7382: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 7383: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7384: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7385: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7386: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7387: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7388: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7389: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7390: $changes{'loginvia'}{$lonhost} = 1;
7391: } else {
7392: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7393: $changes{'loginvia'}{$lonhost} = 1;
7394: }
7395: } else {
7396: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7397: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7398: $changes{'loginvia'}{$lonhost} = 1;
7399: }
7400: }
7401: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7402: foreach my $item (@loginvia_attribs) {
7403: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7404: }
7405: } else {
7406: foreach my $item (@loginvia_attribs) {
7407: my $new = $env{'form.'.$lonhost.'_'.$item};
7408: if (($item eq 'serverpath') && ($new eq 'custom')) {
7409: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7410: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7411: $new = '/';
7412: }
7413: }
7414: if (($item eq 'custompath') &&
7415: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7416: $new = '';
7417: }
7418: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7419: $changes{'loginvia'}{$lonhost} = 1;
7420: }
7421: if ($item eq 'exempt') {
1.256 raeburn 7422: $new = &check_exempt_addresses($new);
1.128 raeburn 7423: }
7424: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7425: }
7426: }
1.112 raeburn 7427: } else {
1.128 raeburn 7428: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7429: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 7430: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 7431: foreach my $item (@loginvia_attribs) {
7432: my $new = $env{'form.'.$lonhost.'_'.$item};
7433: if (($item eq 'serverpath') && ($new eq 'custom')) {
7434: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7435: $new = '/';
7436: }
7437: }
7438: if (($item eq 'custompath') &&
7439: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7440: $new = '';
7441: }
7442: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7443: }
1.110 raeburn 7444: }
7445: }
7446: }
7447: }
1.119 raeburn 7448:
1.168 raeburn 7449: my $servadm = $r->dir_config('lonAdmEMail');
7450: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
7451: if (ref($domconfig{'login'}) eq 'HASH') {
7452: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
7453: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
7454: if ($lang eq 'nolang') {
7455: push(@currlangs,$lang);
7456: } elsif (defined($langchoices{$lang})) {
7457: push(@currlangs,$lang);
7458: } else {
7459: next;
7460: }
7461: }
7462: }
7463: }
7464: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
7465: if (@currlangs > 0) {
7466: foreach my $lang (@currlangs) {
7467: if (grep(/^\Q$lang\E$/,@delurls)) {
7468: $changes{'helpurl'}{$lang} = 1;
7469: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
7470: $changes{'helpurl'}{$lang} = 1;
7471: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
7472: push(@newlangs,$lang);
7473: } else {
7474: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7475: }
7476: }
7477: }
7478: unless (grep(/^nolang$/,@currlangs)) {
7479: if ($env{'form.loginhelpurl_nolang.filename'}) {
7480: $changes{'helpurl'}{'nolang'} = 1;
7481: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
7482: push(@newlangs,'nolang');
7483: }
7484: }
7485: if ($env{'form.loginhelpurl_add_lang'}) {
7486: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
7487: ($env{'form.loginhelpurl_add_file.filename'})) {
7488: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
7489: $addedfile = $env{'form.loginhelpurl_add_lang'};
7490: }
7491: }
7492: if ((@newlangs > 0) || ($addedfile)) {
7493: my $error;
7494: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7495: if ($configuserok eq 'ok') {
7496: if ($switchserver) {
7497: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7498: } elsif ($author_ok eq 'ok') {
7499: my @allnew = @newlangs;
7500: if ($addedfile ne '') {
7501: push(@allnew,$addedfile);
7502: }
7503: foreach my $lang (@allnew) {
7504: my $formelem = 'loginhelpurl_'.$lang;
7505: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
7506: $formelem = 'loginhelpurl_add_file';
7507: }
7508: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7509: "help/$lang",'','',$newfile{$lang});
7510: if ($result eq 'ok') {
7511: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
7512: $changes{'helpurl'}{$lang} = 1;
7513: } else {
7514: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
7515: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 7516: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 7517: (!grep(/^\Q$lang\E$/,@delurls))) {
7518: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7519: }
7520: }
7521: }
7522: } else {
7523: $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);
7524: }
7525: } else {
7526: $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);
7527: }
7528: if ($error) {
7529: &Apache::lonnet::logthis($error);
7530: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7531: }
7532: }
1.256 raeburn 7533:
7534: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
7535: if (ref($domconfig{'login'}) eq 'HASH') {
7536: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
7537: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
7538: if ($domservers{$lonhost}) {
7539: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7540: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 7541: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 7542: }
7543: }
7544: }
7545: }
7546: }
7547: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
7548: foreach my $lonhost (sort(keys(%domservers))) {
7549: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7550: $changes{'headtag'}{$lonhost} = 1;
7551: } else {
7552: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
7553: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
7554: }
7555: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
7556: push(@newhosts,$lonhost);
7557: } elsif ($currheadtagurls{$lonhost}) {
7558: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
7559: if ($currexempt{$lonhost}) {
7560: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
7561: $changes{'headtag'}{$lonhost} = 1;
7562: }
7563: } elsif ($possexempt{$lonhost}) {
7564: $changes{'headtag'}{$lonhost} = 1;
7565: }
7566: if ($possexempt{$lonhost}) {
7567: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7568: }
7569: }
7570: }
7571: }
7572: if (@newhosts) {
7573: my $error;
7574: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7575: if ($configuserok eq 'ok') {
7576: if ($switchserver) {
7577: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
7578: } elsif ($author_ok eq 'ok') {
7579: foreach my $lonhost (@newhosts) {
7580: my $formelem = 'loginheadtag_'.$lonhost;
7581: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7582: "login/headtag/$lonhost",'','',
7583: $env{'form.loginheadtag_'.$lonhost.'.filename'});
7584: if ($result eq 'ok') {
7585: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
7586: $changes{'headtag'}{$lonhost} = 1;
7587: if ($possexempt{$lonhost}) {
7588: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7589: }
7590: } else {
7591: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7592: $newheadtagurls{$lonhost},$result);
7593: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7594: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7595: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7596: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7597: }
7598: }
7599: }
7600: } else {
7601: $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);
7602: }
7603: } else {
7604: $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);
7605: }
7606: if ($error) {
7607: &Apache::lonnet::logthis($error);
7608: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7609: }
7610: }
1.169 raeburn 7611: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 7612:
7613: my $defaulthelpfile = '/adm/loginproblems.html';
7614: my $defaulttext = &mt('Default in use');
7615:
1.1 raeburn 7616: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7617: $dom);
7618: if ($putresult eq 'ok') {
1.188 raeburn 7619: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7620: my %defaultchecked = (
7621: 'coursecatalog' => 'on',
1.188 raeburn 7622: 'helpdesk' => 'on',
1.42 raeburn 7623: 'adminmail' => 'off',
1.43 raeburn 7624: 'newuser' => 'off',
1.42 raeburn 7625: );
1.55 raeburn 7626: if (ref($domconfig{'login'}) eq 'HASH') {
7627: foreach my $item (@toggles) {
7628: if ($defaultchecked{$item} eq 'on') {
7629: if (($domconfig{'login'}{$item} eq '0') &&
7630: ($env{'form.'.$item} eq '1')) {
7631: $changes{$item} = 1;
7632: } elsif (($domconfig{'login'}{$item} eq '' ||
7633: $domconfig{'login'}{$item} eq '1') &&
7634: ($env{'form.'.$item} eq '0')) {
7635: $changes{$item} = 1;
7636: }
7637: } elsif ($defaultchecked{$item} eq 'off') {
7638: if (($domconfig{'login'}{$item} eq '1') &&
7639: ($env{'form.'.$item} eq '0')) {
7640: $changes{$item} = 1;
7641: } elsif (($domconfig{'login'}{$item} eq '' ||
7642: $domconfig{'login'}{$item} eq '0') &&
7643: ($env{'form.'.$item} eq '1')) {
7644: $changes{$item} = 1;
7645: }
1.42 raeburn 7646: }
7647: }
1.41 raeburn 7648: }
1.6 raeburn 7649: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7650: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7651: if (ref($lastactref) eq 'HASH') {
7652: $lastactref->{'domainconfig'} = 1;
7653: }
1.1 raeburn 7654: $resulttext = &mt('Changes made:').'<ul>';
7655: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7656: if ($item eq 'loginvia') {
1.112 raeburn 7657: if (ref($changes{$item}) eq 'HASH') {
7658: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7659: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7660: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7661: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7662: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7663: $protocol = 'http' if ($protocol ne 'https');
7664: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7665:
7666: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7667: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7668: } else {
7669: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7670: }
7671: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7672: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7673: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7674: }
7675: $resulttext .= '</li>';
7676: } else {
7677: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7678: }
1.112 raeburn 7679: } else {
1.128 raeburn 7680: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7681: }
7682: }
1.128 raeburn 7683: $resulttext .= '</ul></li>';
1.112 raeburn 7684: }
1.168 raeburn 7685: } elsif ($item eq 'helpurl') {
7686: if (ref($changes{$item}) eq 'HASH') {
7687: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7688: if (grep(/^\Q$lang\E$/,@delurls)) {
7689: my ($chg,$link);
7690: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7691: if ($lang eq 'nolang') {
7692: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7693: } else {
7694: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7695: }
7696: $resulttext .= '<li>'.$chg.'</li>';
7697: } else {
7698: my $chg;
7699: if ($lang eq 'nolang') {
7700: $chg = &mt('custom log-in help file for no preferred language');
7701: } else {
7702: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7703: }
7704: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7705: $loginhash{'login'}{'helpurl'}{$lang}.
7706: '?inhibitmenu=yes',$chg,600,500).
7707: '</li>';
7708: }
7709: }
7710: }
1.256 raeburn 7711: } elsif ($item eq 'headtag') {
7712: if (ref($changes{$item}) eq 'HASH') {
7713: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7714: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7715: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7716: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7717: $resulttext .= '<li><a href="'.
7718: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7719: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7720: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7721: if ($possexempt{$lonhost}) {
7722: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7723: } else {
7724: $resulttext .= &mt('included for any client IP');
7725: }
7726: $resulttext .= '</li>';
7727: }
7728: }
7729: }
1.169 raeburn 7730: } elsif ($item eq 'captcha') {
7731: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 7732: my $chgtxt;
1.169 raeburn 7733: if ($loginhash{'login'}{$item} eq 'notused') {
7734: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7735: } else {
7736: my %captchas = &captcha_phrases();
7737: if ($captchas{$loginhash{'login'}{$item}}) {
7738: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7739: } else {
7740: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7741: }
7742: }
7743: $resulttext .= '<li>'.$chgtxt.'</li>';
7744: }
7745: } elsif ($item eq 'recaptchakeys') {
7746: if (ref($loginhash{'login'}) eq 'HASH') {
7747: my ($privkey,$pubkey);
7748: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7749: $pubkey = $loginhash{'login'}{$item}{'public'};
7750: $privkey = $loginhash{'login'}{$item}{'private'};
7751: }
7752: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7753: if (!$pubkey) {
7754: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7755: } else {
7756: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7757: }
7758: if (!$privkey) {
7759: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7760: } else {
1.251 raeburn 7761: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 7762: }
7763: $chgtxt .= '</ul>';
7764: $resulttext .= '<li>'.$chgtxt.'</li>';
7765: }
1.269 raeburn 7766: } elsif ($item eq 'recaptchaversion') {
7767: if (ref($loginhash{'login'}) eq 'HASH') {
7768: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 7769: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 7770: '</li>';
7771: }
7772: }
1.41 raeburn 7773: } else {
7774: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7775: }
1.1 raeburn 7776: }
1.6 raeburn 7777: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7778: } else {
7779: $resulttext = &mt('No changes made to log-in page settings');
7780: }
7781: } else {
1.11 albertel 7782: $resulttext = '<span class="LC_error">'.
7783: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7784: }
1.6 raeburn 7785: if ($errors) {
1.9 raeburn 7786: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7787: $errors.'</ul>';
7788: }
7789: return $resulttext;
7790: }
7791:
1.256 raeburn 7792:
7793: sub check_exempt_addresses {
7794: my ($iplist) = @_;
7795: $iplist =~ s/^\s+//;
7796: $iplist =~ s/\s+$//;
7797: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7798: my (@okips,$new);
7799: foreach my $ip (@poss_ips) {
7800: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7801: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7802: push(@okips,$ip);
7803: }
7804: }
7805: }
7806: if (@okips > 0) {
7807: $new = join(',',@okips);
7808: } else {
7809: $new = '';
7810: }
7811: return $new;
7812: }
7813:
1.6 raeburn 7814: sub color_font_choices {
7815: my %choices =
7816: &Apache::lonlocal::texthash (
7817: img => "Header",
7818: bgs => "Background colors",
7819: links => "Link colors",
1.55 raeburn 7820: images => "Images",
1.6 raeburn 7821: font => "Font color",
1.201 raeburn 7822: fontmenu => "Font menu",
1.76 raeburn 7823: pgbg => "Page",
1.6 raeburn 7824: tabbg => "Header",
7825: sidebg => "Border",
7826: link => "Link",
7827: alink => "Active link",
7828: vlink => "Visited link",
7829: );
7830: return %choices;
7831: }
7832:
7833: sub modify_rolecolors {
1.205 raeburn 7834: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7835: my ($resulttext,%rolehash);
7836: $rolehash{'rolecolors'} = {};
1.55 raeburn 7837: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7838: if ($domconfig{'rolecolors'} eq '') {
7839: $domconfig{'rolecolors'} = {};
7840: }
7841: }
1.9 raeburn 7842: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7843: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7844: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7845: $dom);
7846: if ($putresult eq 'ok') {
7847: if (keys(%changes) > 0) {
1.41 raeburn 7848: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7849: if (ref($lastactref) eq 'HASH') {
7850: $lastactref->{'domainconfig'} = 1;
7851: }
1.6 raeburn 7852: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7853: $rolehash{'rolecolors'});
7854: } else {
7855: $resulttext = &mt('No changes made to default color schemes');
7856: }
7857: } else {
1.11 albertel 7858: $resulttext = '<span class="LC_error">'.
7859: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7860: }
7861: if ($errors) {
7862: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7863: $errors.'</ul>';
7864: }
7865: return $resulttext;
7866: }
7867:
7868: sub modify_colors {
1.9 raeburn 7869: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7870: my (%changes,%choices);
1.51 raeburn 7871: my @bgs;
1.6 raeburn 7872: my @links = ('link','alink','vlink');
1.41 raeburn 7873: my @logintext;
1.6 raeburn 7874: my @images;
7875: my $servadm = $r->dir_config('lonAdmEMail');
7876: my $errors;
1.200 raeburn 7877: my %defaults;
1.6 raeburn 7878: foreach my $role (@{$roles}) {
7879: if ($role eq 'login') {
1.12 raeburn 7880: %choices = &login_choices();
1.41 raeburn 7881: @logintext = ('textcol','bgcol');
1.12 raeburn 7882: } else {
7883: %choices = &color_font_choices();
7884: }
7885: if ($role eq 'login') {
1.41 raeburn 7886: @images = ('img','logo','domlogo','login');
1.51 raeburn 7887: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7888: } else {
7889: @images = ('img');
1.200 raeburn 7890: @bgs = ('pgbg','tabbg','sidebg');
7891: }
7892: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7893: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7894: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7895: }
7896: if ($role eq 'login') {
7897: foreach my $item (@logintext) {
1.234 raeburn 7898: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7899: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7900: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7901: }
7902: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 7903: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7904: }
7905: }
7906: } else {
1.234 raeburn 7907: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7908: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7909: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7910: }
7911: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 7912: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7913: }
1.6 raeburn 7914: }
1.200 raeburn 7915: foreach my $item (@bgs) {
1.234 raeburn 7916: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7917: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7918: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7919: }
7920: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 7921: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7922: }
7923: }
7924: foreach my $item (@links) {
1.234 raeburn 7925: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7926: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7927: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7928: }
7929: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 7930: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7931: }
1.6 raeburn 7932: }
1.46 raeburn 7933: my ($configuserok,$author_ok,$switchserver) =
7934: &config_check($dom,$confname,$servadm);
1.9 raeburn 7935: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7936: if (ref($domconfig->{$role}) ne 'HASH') {
7937: $domconfig->{$role} = {};
7938: }
1.8 raeburn 7939: foreach my $img (@images) {
1.70 raeburn 7940: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7941: if (defined($env{'form.login_showlogo_'.$img})) {
7942: $confhash->{$role}{'showlogo'}{$img} = 1;
7943: } else {
7944: $confhash->{$role}{'showlogo'}{$img} = 0;
7945: }
7946: }
1.18 albertel 7947: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7948: && !defined($domconfig->{$role}{$img})
7949: && !$env{'form.'.$role.'_del_'.$img}
7950: && $env{'form.'.$role.'_import_'.$img}) {
7951: # import the old configured image from the .tab setting
7952: # if they haven't provided a new one
7953: $domconfig->{$role}{$img} =
7954: $env{'form.'.$role.'_import_'.$img};
7955: }
1.6 raeburn 7956: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7957: my $error;
1.6 raeburn 7958: if ($configuserok eq 'ok') {
1.9 raeburn 7959: if ($switchserver) {
1.12 raeburn 7960: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7961: } else {
7962: if ($author_ok eq 'ok') {
7963: my ($result,$logourl) =
7964: &publishlogo($r,'upload',$role.'_'.$img,
7965: $dom,$confname,$img,$width,$height);
7966: if ($result eq 'ok') {
7967: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7968: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7969: } else {
1.12 raeburn 7970: $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 7971: }
7972: } else {
1.46 raeburn 7973: $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 7974: }
7975: }
7976: } else {
1.46 raeburn 7977: $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 7978: }
7979: if ($error) {
1.8 raeburn 7980: &Apache::lonnet::logthis($error);
1.11 albertel 7981: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7982: }
7983: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7984: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7985: my $error;
7986: if ($configuserok eq 'ok') {
7987: # is confname an author?
7988: if ($switchserver eq '') {
7989: if ($author_ok eq 'ok') {
7990: my ($result,$logourl) =
7991: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7992: $dom,$confname,$img,$width,$height);
7993: if ($result eq 'ok') {
7994: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7995: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7996: }
7997: }
7998: }
7999: }
1.6 raeburn 8000: }
8001: }
8002: }
8003: if (ref($domconfig) eq 'HASH') {
8004: if (ref($domconfig->{$role}) eq 'HASH') {
8005: foreach my $img (@images) {
8006: if ($domconfig->{$role}{$img} ne '') {
8007: if ($env{'form.'.$role.'_del_'.$img}) {
8008: $confhash->{$role}{$img} = '';
1.12 raeburn 8009: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8010: } else {
1.9 raeburn 8011: if ($confhash->{$role}{$img} eq '') {
8012: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8013: }
1.6 raeburn 8014: }
8015: } else {
8016: if ($env{'form.'.$role.'_del_'.$img}) {
8017: $confhash->{$role}{$img} = '';
1.12 raeburn 8018: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8019: }
8020: }
1.70 raeburn 8021: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8022: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8023: if ($confhash->{$role}{'showlogo'}{$img} ne
8024: $domconfig->{$role}{'showlogo'}{$img}) {
8025: $changes{$role}{'showlogo'}{$img} = 1;
8026: }
8027: } else {
8028: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8029: $changes{$role}{'showlogo'}{$img} = 1;
8030: }
8031: }
8032: }
8033: }
1.6 raeburn 8034: if ($domconfig->{$role}{'font'} ne '') {
8035: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8036: $changes{$role}{'font'} = 1;
8037: }
8038: } else {
8039: if ($confhash->{$role}{'font'}) {
8040: $changes{$role}{'font'} = 1;
8041: }
8042: }
1.107 raeburn 8043: if ($role ne 'login') {
8044: if ($domconfig->{$role}{'fontmenu'} ne '') {
8045: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8046: $changes{$role}{'fontmenu'} = 1;
8047: }
8048: } else {
8049: if ($confhash->{$role}{'fontmenu'}) {
8050: $changes{$role}{'fontmenu'} = 1;
8051: }
1.97 tempelho 8052: }
8053: }
1.6 raeburn 8054: foreach my $item (@bgs) {
8055: if ($domconfig->{$role}{$item} ne '') {
8056: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8057: $changes{$role}{'bgs'}{$item} = 1;
8058: }
8059: } else {
8060: if ($confhash->{$role}{$item}) {
8061: $changes{$role}{'bgs'}{$item} = 1;
8062: }
8063: }
8064: }
8065: foreach my $item (@links) {
8066: if ($domconfig->{$role}{$item} ne '') {
8067: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8068: $changes{$role}{'links'}{$item} = 1;
8069: }
8070: } else {
8071: if ($confhash->{$role}{$item}) {
8072: $changes{$role}{'links'}{$item} = 1;
8073: }
8074: }
8075: }
1.41 raeburn 8076: foreach my $item (@logintext) {
8077: if ($domconfig->{$role}{$item} ne '') {
8078: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8079: $changes{$role}{'logintext'}{$item} = 1;
8080: }
8081: } else {
8082: if ($confhash->{$role}{$item}) {
8083: $changes{$role}{'logintext'}{$item} = 1;
8084: }
8085: }
8086: }
1.6 raeburn 8087: } else {
8088: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8089: \@logintext,$confhash,\%changes);
1.6 raeburn 8090: }
8091: } else {
8092: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8093: \@logintext,$confhash,\%changes);
1.6 raeburn 8094: }
8095: }
8096: return ($errors,%changes);
8097: }
8098:
1.46 raeburn 8099: sub config_check {
8100: my ($dom,$confname,$servadm) = @_;
8101: my ($configuserok,$author_ok,$switchserver,%currroles);
8102: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8103: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8104: $confname,$servadm);
8105: if ($configuserok eq 'ok') {
8106: $switchserver = &check_switchserver($dom,$confname);
8107: if ($switchserver eq '') {
8108: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8109: }
8110: }
8111: return ($configuserok,$author_ok,$switchserver);
8112: }
8113:
1.6 raeburn 8114: sub default_change_checker {
1.41 raeburn 8115: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8116: foreach my $item (@{$links}) {
8117: if ($confhash->{$role}{$item}) {
8118: $changes->{$role}{'links'}{$item} = 1;
8119: }
8120: }
8121: foreach my $item (@{$bgs}) {
8122: if ($confhash->{$role}{$item}) {
8123: $changes->{$role}{'bgs'}{$item} = 1;
8124: }
8125: }
1.41 raeburn 8126: foreach my $item (@{$logintext}) {
8127: if ($confhash->{$role}{$item}) {
8128: $changes->{$role}{'logintext'}{$item} = 1;
8129: }
8130: }
1.6 raeburn 8131: foreach my $img (@{$images}) {
8132: if ($env{'form.'.$role.'_del_'.$img}) {
8133: $confhash->{$role}{$img} = '';
1.12 raeburn 8134: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8135: }
1.70 raeburn 8136: if ($role eq 'login') {
8137: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8138: $changes->{$role}{'showlogo'}{$img} = 1;
8139: }
8140: }
1.6 raeburn 8141: }
8142: if ($confhash->{$role}{'font'}) {
8143: $changes->{$role}{'font'} = 1;
8144: }
1.48 raeburn 8145: }
1.6 raeburn 8146:
8147: sub display_colorchgs {
8148: my ($dom,$changes,$roles,$confhash) = @_;
8149: my (%choices,$resulttext);
8150: if (!grep(/^login$/,@{$roles})) {
8151: $resulttext = &mt('Changes made:').'<br />';
8152: }
8153: foreach my $role (@{$roles}) {
8154: if ($role eq 'login') {
8155: %choices = &login_choices();
8156: } else {
8157: %choices = &color_font_choices();
8158: }
8159: if (ref($changes->{$role}) eq 'HASH') {
8160: if ($role ne 'login') {
8161: $resulttext .= '<h4>'.&mt($role).'</h4>';
8162: }
8163: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8164: if ($role ne 'login') {
8165: $resulttext .= '<ul>';
8166: }
8167: if (ref($changes->{$role}{$key}) eq 'HASH') {
8168: if ($role ne 'login') {
8169: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8170: }
8171: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8172: if (($role eq 'login') && ($key eq 'showlogo')) {
8173: if ($confhash->{$role}{$key}{$item}) {
8174: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8175: } else {
8176: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8177: }
8178: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8179: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8180: } else {
1.12 raeburn 8181: my $newitem = $confhash->{$role}{$item};
8182: if ($key eq 'images') {
8183: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
8184: }
8185: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8186: }
8187: }
8188: if ($role ne 'login') {
8189: $resulttext .= '</ul></li>';
8190: }
8191: } else {
8192: if ($confhash->{$role}{$key} eq '') {
8193: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8194: } else {
8195: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8196: }
8197: }
8198: if ($role ne 'login') {
8199: $resulttext .= '</ul>';
8200: }
8201: }
8202: }
8203: }
1.3 raeburn 8204: return $resulttext;
1.1 raeburn 8205: }
8206:
1.9 raeburn 8207: sub thumb_dimensions {
8208: return ('200','50');
8209: }
8210:
1.16 raeburn 8211: sub check_dimensions {
8212: my ($inputfile) = @_;
8213: my ($fullwidth,$fullheight);
8214: if ($inputfile =~ m|^[/\w.\-]+$|) {
8215: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8216: my $imageinfo = <PIPE>;
8217: if (!close(PIPE)) {
8218: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8219: }
8220: chomp($imageinfo);
8221: my ($fullsize) =
1.21 raeburn 8222: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8223: if ($fullsize) {
8224: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8225: }
8226: }
8227: }
8228: return ($fullwidth,$fullheight);
8229: }
8230:
1.9 raeburn 8231: sub check_configuser {
8232: my ($uhome,$dom,$confname,$servadm) = @_;
8233: my ($configuserok,%currroles);
8234: if ($uhome eq 'no_host') {
8235: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
8236: my $configpass = &LONCAPA::Enrollment::create_password();
8237: $configuserok =
8238: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8239: $configpass,'','','','','',undef,$servadm);
8240: } else {
8241: $configuserok = 'ok';
8242: %currroles =
8243: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8244: }
8245: return ($configuserok,%currroles);
8246: }
8247:
8248: sub check_authorstatus {
8249: my ($dom,$confname,%currroles) = @_;
8250: my $author_ok;
1.40 raeburn 8251: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8252: my $start = time;
8253: my $end = 0;
8254: $author_ok =
8255: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8256: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8257: } else {
8258: $author_ok = 'ok';
8259: }
8260: return $author_ok;
8261: }
8262:
8263: sub publishlogo {
1.46 raeburn 8264: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 8265: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 8266: if ($action eq 'upload') {
8267: $fname=$env{'form.'.$formname.'.filename'};
8268: chop($env{'form.'.$formname});
8269: } else {
8270: ($fname) = ($formname =~ /([^\/]+)$/);
8271: }
1.46 raeburn 8272: if ($savefileas ne '') {
8273: $fname = $savefileas;
8274: }
1.9 raeburn 8275: $fname=&Apache::lonnet::clean_filename($fname);
8276: # See if there is anything left
8277: unless ($fname) { return ('error: no uploaded file'); }
8278: $fname="$subdir/$fname";
1.210 raeburn 8279: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 8280: my $filepath="$docroot/priv";
8281: my $relpath = "$dom/$confname";
1.9 raeburn 8282: my ($fnamepath,$file,$fetchthumb);
8283: $file=$fname;
8284: if ($fname=~m|/|) {
8285: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8286: }
1.164 raeburn 8287: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8288: my $count;
1.164 raeburn 8289: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8290: $filepath.="/$parts[$count]";
8291: if ((-e $filepath)!=1) {
8292: mkdir($filepath,02770);
8293: }
8294: }
8295: # Check for bad extension and disallow upload
8296: if ($file=~/\.(\w+)$/ &&
8297: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8298: $output =
1.207 bisitz 8299: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8300: } elsif ($file=~/\.(\w+)$/ &&
8301: !defined(&Apache::loncommon::fileembstyle($1))) {
8302: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8303: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 8304: $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 8305: } elsif (-d "$filepath/$file") {
1.195 bisitz 8306: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8307: } else {
8308: my $source = $filepath.'/'.$file;
8309: my $logfile;
8310: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 8311: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8312: }
8313: print $logfile
8314: "\n================= Publish ".localtime()." ================\n".
8315: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8316: # Save the file
8317: if (!open(FH,'>'.$source)) {
8318: &Apache::lonnet::logthis('Failed to create '.$source);
8319: return (&mt('Failed to create file'));
8320: }
8321: if ($action eq 'upload') {
8322: if (!print FH ($env{'form.'.$formname})) {
8323: &Apache::lonnet::logthis('Failed to write to '.$source);
8324: return (&mt('Failed to write file'));
8325: }
8326: } else {
8327: my $original = &Apache::lonnet::filelocation('',$formname);
8328: if(!copy($original,$source)) {
8329: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8330: return (&mt('Failed to write file'));
8331: }
8332: }
8333: close(FH);
8334: chmod(0660, $source); # Permissions to rw-rw---.
8335:
8336: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8337: my $copyfile=$targetdir.'/'.$file;
8338:
8339: my @parts=split(/\//,$targetdir);
8340: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8341: for (my $count=5;$count<=$#parts;$count++) {
8342: $path.="/$parts[$count]";
8343: if (!-e $path) {
8344: print $logfile "\nCreating directory ".$path;
8345: mkdir($path,02770);
8346: }
8347: }
8348: my $versionresult;
8349: if (-e $copyfile) {
8350: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8351: } else {
8352: $versionresult = 'ok';
8353: }
8354: if ($versionresult eq 'ok') {
8355: if (copy($source,$copyfile)) {
8356: print $logfile "\nCopied original source to ".$copyfile."\n";
8357: $output = 'ok';
8358: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8359: push(@{$modified_urls},[$copyfile,$source]);
8360: my $metaoutput =
8361: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8362: unless ($registered_cleanup) {
8363: my $handlers = $r->get_handlers('PerlCleanupHandler');
8364: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8365: $registered_cleanup=1;
8366: }
1.9 raeburn 8367: } else {
8368: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8369: $output = &mt('Failed to copy file to RES space').", $!";
8370: }
8371: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8372: my $inputfile = $filepath.'/'.$file;
8373: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8374: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8375: if ($fullwidth ne '' && $fullheight ne '') {
8376: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8377: my $thumbsize = $thumbwidth.'x'.$thumbheight;
8378: system("convert -sample $thumbsize $inputfile $outfile");
8379: chmod(0660, $filepath.'/tn-'.$file);
8380: if (-e $outfile) {
8381: my $copyfile=$targetdir.'/tn-'.$file;
8382: if (copy($outfile,$copyfile)) {
8383: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8384: my $thumb_metaoutput =
8385: &write_metadata($dom,$confname,$formname,
8386: $targetdir,'tn-'.$file,$logfile);
8387: push(@{$modified_urls},[$copyfile,$outfile]);
8388: unless ($registered_cleanup) {
8389: my $handlers = $r->get_handlers('PerlCleanupHandler');
8390: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8391: $registered_cleanup=1;
8392: }
1.267 raeburn 8393: $madethumb = 1;
1.16 raeburn 8394: } else {
8395: print $logfile "\nUnable to write ".$copyfile.
8396: ':'.$!."\n";
8397: }
8398: }
1.9 raeburn 8399: }
8400: }
8401: }
8402: } else {
8403: $output = $versionresult;
8404: }
8405: }
1.267 raeburn 8406: return ($output,$logourl,$madethumb);
1.9 raeburn 8407: }
8408:
8409: sub logo_versioning {
8410: my ($targetdir,$file,$logfile) = @_;
8411: my $target = $targetdir.'/'.$file;
8412: my ($maxversion,$fn,$extn,$output);
8413: $maxversion = 0;
8414: if ($file =~ /^(.+)\.(\w+)$/) {
8415: $fn=$1;
8416: $extn=$2;
8417: }
8418: opendir(DIR,$targetdir);
8419: while (my $filename=readdir(DIR)) {
8420: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8421: $maxversion=($1>$maxversion)?$1:$maxversion;
8422: }
8423: }
8424: $maxversion++;
8425: print $logfile "\nCreating old version ".$maxversion."\n";
8426: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8427: if (copy($target,$copyfile)) {
8428: print $logfile "Copied old target to ".$copyfile."\n";
8429: $copyfile=$copyfile.'.meta';
8430: if (copy($target.'.meta',$copyfile)) {
8431: print $logfile "Copied old target metadata to ".$copyfile."\n";
8432: $output = 'ok';
8433: } else {
8434: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8435: $output = &mt('Failed to copy old meta').", $!, ";
8436: }
8437: } else {
8438: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8439: $output = &mt('Failed to copy old target').", $!, ";
8440: }
8441: return $output;
8442: }
8443:
8444: sub write_metadata {
8445: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
8446: my (%metadatafields,%metadatakeys,$output);
8447: $metadatafields{'title'}=$formname;
8448: $metadatafields{'creationdate'}=time;
8449: $metadatafields{'lastrevisiondate'}=time;
8450: $metadatafields{'copyright'}='public';
8451: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
8452: $env{'user.domain'};
8453: $metadatafields{'authorspace'}=$confname.':'.$dom;
8454: $metadatafields{'domain'}=$dom;
8455: {
8456: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
8457: my $mfh;
1.155 raeburn 8458: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 8459: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 8460: unless ($_=~/\./) {
8461: my $unikey=$_;
8462: $unikey=~/^([A-Za-z]+)/;
8463: my $tag=$1;
8464: $tag=~tr/A-Z/a-z/;
8465: print $mfh "\n\<$tag";
8466: foreach (split(/\,/,$metadatakeys{$unikey})) {
8467: my $value=$metadatafields{$unikey.'.'.$_};
8468: $value=~s/\"/\'\'/g;
8469: print $mfh ' '.$_.'="'.$value.'"';
8470: }
8471: print $mfh '>'.
8472: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
8473: .'</'.$tag.'>';
8474: }
8475: }
8476: $output = 'ok';
8477: print $logfile "\nWrote metadata";
8478: close($mfh);
8479: } else {
8480: print $logfile "\nFailed to open metadata file";
1.9 raeburn 8481: $output = &mt('Could not write metadata');
8482: }
8483: }
1.155 raeburn 8484: return $output;
8485: }
8486:
8487: sub notifysubscribed {
8488: foreach my $targetsource (@{$modified_urls}){
8489: next unless (ref($targetsource) eq 'ARRAY');
8490: my ($target,$source)=@{$targetsource};
8491: if ($source ne '') {
8492: if (open(my $logfh,'>>'.$source.'.log')) {
8493: print $logfh "\nCleanup phase: Notifications\n";
8494: my @subscribed=&subscribed_hosts($target);
8495: foreach my $subhost (@subscribed) {
8496: print $logfh "\nNotifying host ".$subhost.':';
8497: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
8498: print $logfh $reply;
8499: }
8500: my @subscribedmeta=&subscribed_hosts("$target.meta");
8501: foreach my $subhost (@subscribedmeta) {
8502: print $logfh "\nNotifying host for metadata only ".$subhost.':';
8503: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
8504: $subhost);
8505: print $logfh $reply;
8506: }
8507: print $logfh "\n============ Done ============\n";
1.160 raeburn 8508: close($logfh);
1.155 raeburn 8509: }
8510: }
8511: }
8512: return OK;
8513: }
8514:
8515: sub subscribed_hosts {
8516: my ($target) = @_;
8517: my @subscribed;
8518: if (open(my $fh,"<$target.subscription")) {
8519: while (my $subline=<$fh>) {
8520: if ($subline =~ /^($match_lonid):/) {
8521: my $host = $1;
8522: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
8523: unless (grep(/^\Q$host\E$/,@subscribed)) {
8524: push(@subscribed,$host);
8525: }
8526: }
8527: }
8528: }
8529: }
8530: return @subscribed;
1.9 raeburn 8531: }
8532:
8533: sub check_switchserver {
8534: my ($dom,$confname) = @_;
8535: my ($allowed,$switchserver);
8536: my $home = &Apache::lonnet::homeserver($confname,$dom);
8537: if ($home eq 'no_host') {
8538: $home = &Apache::lonnet::domain($dom,'primary');
8539: }
8540: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 8541: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
8542: if (!$allowed) {
1.180 raeburn 8543: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 8544: }
8545: return $switchserver;
8546: }
8547:
1.1 raeburn 8548: sub modify_quotas {
1.216 raeburn 8549: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 8550: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 8551: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 8552: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8553: $validationfieldsref);
1.86 raeburn 8554: if ($action eq 'quotas') {
8555: $context = 'tools';
1.163 raeburn 8556: } else {
1.86 raeburn 8557: $context = $action;
8558: }
8559: if ($context eq 'requestcourses') {
1.271 raeburn 8560: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 8561: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 8562: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8563: %titles = &courserequest_titles();
8564: $toolregexp = join('|',@usertools);
8565: %conditions = &courserequest_conditions();
1.216 raeburn 8566: $confname = $dom.'-domainconfig';
8567: my $servadm = $r->dir_config('lonAdmEMail');
8568: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 8569: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8570: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 8571: } elsif ($context eq 'requestauthor') {
8572: @usertools = ('author');
8573: %titles = &authorrequest_titles();
1.86 raeburn 8574: } else {
1.162 raeburn 8575: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 8576: %titles = &tool_titles();
1.86 raeburn 8577: }
1.212 raeburn 8578: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 8579: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8580: foreach my $key (keys(%env)) {
1.101 raeburn 8581: if ($context eq 'requestcourses') {
8582: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8583: my $item = $1;
8584: my $type = $2;
8585: if ($type =~ /^limit_(.+)/) {
8586: $limithash{$item}{$1} = $env{$key};
8587: } else {
8588: $confhash{$item}{$type} = $env{$key};
8589: }
8590: }
1.163 raeburn 8591: } elsif ($context eq 'requestauthor') {
8592: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8593: $confhash{$1} = $env{$key};
8594: }
1.101 raeburn 8595: } else {
1.86 raeburn 8596: if ($key =~ /^form\.quota_(.+)$/) {
8597: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 8598: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8599: $confhash{'authorquota'}{$1} = $env{$key};
8600: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8601: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8602: }
1.72 raeburn 8603: }
8604: }
1.163 raeburn 8605: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 8606: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8607: @approvalnotify = sort(@approvalnotify);
8608: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 8609: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 8610: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8611: foreach my $type (@hasuniquecode) {
8612: if (grep(/^\Q$type\E$/,@crstypes)) {
8613: $confhash{'uniquecode'}{$type} = 1;
8614: }
1.216 raeburn 8615: }
1.242 raeburn 8616: my (%newbook,%allpos);
1.216 raeburn 8617: if ($context eq 'requestcourses') {
1.242 raeburn 8618: foreach my $type ('textbooks','templates') {
8619: @{$allpos{$type}} = ();
8620: my $invalid;
8621: if ($type eq 'textbooks') {
8622: $invalid = &mt('Invalid LON-CAPA course for textbook');
8623: } else {
8624: $invalid = &mt('Invalid LON-CAPA course for template');
8625: }
8626: if ($env{'form.'.$type.'_addbook'}) {
8627: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8628: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8629: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8630: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8631: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8632: } else {
8633: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8634: my $position = $env{'form.'.$type.'_addbook_pos'};
8635: $position =~ s/\D+//g;
8636: if ($position ne '') {
8637: $allpos{$type}[$position] = $newbook{$type};
8638: }
1.216 raeburn 8639: }
1.242 raeburn 8640: } else {
8641: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 8642: }
8643: }
1.242 raeburn 8644: }
1.216 raeburn 8645: }
1.102 raeburn 8646: if (ref($domconfig{$action}) eq 'HASH') {
8647: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8648: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8649: $changes{'notify'}{'approval'} = 1;
8650: }
8651: } else {
1.144 raeburn 8652: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8653: $changes{'notify'}{'approval'} = 1;
8654: }
8655: }
1.218 raeburn 8656: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8657: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8658: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8659: unless ($confhash{'uniquecode'}{$crstype}) {
8660: $changes{'uniquecode'} = 1;
8661: }
8662: }
8663: unless ($changes{'uniquecode'}) {
8664: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8665: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8666: $changes{'uniquecode'} = 1;
8667: }
8668: }
8669: }
8670: } else {
8671: $changes{'uniquecode'} = 1;
8672: }
8673: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8674: $changes{'uniquecode'} = 1;
1.216 raeburn 8675: }
8676: if ($context eq 'requestcourses') {
1.242 raeburn 8677: foreach my $type ('textbooks','templates') {
8678: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8679: my %deletions;
8680: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8681: if (@todelete) {
8682: map { $deletions{$_} = 1; } @todelete;
8683: }
8684: my %imgdeletions;
8685: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8686: if (@todeleteimages) {
8687: map { $imgdeletions{$_} = 1; } @todeleteimages;
8688: }
8689: my $maxnum = $env{'form.'.$type.'_maxnum'};
8690: for (my $i=0; $i<=$maxnum; $i++) {
8691: my $itemid = $env{'form.'.$type.'_id_'.$i};
8692: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8693: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8694: if ($deletions{$key}) {
8695: if ($domconfig{$action}{$type}{$key}{'image'}) {
8696: #FIXME need to obsolete item in RES space
8697: }
8698: next;
8699: } else {
8700: my $newpos = $env{'form.'.$itemid};
8701: $newpos =~ s/\D+//g;
1.243 raeburn 8702: foreach my $item ('subject','title','publisher','author') {
8703: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8704: ($type eq 'templates'));
1.242 raeburn 8705: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8706: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8707: $changes{$type}{$key} = 1;
8708: }
8709: }
8710: $allpos{$type}[$newpos] = $key;
8711: }
8712: if ($imgdeletions{$key}) {
8713: $changes{$type}{$key} = 1;
1.216 raeburn 8714: #FIXME need to obsolete item in RES space
1.242 raeburn 8715: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8716: my ($cdom,$cnum) = split(/_/,$key);
8717: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8718: $cdom,$cnum,$type,$configuserok,
8719: $switchserver,$author_ok);
8720: if ($imgurl) {
8721: $confhash{$type}{$key}{'image'} = $imgurl;
8722: $changes{$type}{$key} = 1;
1.216 raeburn 8723: }
1.242 raeburn 8724: if ($error) {
8725: &Apache::lonnet::logthis($error);
8726: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8727: }
8728: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8729: $confhash{$type}{$key}{'image'} =
8730: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 8731: }
8732: }
8733: }
8734: }
8735: }
8736: }
1.102 raeburn 8737: } else {
1.144 raeburn 8738: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8739: $changes{'notify'}{'approval'} = 1;
8740: }
1.218 raeburn 8741: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 8742: $changes{'uniquecode'} = 1;
8743: }
8744: }
8745: if ($context eq 'requestcourses') {
1.242 raeburn 8746: foreach my $type ('textbooks','templates') {
8747: if ($newbook{$type}) {
8748: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 8749: foreach my $item ('subject','title','publisher','author') {
8750: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8751: ($type eq 'template'));
1.242 raeburn 8752: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8753: if ($env{'form.'.$type.'_addbook_'.$item}) {
8754: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8755: }
8756: }
8757: if ($type eq 'textbooks') {
8758: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8759: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8760: my ($imageurl,$error) =
8761: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8762: $configuserok,$switchserver,$author_ok);
8763: if ($imageurl) {
8764: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8765: }
8766: if ($error) {
8767: &Apache::lonnet::logthis($error);
8768: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8769: }
8770: }
1.216 raeburn 8771: }
8772: }
1.242 raeburn 8773: if (@{$allpos{$type}} > 0) {
8774: my $idx = 0;
8775: foreach my $item (@{$allpos{$type}}) {
8776: if ($item ne '') {
8777: $confhash{$type}{$item}{'order'} = $idx;
8778: if (ref($domconfig{$action}) eq 'HASH') {
8779: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8780: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8781: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8782: $changes{$type}{$item} = 1;
8783: }
1.216 raeburn 8784: }
8785: }
8786: }
1.242 raeburn 8787: $idx ++;
1.216 raeburn 8788: }
8789: }
8790: }
8791: }
1.235 raeburn 8792: if (ref($validationitemsref) eq 'ARRAY') {
8793: foreach my $item (@{$validationitemsref}) {
8794: if ($item eq 'fields') {
8795: my @changed;
8796: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8797: if (@{$confhash{'validation'}{$item}} > 0) {
8798: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8799: }
1.266 raeburn 8800: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8801: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8802: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8803: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8804: $domconfig{'requestcourses'}{'validation'}{$item});
8805: } else {
8806: @changed = @{$confhash{'validation'}{$item}};
8807: }
1.235 raeburn 8808: } else {
8809: @changed = @{$confhash{'validation'}{$item}};
8810: }
8811: } else {
8812: @changed = @{$confhash{'validation'}{$item}};
8813: }
8814: if (@changed) {
8815: if ($confhash{'validation'}{$item}) {
8816: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8817: } else {
8818: $changes{'validation'}{$item} = &mt('None');
8819: }
8820: }
8821: } else {
8822: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8823: if ($item eq 'markup') {
8824: if ($env{'form.requestcourses_validation_'.$item}) {
8825: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8826: }
8827: }
1.266 raeburn 8828: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8829: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8830: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8831: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8832: }
8833: } else {
8834: if ($confhash{'validation'}{$item} ne '') {
8835: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8836: }
1.235 raeburn 8837: }
8838: } else {
8839: if ($confhash{'validation'}{$item} ne '') {
8840: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8841: }
8842: }
8843: }
8844: }
8845: }
8846: if ($env{'form.validationdc'}) {
8847: my $newval = $env{'form.validationdc'};
1.285 raeburn 8848: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 8849: if (exists($domcoords{$newval})) {
8850: $confhash{'validation'}{'dc'} = $newval;
8851: }
8852: }
8853: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 8854: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8855: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8856: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8857: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8858: if ($confhash{'validation'}{'dc'} eq '') {
8859: $changes{'validation'}{'dc'} = &mt('None');
8860: } else {
8861: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8862: }
1.235 raeburn 8863: }
1.266 raeburn 8864: } elsif ($confhash{'validation'}{'dc'} ne '') {
8865: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 8866: }
8867: } elsif ($confhash{'validation'}{'dc'} ne '') {
8868: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8869: }
8870: } elsif ($confhash{'validation'}{'dc'} ne '') {
8871: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.266 raeburn 8872: }
8873: } else {
8874: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8875: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8876: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8877: $changes{'validation'}{'dc'} = &mt('None');
8878: }
8879: }
1.235 raeburn 8880: }
8881: }
1.102 raeburn 8882: }
8883: } else {
1.86 raeburn 8884: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 8885: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8886: }
1.72 raeburn 8887: foreach my $item (@usertools) {
8888: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8889: my $unset;
1.101 raeburn 8890: if ($context eq 'requestcourses') {
1.104 raeburn 8891: $unset = '0';
8892: if ($type eq '_LC_adv') {
8893: $unset = '';
8894: }
1.101 raeburn 8895: if ($confhash{$item}{$type} eq 'autolimit') {
8896: $confhash{$item}{$type} .= '=';
8897: unless ($limithash{$item}{$type} =~ /\D/) {
8898: $confhash{$item}{$type} .= $limithash{$item}{$type};
8899: }
8900: }
1.163 raeburn 8901: } elsif ($context eq 'requestauthor') {
8902: $unset = '0';
8903: if ($type eq '_LC_adv') {
8904: $unset = '';
8905: }
1.72 raeburn 8906: } else {
1.101 raeburn 8907: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8908: $confhash{$item}{$type} = 1;
8909: } else {
8910: $confhash{$item}{$type} = 0;
8911: }
1.72 raeburn 8912: }
1.86 raeburn 8913: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 8914: if ($action eq 'requestauthor') {
8915: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8916: $changes{$type} = 1;
8917: }
8918: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8919: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8920: $changes{$item}{$type} = 1;
8921: }
8922: } else {
8923: if ($context eq 'requestcourses') {
1.104 raeburn 8924: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8925: $changes{$item}{$type} = 1;
8926: }
8927: } else {
8928: if (!$confhash{$item}{$type}) {
8929: $changes{$item}{$type} = 1;
8930: }
8931: }
8932: }
8933: } else {
8934: if ($context eq 'requestcourses') {
1.104 raeburn 8935: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8936: $changes{$item}{$type} = 1;
8937: }
1.163 raeburn 8938: } elsif ($context eq 'requestauthor') {
8939: if ($confhash{$type} ne $unset) {
8940: $changes{$type} = 1;
8941: }
1.72 raeburn 8942: } else {
8943: if (!$confhash{$item}{$type}) {
8944: $changes{$item}{$type} = 1;
8945: }
8946: }
8947: }
1.1 raeburn 8948: }
8949: }
1.163 raeburn 8950: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8951: if (ref($domconfig{'quotas'}) eq 'HASH') {
8952: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8953: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8954: if (exists($confhash{'defaultquota'}{$key})) {
8955: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8956: $changes{'defaultquota'}{$key} = 1;
8957: }
8958: } else {
8959: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8960: }
8961: }
1.86 raeburn 8962: } else {
8963: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8964: if (exists($confhash{'defaultquota'}{$key})) {
8965: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8966: $changes{'defaultquota'}{$key} = 1;
8967: }
8968: } else {
8969: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8970: }
1.1 raeburn 8971: }
8972: }
1.197 raeburn 8973: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8974: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8975: if (exists($confhash{'authorquota'}{$key})) {
8976: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8977: $changes{'authorquota'}{$key} = 1;
8978: }
8979: } else {
8980: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8981: }
8982: }
8983: }
1.1 raeburn 8984: }
1.86 raeburn 8985: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8986: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8987: if (ref($domconfig{'quotas'}) eq 'HASH') {
8988: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8989: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8990: $changes{'defaultquota'}{$key} = 1;
8991: }
8992: } else {
8993: if (!exists($domconfig{'quotas'}{$key})) {
8994: $changes{'defaultquota'}{$key} = 1;
8995: }
1.72 raeburn 8996: }
8997: } else {
1.86 raeburn 8998: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8999: }
1.1 raeburn 9000: }
9001: }
1.197 raeburn 9002: if (ref($confhash{'authorquota'}) eq 'HASH') {
9003: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9004: if (ref($domconfig{'quotas'}) eq 'HASH') {
9005: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9006: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9007: $changes{'authorquota'}{$key} = 1;
9008: }
9009: } else {
9010: $changes{'authorquota'}{$key} = 1;
9011: }
9012: } else {
9013: $changes{'authorquota'}{$key} = 1;
9014: }
9015: }
9016: }
1.1 raeburn 9017: }
1.72 raeburn 9018:
1.163 raeburn 9019: if ($context eq 'requestauthor') {
9020: $domdefaults{'requestauthor'} = \%confhash;
9021: } else {
9022: foreach my $key (keys(%confhash)) {
1.242 raeburn 9023: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 9024: $domdefaults{$key} = $confhash{$key};
9025: }
1.163 raeburn 9026: }
1.72 raeburn 9027: }
1.163 raeburn 9028:
1.1 raeburn 9029: my %quotahash = (
1.86 raeburn 9030: $action => { %confhash }
1.1 raeburn 9031: );
9032: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9033: $dom);
9034: if ($putresult eq 'ok') {
9035: if (keys(%changes) > 0) {
1.72 raeburn 9036: my $cachetime = 24*60*60;
9037: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9038: if (ref($lastactref) eq 'HASH') {
9039: $lastactref->{'domdefaults'} = 1;
9040: }
1.1 raeburn 9041: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 9042: unless (($context eq 'requestcourses') ||
1.163 raeburn 9043: ($context eq 'requestauthor')) {
1.86 raeburn 9044: if (ref($changes{'defaultquota'}) eq 'HASH') {
9045: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9046: foreach my $type (@{$types},'default') {
9047: if (defined($changes{'defaultquota'}{$type})) {
9048: my $typetitle = $usertypes->{$type};
9049: if ($type eq 'default') {
9050: $typetitle = $othertitle;
9051: }
1.213 raeburn 9052: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9053: }
9054: }
1.86 raeburn 9055: $resulttext .= '</ul></li>';
1.72 raeburn 9056: }
1.197 raeburn 9057: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 9058: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 9059: foreach my $type (@{$types},'default') {
9060: if (defined($changes{'authorquota'}{$type})) {
9061: my $typetitle = $usertypes->{$type};
9062: if ($type eq 'default') {
9063: $typetitle = $othertitle;
9064: }
1.213 raeburn 9065: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 9066: }
9067: }
9068: $resulttext .= '</ul></li>';
9069: }
1.72 raeburn 9070: }
1.80 raeburn 9071: my %newenv;
1.72 raeburn 9072: foreach my $item (@usertools) {
1.163 raeburn 9073: my (%haschgs,%inconf);
9074: if ($context eq 'requestauthor') {
9075: %haschgs = %changes;
1.210 raeburn 9076: %inconf = %confhash;
1.163 raeburn 9077: } else {
9078: if (ref($changes{$item}) eq 'HASH') {
9079: %haschgs = %{$changes{$item}};
9080: }
9081: if (ref($confhash{$item}) eq 'HASH') {
9082: %inconf = %{$confhash{$item}};
9083: }
9084: }
9085: if (keys(%haschgs) > 0) {
1.80 raeburn 9086: my $newacc =
9087: &Apache::lonnet::usertools_access($env{'user.name'},
9088: $env{'user.domain'},
1.86 raeburn 9089: $item,'reload',$context);
1.210 raeburn 9090: if (($context eq 'requestcourses') ||
1.163 raeburn 9091: ($context eq 'requestauthor')) {
1.108 raeburn 9092: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9093: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9094: }
9095: } else {
9096: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9097: $newenv{'environment.availabletools.'.$item} = $newacc;
9098: }
1.80 raeburn 9099: }
1.163 raeburn 9100: unless ($context eq 'requestauthor') {
9101: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9102: }
1.72 raeburn 9103: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 9104: if ($haschgs{$type}) {
1.72 raeburn 9105: my $typetitle = $usertypes->{$type};
9106: if ($type eq 'default') {
9107: $typetitle = $othertitle;
9108: } elsif ($type eq '_LC_adv') {
9109: $typetitle = 'LON-CAPA Advanced Users';
9110: }
1.163 raeburn 9111: if ($inconf{$type}) {
1.101 raeburn 9112: if ($context eq 'requestcourses') {
9113: my $cond;
1.163 raeburn 9114: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9115: if ($1 eq '') {
9116: $cond = &mt('(Automatic processing of any request).');
9117: } else {
9118: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9119: }
9120: } else {
1.163 raeburn 9121: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9122: }
9123: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 9124: } elsif ($context eq 'requestauthor') {
9125: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9126: $titles{$inconf{$type}},$typetitle);
9127:
1.101 raeburn 9128: } else {
9129: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9130: }
1.72 raeburn 9131: } else {
1.104 raeburn 9132: if ($type eq '_LC_adv') {
1.163 raeburn 9133: if ($inconf{$type} eq '0') {
1.104 raeburn 9134: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9135: } else {
9136: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9137: }
9138: } else {
9139: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9140: }
1.72 raeburn 9141: }
9142: }
1.26 raeburn 9143: }
1.163 raeburn 9144: unless ($context eq 'requestauthor') {
9145: $resulttext .= '</ul></li>';
9146: }
1.26 raeburn 9147: }
1.1 raeburn 9148: }
1.163 raeburn 9149: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9150: if (ref($changes{'notify'}) eq 'HASH') {
9151: if ($changes{'notify'}{'approval'}) {
9152: if (ref($confhash{'notify'}) eq 'HASH') {
9153: if ($confhash{'notify'}{'approval'}) {
9154: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9155: } else {
1.163 raeburn 9156: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9157: }
9158: }
9159: }
9160: }
9161: }
1.216 raeburn 9162: if ($action eq 'requestcourses') {
9163: my @offon = ('off','on');
9164: if ($changes{'uniquecode'}) {
1.218 raeburn 9165: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9166: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9167: $resulttext .= '<li>'.
9168: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9169: '</li>';
9170: } else {
9171: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9172: '</li>';
9173: }
1.216 raeburn 9174: }
1.242 raeburn 9175: foreach my $type ('textbooks','templates') {
9176: if (ref($changes{$type}) eq 'HASH') {
9177: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9178: foreach my $key (sort(keys(%{$changes{$type}}))) {
9179: my %coursehash = &Apache::lonnet::coursedescription($key);
9180: my $coursetitle = $coursehash{'description'};
9181: my $position = $confhash{$type}{$key}{'order'} + 1;
9182: $resulttext .= '<li>';
1.243 raeburn 9183: foreach my $item ('subject','title','publisher','author') {
9184: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9185: ($type eq 'templates'));
1.242 raeburn 9186: my $name = $item.':';
9187: $name =~ s/^(\w)/\U$1/;
9188: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9189: }
9190: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9191: if ($type eq 'textbooks') {
9192: if ($confhash{$type}{$key}{'image'}) {
9193: $resulttext .= ' '.&mt('Image: [_1]',
9194: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9195: ' alt="Textbook cover" />').'<br />';
9196: }
9197: }
9198: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 9199: }
1.242 raeburn 9200: $resulttext .= '</ul></li>';
1.216 raeburn 9201: }
9202: }
1.235 raeburn 9203: if (ref($changes{'validation'}) eq 'HASH') {
9204: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9205: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9206: foreach my $item (@{$validationitemsref}) {
9207: if (exists($changes{'validation'}{$item})) {
9208: if ($item eq 'markup') {
9209: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9210: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9211: } else {
9212: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9213: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9214: }
9215: }
9216: }
9217: if (exists($changes{'validation'}{'dc'})) {
9218: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9219: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9220: }
9221: }
9222: }
1.216 raeburn 9223: }
1.1 raeburn 9224: $resulttext .= '</ul>';
1.80 raeburn 9225: if (keys(%newenv)) {
9226: &Apache::lonnet::appenv(\%newenv);
9227: }
1.1 raeburn 9228: } else {
1.86 raeburn 9229: if ($context eq 'requestcourses') {
9230: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 9231: } elsif ($context eq 'requestauthor') {
9232: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9233: } else {
1.90 weissno 9234: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9235: }
1.1 raeburn 9236: }
9237: } else {
1.11 albertel 9238: $resulttext = '<span class="LC_error">'.
9239: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9240: }
1.216 raeburn 9241: if ($errors) {
9242: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9243: '<ul>'.$errors.'</ul></p>';
9244: }
1.3 raeburn 9245: return $resulttext;
1.1 raeburn 9246: }
9247:
1.216 raeburn 9248: sub process_textbook_image {
1.242 raeburn 9249: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 9250: my $filename = $env{'form.'.$caller.'.filename'};
9251: my ($error,$url);
9252: my ($width,$height) = (50,50);
9253: if ($configuserok eq 'ok') {
9254: if ($switchserver) {
9255: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9256: $switchserver);
9257: } elsif ($author_ok eq 'ok') {
9258: my ($result,$imageurl) =
9259: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 9260: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 9261: if ($result eq 'ok') {
9262: $url = $imageurl;
9263: } else {
9264: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9265: }
9266: } else {
9267: $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);
9268: }
9269: } else {
9270: $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);
9271: }
9272: return ($url,$error);
9273: }
9274:
1.267 raeburn 9275: sub modify_ltitools {
9276: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
9277: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9278: my ($newid,@allpos,%changes,%confhash,$errors,$resulttext);
9279: my $confname = $dom.'-domainconfig';
9280: my $servadm = $r->dir_config('lonAdmEMail');
9281: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9282: my (%posslti,%possfield);
9283: my @courseroles = ('cc','in','ta','ep','st');
9284: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
9285: map { $posslti{$_} = 1; } @ltiroles;
9286: my @allfields = ('fullname','firstname','lastname','email','user','roles');
9287: map { $possfield{$_} = 1; } @allfields;
9288: my %lt = <itools_names();
9289: if ($env{'form.ltitools_add'}) {
9290: my $title = $env{'form.ltitools_add_title'};
9291: $title =~ s/(`)/'/g;
9292: ($newid,my $error) = &get_ltitools_id($dom,$title);
9293: if ($newid) {
9294: my $position = $env{'form.ltitools_add_pos'};
9295: $position =~ s/\D+//g;
9296: if ($position ne '') {
9297: $allpos[$position] = $newid;
9298: }
9299: $changes{$newid} = 1;
9300: foreach my $item ('title','url','key','secret') {
9301: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
9302: if ($env{'form.ltitools_add_'.$item}) {
9303: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9304: }
9305: }
9306: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
9307: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
9308: }
9309: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
9310: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
9311: }
9312: foreach my $item ('width','height') {
9313: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
9314: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
9315: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
9316: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9317: }
9318: }
9319: if ($env{'form.ltitools_add_target'} eq 'window') {
9320: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
9321: } else {
9322: $confhash{$newid}{'display'}{'target'} = 'iframe';
9323: }
9324: foreach my $item ('passback','roster') {
9325: if ($env{'form.ltitools_add_'.$item}) {
9326: $confhash{$newid}{$item} = 1;
9327: }
9328: }
9329: if ($env{'form.ltitools_add_image.filename'} ne '') {
9330: my ($imageurl,$error) =
9331: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
9332: $configuserok,$switchserver,$author_ok);
9333: if ($imageurl) {
9334: $confhash{$newid}{'image'} = $imageurl;
9335: }
9336: if ($error) {
9337: &Apache::lonnet::logthis($error);
9338: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9339: }
9340: }
9341: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
9342: foreach my $field (@fields) {
9343: if ($possfield{$field}) {
9344: if ($field eq 'roles') {
9345: foreach my $role (@courseroles) {
9346: my $choice = $env{'form.ltitools_add_roles_'.$role};
9347: if (($choice ne '') && ($posslti{$choice})) {
9348: $confhash{$newid}{'roles'}{$role} = $choice;
9349: if ($role eq 'cc') {
9350: $confhash{$newid}{'roles'}{'co'} = $choice;
9351: }
9352: }
9353: }
9354: } else {
9355: $confhash{$newid}{'fields'}{$field} = 1;
9356: }
9357: }
9358: }
1.273 raeburn 9359: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
9360: foreach my $item (@courseconfig) {
9361: $confhash{$newid}{'crsconf'}{$item} = 1;
9362: }
1.267 raeburn 9363: if ($env{'form.ltitools_add_custom'}) {
9364: my $name = $env{'form.ltitools_add_custom_name'};
9365: my $value = $env{'form.ltitools_add_custom_value'};
9366: $value =~ s/(`)/'/g;
9367: $name =~ s/(`)/'/g;
9368: $confhash{$newid}{'custom'}{$name} = $value;
9369: }
9370: } else {
9371: my $error = &mt('Failed to acquire unique ID for new external tool');
9372: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9373: }
9374: }
9375: if (ref($domconfig{$action}) eq 'HASH') {
9376: my %deletions;
9377: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
9378: if (@todelete) {
9379: map { $deletions{$_} = 1; } @todelete;
9380: }
9381: my %customadds;
9382: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
9383: if (@newcustom) {
9384: map { $customadds{$_} = 1; } @newcustom;
9385: }
9386: my %imgdeletions;
9387: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
9388: if (@todeleteimages) {
9389: map { $imgdeletions{$_} = 1; } @todeleteimages;
9390: }
9391: my $maxnum = $env{'form.ltitools_maxnum'};
9392: for (my $i=0; $i<=$maxnum; $i++) {
9393: my $itemid = $env{'form.ltitools_id_'.$i};
9394: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9395: if ($deletions{$itemid}) {
9396: if ($domconfig{$action}{$itemid}{'image'}) {
9397: #FIXME need to obsolete item in RES space
9398: }
9399: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
9400: next;
9401: } else {
9402: my $newpos = $env{'form.ltitools_'.$itemid};
9403: $newpos =~ s/\D+//g;
9404: foreach my $item ('title','url','key','secret') {
9405: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9406: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
9407: $changes{$itemid} = 1;
9408: }
9409: }
9410: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
9411: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
9412: }
9413: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
9414: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
9415: }
9416: foreach my $size ('width','height') {
9417: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
9418: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
9419: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
9420: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
9421: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9422: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
9423: $changes{$itemid} = 1;
9424: }
9425: } else {
9426: $changes{$itemid} = 1;
9427: }
9428: }
9429: }
9430: if ($env{'form.ltitools_target_'.$i} eq 'window') {
9431: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
9432: } else {
9433: $confhash{$itemid}{'display'}{'target'} = 'iframe';
9434: }
9435: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9436: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
9437: $changes{$itemid} = 1;
9438: }
9439: } else {
9440: $changes{$itemid} = 1;
9441: }
9442: foreach my $extra ('passback','roster') {
9443: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
9444: $confhash{$itemid}{$extra} = 1;
9445: }
9446: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
9447: $changes{$itemid} = 1;
9448: }
9449: }
1.273 raeburn 9450: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
9451: foreach my $item ('label','title','target') {
9452: if (grep(/^\Q$item\E$/,@courseconfig)) {
9453: $confhash{$itemid}{'crsconf'}{$item} = 1;
9454: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
9455: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
9456: $changes{$itemid} = 1;
9457: }
9458: } else {
9459: $changes{$itemid} = 1;
9460: }
9461: }
9462: }
1.267 raeburn 9463: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
9464: foreach my $field (@fields) {
9465: if ($possfield{$field}) {
9466: if ($field eq 'roles') {
9467: foreach my $role (@courseroles) {
9468: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
9469: if (($choice ne '') && ($posslti{$choice})) {
9470: $confhash{$itemid}{'roles'}{$role} = $choice;
9471: if ($role eq 'cc') {
9472: $confhash{$itemid}{'roles'}{'co'} = $choice;
9473: }
9474: }
9475: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
9476: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
9477: $changes{$itemid} = 1;
9478: }
9479: } elsif ($confhash{$itemid}{'roles'}{$role}) {
9480: $changes{$itemid} = 1;
9481: }
9482: }
9483: } else {
9484: $confhash{$itemid}{'fields'}{$field} = 1;
9485: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
9486: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
9487: $changes{$itemid} = 1;
9488: }
9489: } else {
9490: $changes{$itemid} = 1;
9491: }
9492: }
9493: }
9494: }
9495: $allpos[$newpos] = $itemid;
9496: }
9497: if ($imgdeletions{$itemid}) {
9498: $changes{$itemid} = 1;
9499: #FIXME need to obsolete item in RES space
9500: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
9501: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
9502: $itemid,$configuserok,$switchserver,
9503: $author_ok);
9504: if ($imgurl) {
9505: $confhash{$itemid}{'image'} = $imgurl;
9506: $changes{$itemid} = 1;
9507: }
9508: if ($error) {
9509: &Apache::lonnet::logthis($error);
9510: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9511: }
9512: } elsif ($domconfig{$action}{$itemid}{'image'}) {
9513: $confhash{$itemid}{'image'} =
9514: $domconfig{$action}{$itemid}{'image'};
9515: }
9516: if ($customadds{$i}) {
9517: my $name = $env{'form.ltitools_custom_name_'.$i};
9518: $name =~ s/(`)/'/g;
9519: $name =~ s/^\s+//;
9520: $name =~ s/\s+$//;
9521: my $value = $env{'form.ltitools_custom_value_'.$i};
9522: $value =~ s/(`)/'/g;
9523: $value =~ s/^\s+//;
9524: $value =~ s/\s+$//;
9525: if ($name ne '') {
9526: $confhash{$itemid}{'custom'}{$name} = $value;
9527: $changes{$itemid} = 1;
9528: }
9529: }
9530: my %customdels;
9531: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
9532: if (@customdeletions) {
9533: $changes{$itemid} = 1;
9534: }
9535: map { $customdels{$_} = 1; } @customdeletions;
9536: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
9537: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
9538: unless ($customdels{$key}) {
9539: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
9540: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
9541: }
9542: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
9543: $changes{$itemid} = 1;
9544: }
9545: }
9546: }
9547: }
9548: unless ($changes{$itemid}) {
9549: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
9550: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
9551: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
9552: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
9553: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
9554: $changes{$itemid} = 1;
9555: last;
9556: }
9557: }
9558: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
9559: $changes{$itemid} = 1;
9560: }
9561: }
9562: last if ($changes{$itemid});
9563: }
9564: }
9565: }
9566: }
9567: }
9568: if (@allpos > 0) {
9569: my $idx = 0;
9570: foreach my $itemid (@allpos) {
9571: if ($itemid ne '') {
9572: $confhash{$itemid}{'order'} = $idx;
9573: if (ref($domconfig{$action}) eq 'HASH') {
9574: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9575: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
9576: $changes{$itemid} = 1;
9577: }
9578: }
9579: }
9580: $idx ++;
9581: }
9582: }
9583: }
9584: my %ltitoolshash = (
9585: $action => { %confhash }
9586: );
9587: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
9588: $dom);
9589: if ($putresult eq 'ok') {
9590: if (keys(%changes) > 0) {
9591: my $cachetime = 24*60*60;
9592: &Apache::lonnet::do_cache_new('ltitools',$dom,\%confhash,$cachetime);
9593: if (ref($lastactref) eq 'HASH') {
9594: $lastactref->{'ltitools'} = 1;
9595: }
9596: $resulttext = &mt('Changes made:').'<ul>';
9597: my %bynum;
9598: foreach my $itemid (sort(keys(%changes))) {
9599: my $position = $confhash{$itemid}{'order'};
9600: $bynum{$position} = $itemid;
9601: }
9602: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9603: my $itemid = $bynum{$pos};
9604: if (ref($confhash{$itemid}) ne 'HASH') {
9605: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9606: } else {
9607: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
9608: if ($confhash{$itemid}{'image'}) {
9609: $resulttext .= ' '.
9610: '<img src="'.$confhash{$itemid}{'image'}.'"'.
9611: ' alt="'.&mt('Tool Provider icon').'" />';
9612: }
9613: $resulttext .= '</li><ul>';
9614: my $position = $pos + 1;
9615: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
9616: foreach my $item ('version','msgtype','url','key') {
9617: if ($confhash{$itemid}{$item} ne '') {
9618: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
9619: }
9620: }
9621: if ($confhash{$itemid}{'secret'} ne '') {
9622: $resulttext .= '<li>'.$lt{'secret'}.': ';
9623: my $num = length($confhash{$itemid}{'secret'});
9624: $resulttext .= ('*'x$num).'</li>';
9625: }
1.273 raeburn 9626: $resulttext .= '<li>'.&mt('Configurable in course:');
9627: my @possconfig = ('label','title','target');
9628: my $numconfig = 0;
9629: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
9630: foreach my $item (@possconfig) {
9631: if ($confhash{$itemid}{'crsconf'}{$item}) {
9632: $numconfig ++;
9633: $resulttext .= ' '.$lt{'crs'.$item};
9634: }
9635: }
9636: }
9637: if (!$numconfig) {
9638: $resulttext .= &mt('None');
9639: }
9640: $resulttext .= '</li>';
1.267 raeburn 9641: foreach my $item ('passback','roster') {
9642: $resulttext .= '<li>'.$lt{$item}.' ';
9643: if ($confhash{$itemid}{$item}) {
9644: $resulttext .= &mt('Yes');
9645: } else {
9646: $resulttext .= &mt('No');
9647: }
9648: $resulttext .= '</li>';
9649: }
9650: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
9651: my $displaylist;
9652: if ($confhash{$itemid}{'display'}{'target'}) {
9653: $displaylist = &mt('Display target').': '.
9654: $confhash{$itemid}{'display'}{'target'}.',';
9655: }
9656: foreach my $size ('width','height') {
9657: if ($confhash{$itemid}{'display'}{$size}) {
9658: $displaylist .= (' 'x2).$lt{$size}.': '.
9659: $confhash{$itemid}{'display'}{$size}.',';
9660: }
9661: }
9662: if ($displaylist) {
9663: $displaylist =~ s/,$//;
9664: $resulttext .= '<li>'.$displaylist.'</li>';
9665: }
9666: }
9667: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
9668: my $fieldlist;
9669: foreach my $field (@allfields) {
9670: if ($confhash{$itemid}{'fields'}{$field}) {
9671: $fieldlist .= (' 'x2).$lt{$field}.',';
9672: }
9673: }
9674: if ($fieldlist) {
9675: $fieldlist =~ s/,$//;
9676: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
9677: }
9678: }
9679: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
9680: my $rolemaps;
9681: foreach my $role (@courseroles) {
9682: if ($confhash{$itemid}{'roles'}{$role}) {
9683: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
9684: $confhash{$itemid}{'roles'}{$role}.',';
9685: }
9686: }
9687: if ($rolemaps) {
9688: $rolemaps =~ s/,$//;
9689: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
9690: }
9691: }
9692: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
9693: my $customlist;
9694: if (keys(%{$confhash{$itemid}{'custom'}})) {
9695: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
9696: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
9697: }
9698: }
9699: if ($customlist) {
9700: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
9701: }
9702: }
9703: $resulttext .= '</ul></li>';
9704: }
9705: }
9706: $resulttext .= '</ul>';
9707: } else {
9708: $resulttext = &mt('No changes made.');
9709: }
9710: } else {
9711: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9712: }
9713: if ($errors) {
9714: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9715: $errors.'</ul>';
9716: }
9717: return $resulttext;
9718: }
9719:
9720: sub process_ltitools_image {
9721: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
9722: my $filename = $env{'form.'.$caller.'.filename'};
9723: my ($error,$url);
9724: my ($width,$height) = (21,21);
9725: if ($configuserok eq 'ok') {
9726: if ($switchserver) {
9727: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
9728: $switchserver);
9729: } elsif ($author_ok eq 'ok') {
9730: my ($result,$imageurl,$madethumb) =
9731: &publishlogo($r,'upload',$caller,$dom,$confname,
9732: "ltitools/$itemid/icon",$width,$height);
9733: if ($result eq 'ok') {
9734: if ($madethumb) {
9735: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
9736: my $imagethumb = "$path/tn-".$imagefile;
9737: $url = $imagethumb;
9738: } else {
9739: $url = $imageurl;
9740: }
9741: } else {
9742: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9743: }
9744: } else {
9745: $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);
9746: }
9747: } else {
9748: $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);
9749: }
9750: return ($url,$error);
9751: }
9752:
9753: sub get_ltitools_id {
9754: my ($cdom,$title) = @_;
9755: # get lock on ltitools db
9756: my $lockhash = {
9757: lock => $env{'user.name'}.
9758: ':'.$env{'user.domain'},
9759: };
9760: my $tries = 0;
9761: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9762: my ($id,$error);
9763:
9764: while (($gotlock ne 'ok') && ($tries<10)) {
9765: $tries ++;
9766: sleep (0.1);
9767: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9768: }
9769: if ($gotlock eq 'ok') {
9770: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
9771: if ($currids{'lock'}) {
9772: delete($currids{'lock'});
9773: if (keys(%currids)) {
9774: my @curr = sort { $a <=> $b } keys(%currids);
9775: if ($curr[-1] =~ /^\d+$/) {
9776: $id = 1 + $curr[-1];
9777: }
9778: } else {
9779: $id = 1;
9780: }
9781: if ($id) {
9782: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
9783: $error = 'nostore';
9784: }
9785: } else {
9786: $error = 'nonumber';
9787: }
9788: }
9789: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
9790: } else {
9791: $error = 'nolock';
9792: }
9793: return ($id,$error);
9794: }
9795:
1.3 raeburn 9796: sub modify_autoenroll {
1.205 raeburn 9797: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 9798: my ($resulttext,%changes);
9799: my %currautoenroll;
9800: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9801: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9802: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9803: }
9804: }
9805: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9806: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 9807: sender => 'Sender for notification messages',
1.274 raeburn 9808: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9809: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 9810: my @offon = ('off','on');
1.17 raeburn 9811: my $sender_uname = $env{'form.sender_uname'};
9812: my $sender_domain = $env{'form.sender_domain'};
9813: if ($sender_domain eq '') {
9814: $sender_uname = '';
9815: } elsif ($sender_uname eq '') {
9816: $sender_domain = '';
9817: }
1.129 raeburn 9818: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 9819: my $failsafe = $env{'form.autoenroll_failsafe'};
9820: $failsafe =~ s{^\s+|\s+$}{}g;
9821: if ($failsafe =~ /\D/) {
9822: undef($failsafe);
9823: }
1.1 raeburn 9824: my %autoenrollhash = (
1.129 raeburn 9825: autoenroll => { 'run' => $env{'form.autoenroll_run'},
9826: 'sender_uname' => $sender_uname,
9827: 'sender_domain' => $sender_domain,
9828: 'co-owners' => $coowners,
1.274 raeburn 9829: 'autofailsafe' => $failsafe,
1.1 raeburn 9830: }
9831: );
1.4 raeburn 9832: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
9833: $dom);
1.1 raeburn 9834: if ($putresult eq 'ok') {
9835: if (exists($currautoenroll{'run'})) {
9836: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
9837: $changes{'run'} = 1;
9838: }
9839: } elsif ($autorun) {
9840: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 9841: $changes{'run'} = 1;
1.1 raeburn 9842: }
9843: }
1.17 raeburn 9844: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 9845: $changes{'sender'} = 1;
9846: }
1.17 raeburn 9847: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 9848: $changes{'sender'} = 1;
9849: }
1.129 raeburn 9850: if ($currautoenroll{'co-owners'} ne '') {
9851: if ($currautoenroll{'co-owners'} ne $coowners) {
9852: $changes{'coowners'} = 1;
9853: }
9854: } elsif ($coowners) {
9855: $changes{'coowners'} = 1;
1.274 raeburn 9856: }
9857: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
9858: $changes{'autofailsafe'} = 1;
9859: }
1.1 raeburn 9860: if (keys(%changes) > 0) {
9861: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 9862: if ($changes{'run'}) {
1.1 raeburn 9863: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
9864: }
9865: if ($changes{'sender'}) {
1.17 raeburn 9866: if ($sender_uname eq '' || $sender_domain eq '') {
9867: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
9868: } else {
9869: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
9870: }
1.1 raeburn 9871: }
1.129 raeburn 9872: if ($changes{'coowners'}) {
9873: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
9874: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9875: if (ref($lastactref) eq 'HASH') {
9876: $lastactref->{'domainconfig'} = 1;
9877: }
1.129 raeburn 9878: }
1.274 raeburn 9879: if ($changes{'autofailsafe'}) {
9880: if ($failsafe ne '') {
9881: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
9882: } else {
9883: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
9884: }
9885: &Apache::lonnet::get_domain_defaults($dom,1);
9886: if (ref($lastactref) eq 'HASH') {
9887: $lastactref->{'domdefaults'} = 1;
9888: }
9889: }
1.1 raeburn 9890: $resulttext .= '</ul>';
9891: } else {
9892: $resulttext = &mt('No changes made to auto-enrollment settings');
9893: }
9894: } else {
1.11 albertel 9895: $resulttext = '<span class="LC_error">'.
9896: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9897: }
1.3 raeburn 9898: return $resulttext;
1.1 raeburn 9899: }
9900:
9901: sub modify_autoupdate {
1.3 raeburn 9902: my ($dom,%domconfig) = @_;
1.1 raeburn 9903: my ($resulttext,%currautoupdate,%fields,%changes);
9904: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
9905: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
9906: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
9907: }
9908: }
9909: my @offon = ('off','on');
9910: my %title = &Apache::lonlocal::texthash (
9911: run => 'Auto-update:',
9912: classlists => 'Updates to user information in classlists?'
9913: );
1.44 raeburn 9914: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9915: my %fieldtitles = &Apache::lonlocal::texthash (
9916: id => 'Student/Employee ID',
1.20 raeburn 9917: permanentemail => 'E-mail address',
1.1 raeburn 9918: lastname => 'Last Name',
9919: firstname => 'First Name',
9920: middlename => 'Middle Name',
1.132 raeburn 9921: generation => 'Generation',
1.1 raeburn 9922: );
1.142 raeburn 9923: $othertitle = &mt('All users');
1.1 raeburn 9924: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 9925: $othertitle = &mt('Other users');
1.1 raeburn 9926: }
9927: foreach my $key (keys(%env)) {
9928: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 9929: my ($usertype,$item) = ($1,$2);
9930: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
9931: if ($usertype eq 'default') {
9932: push(@{$fields{$1}},$2);
9933: } elsif (ref($types) eq 'ARRAY') {
9934: if (grep(/^\Q$usertype\E$/,@{$types})) {
9935: push(@{$fields{$1}},$2);
9936: }
9937: }
9938: }
1.1 raeburn 9939: }
9940: }
1.131 raeburn 9941: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
9942: @lockablenames = sort(@lockablenames);
9943: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
9944: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9945: if (@changed) {
9946: $changes{'lockablenames'} = 1;
9947: }
9948: } else {
9949: if (@lockablenames) {
9950: $changes{'lockablenames'} = 1;
9951: }
9952: }
1.1 raeburn 9953: my %updatehash = (
9954: autoupdate => { run => $env{'form.autoupdate_run'},
9955: classlists => $env{'form.classlists'},
9956: fields => {%fields},
1.131 raeburn 9957: lockablenames => \@lockablenames,
1.1 raeburn 9958: }
9959: );
9960: foreach my $key (keys(%currautoupdate)) {
9961: if (($key eq 'run') || ($key eq 'classlists')) {
9962: if (exists($updatehash{autoupdate}{$key})) {
9963: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
9964: $changes{$key} = 1;
9965: }
9966: }
9967: } elsif ($key eq 'fields') {
9968: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 9969: foreach my $item (@{$types},'default') {
1.1 raeburn 9970: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
9971: my $change = 0;
9972: foreach my $type (@{$currautoupdate{$key}{$item}}) {
9973: if (!exists($fields{$item})) {
9974: $change = 1;
1.132 raeburn 9975: last;
1.1 raeburn 9976: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 9977: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 9978: $change = 1;
1.132 raeburn 9979: last;
1.1 raeburn 9980: }
9981: }
9982: }
9983: if ($change) {
9984: push(@{$changes{$key}},$item);
9985: }
1.26 raeburn 9986: }
1.1 raeburn 9987: }
9988: }
1.131 raeburn 9989: } elsif ($key eq 'lockablenames') {
9990: if (ref($currautoupdate{$key}) eq 'ARRAY') {
9991: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9992: if (@changed) {
9993: $changes{'lockablenames'} = 1;
9994: }
9995: } else {
9996: if (@lockablenames) {
9997: $changes{'lockablenames'} = 1;
9998: }
9999: }
10000: }
10001: }
10002: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10003: if (@lockablenames) {
10004: $changes{'lockablenames'} = 1;
1.1 raeburn 10005: }
10006: }
1.26 raeburn 10007: foreach my $item (@{$types},'default') {
10008: if (defined($fields{$item})) {
10009: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 10010: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10011: my $change = 0;
10012: if (ref($fields{$item}) eq 'ARRAY') {
10013: foreach my $type (@{$fields{$item}}) {
10014: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10015: $change = 1;
10016: last;
10017: }
10018: }
10019: }
10020: if ($change) {
10021: push(@{$changes{'fields'}},$item);
10022: }
10023: } else {
1.26 raeburn 10024: push(@{$changes{'fields'}},$item);
10025: }
10026: } else {
10027: push(@{$changes{'fields'}},$item);
1.1 raeburn 10028: }
10029: }
10030: }
10031: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10032: $dom);
10033: if ($putresult eq 'ok') {
10034: if (keys(%changes) > 0) {
10035: $resulttext = &mt('Changes made:').'<ul>';
10036: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 10037: if ($key eq 'lockablenames') {
10038: $resulttext .= '<li>';
10039: if (@lockablenames) {
10040: $usertypes->{'default'} = $othertitle;
10041: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10042: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10043: } else {
10044: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10045: }
10046: $resulttext .= '</li>';
10047: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 10048: foreach my $item (@{$changes{$key}}) {
10049: my @newvalues;
10050: foreach my $type (@{$fields{$item}}) {
10051: push(@newvalues,$fieldtitles{$type});
10052: }
1.3 raeburn 10053: my $newvaluestr;
10054: if (@newvalues > 0) {
10055: $newvaluestr = join(', ',@newvalues);
10056: } else {
10057: $newvaluestr = &mt('none');
1.6 raeburn 10058: }
1.1 raeburn 10059: if ($item eq 'default') {
1.26 raeburn 10060: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 10061: } else {
1.26 raeburn 10062: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 10063: }
10064: }
10065: } else {
10066: my $newvalue;
10067: if ($key eq 'run') {
10068: $newvalue = $offon[$env{'form.autoupdate_run'}];
10069: } else {
10070: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 10071: }
1.1 raeburn 10072: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
10073: }
10074: }
10075: $resulttext .= '</ul>';
10076: } else {
1.3 raeburn 10077: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 10078: }
10079: } else {
1.11 albertel 10080: $resulttext = '<span class="LC_error">'.
10081: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10082: }
1.3 raeburn 10083: return $resulttext;
1.1 raeburn 10084: }
10085:
1.125 raeburn 10086: sub modify_autocreate {
10087: my ($dom,%domconfig) = @_;
10088: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10089: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10090: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10091: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10092: }
10093: }
10094: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10095: req => 'Auto-creation of validated requests for official courses',
10096: xmldc => 'Identity of course creator of courses from XML files',
10097: );
10098: my @types = ('xml','req');
10099: foreach my $item (@types) {
10100: $newvals{$item} = $env{'form.autocreate_'.$item};
10101: $newvals{$item} =~ s/\D//g;
10102: $newvals{$item} = 0 if ($newvals{$item} eq '');
10103: }
10104: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 10105: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 10106: unless (exists($domcoords{$newvals{'xmldc'}})) {
10107: $newvals{'xmldc'} = '';
10108: }
10109: %autocreatehash = (
10110: autocreate => { xml => $newvals{'xml'},
10111: req => $newvals{'req'},
10112: }
10113: );
10114: if ($newvals{'xmldc'} ne '') {
10115: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10116: }
10117: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10118: $dom);
10119: if ($putresult eq 'ok') {
10120: my @items = @types;
10121: if ($newvals{'xml'}) {
10122: push(@items,'xmldc');
10123: }
10124: foreach my $item (@items) {
10125: if (exists($currautocreate{$item})) {
10126: if ($currautocreate{$item} ne $newvals{$item}) {
10127: $changes{$item} = 1;
10128: }
10129: } elsif ($newvals{$item}) {
10130: $changes{$item} = 1;
10131: }
10132: }
10133: if (keys(%changes) > 0) {
10134: my @offon = ('off','on');
10135: $resulttext = &mt('Changes made:').'<ul>';
10136: foreach my $item (@types) {
10137: if ($changes{$item}) {
10138: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 10139: $resulttext .= '<li>'.
10140: &mt("$title{$item} set to [_1]$newtxt [_2]",
10141: '<b>','</b>').
10142: '</li>';
1.125 raeburn 10143: }
10144: }
10145: if ($changes{'xmldc'}) {
10146: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10147: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 10148: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 10149: }
10150: $resulttext .= '</ul>';
10151: } else {
10152: $resulttext = &mt('No changes made to auto-creation settings');
10153: }
10154: } else {
10155: $resulttext = '<span class="LC_error">'.
10156: &mt('An error occurred: [_1]',$putresult).'</span>';
10157: }
10158: return $resulttext;
10159: }
10160:
1.23 raeburn 10161: sub modify_directorysrch {
10162: my ($dom,%domconfig) = @_;
10163: my ($resulttext,%changes);
10164: my %currdirsrch;
10165: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10166: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10167: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10168: }
10169: }
1.277 raeburn 10170: my %title = ( available => 'Institutional directory search available',
10171: localonly => 'Other domains can search institution',
10172: lcavailable => 'LON-CAPA directory search available',
10173: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 10174: searchby => 'Search types',
10175: searchtypes => 'Search latitude');
10176: my @offon = ('off','on');
1.24 raeburn 10177: my @otherdoms = ('Yes','No');
1.23 raeburn 10178:
1.25 raeburn 10179: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 10180: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10181: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10182:
1.44 raeburn 10183: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 10184: if (keys(%{$usertypes}) == 0) {
10185: @cansearch = ('default');
10186: } else {
10187: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10188: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10189: if (!grep(/^\Q$type\E$/,@cansearch)) {
10190: push(@{$changes{'cansearch'}},$type);
10191: }
1.23 raeburn 10192: }
1.26 raeburn 10193: foreach my $type (@cansearch) {
10194: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10195: push(@{$changes{'cansearch'}},$type);
10196: }
1.23 raeburn 10197: }
1.26 raeburn 10198: } else {
10199: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 10200: }
10201: }
10202:
10203: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10204: foreach my $by (@{$currdirsrch{'searchby'}}) {
10205: if (!grep(/^\Q$by\E$/,@searchby)) {
10206: push(@{$changes{'searchby'}},$by);
10207: }
10208: }
10209: foreach my $by (@searchby) {
10210: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10211: push(@{$changes{'searchby'}},$by);
10212: }
10213: }
10214: } else {
10215: push(@{$changes{'searchby'}},@searchby);
10216: }
1.25 raeburn 10217:
10218: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10219: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10220: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10221: push(@{$changes{'searchtypes'}},$type);
10222: }
10223: }
10224: foreach my $type (@searchtypes) {
10225: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10226: push(@{$changes{'searchtypes'}},$type);
10227: }
10228: }
10229: } else {
10230: if (exists($currdirsrch{'searchtypes'})) {
10231: foreach my $type (@searchtypes) {
10232: if ($type ne $currdirsrch{'searchtypes'}) {
10233: push(@{$changes{'searchtypes'}},$type);
10234: }
10235: }
10236: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10237: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10238: }
10239: } else {
10240: push(@{$changes{'searchtypes'}},@searchtypes);
10241: }
10242: }
10243:
1.23 raeburn 10244: my %dirsrch_hash = (
10245: directorysrch => { available => $env{'form.dirsrch_available'},
10246: cansearch => \@cansearch,
1.277 raeburn 10247: localonly => $env{'form.dirsrch_instlocalonly'},
10248: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10249: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 10250: searchby => \@searchby,
1.25 raeburn 10251: searchtypes => \@searchtypes,
1.23 raeburn 10252: }
10253: );
10254: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10255: $dom);
10256: if ($putresult eq 'ok') {
10257: if (exists($currdirsrch{'available'})) {
10258: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10259: $changes{'available'} = 1;
10260: }
10261: } else {
10262: if ($env{'form.dirsrch_available'} eq '1') {
10263: $changes{'available'} = 1;
10264: }
10265: }
1.277 raeburn 10266: if (exists($currdirsrch{'lcavailable'})) {
10267: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
10268: $changes{'lcavailable'} = 1;
10269: }
10270: } else {
10271: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10272: $changes{'lcavailable'} = 1;
10273: }
10274: }
1.24 raeburn 10275: if (exists($currdirsrch{'localonly'})) {
1.277 raeburn 10276: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 10277: $changes{'localonly'} = 1;
10278: }
10279: } else {
1.277 raeburn 10280: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 10281: $changes{'localonly'} = 1;
10282: }
10283: }
1.277 raeburn 10284: if (exists($currdirsrch{'lclocalonly'})) {
10285: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
10286: $changes{'lclocalonly'} = 1;
10287: }
10288: } else {
10289: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10290: $changes{'lclocalonly'} = 1;
10291: }
10292: }
1.23 raeburn 10293: if (keys(%changes) > 0) {
10294: $resulttext = &mt('Changes made:').'<ul>';
10295: if ($changes{'available'}) {
10296: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10297: }
1.277 raeburn 10298: if ($changes{'lcavailable'}) {
10299: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10300: }
1.24 raeburn 10301: if ($changes{'localonly'}) {
1.277 raeburn 10302: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 10303: }
1.277 raeburn 10304: if ($changes{'lclocalonly'}) {
10305: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
10306: }
1.23 raeburn 10307: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10308: my $chgtext;
1.26 raeburn 10309: if (ref($usertypes) eq 'HASH') {
10310: if (keys(%{$usertypes}) > 0) {
10311: foreach my $type (@{$types}) {
10312: if (grep(/^\Q$type\E$/,@cansearch)) {
10313: $chgtext .= $usertypes->{$type}.'; ';
10314: }
10315: }
10316: if (grep(/^default$/,@cansearch)) {
10317: $chgtext .= $othertitle;
10318: } else {
10319: $chgtext =~ s/\; $//;
10320: }
1.210 raeburn 10321: $resulttext .=
1.178 raeburn 10322: '<li>'.
10323: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10324: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10325: '</li>';
1.23 raeburn 10326: }
10327: }
10328: }
10329: if (ref($changes{'searchby'}) eq 'ARRAY') {
10330: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10331: my $chgtext;
10332: foreach my $type (@{$titleorder}) {
10333: if (grep(/^\Q$type\E$/,@searchby)) {
10334: if (defined($searchtitles->{$type})) {
10335: $chgtext .= $searchtitles->{$type}.'; ';
10336: }
10337: }
10338: }
10339: $chgtext =~ s/\; $//;
10340: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10341: }
1.25 raeburn 10342: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10343: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10344: my $chgtext;
10345: foreach my $type (@{$srchtypeorder}) {
10346: if (grep(/^\Q$type\E$/,@searchtypes)) {
10347: if (defined($srchtypes_desc->{$type})) {
10348: $chgtext .= $srchtypes_desc->{$type}.'; ';
10349: }
10350: }
10351: }
10352: $chgtext =~ s/\; $//;
1.178 raeburn 10353: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 10354: }
10355: $resulttext .= '</ul>';
10356: } else {
1.277 raeburn 10357: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 10358: }
10359: } else {
10360: $resulttext = '<span class="LC_error">'.
1.27 raeburn 10361: &mt('An error occurred: [_1]',$putresult).'</span>';
10362: }
10363: return $resulttext;
10364: }
10365:
1.28 raeburn 10366: sub modify_contacts {
1.205 raeburn 10367: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 10368: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10369: if (ref($domconfig{'contacts'}) eq 'HASH') {
10370: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10371: $currsetting{$key} = $domconfig{'contacts'}{$key};
10372: }
10373: }
1.286 raeburn 10374: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 10375: my @contacts = ('supportemail','adminemail');
1.286 raeburn 10376: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
10377: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 10378: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 10379: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 10380: foreach my $type (@mailings) {
10381: @{$newsetting{$type}} =
10382: &Apache::loncommon::get_env_multiple('form.'.$type);
10383: foreach my $item (@contacts) {
10384: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
10385: $contacts_hash{contacts}{$type}{$item} = 1;
10386: } else {
10387: $contacts_hash{contacts}{$type}{$item} = 0;
10388: }
10389: }
10390: $others{$type} = $env{'form.'.$type.'_others'};
10391: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 10392: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10393: $bcc{$type} = $env{'form.'.$type.'_bcc'};
10394: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 10395: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
10396: $includestr{$type} = $env{'form.'.$type.'_includestr'};
10397: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
10398: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10399: }
1.134 raeburn 10400: }
1.28 raeburn 10401: }
10402: foreach my $item (@contacts) {
10403: $to{$item} = $env{'form.'.$item};
10404: $contacts_hash{'contacts'}{$item} = $to{$item};
10405: }
1.203 raeburn 10406: foreach my $item (@toggles) {
10407: if ($env{'form.'.$item} =~ /^(0|1)$/) {
10408: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
10409: }
10410: }
1.286 raeburn 10411: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
10412: foreach my $field (@{$fields}) {
10413: if (ref($possoptions->{$field}) eq 'ARRAY') {
10414: my $value = $env{'form.helpform_'.$field};
10415: $value =~ s/^\s+|\s+$//g;
10416: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
10417: $contacts_hash{contacts}{'helpform'}{$field} = $value;
10418: if ($field eq 'screenshot') {
10419: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
10420: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
10421: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
10422: }
10423: }
10424: }
10425: }
10426: }
10427: }
1.28 raeburn 10428: if (keys(%currsetting) > 0) {
10429: foreach my $item (@contacts) {
10430: if ($to{$item} ne $currsetting{$item}) {
10431: $changes{$item} = 1;
10432: }
10433: }
10434: foreach my $type (@mailings) {
10435: foreach my $item (@contacts) {
10436: if (ref($currsetting{$type}) eq 'HASH') {
10437: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
10438: push(@{$changes{$type}},$item);
10439: }
10440: } else {
10441: push(@{$changes{$type}},@{$newsetting{$type}});
10442: }
10443: }
10444: if ($others{$type} ne $currsetting{$type}{'others'}) {
10445: push(@{$changes{$type}},'others');
10446: }
1.286 raeburn 10447: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10448: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
10449: push(@{$changes{$type}},'bcc');
10450: }
1.286 raeburn 10451: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
10452: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
10453: push(@{$changes{$type}},'include');
10454: }
10455: }
10456: }
10457: if (ref($fields) eq 'ARRAY') {
10458: if (ref($currsetting{'helpform'}) eq 'HASH') {
10459: foreach my $field (@{$fields}) {
10460: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
10461: push(@{$changes{'helpform'}},$field);
10462: }
10463: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10464: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
10465: push(@{$changes{'helpform'}},'maxsize');
10466: }
10467: }
10468: }
10469: } else {
10470: foreach my $field (@{$fields}) {
10471: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10472: push(@{$changes{'helpform'}},$field);
10473: }
10474: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10475: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10476: push(@{$changes{'helpform'}},'maxsize');
10477: }
10478: }
10479: }
1.134 raeburn 10480: }
1.28 raeburn 10481: }
10482: } else {
10483: my %default;
10484: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
10485: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
10486: $default{'errormail'} = 'adminemail';
10487: $default{'packagesmail'} = 'adminemail';
10488: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 10489: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 10490: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 10491: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 10492: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 10493: foreach my $item (@contacts) {
10494: if ($to{$item} ne $default{$item}) {
1.286 raeburn 10495: $changes{$item} = 1;
1.203 raeburn 10496: }
1.28 raeburn 10497: }
10498: foreach my $type (@mailings) {
10499: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
10500: push(@{$changes{$type}},@{$newsetting{$type}});
10501: }
10502: if ($others{$type} ne '') {
10503: push(@{$changes{$type}},'others');
1.134 raeburn 10504: }
1.286 raeburn 10505: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10506: if ($bcc{$type} ne '') {
10507: push(@{$changes{$type}},'bcc');
10508: }
1.286 raeburn 10509: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
10510: push(@{$changes{$type}},'include');
10511: }
1.134 raeburn 10512: }
1.28 raeburn 10513: }
1.286 raeburn 10514: if (ref($fields) eq 'ARRAY') {
10515: foreach my $field (@{$fields}) {
10516: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10517: push(@{$changes{'helpform'}},$field);
10518: }
10519: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10520: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10521: push(@{$changes{'helpform'}},'maxsize');
10522: }
10523: }
10524: }
10525: }
1.28 raeburn 10526: }
1.203 raeburn 10527: foreach my $item (@toggles) {
10528: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
10529: $changes{$item} = 1;
10530: } elsif ((!$env{'form.'.$item}) &&
10531: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
10532: $changes{$item} = 1;
10533: }
10534: }
1.28 raeburn 10535: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
10536: $dom);
10537: if ($putresult eq 'ok') {
10538: if (keys(%changes) > 0) {
1.205 raeburn 10539: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10540: if (ref($lastactref) eq 'HASH') {
10541: $lastactref->{'domainconfig'} = 1;
10542: }
1.28 raeburn 10543: my ($titles,$short_titles) = &contact_titles();
10544: $resulttext = &mt('Changes made:').'<ul>';
10545: foreach my $item (@contacts) {
10546: if ($changes{$item}) {
10547: $resulttext .= '<li>'.$titles->{$item}.
10548: &mt(' set to: ').
10549: '<span class="LC_cusr_emph">'.
10550: $to{$item}.'</span></li>';
10551: }
10552: }
10553: foreach my $type (@mailings) {
10554: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 10555: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
10556: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
10557: } else {
10558: $resulttext .= '<li>'.$titles->{$type}.': ';
10559: }
1.28 raeburn 10560: my @text;
10561: foreach my $item (@{$newsetting{$type}}) {
10562: push(@text,$short_titles->{$item});
10563: }
10564: if ($others{$type} ne '') {
10565: push(@text,$others{$type});
10566: }
1.286 raeburn 10567: if (@text) {
10568: $resulttext .= '<span class="LC_cusr_emph">'.
10569: join(', ',@text).'</span>';
10570: }
10571: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10572: if ($bcc{$type} ne '') {
1.286 raeburn 10573: my $bcctext;
10574: if (@text) {
10575: $bcctext = ' '.&mt('with Bcc to');
10576: } else {
10577: $bcctext = '(Bcc)';
10578: }
10579: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10580: } elsif (!@text) {
10581: $resulttext .= &mt('No one');
10582: }
10583: if ($includestr{$type} ne '') {
10584: if ($includeloc{$type} eq 'b') {
10585: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
10586: } elsif ($includeloc{$type} eq 's') {
10587: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
10588: }
1.134 raeburn 10589: }
1.286 raeburn 10590: } elsif (!@text) {
10591: $resulttext .= &mt('No recipients');
1.134 raeburn 10592: }
10593: $resulttext .= '</li>';
1.28 raeburn 10594: }
10595: }
1.203 raeburn 10596: my @offon = ('off','on');
10597: if ($changes{'reporterrors'}) {
10598: $resulttext .= '<li>'.
10599: &mt('E-mail error reports to [_1] set to "'.
10600: $offon[$env{'form.reporterrors'}].'".',
10601: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10602: &mt('LON-CAPA core group - MSU'),600,500)).
10603: '</li>';
10604: }
10605: if ($changes{'reportupdates'}) {
10606: $resulttext .= '<li>'.
10607: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
10608: $offon[$env{'form.reportupdates'}].'".',
10609: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10610: &mt('LON-CAPA core group - MSU'),600,500)).
10611: '</li>';
10612: }
1.286 raeburn 10613: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
10614: my (@optional,@required,@unused,$maxsizechg);
10615: foreach my $field (@{$changes{'helpform'}}) {
10616: if ($field eq 'maxsize') {
10617: $maxsizechg = 1;
10618: next;
10619: }
10620: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
10621: push(@optional,$field);
10622: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
10623: push(@unused,$field);
10624: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
10625: push(@required,$field);
10626: }
10627: }
10628: if (@optional) {
10629: $resulttext .= '<li>'.
10630: &mt('Help form fields changed to "Optional": [_1].',
10631: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
10632: '</li>';
10633: }
10634: if (@required) {
10635: $resulttext .= '<li>'.
10636: &mt('Help form fields changed to "Required": [_1].',
10637: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
10638: '</li>';
10639: }
10640: if (@unused) {
10641: $resulttext .= '<li>'.
10642: &mt('Help form fields changed to "Not shown": [_1].',
10643: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
10644: '</li>';
10645: }
10646: if ($maxsizechg) {
10647: $resulttext .= '<li>'.
10648: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
10649: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
10650: '</li>';
10651:
10652: }
10653: }
1.28 raeburn 10654: $resulttext .= '</ul>';
10655: } else {
1.288 ! raeburn 10656: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 10657: }
10658: } else {
10659: $resulttext = '<span class="LC_error">'.
10660: &mt('An error occurred: [_1].',$putresult).'</span>';
10661: }
10662: return $resulttext;
10663: }
10664:
10665: sub modify_usercreation {
1.27 raeburn 10666: my ($dom,%domconfig) = @_;
1.224 raeburn 10667: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 10668: my $warningmsg;
1.27 raeburn 10669: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10670: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 10671: if ($key eq 'cancreate') {
10672: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10673: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10674: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269 raeburn 10675: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
10676: ($item eq 'recaptchaversion')) {
1.224 raeburn 10677: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10678: } else {
10679: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10680: }
10681: }
10682: }
10683: } elsif ($key eq 'email_rule') {
10684: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10685: } else {
10686: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10687: }
1.27 raeburn 10688: }
10689: }
10690: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 10691: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 10692: my @contexts = ('author','course','requestcrs');
1.34 raeburn 10693: foreach my $item(@contexts) {
1.224 raeburn 10694: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 10695: }
1.34 raeburn 10696: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10697: foreach my $item (@contexts) {
1.224 raeburn 10698: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
10699: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 10700: }
1.27 raeburn 10701: }
1.34 raeburn 10702: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
10703: foreach my $item (@contexts) {
1.43 raeburn 10704: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 10705: if ($cancreate{$item} ne 'any') {
10706: push(@{$changes{'cancreate'}},$item);
10707: }
10708: } else {
10709: if ($cancreate{$item} ne 'none') {
10710: push(@{$changes{'cancreate'}},$item);
10711: }
1.27 raeburn 10712: }
10713: }
10714: } else {
1.43 raeburn 10715: foreach my $item (@contexts) {
1.34 raeburn 10716: push(@{$changes{'cancreate'}},$item);
10717: }
1.27 raeburn 10718: }
1.34 raeburn 10719:
1.27 raeburn 10720: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
10721: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
10722: if (!grep(/^\Q$type\E$/,@username_rule)) {
10723: push(@{$changes{'username_rule'}},$type);
10724: }
10725: }
10726: foreach my $type (@username_rule) {
10727: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
10728: push(@{$changes{'username_rule'}},$type);
10729: }
10730: }
10731: } else {
10732: push(@{$changes{'username_rule'}},@username_rule);
10733: }
10734:
1.32 raeburn 10735: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
10736: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
10737: if (!grep(/^\Q$type\E$/,@id_rule)) {
10738: push(@{$changes{'id_rule'}},$type);
10739: }
10740: }
10741: foreach my $type (@id_rule) {
10742: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
10743: push(@{$changes{'id_rule'}},$type);
10744: }
10745: }
10746: } else {
10747: push(@{$changes{'id_rule'}},@id_rule);
10748: }
10749:
1.43 raeburn 10750: my @authen_contexts = ('author','course','domain');
1.28 raeburn 10751: my @authtypes = ('int','krb4','krb5','loc');
10752: my %authhash;
1.43 raeburn 10753: foreach my $item (@authen_contexts) {
1.28 raeburn 10754: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
10755: foreach my $auth (@authtypes) {
10756: if (grep(/^\Q$auth\E$/,@authallowed)) {
10757: $authhash{$item}{$auth} = 1;
10758: } else {
10759: $authhash{$item}{$auth} = 0;
10760: }
10761: }
10762: }
10763: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 10764: foreach my $item (@authen_contexts) {
1.28 raeburn 10765: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
10766: foreach my $auth (@authtypes) {
10767: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
10768: push(@{$changes{'authtypes'}},$item);
10769: last;
10770: }
10771: }
10772: }
10773: }
10774: } else {
1.43 raeburn 10775: foreach my $item (@authen_contexts) {
1.28 raeburn 10776: push(@{$changes{'authtypes'}},$item);
10777: }
10778: }
10779:
1.224 raeburn 10780: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
10781: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
10782: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
10783: $save_usercreate{'id_rule'} = \@id_rule;
10784: $save_usercreate{'username_rule'} = \@username_rule,
10785: $save_usercreate{'authtypes'} = \%authhash;
10786:
1.27 raeburn 10787: my %usercreation_hash = (
1.224 raeburn 10788: usercreation => \%save_usercreate,
10789: );
1.27 raeburn 10790:
10791: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
10792: $dom);
1.50 raeburn 10793:
1.224 raeburn 10794: if ($putresult eq 'ok') {
10795: if (keys(%changes) > 0) {
10796: $resulttext = &mt('Changes made:').'<ul>';
10797: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10798: my %lt = &usercreation_types();
10799: foreach my $type (@{$changes{'cancreate'}}) {
10800: my $chgtext = $lt{$type}.', ';
10801: if ($cancreate{$type} eq 'none') {
10802: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
10803: } elsif ($cancreate{$type} eq 'any') {
10804: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
10805: } elsif ($cancreate{$type} eq 'official') {
10806: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
10807: } elsif ($cancreate{$type} eq 'unofficial') {
10808: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
10809: }
10810: $resulttext .= '<li>'.$chgtext.'</li>';
10811: }
10812: }
10813: if (ref($changes{'username_rule'}) eq 'ARRAY') {
10814: my ($rules,$ruleorder) =
10815: &Apache::lonnet::inst_userrules($dom,'username');
10816: my $chgtext = '<ul>';
10817: foreach my $type (@username_rule) {
10818: if (ref($rules->{$type}) eq 'HASH') {
10819: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
10820: }
10821: }
10822: $chgtext .= '</ul>';
10823: if (@username_rule > 0) {
10824: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10825: } else {
10826: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
10827: }
10828: }
10829: if (ref($changes{'id_rule'}) eq 'ARRAY') {
10830: my ($idrules,$idruleorder) =
10831: &Apache::lonnet::inst_userrules($dom,'id');
10832: my $chgtext = '<ul>';
10833: foreach my $type (@id_rule) {
10834: if (ref($idrules->{$type}) eq 'HASH') {
10835: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
10836: }
10837: }
10838: $chgtext .= '</ul>';
10839: if (@id_rule > 0) {
10840: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10841: } else {
10842: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
10843: }
10844: }
10845: my %authname = &authtype_names();
10846: my %context_title = &context_names();
10847: if (ref($changes{'authtypes'}) eq 'ARRAY') {
10848: my $chgtext = '<ul>';
10849: foreach my $type (@{$changes{'authtypes'}}) {
10850: my @allowed;
10851: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
10852: foreach my $auth (@authtypes) {
10853: if ($authhash{$type}{$auth}) {
10854: push(@allowed,$authname{$auth});
10855: }
10856: }
10857: if (@allowed > 0) {
10858: $chgtext .= join(', ',@allowed).'</li>';
10859: } else {
10860: $chgtext .= &mt('none').'</li>';
10861: }
10862: }
10863: $chgtext .= '</ul>';
10864: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
10865: $resulttext .= '</li>';
10866: }
10867: $resulttext .= '</ul>';
10868: } else {
10869: $resulttext = &mt('No changes made to user creation settings');
10870: }
10871: } else {
10872: $resulttext = '<span class="LC_error">'.
10873: &mt('An error occurred: [_1]',$putresult).'</span>';
10874: }
10875: if ($warningmsg ne '') {
10876: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10877: }
10878: return $resulttext;
10879: }
10880:
10881: sub modify_selfcreation {
10882: my ($dom,%domconfig) = @_;
10883: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
10884: my (%save_usercreate,%save_usermodify);
1.228 raeburn 10885: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10886: if (ref($types) eq 'ARRAY') {
10887: $usertypes->{'default'} = $othertitle;
10888: push(@{$types},'default');
10889: }
1.224 raeburn 10890: #
10891: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
10892: #
10893: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10894: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
10895: if ($key eq 'cancreate') {
10896: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10897: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10898: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
10899: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.269 raeburn 10900: ($item eq 'recaptchaversion') ||
1.236 raeburn 10901: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 10902: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 10903: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10904: } else {
10905: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10906: }
10907: }
10908: }
10909: } elsif ($key eq 'email_rule') {
10910: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10911: } else {
10912: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10913: }
10914: }
10915: }
10916: #
10917: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
10918: #
10919: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10920: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
10921: if ($key eq 'selfcreate') {
10922: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
10923: } else {
10924: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
10925: }
10926: }
10927: }
10928:
10929: my @contexts = ('selfcreate');
10930: @{$cancreate{'selfcreate'}} = ();
10931: %{$cancreate{'emailusername'}} = ();
10932: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 10933: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 10934: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 10935: my %selfcreatetypes = (
10936: sso => 'users authenticated by institutional single sign on',
10937: login => 'users authenticated by institutional log-in',
1.236 raeburn 10938: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 10939: );
1.224 raeburn 10940: #
10941: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
10942: # is permitted.
10943: #
1.236 raeburn 10944:
10945: my @statuses;
10946: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10947: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
10948: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
10949: }
10950: }
10951: push(@statuses,'default');
10952:
1.228 raeburn 10953: foreach my $item ('login','sso','email') {
1.224 raeburn 10954: if ($item eq 'email') {
1.236 raeburn 10955: if ($env{'form.cancreate_email'}) {
1.224 raeburn 10956: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 10957: push(@contexts,'selfcreateprocessing');
10958: foreach my $type (@statuses) {
10959: if ($type eq 'default') {
10960: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
10961: } else {
10962: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
10963: }
10964: }
1.224 raeburn 10965: }
10966: } else {
10967: if ($env{'form.cancreate_'.$item}) {
10968: push(@{$cancreate{'selfcreate'}},$item);
10969: }
10970: }
10971: }
10972: my (@email_rule,%userinfo,%savecaptcha);
10973: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
10974: #
1.228 raeburn 10975: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
10976: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 10977: #
1.236 raeburn 10978:
1.244 raeburn 10979: if ($env{'form.cancreate_email'}) {
1.228 raeburn 10980: push(@contexts,'emailusername');
10981: if (ref($types) eq 'ARRAY') {
10982: foreach my $type (@{$types}) {
10983: if (ref($infofields) eq 'ARRAY') {
10984: foreach my $field (@{$infofields}) {
10985: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
10986: $cancreate{'emailusername'}{$type}{$field} = $1;
10987: }
10988: }
1.224 raeburn 10989: }
10990: }
10991: }
10992: #
10993: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
10994: # queued requests for self-creation of account using e-mail address as username
10995: #
10996:
10997: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
10998: @approvalnotify = sort(@approvalnotify);
10999: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
11000: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11001: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11002: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11003: push(@{$changes{'cancreate'}},'notify');
11004: }
11005: } else {
11006: if ($cancreate{'notify'}{'approval'}) {
11007: push(@{$changes{'cancreate'}},'notify');
11008: }
11009: }
11010: } elsif ($cancreate{'notify'}{'approval'}) {
11011: push(@{$changes{'cancreate'}},'notify');
11012: }
11013:
11014: #
11015: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
11016: #
11017: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
11018: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11019: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11020: if (@{$curr_usercreation{'email_rule'}} > 0) {
11021: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
11022: if (!grep(/^\Q$type\E$/,@email_rule)) {
11023: push(@{$changes{'email_rule'}},$type);
11024: }
11025: }
11026: }
11027: if (@email_rule > 0) {
11028: foreach my $type (@email_rule) {
11029: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
11030: push(@{$changes{'email_rule'}},$type);
11031: }
11032: }
11033: }
11034: } elsif (@email_rule > 0) {
11035: push(@{$changes{'email_rule'}},@email_rule);
11036: }
11037: }
11038: #
1.236 raeburn 11039: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 11040: # institutional log-in.
11041: #
11042: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11043: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11044: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11045: ($domdefaults{'auth_def'} eq 'localauth'))) {
11046: $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.').' '.
11047: &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.');
11048: }
11049: }
11050: my @fields = ('lastname','firstname','middlename','generation',
11051: 'permanentemail','id');
1.240 raeburn 11052: my @shibfields = (@fields,'inststatus');
1.224 raeburn 11053: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11054: #
11055: # Where usernames may created for institutional log-in and/or institutional single sign on:
11056: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11057: # may self-create accounts
11058: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11059: # which the user may supply, if institutional data is unavailable.
11060: #
11061: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
11062: if (ref($types) eq 'ARRAY') {
1.228 raeburn 11063: if (@{$types} > 1) {
1.224 raeburn 11064: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11065: push(@contexts,'statustocreate');
11066: } else {
11067: undef($cancreate{'statustocreate'});
11068: }
11069: foreach my $type (@{$types}) {
11070: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11071: foreach my $field (@fields) {
11072: if (grep(/^\Q$field\E$/,@modifiable)) {
11073: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11074: } else {
11075: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11076: }
11077: }
11078: }
11079: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
11080: foreach my $type (@{$types}) {
11081: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11082: foreach my $field (@fields) {
11083: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11084: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11085: push(@{$changes{'selfcreate'}},$type);
11086: last;
11087: }
11088: }
11089: }
11090: }
11091: } else {
11092: foreach my $type (@{$types}) {
11093: push(@{$changes{'selfcreate'}},$type);
11094: }
11095: }
11096: }
1.240 raeburn 11097: foreach my $field (@shibfields) {
11098: if ($env{'form.shibenv_'.$field} ne '') {
11099: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11100: }
11101: }
11102: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11103: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11104: foreach my $field (@shibfields) {
11105: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11106: push(@{$changes{'cancreate'}},'shibenv');
11107: }
11108: }
11109: } else {
11110: foreach my $field (@shibfields) {
11111: if ($env{'form.shibenv_'.$field}) {
11112: push(@{$changes{'cancreate'}},'shibenv');
11113: last;
11114: }
11115: }
11116: }
11117: }
1.224 raeburn 11118: }
11119: foreach my $item (@contexts) {
11120: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11121: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11122: if (ref($cancreate{$item}) eq 'ARRAY') {
11123: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11124: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11125: push(@{$changes{'cancreate'}},$item);
11126: }
11127: }
11128: }
11129: }
11130: if (ref($cancreate{$item}) eq 'ARRAY') {
11131: foreach my $type (@{$cancreate{$item}}) {
11132: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11133: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11134: push(@{$changes{'cancreate'}},$item);
11135: }
11136: }
11137: }
11138: }
11139: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11140: if (ref($cancreate{$item}) eq 'HASH') {
11141: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 11142: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
11143: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
11144: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
11145: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11146: push(@{$changes{'cancreate'}},$item);
11147: }
11148: }
11149: }
1.236 raeburn 11150: } elsif ($item eq 'selfcreateprocessing') {
11151: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
11152: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11153: push(@{$changes{'cancreate'}},$item);
11154: }
11155: }
1.228 raeburn 11156: } else {
11157: if (!$cancreate{$item}{$curr}) {
11158: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11159: push(@{$changes{'cancreate'}},$item);
11160: }
1.224 raeburn 11161: }
11162: }
11163: }
11164: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 11165: if (ref($cancreate{$item}{$field}) eq 'HASH') {
11166: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
11167: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
11168: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
11169: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11170: push(@{$changes{'cancreate'}},$item);
11171: }
11172: }
11173: } else {
11174: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11175: push(@{$changes{'cancreate'}},$item);
11176: }
11177: }
11178: }
1.236 raeburn 11179: } elsif ($item eq 'selfcreateprocessing') {
11180: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
11181: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11182: push(@{$changes{'cancreate'}},$item);
11183: }
11184: }
1.228 raeburn 11185: } else {
11186: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
11187: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11188: push(@{$changes{'cancreate'}},$item);
11189: }
1.224 raeburn 11190: }
11191: }
11192: }
11193: }
11194: } elsif ($curr_usercreation{'cancreate'}{$item}) {
11195: if (ref($cancreate{$item}) eq 'ARRAY') {
11196: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
11197: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11198: push(@{$changes{'cancreate'}},$item);
11199: }
11200: }
11201: } elsif (ref($cancreate{$item}) eq 'HASH') {
11202: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
11203: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11204: push(@{$changes{'cancreate'}},$item);
11205: }
11206: }
11207: }
11208: } elsif ($item eq 'emailusername') {
1.228 raeburn 11209: if (ref($cancreate{$item}) eq 'HASH') {
11210: foreach my $type (keys(%{$cancreate{$item}})) {
11211: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11212: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11213: if ($cancreate{$item}{$type}{$field}) {
11214: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11215: push(@{$changes{'cancreate'}},$item);
11216: }
11217: last;
11218: }
11219: }
11220: }
11221: }
1.224 raeburn 11222: }
11223: }
11224: }
11225: #
11226: # Populate %save_usercreate hash with updates to self-creation configuration.
11227: #
11228: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
11229: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 11230: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 11231: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
11232: if (ref($cancreate{'notify'}) eq 'HASH') {
11233: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
11234: }
1.236 raeburn 11235: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
11236: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
11237: }
1.224 raeburn 11238: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11239: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
11240: }
1.240 raeburn 11241: if (ref($cancreate{'shibenv'}) eq 'HASH') {
11242: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
11243: }
1.224 raeburn 11244: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
11245: $save_usercreate{'emailrule'} = \@email_rule;
11246:
11247: my %userconfig_hash = (
11248: usercreation => \%save_usercreate,
11249: usermodification => \%save_usermodify,
11250: );
11251: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
11252: $dom);
11253: #
11254: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
11255: #
1.27 raeburn 11256: if ($putresult eq 'ok') {
11257: if (keys(%changes) > 0) {
11258: $resulttext = &mt('Changes made:').'<ul>';
11259: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 11260: my %lt = &selfcreation_types();
1.34 raeburn 11261: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 11262: my $chgtext;
1.45 raeburn 11263: if ($type eq 'selfcreate') {
1.50 raeburn 11264: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 11265: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 11266: } else {
1.224 raeburn 11267: $chgtext .= &mt('Self-creation of a new account is permitted for:').
11268: '<ul>';
1.50 raeburn 11269: foreach my $case (@{$cancreate{$type}}) {
11270: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
11271: }
11272: $chgtext .= '</ul>';
1.100 raeburn 11273: if (ref($cancreate{$type}) eq 'ARRAY') {
11274: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
11275: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11276: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 11277: $chgtext .= '<br />'.
11278: '<span class="LC_warning">'.
11279: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11280: '</span>';
1.100 raeburn 11281: }
11282: }
11283: }
11284: }
1.43 raeburn 11285: }
1.240 raeburn 11286: } elsif ($type eq 'shibenv') {
11287: if (keys(%{$cancreate{$type}}) == 0) {
11288: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
11289: } else {
11290: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
11291: '<ul>';
11292: foreach my $field (@shibfields) {
11293: next if ($cancreate{$type}{$field} eq '');
11294: if ($field eq 'inststatus') {
11295: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
11296: } else {
11297: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
11298: }
11299: }
11300: $chgtext .= '</ul>';
11301: }
1.93 raeburn 11302: } elsif ($type eq 'statustocreate') {
1.96 raeburn 11303: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
11304: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
11305: if (@{$cancreate{'selfcreate'}} > 0) {
11306: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 11307: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 11308: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 11309: $chgtext .= '<br />'.
11310: '<span class="LC_warning">'.
11311: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11312: '</span>';
11313: }
1.96 raeburn 11314: } elsif (ref($usertypes) eq 'HASH') {
11315: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 11316: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
11317: } else {
11318: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
11319: }
11320: $chgtext .= '<ul>';
11321: foreach my $case (@{$cancreate{$type}}) {
11322: if ($case eq 'default') {
11323: $chgtext .= '<li>'.$othertitle.'</li>';
11324: } else {
11325: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 11326: }
11327: }
1.100 raeburn 11328: $chgtext .= '</ul>';
11329: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 11330: $chgtext .= '<br /><span class="LC_warning">'.
11331: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
11332: '</span>';
1.100 raeburn 11333: }
11334: }
11335: } else {
11336: if (@{$cancreate{$type}} == 0) {
11337: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
11338: } else {
11339: $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 11340: }
11341: }
11342: }
1.236 raeburn 11343: } elsif ($type eq 'selfcreateprocessing') {
11344: my %choices = &Apache::lonlocal::texthash (
11345: automatic => 'Automatic approval',
11346: approval => 'Queued for approval',
11347: );
11348: if (@statuses > 1) {
11349: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
11350: '<ul>';
11351: foreach my $type (@statuses) {
11352: if ($type eq 'default') {
11353: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11354: } else {
11355: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11356: }
11357: }
11358: $chgtext .= '</ul>';
11359: } else {
11360: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
11361: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
11362: }
1.165 raeburn 11363: } elsif ($type eq 'captcha') {
1.224 raeburn 11364: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 11365: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
11366: } else {
11367: my %captchas = &captcha_phrases();
1.224 raeburn 11368: if ($captchas{$savecaptcha{$type}}) {
11369: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 11370: } else {
1.210 raeburn 11371: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 11372: }
11373: }
11374: } elsif ($type eq 'recaptchakeys') {
11375: my ($privkey,$pubkey);
1.224 raeburn 11376: if (ref($savecaptcha{$type}) eq 'HASH') {
11377: $pubkey = $savecaptcha{$type}{'public'};
11378: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 11379: }
11380: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
11381: if (!$pubkey) {
11382: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
11383: } else {
11384: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11385: }
11386: if (!$privkey) {
11387: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
11388: } else {
11389: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
11390: }
11391: $chgtext .= '</ul>';
1.269 raeburn 11392: } elsif ($type eq 'recaptchaversion') {
11393: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 11394: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 11395: }
1.224 raeburn 11396: } elsif ($type eq 'emailusername') {
11397: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 11398: if (ref($types) eq 'ARRAY') {
11399: foreach my $type (@{$types}) {
11400: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
11401: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 11402: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 11403: '<ul>';
11404: foreach my $field (@{$infofields}) {
11405: if ($cancreate{'emailusername'}{$type}{$field}) {
11406: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
11407: }
11408: }
1.245 raeburn 11409: $chgtext .= '</ul>';
11410: } else {
11411: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.228 raeburn 11412: }
11413: } else {
1.245 raeburn 11414: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.224 raeburn 11415: }
11416: }
11417: }
11418: }
11419: } elsif ($type eq 'notify') {
11420: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
11421: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11422: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
11423: if ($cancreate{'notify'}{'approval'}) {
11424: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
11425: }
11426: }
1.43 raeburn 11427: }
1.34 raeburn 11428: }
1.224 raeburn 11429: if ($chgtext) {
11430: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 11431: }
11432: }
11433: }
1.43 raeburn 11434: if (ref($changes{'email_rule'}) eq 'ARRAY') {
11435: my ($emailrules,$emailruleorder) =
11436: &Apache::lonnet::inst_userrules($dom,'email');
11437: my $chgtext = '<ul>';
11438: foreach my $type (@email_rule) {
11439: if (ref($emailrules->{$type}) eq 'HASH') {
11440: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
11441: }
11442: }
11443: $chgtext .= '</ul>';
11444: if (@email_rule > 0) {
1.224 raeburn 11445: $resulttext .= '<li>'.
11446: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
11447: $chgtext.
11448: '</li>';
1.43 raeburn 11449: } else {
1.224 raeburn 11450: $resulttext .= '<li>'.
11451: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
11452: '</li>';
1.43 raeburn 11453: }
11454: }
1.224 raeburn 11455: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
11456: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
11457: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11458: foreach my $type (@{$changes{'selfcreate'}}) {
11459: my $typename = $type;
11460: if (ref($usertypes) eq 'HASH') {
11461: if ($usertypes->{$type} ne '') {
11462: $typename = $usertypes->{$type};
11463: }
11464: }
11465: my @modifiable;
11466: $resulttext .= '<li>'.
11467: &mt('Self-creation of account by users with status: [_1]',
11468: '<span class="LC_cusr_emph">'.$typename.'</span>').
11469: ' - '.&mt('modifiable fields (if institutional data blank): ');
11470: foreach my $field (@fields) {
11471: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
11472: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 11473: }
11474: }
1.224 raeburn 11475: if (@modifiable > 0) {
11476: $resulttext .= join(', ',@modifiable);
1.43 raeburn 11477: } else {
1.224 raeburn 11478: $resulttext .= &mt('none');
1.43 raeburn 11479: }
1.224 raeburn 11480: $resulttext .= '</li>';
1.28 raeburn 11481: }
1.224 raeburn 11482: $resulttext .= '</ul></li>';
1.28 raeburn 11483: }
1.27 raeburn 11484: $resulttext .= '</ul>';
11485: } else {
1.224 raeburn 11486: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 11487: }
11488: } else {
11489: $resulttext = '<span class="LC_error">'.
1.23 raeburn 11490: &mt('An error occurred: [_1]',$putresult).'</span>';
11491: }
1.43 raeburn 11492: if ($warningmsg ne '') {
11493: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11494: }
1.23 raeburn 11495: return $resulttext;
11496: }
11497:
1.165 raeburn 11498: sub process_captcha {
11499: my ($container,$changes,$newsettings,$current) = @_;
11500: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
11501: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
11502: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
11503: $newsettings->{'captcha'} = 'original';
11504: }
11505: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 11506: if ($container eq 'cancreate') {
1.169 raeburn 11507: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11508: push(@{$changes->{'cancreate'}},'captcha');
11509: } elsif (!defined($changes->{'cancreate'})) {
11510: $changes->{'cancreate'} = ['captcha'];
11511: }
11512: } else {
11513: $changes->{'captcha'} = 1;
1.165 raeburn 11514: }
11515: }
1.269 raeburn 11516: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 11517: if ($newsettings->{'captcha'} eq 'recaptcha') {
11518: $newpub = $env{'form.'.$container.'_recaptchapub'};
11519: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 11520: $newpub =~ s/[^\w\-]//g;
11521: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 11522: $newsettings->{'recaptchakeys'} = {
11523: public => $newpub,
11524: private => $newpriv,
11525: };
1.269 raeburn 11526: $newversion = $env{'form.'.$container.'_recaptchaversion'};
11527: $newversion =~ s/\D//g;
11528: if ($newversion ne '2') {
11529: $newversion = 1;
11530: }
11531: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 11532: }
11533: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
11534: $currpub = $current->{'recaptchakeys'}{'public'};
11535: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 11536: unless ($newsettings->{'captcha'} eq 'recaptcha') {
11537: $newsettings->{'recaptchakeys'} = {
11538: public => '',
11539: private => '',
11540: }
11541: }
1.165 raeburn 11542: }
1.269 raeburn 11543: if ($current->{'captcha'} eq 'recaptcha') {
11544: $currversion = $current->{'recaptchaversion'};
11545: if ($currversion ne '2') {
11546: $currversion = 1;
11547: }
11548: }
11549: if ($currversion ne $newversion) {
11550: if ($container eq 'cancreate') {
11551: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11552: push(@{$changes->{'cancreate'}},'recaptchaversion');
11553: } elsif (!defined($changes->{'cancreate'})) {
11554: $changes->{'cancreate'} = ['recaptchaversion'];
11555: }
11556: } else {
11557: $changes->{'recaptchaversion'} = 1;
11558: }
11559: }
1.165 raeburn 11560: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 11561: if ($container eq 'cancreate') {
11562: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11563: push(@{$changes->{'cancreate'}},'recaptchakeys');
11564: } elsif (!defined($changes->{'cancreate'})) {
11565: $changes->{'cancreate'} = ['recaptchakeys'];
11566: }
11567: } else {
1.210 raeburn 11568: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 11569: }
11570: }
11571: return;
11572: }
11573:
1.33 raeburn 11574: sub modify_usermodification {
11575: my ($dom,%domconfig) = @_;
1.224 raeburn 11576: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 11577: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11578: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 11579: if ($key eq 'selfcreate') {
11580: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
11581: } else {
11582: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
11583: }
1.33 raeburn 11584: }
11585: }
1.224 raeburn 11586: my @contexts = ('author','course');
1.33 raeburn 11587: my %context_title = (
11588: author => 'In author context',
11589: course => 'In course context',
11590: );
11591: my @fields = ('lastname','firstname','middlename','generation',
11592: 'permanentemail','id');
11593: my %roles = (
11594: author => ['ca','aa'],
11595: course => ['st','ep','ta','in','cr'],
11596: );
11597: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11598: foreach my $context (@contexts) {
11599: foreach my $role (@{$roles{$context}}) {
11600: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
11601: foreach my $item (@fields) {
11602: if (grep(/^\Q$item\E$/,@modifiable)) {
11603: $modifyhash{$context}{$role}{$item} = 1;
11604: } else {
11605: $modifyhash{$context}{$role}{$item} = 0;
11606: }
11607: }
11608: }
11609: if (ref($curr_usermodification{$context}) eq 'HASH') {
11610: foreach my $role (@{$roles{$context}}) {
11611: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
11612: foreach my $field (@fields) {
11613: if ($modifyhash{$context}{$role}{$field} ne
11614: $curr_usermodification{$context}{$role}{$field}) {
11615: push(@{$changes{$context}},$role);
11616: last;
11617: }
11618: }
11619: }
11620: }
11621: } else {
11622: foreach my $context (@contexts) {
11623: foreach my $role (@{$roles{$context}}) {
11624: push(@{$changes{$context}},$role);
11625: }
11626: }
11627: }
11628: }
11629: my %usermodification_hash = (
11630: usermodification => \%modifyhash,
11631: );
11632: my $putresult = &Apache::lonnet::put_dom('configuration',
11633: \%usermodification_hash,$dom);
11634: if ($putresult eq 'ok') {
11635: if (keys(%changes) > 0) {
11636: $resulttext = &mt('Changes made: ').'<ul>';
11637: foreach my $context (@contexts) {
11638: if (ref($changes{$context}) eq 'ARRAY') {
11639: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
11640: if (ref($changes{$context}) eq 'ARRAY') {
11641: foreach my $role (@{$changes{$context}}) {
11642: my $rolename;
1.224 raeburn 11643: if ($role eq 'cr') {
11644: $rolename = &mt('Custom');
1.33 raeburn 11645: } else {
1.224 raeburn 11646: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 11647: }
11648: my @modifiable;
1.224 raeburn 11649: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 11650: foreach my $field (@fields) {
11651: if ($modifyhash{$context}{$role}{$field}) {
11652: push(@modifiable,$fieldtitles{$field});
11653: }
11654: }
11655: if (@modifiable > 0) {
11656: $resulttext .= join(', ',@modifiable);
11657: } else {
11658: $resulttext .= &mt('none');
11659: }
11660: $resulttext .= '</li>';
11661: }
11662: $resulttext .= '</ul></li>';
11663: }
11664: }
11665: }
11666: $resulttext .= '</ul>';
11667: } else {
11668: $resulttext = &mt('No changes made to user modification settings');
11669: }
11670: } else {
11671: $resulttext = '<span class="LC_error">'.
11672: &mt('An error occurred: [_1]',$putresult).'</span>';
11673: }
11674: return $resulttext;
11675: }
11676:
1.43 raeburn 11677: sub modify_defaults {
1.212 raeburn 11678: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 11679: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 11680: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 11681: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 11682: my @authtypes = ('internal','krb4','krb5','localauth');
11683: foreach my $item (@items) {
11684: $newvalues{$item} = $env{'form.'.$item};
11685: if ($item eq 'auth_def') {
11686: if ($newvalues{$item} ne '') {
11687: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
11688: push(@errors,$item);
11689: }
11690: }
11691: } elsif ($item eq 'lang_def') {
11692: if ($newvalues{$item} ne '') {
11693: if ($newvalues{$item} =~ /^(\w+)/) {
11694: my $langcode = $1;
1.103 raeburn 11695: if ($langcode ne 'x_chef') {
11696: if (code2language($langcode) eq '') {
11697: push(@errors,$item);
11698: }
1.43 raeburn 11699: }
11700: } else {
11701: push(@errors,$item);
11702: }
11703: }
1.54 raeburn 11704: } elsif ($item eq 'timezone_def') {
11705: if ($newvalues{$item} ne '') {
1.62 raeburn 11706: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 11707: push(@errors,$item);
11708: }
11709: }
1.68 raeburn 11710: } elsif ($item eq 'datelocale_def') {
11711: if ($newvalues{$item} ne '') {
11712: my @datelocale_ids = DateTime::Locale->ids();
11713: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
11714: push(@errors,$item);
11715: }
11716: }
1.141 raeburn 11717: } elsif ($item eq 'portal_def') {
11718: if ($newvalues{$item} ne '') {
11719: 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])\/?$/) {
11720: push(@errors,$item);
11721: }
11722: }
1.43 raeburn 11723: }
11724: if (grep(/^\Q$item\E$/,@errors)) {
11725: $newvalues{$item} = $domdefaults{$item};
11726: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
11727: $changes{$item} = 1;
11728: }
1.72 raeburn 11729: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 11730: }
11731: my %defaults_hash = (
1.72 raeburn 11732: defaults => \%newvalues,
11733: );
1.43 raeburn 11734: my $title = &defaults_titles();
1.236 raeburn 11735:
11736: my $currinststatus;
11737: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11738: $currinststatus = $domconfig{'inststatus'};
11739: } else {
11740: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11741: $currinststatus = {
11742: inststatustypes => $usertypes,
11743: inststatusorder => $types,
11744: inststatusguest => [],
11745: };
11746: }
11747: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
11748: my @allpos;
11749: my %guests;
11750: my %alltypes;
11751: my ($currtitles,$currguests,$currorder);
11752: if (ref($currinststatus) eq 'HASH') {
11753: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
11754: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
11755: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
11756: if ($currinststatus->{inststatustypes}->{$type} ne '') {
11757: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
11758: }
11759: }
11760: unless (grep(/^\Q$type\E$/,@todelete)) {
11761: my $position = $env{'form.inststatus_pos_'.$type};
11762: $position =~ s/\D+//g;
11763: $allpos[$position] = $type;
11764: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
11765: $alltypes{$type} =~ s/`//g;
11766: if ($env{'form.inststatus_guest_'.$type}) {
11767: $guests{$type} = 1;
11768: }
11769: }
11770: }
11771: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
11772: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
11773: }
11774: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
11775: $currtitles =~ s/,$//;
11776: }
11777: }
11778: if ($env{'form.addinststatus'}) {
11779: my $newtype = $env{'form.addinststatus'};
11780: $newtype =~ s/\W//g;
11781: unless (exists($alltypes{$newtype})) {
11782: if ($env{'form.addinststatus_guest'}) {
11783: $guests{$newtype} = 1;
11784: }
11785: $alltypes{$newtype} = $env{'form.addinststatus_title'};
11786: $alltypes{$newtype} =~ s/`//g;
11787: my $position = $env{'form.addinststatus_pos'};
11788: $position =~ s/\D+//g;
11789: if ($position ne '') {
11790: $allpos[$position] = $newtype;
11791: }
11792: }
11793: }
11794: my (@orderedstatus,@orderedguests);
11795: foreach my $type (@allpos) {
11796: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
11797: push(@orderedstatus,$type);
11798: if ($guests{$type}) {
11799: push(@orderedguests,$type);
11800: }
11801: }
11802: }
11803: foreach my $type (keys(%alltypes)) {
11804: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
11805: delete($alltypes{$type});
11806: }
11807: }
11808: $defaults_hash{'inststatus'} = {
11809: inststatustypes => \%alltypes,
11810: inststatusorder => \@orderedstatus,
11811: inststatusguest => \@orderedguests,
11812: };
11813: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
11814: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
11815: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
11816: }
11817: }
11818: if ($currorder ne join(',',@orderedstatus)) {
11819: $changes{'inststatus'}{'inststatusorder'} = 1;
11820: }
11821: if ($currguests ne join(',',@orderedguests)) {
11822: $changes{'inststatus'}{'inststatusguest'} = 1;
11823: }
11824: my $newtitles;
11825: foreach my $item (@orderedstatus) {
11826: $newtitles .= $alltypes{$item}.',';
11827: }
11828: $newtitles =~ s/,$//;
11829: if ($currtitles ne $newtitles) {
11830: $changes{'inststatus'}{'inststatustypes'} = 1;
11831: }
1.43 raeburn 11832: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
11833: $dom);
11834: if ($putresult eq 'ok') {
11835: if (keys(%changes) > 0) {
11836: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 11837: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 11838: 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";
11839: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 11840: if ($item eq 'inststatus') {
11841: if (ref($changes{'inststatus'}) eq 'HASH') {
11842: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
11843: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
11844: foreach my $type (@orderedstatus) {
11845: $resulttext .= $alltypes{$type}.', ';
11846: }
11847: $resulttext =~ s/, $//;
11848: $resulttext .= '</li>';
11849: }
11850: if ($changes{'inststatus'}{'inststatusguest'}) {
11851: $resulttext .= '<li>';
11852: if (@orderedguests) {
11853: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
11854: foreach my $type (@orderedguests) {
11855: $resulttext .= $alltypes{$type}.', ';
11856: }
11857: $resulttext =~ s/, $//;
11858: } else {
11859: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
11860: }
11861: $resulttext .= '</li>';
11862: }
11863: }
11864: } else {
11865: my $value = $env{'form.'.$item};
11866: if ($value eq '') {
11867: $value = &mt('none');
11868: } elsif ($item eq 'auth_def') {
11869: my %authnames = &authtype_names();
11870: my %shortauth = (
11871: internal => 'int',
11872: krb4 => 'krb4',
11873: krb5 => 'krb5',
11874: localauth => 'loc',
11875: );
11876: $value = $authnames{$shortauth{$value}};
11877: }
11878: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
11879: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 11880: }
11881: }
11882: $resulttext .= '</ul>';
11883: $mailmsgtext .= "\n";
11884: my $cachetime = 24*60*60;
1.72 raeburn 11885: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11886: if (ref($lastactref) eq 'HASH') {
11887: $lastactref->{'domdefaults'} = 1;
11888: }
1.68 raeburn 11889: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 11890: my $notify = 1;
11891: if (ref($domconfig{'contacts'}) eq 'HASH') {
11892: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
11893: $notify = 0;
11894: }
11895: }
11896: if ($notify) {
11897: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
11898: "LON-CAPA Domain Settings Change - $dom",
11899: $mailmsgtext);
11900: }
1.54 raeburn 11901: }
1.43 raeburn 11902: } else {
1.54 raeburn 11903: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 11904: }
11905: } else {
11906: $resulttext = '<span class="LC_error">'.
11907: &mt('An error occurred: [_1]',$putresult).'</span>';
11908: }
11909: if (@errors > 0) {
11910: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
11911: foreach my $item (@errors) {
11912: $resulttext .= ' "'.$title->{$item}.'",';
11913: }
11914: $resulttext =~ s/,$//;
11915: }
11916: return $resulttext;
11917: }
11918:
1.46 raeburn 11919: sub modify_scantron {
1.205 raeburn 11920: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 11921: my ($resulttext,%confhash,%changes,$errors);
11922: my $custom = 'custom.tab';
11923: my $default = 'default.tab';
11924: my $servadm = $r->dir_config('lonAdmEMail');
11925: my ($configuserok,$author_ok,$switchserver) =
11926: &config_check($dom,$confname,$servadm);
11927: if ($env{'form.scantronformat.filename'} ne '') {
11928: my $error;
11929: if ($configuserok eq 'ok') {
11930: if ($switchserver) {
1.130 raeburn 11931: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 11932: } else {
11933: if ($author_ok eq 'ok') {
11934: my ($result,$scantronurl) =
11935: &publishlogo($r,'upload','scantronformat',$dom,
11936: $confname,'scantron','','',$custom);
11937: if ($result eq 'ok') {
11938: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 11939: $changes{'scantronformat'} = 1;
1.46 raeburn 11940: } else {
11941: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
11942: }
11943: } else {
11944: $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);
11945: }
11946: }
11947: } else {
11948: $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);
11949: }
11950: if ($error) {
11951: &Apache::lonnet::logthis($error);
11952: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11953: }
11954: }
1.48 raeburn 11955: if (ref($domconfig{'scantron'}) eq 'HASH') {
11956: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
11957: if ($env{'form.scantronformat_del'}) {
11958: $confhash{'scantron'}{'scantronformat'} = '';
11959: $changes{'scantronformat'} = 1;
1.46 raeburn 11960: }
11961: }
11962: }
11963: if (keys(%confhash) > 0) {
11964: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
11965: $dom);
11966: if ($putresult eq 'ok') {
11967: if (keys(%changes) > 0) {
1.48 raeburn 11968: if (ref($confhash{'scantron'}) eq 'HASH') {
11969: $resulttext = &mt('Changes made:').'<ul>';
11970: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 11971: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 11972: } else {
1.130 raeburn 11973: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 11974: }
1.48 raeburn 11975: $resulttext .= '</ul>';
11976: } else {
1.130 raeburn 11977: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 11978: }
11979: $resulttext .= '</ul>';
11980: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11981: if (ref($lastactref) eq 'HASH') {
11982: $lastactref->{'domainconfig'} = 1;
11983: }
1.46 raeburn 11984: } else {
1.130 raeburn 11985: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11986: }
11987: } else {
11988: $resulttext = '<span class="LC_error">'.
11989: &mt('An error occurred: [_1]',$putresult).'</span>';
11990: }
11991: } else {
1.130 raeburn 11992: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11993: }
11994: if ($errors) {
11995: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11996: $errors.'</ul>';
11997: }
11998: return $resulttext;
11999: }
12000:
1.48 raeburn 12001: sub modify_coursecategories {
1.239 raeburn 12002: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 12003: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
12004: $cathash);
1.48 raeburn 12005: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 12006: my @catitems = ('unauth','auth');
12007: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 12008: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 12009: $cathash = $domconfig{'coursecategories'}{'cats'};
12010: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
12011: $changes{'togglecats'} = 1;
12012: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
12013: }
12014: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
12015: $changes{'categorize'} = 1;
12016: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
12017: }
1.120 raeburn 12018: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
12019: $changes{'togglecatscomm'} = 1;
12020: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
12021: }
12022: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
12023: $changes{'categorizecomm'} = 1;
12024: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 12025:
12026: }
12027: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
12028: $changes{'togglecatsplace'} = 1;
12029: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
12030: }
12031: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
12032: $changes{'categorizeplace'} = 1;
12033: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 12034: }
1.238 raeburn 12035: foreach my $item (@catitems) {
12036: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12037: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
12038: $changes{$item} = 1;
12039: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12040: }
12041: }
12042: }
1.57 raeburn 12043: } else {
12044: $changes{'togglecats'} = 1;
12045: $changes{'categorize'} = 1;
1.124 raeburn 12046: $changes{'togglecatscomm'} = 1;
12047: $changes{'categorizecomm'} = 1;
1.272 raeburn 12048: $changes{'togglecatsplace'} = 1;
12049: $changes{'categorizeplace'} = 1;
1.87 raeburn 12050: $domconfig{'coursecategories'} = {
12051: togglecats => $env{'form.togglecats'},
12052: categorize => $env{'form.categorize'},
1.124 raeburn 12053: togglecatscomm => $env{'form.togglecatscomm'},
12054: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 12055: togglecatsplace => $env{'form.togglecatsplace'},
12056: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 12057: };
1.238 raeburn 12058: foreach my $item (@catitems) {
12059: if ($env{'form.coursecat_'.$item} ne 'std') {
12060: $changes{$item} = 1;
12061: }
12062: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12063: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12064: }
12065: }
1.57 raeburn 12066: }
12067: if (ref($cathash) eq 'HASH') {
12068: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 12069: push (@deletecategory,'instcode::0');
12070: }
1.120 raeburn 12071: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
12072: push(@deletecategory,'communities::0');
12073: }
1.272 raeburn 12074: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
12075: push(@deletecategory,'placement::0');
12076: }
1.48 raeburn 12077: }
1.57 raeburn 12078: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
12079: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12080: if (@deletecategory > 0) {
12081: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 12082: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 12083: foreach my $item (@deletecategory) {
1.57 raeburn 12084: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
12085: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 12086: $deletions{$item} = 1;
1.57 raeburn 12087: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 12088: }
12089: }
12090: }
1.57 raeburn 12091: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 12092: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 12093: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 12094: $reorderings{$item} = 1;
1.57 raeburn 12095: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 12096: }
12097: if ($env{'form.addcategory_name_'.$item} ne '') {
12098: my $newcat = $env{'form.addcategory_name_'.$item};
12099: my $newdepth = $depth+1;
12100: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12101: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 12102: $adds{$newitem} = 1;
12103: }
12104: if ($env{'form.subcat_'.$item} ne '') {
12105: my $newcat = $env{'form.subcat_'.$item};
12106: my $newdepth = $depth+1;
12107: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12108: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 12109: $adds{$newitem} = 1;
12110: }
12111: }
12112: }
12113: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 12114: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12115: my $newitem = 'instcode::0';
1.57 raeburn 12116: if ($cathash->{$newitem} eq '') {
12117: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12118: $adds{$newitem} = 1;
12119: }
12120: } else {
12121: my $newitem = 'instcode::0';
1.57 raeburn 12122: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12123: $adds{$newitem} = 1;
12124: }
12125: }
1.120 raeburn 12126: if ($env{'form.communities'} eq '1') {
12127: if (ref($cathash) eq 'HASH') {
12128: my $newitem = 'communities::0';
12129: if ($cathash->{$newitem} eq '') {
12130: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12131: $adds{$newitem} = 1;
12132: }
12133: } else {
12134: my $newitem = 'communities::0';
12135: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12136: $adds{$newitem} = 1;
12137: }
12138: }
1.272 raeburn 12139: if ($env{'form.placement'} eq '1') {
12140: if (ref($cathash) eq 'HASH') {
12141: my $newitem = 'placement::0';
12142: if ($cathash->{$newitem} eq '') {
12143: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12144: $adds{$newitem} = 1;
12145: }
12146: } else {
12147: my $newitem = 'placement::0';
12148: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12149: $adds{$newitem} = 1;
12150: }
12151: }
1.48 raeburn 12152: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 12153: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 12154: ($env{'form.addcategory_name'} ne 'communities') &&
12155: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 12156: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
12157: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
12158: $adds{$newitem} = 1;
12159: }
1.48 raeburn 12160: }
1.57 raeburn 12161: my $putresult;
1.48 raeburn 12162: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12163: if (keys(%deletions) > 0) {
12164: foreach my $key (keys(%deletions)) {
12165: if ($predelallitems{$key} ne '') {
12166: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
12167: }
12168: }
12169: }
12170: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 12171: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 12172: if (ref($chkcats[0]) eq 'ARRAY') {
12173: my $depth = 0;
12174: my $chg = 0;
12175: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
12176: my $name = $chkcats[0][$i];
12177: my $item;
12178: if ($name eq '') {
12179: $chg ++;
12180: } else {
12181: $item = &escape($name).'::0';
12182: if ($chg) {
1.57 raeburn 12183: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 12184: }
12185: $depth ++;
1.57 raeburn 12186: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 12187: $depth --;
12188: }
12189: }
12190: }
1.57 raeburn 12191: }
12192: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12193: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 12194: if ($putresult eq 'ok') {
1.57 raeburn 12195: my %title = (
1.120 raeburn 12196: togglecats => 'Show/Hide a course in catalog',
12197: categorize => 'Assign a category to a course',
12198: togglecatscomm => 'Show/Hide a community in catalog',
12199: categorizecomm => 'Assign a category to a community',
1.57 raeburn 12200: );
12201: my %level = (
1.120 raeburn 12202: dom => 'set in Domain ("Modify Course/Community")',
12203: crs => 'set in Course ("Course Configuration")',
12204: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 12205: none => 'No catalog',
12206: std => 'Standard catalog',
12207: domonly => 'Domain-only catalog',
12208: codesrch => 'Code search form',
1.57 raeburn 12209: );
1.48 raeburn 12210: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 12211: if ($changes{'togglecats'}) {
12212: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
12213: }
12214: if ($changes{'categorize'}) {
12215: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 12216: }
1.120 raeburn 12217: if ($changes{'togglecatscomm'}) {
12218: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
12219: }
12220: if ($changes{'categorizecomm'}) {
12221: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
12222: }
1.238 raeburn 12223: if ($changes{'unauth'}) {
12224: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
12225: }
12226: if ($changes{'auth'}) {
12227: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
12228: }
1.57 raeburn 12229: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12230: my $cathash;
12231: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
12232: $cathash = $domconfig{'coursecategories'}{'cats'};
12233: } else {
12234: $cathash = {};
12235: }
12236: my (@cats,@trails,%allitems);
12237: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
12238: if (keys(%deletions) > 0) {
12239: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
12240: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
12241: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
12242: }
12243: $resulttext .= '</ul></li>';
12244: }
12245: if (keys(%reorderings) > 0) {
12246: my %sort_by_trail;
12247: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
12248: foreach my $key (keys(%reorderings)) {
12249: if ($allitems{$key} ne '') {
12250: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12251: }
1.48 raeburn 12252: }
1.57 raeburn 12253: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12254: $resulttext .= '<li>'.$trails[$trail].'</li>';
12255: }
12256: $resulttext .= '</ul></li>';
1.48 raeburn 12257: }
1.57 raeburn 12258: if (keys(%adds) > 0) {
12259: my %sort_by_trail;
12260: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
12261: foreach my $key (keys(%adds)) {
12262: if ($allitems{$key} ne '') {
12263: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12264: }
12265: }
12266: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12267: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 12268: }
1.57 raeburn 12269: $resulttext .= '</ul></li>';
1.48 raeburn 12270: }
12271: }
12272: $resulttext .= '</ul>';
1.239 raeburn 12273: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 12274: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12275: if ($changes{'auth'}) {
12276: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
12277: }
12278: if ($changes{'unauth'}) {
12279: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
12280: }
12281: my $cachetime = 24*60*60;
12282: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 12283: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 12284: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 12285: }
12286: }
1.48 raeburn 12287: } else {
12288: $resulttext = '<span class="LC_error">'.
1.57 raeburn 12289: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 12290: }
12291: } else {
1.120 raeburn 12292: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 12293: }
12294: return $resulttext;
12295: }
12296:
1.69 raeburn 12297: sub modify_serverstatuses {
12298: my ($dom,%domconfig) = @_;
12299: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
12300: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
12301: %currserverstatus = %{$domconfig{'serverstatuses'}};
12302: }
12303: my @pages = &serverstatus_pages();
12304: foreach my $type (@pages) {
12305: $newserverstatus{$type}{'namedusers'} = '';
12306: $newserverstatus{$type}{'machines'} = '';
12307: if (defined($env{'form.'.$type.'_namedusers'})) {
12308: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
12309: my @okusers;
12310: foreach my $user (@users) {
12311: my ($uname,$udom) = split(/:/,$user);
12312: if (($udom =~ /^$match_domain$/) &&
12313: (&Apache::lonnet::domain($udom)) &&
12314: ($uname =~ /^$match_username$/)) {
12315: if (!grep(/^\Q$user\E/,@okusers)) {
12316: push(@okusers,$user);
12317: }
12318: }
12319: }
12320: if (@okusers > 0) {
12321: @okusers = sort(@okusers);
12322: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
12323: }
12324: }
12325: if (defined($env{'form.'.$type.'_machines'})) {
12326: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
12327: my @okmachines;
12328: foreach my $ip (@machines) {
12329: my @parts = split(/\./,$ip);
12330: next if (@parts < 4);
12331: my $badip = 0;
12332: for (my $i=0; $i<4; $i++) {
12333: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
12334: $badip = 1;
12335: last;
12336: }
12337: }
12338: if (!$badip) {
12339: push(@okmachines,$ip);
12340: }
12341: }
12342: @okmachines = sort(@okmachines);
12343: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
12344: }
12345: }
12346: my %serverstatushash = (
12347: serverstatuses => \%newserverstatus,
12348: );
12349: foreach my $type (@pages) {
1.83 raeburn 12350: foreach my $setting ('namedusers','machines') {
1.84 raeburn 12351: my (@current,@new);
1.83 raeburn 12352: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 12353: if ($currserverstatus{$type}{$setting} ne '') {
12354: @current = split(/,/,$currserverstatus{$type}{$setting});
12355: }
12356: }
12357: if ($newserverstatus{$type}{$setting} ne '') {
12358: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 12359: }
12360: if (@current > 0) {
12361: if (@new > 0) {
12362: foreach my $item (@current) {
12363: if (!grep(/^\Q$item\E$/,@new)) {
12364: $changes{$type}{$setting} = 1;
1.82 raeburn 12365: last;
12366: }
12367: }
1.84 raeburn 12368: foreach my $item (@new) {
12369: if (!grep(/^\Q$item\E$/,@current)) {
12370: $changes{$type}{$setting} = 1;
12371: last;
1.82 raeburn 12372: }
12373: }
12374: } else {
1.83 raeburn 12375: $changes{$type}{$setting} = 1;
1.69 raeburn 12376: }
1.83 raeburn 12377: } elsif (@new > 0) {
12378: $changes{$type}{$setting} = 1;
1.69 raeburn 12379: }
12380: }
12381: }
12382: if (keys(%changes) > 0) {
1.81 raeburn 12383: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 12384: my $putresult = &Apache::lonnet::put_dom('configuration',
12385: \%serverstatushash,$dom);
12386: if ($putresult eq 'ok') {
12387: $resulttext .= &mt('Changes made:').'<ul>';
12388: foreach my $type (@pages) {
1.84 raeburn 12389: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 12390: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 12391: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 12392: if ($newserverstatus{$type}{'namedusers'} eq '') {
12393: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
12394: } else {
12395: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
12396: }
1.84 raeburn 12397: }
12398: if ($changes{$type}{'machines'}) {
1.69 raeburn 12399: if ($newserverstatus{$type}{'machines'} eq '') {
12400: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
12401: } else {
12402: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
12403: }
12404:
12405: }
12406: $resulttext .= '</ul></li>';
12407: }
12408: }
12409: $resulttext .= '</ul>';
12410: } else {
12411: $resulttext = '<span class="LC_error">'.
12412: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
12413:
12414: }
12415: } else {
12416: $resulttext = &mt('No changes made to access to server status pages');
12417: }
12418: return $resulttext;
12419: }
12420:
1.118 jms 12421: sub modify_helpsettings {
1.285 raeburn 12422: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 12423: my ($resulttext,$errors,%changes,%helphash);
12424: my %defaultchecked = ('submitbugs' => 'on');
12425: my @offon = ('off','on');
1.118 jms 12426: my @toggles = ('submitbugs');
1.285 raeburn 12427: my %current = ('submitbugs' => '',
12428: 'adhoc' => {},
12429: );
1.118 jms 12430: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 12431: %current = %{$domconfig{'helpsettings'}};
12432: }
1.285 raeburn 12433: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 12434: foreach my $item (@toggles) {
12435: if ($defaultchecked{$item} eq 'on') {
12436: if ($current{$item} eq '') {
12437: if ($env{'form.'.$item} eq '0') {
12438: $changes{$item} = 1;
12439: }
12440: } elsif ($current{$item} ne $env{'form.'.$item}) {
12441: $changes{$item} = 1;
12442: }
12443: } elsif ($defaultchecked{$item} eq 'off') {
12444: if ($current{$item} eq '') {
12445: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 12446: $changes{$item} = 1;
12447: }
1.282 raeburn 12448: } elsif ($current{$item} ne $env{'form.'.$item}) {
12449: $changes{$item} = 1;
12450: }
12451: }
12452: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
12453: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
12454: }
12455: }
1.285 raeburn 12456: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 12457: my $confname = $dom.'-domainconfig';
12458: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 12459: my (@allpos,%newsettings,%changedprivs,$newrole);
12460: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12461: my @accesstypes = ('all','none','status','inc','exc');
12462: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh']);
12463: my %lt = &Apache::lonlocal::texthash(
12464: s => 'system',
12465: d => 'domain',
12466: order => 'Display order',
12467: access => 'Role usage',
12468: all => 'All',
12469: none => 'None',
12470: status => 'Determined based on institutional status',
12471: inc => 'Include all, but exclude specific personnel',
12472: exc => 'Exclude all, but include specific personnel',
12473: );
12474: for (my $num=0; $num<=$maxnum; $num++) {
12475: my ($prefix,$identifier,$rolename,%curr);
12476: if ($num == $maxnum) {
12477: next unless ($env{'form.newcusthelp'} == $maxnum);
12478: $identifier = 'custhelp'.$num;
12479: $prefix = 'helproles_'.$num;
12480: $rolename = $env{'form.custhelpname'.$num};
12481: $rolename=~s/[^A-Za-z0-9]//gs;
12482: next if ($rolename eq '');
12483: next if (exists($existing{'rolesdef_'.$rolename}));
12484: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12485: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12486: $newprivs{'c'},$confname,$dom);
12487: if ($result ne 'ok') {
12488: $errors .= '<li><span class="LC_error">'.
12489: &mt('An error occurred storing the new custom role: [_1]',
12490: $result).'</span></li>';
12491: next;
12492: } else {
12493: $changedprivs{$rolename} = \%newprivs;
12494: $newrole = $rolename;
12495: }
12496: } else {
12497: $prefix = 'helproles_'.$num;
12498: $rolename = $env{'form.'.$prefix};
12499: next if ($rolename eq '');
12500: next unless (exists($existing{'rolesdef_'.$rolename}));
12501: $identifier = 'custhelp'.$num;
12502: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12503: my %currprivs;
12504: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
12505: split(/\_/,$existing{'rolesdef_'.$rolename});
12506: foreach my $level ('c','d','s') {
12507: if ($newprivs{$level} ne $currprivs{$level}) {
12508: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12509: $newprivs{'c'},$confname,$dom);
12510: if ($result ne 'ok') {
12511: $errors .= '<li><span class="LC_error">'.
12512: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
12513: $rolename,$result).'</span></li>';
12514: } else {
12515: $changedprivs{$rolename} = \%newprivs;
12516: }
12517: last;
12518: }
12519: }
12520: if (ref($current{'adhoc'}) eq 'HASH') {
12521: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12522: %curr = %{$current{'adhoc'}{$rolename}};
12523: }
12524: }
12525: }
12526: my $newpos = $env{'form.'.$prefix.'_pos'};
12527: $newpos =~ s/\D+//g;
12528: $allpos[$newpos] = $rolename;
12529: my $newdesc = $env{'form.'.$prefix.'_desc'};
12530: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
12531: if ($curr{'desc'}) {
12532: if ($curr{'desc'} ne $newdesc) {
12533: $changes{'customrole'}{$rolename}{'desc'} = 1;
12534: $newsettings{$rolename}{'desc'} = $newdesc;
12535: }
12536: } elsif ($newdesc ne '') {
12537: $changes{'customrole'}{$rolename}{'desc'} = 1;
12538: $newsettings{$rolename}{'desc'} = $newdesc;
12539: }
12540: my $access = $env{'form.'.$prefix.'_access'};
12541: if (grep(/^\Q$access\E$/,@accesstypes)) {
12542: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
12543: if ($access eq 'status') {
12544: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
12545: if (scalar(@statuses) == 0) {
12546: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
12547: } else {
12548: my (@shownstatus,$numtypes);
12549: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12550: if (ref($types) eq 'ARRAY') {
12551: $numtypes = scalar(@{$types});
12552: foreach my $type (sort(@statuses)) {
12553: if ($type eq 'default') {
12554: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12555: } elsif (grep(/^\Q$type\E$/,@{$types})) {
12556: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12557: push(@shownstatus,$usertypes->{$type});
12558: }
12559: }
12560: }
12561: if (grep(/^default$/,@statuses)) {
12562: push(@shownstatus,$othertitle);
12563: }
12564: if (scalar(@shownstatus) == 1+$numtypes) {
12565: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
12566: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
12567: } else {
12568: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
12569: if (ref($curr{'status'}) eq 'ARRAY') {
12570: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12571: if (@diffs) {
12572: $changes{'customrole'}{$rolename}{$access} = 1;
12573: }
12574: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12575: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 12576: }
1.166 raeburn 12577: }
12578: }
1.285 raeburn 12579: } elsif (($access eq 'inc') || ($access eq 'exc')) {
12580: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
12581: my @newspecstaff;
12582: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12583: foreach my $person (sort(@personnel)) {
12584: if ($domhelpdesk{$person}) {
12585: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
12586: }
12587: }
12588: if (ref($curr{$access}) eq 'ARRAY') {
12589: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12590: if (@diffs) {
12591: $changes{'customrole'}{$rolename}{$access} = 1;
12592: }
12593: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12594: $changes{'customrole'}{$rolename}{$access} = 1;
12595: }
12596: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12597: my ($uname,$udom) = split(/:/,$person);
12598: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
12599: }
12600: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 12601: }
1.285 raeburn 12602: } else {
12603: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
12604: }
12605: unless ($curr{'access'} eq $access) {
12606: $changes{'customrole'}{$rolename}{'access'} = 1;
12607: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 12608: }
12609: }
1.285 raeburn 12610: if (@allpos > 0) {
12611: my $idx = 0;
12612: foreach my $rolename (@allpos) {
12613: if ($rolename ne '') {
12614: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
12615: if (ref($current{'adhoc'}) eq 'HASH') {
12616: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12617: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
12618: $changes{'customrole'}{$rolename}{'order'} = 1;
12619: $newsettings{$rolename}{'order'} = $idx+1;
12620: }
12621: }
1.282 raeburn 12622: }
1.285 raeburn 12623: $idx ++;
1.166 raeburn 12624: }
12625: }
1.118 jms 12626: }
1.123 jms 12627: my $putresult;
12628: if (keys(%changes) > 0) {
1.166 raeburn 12629: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 12630: if ($putresult eq 'ok') {
1.285 raeburn 12631: if (ref($helphash{'helpsettings'}) eq 'HASH') {
12632: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
12633: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
12634: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
12635: }
12636: }
12637: my $cachetime = 24*60*60;
12638: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12639: if (ref($lastactref) eq 'HASH') {
12640: $lastactref->{'domdefaults'} = 1;
12641: }
12642: } else {
12643: $errors .= '<li><span class="LC_error">'.
12644: &mt('An error occurred storing the settings: [_1]',
12645: $putresult).'</span></li>';
12646: }
12647: }
12648: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
12649: $resulttext = &mt('Changes made:').'<ul>';
12650: my (%shownprivs,@levelorder);
12651: @levelorder = ('c','d','s');
12652: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 12653: foreach my $item (sort(keys(%changes))) {
12654: if ($item eq 'submitbugs') {
12655: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
12656: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
12657: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 12658: } elsif ($item eq 'customrole') {
12659: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 12660: my @keyorder = ('order','desc','access','status','exc','inc');
12661: my %keytext = &Apache::lonlocal::texthash(
12662: order => 'Order',
12663: desc => 'Role description',
12664: access => 'Role usage',
12665: status => 'Allowed instituional types',
12666: exc => 'Allowed personnel',
12667: inc => 'Disallowed personnel',
12668: );
1.282 raeburn 12669: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 12670: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
12671: if ($role eq $newrole) {
12672: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
12673: $role).'<ul>';
12674: } else {
12675: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12676: $role).'<ul>';
12677: }
12678: foreach my $key (@keyorder) {
12679: if ($changes{'customrole'}{$role}{$key}) {
12680: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
12681: $keytext{$key},$newsettings{$role}{$key}).
12682: '</li>';
12683: }
12684: }
12685: if (ref($changedprivs{$role}) eq 'HASH') {
12686: $shownprivs{$role} = 1;
12687: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
12688: foreach my $level (@levelorder) {
12689: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12690: next if ($item eq '');
12691: my ($priv) = split(/\&/,$item,2);
12692: if (&Apache::lonnet::plaintext($priv)) {
12693: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12694: unless ($level eq 'c') {
12695: $resulttext .= ' ('.$lt{$level}.')';
12696: }
12697: $resulttext .= '</li>';
12698: }
12699: }
12700: }
12701: $resulttext .= '</ul>';
12702: }
12703: $resulttext .= '</ul></li>';
12704: }
12705: }
12706: }
12707: }
12708: }
12709: }
12710: if (keys(%changedprivs)) {
12711: foreach my $role (sort(keys(%changedprivs))) {
12712: unless ($shownprivs{$role}) {
12713: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12714: $role).'<ul>'.
12715: '<li>'.&mt('Privileges set to :').'<ul>';
12716: foreach my $level (@levelorder) {
12717: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12718: next if ($item eq '');
12719: my ($priv) = split(/\&/,$item,2);
12720: if (&Apache::lonnet::plaintext($priv)) {
12721: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12722: unless ($level eq 'c') {
12723: $resulttext .= ' ('.$lt{$level}.')';
12724: }
12725: $resulttext .= '</li>';
12726: }
1.282 raeburn 12727: }
12728: }
1.285 raeburn 12729: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 12730: }
12731: }
12732: }
1.285 raeburn 12733: $resulttext .= '</ul>';
12734: } else {
12735: $resulttext = &mt('No changes made to help settings');
1.118 jms 12736: }
12737: if ($errors) {
1.168 raeburn 12738: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 12739: $errors.'</ul>';
1.118 jms 12740: }
12741: return $resulttext;
12742: }
12743:
1.121 raeburn 12744: sub modify_coursedefaults {
1.212 raeburn 12745: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 12746: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 12747: my %defaultchecked = (
12748: 'canuse_pdfforms' => 'off',
12749: 'uselcmath' => 'on',
12750: 'usejsme' => 'on'
12751: );
12752: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 12753: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 12754: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
12755: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
12756: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 12757: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 12758: my %staticdefaults = (
12759: anonsurvey_threshold => 10,
12760: uploadquota => 500,
1.257 raeburn 12761: postsubmit => 60,
1.276 raeburn 12762: mysqltables => 172800,
1.198 raeburn 12763: );
1.121 raeburn 12764:
12765: $defaultshash{'coursedefaults'} = {};
12766:
12767: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
12768: if ($domconfig{'coursedefaults'} eq '') {
12769: $domconfig{'coursedefaults'} = {};
12770: }
12771: }
12772:
12773: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
12774: foreach my $item (@toggles) {
12775: if ($defaultchecked{$item} eq 'on') {
12776: if (($domconfig{'coursedefaults'}{$item} eq '') &&
12777: ($env{'form.'.$item} eq '0')) {
12778: $changes{$item} = 1;
1.192 raeburn 12779: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 12780: $changes{$item} = 1;
12781: }
12782: } elsif ($defaultchecked{$item} eq 'off') {
12783: if (($domconfig{'coursedefaults'}{$item} eq '') &&
12784: ($env{'form.'.$item} eq '1')) {
12785: $changes{$item} = 1;
12786: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
12787: $changes{$item} = 1;
12788: }
12789: }
12790: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
12791: }
1.198 raeburn 12792: foreach my $item (@numbers) {
12793: my ($currdef,$newdef);
1.208 raeburn 12794: $newdef = $env{'form.'.$item};
1.198 raeburn 12795: if ($item eq 'anonsurvey_threshold') {
12796: $currdef = $domconfig{'coursedefaults'}{$item};
12797: $newdef =~ s/\D//g;
12798: if ($newdef eq '' || $newdef < 1) {
12799: $newdef = 1;
12800: }
12801: $defaultshash{'coursedefaults'}{$item} = $newdef;
12802: } else {
1.276 raeburn 12803: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
12804: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
12805: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 12806: }
12807: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 12808: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 12809: }
12810: if ($currdef ne $newdef) {
12811: my $staticdef;
12812: if ($item eq 'anonsurvey_threshold') {
12813: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
12814: $changes{$item} = 1;
12815: }
1.276 raeburn 12816: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
12817: my $setting = $1;
12818: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
12819: $changes{$setting} = 1;
1.198 raeburn 12820: }
12821: }
1.139 raeburn 12822: }
12823: }
1.264 raeburn 12824: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
12825: my @currclonecode;
12826: if (ref($currclone) eq 'HASH') {
12827: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
12828: @currclonecode = @{$currclone->{'instcode'}};
12829: }
12830: }
12831: my $newclone;
12832: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
12833: $newclone = $env{'form.canclone'};
12834: }
12835: if ($newclone eq 'instcode') {
12836: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
12837: my (%codedefaults,@code_order,@clonecode);
12838: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
12839: \@code_order);
12840: foreach my $item (@code_order) {
12841: if (grep(/^\Q$item\E$/,@newcodes)) {
12842: push(@clonecode,$item);
12843: }
12844: }
12845: if (@clonecode) {
12846: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
12847: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
12848: if (@diffs) {
12849: $changes{'canclone'} = 1;
12850: }
12851: } else {
12852: $newclone eq '';
12853: }
12854: } elsif ($newclone ne '') {
12855: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
12856: }
12857: if ($newclone ne $currclone) {
12858: $changes{'canclone'} = 1;
12859: }
1.257 raeburn 12860: my %credits;
12861: foreach my $type (@types) {
12862: unless ($type eq 'community') {
12863: $credits{$type} = $env{'form.'.$type.'_credits'};
12864: $credits{$type} =~ s/[^\d.]+//g;
12865: }
12866: }
12867: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
12868: ($env{'form.coursecredits'} eq '1')) {
12869: $changes{'coursecredits'} = 1;
12870: foreach my $type (keys(%credits)) {
12871: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
12872: }
12873: } else {
12874: if ($env{'form.coursecredits'} eq '1') {
12875: foreach my $type (@types) {
12876: unless ($type eq 'community') {
12877: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
12878: $changes{'coursecredits'} = 1;
12879: }
12880: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
12881: }
12882: }
12883: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
12884: foreach my $type (@types) {
12885: unless ($type eq 'community') {
12886: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
12887: $changes{'coursecredits'} = 1;
12888: last;
12889: }
12890: }
12891: }
12892: }
12893: }
12894: if ($env{'form.postsubmit'} eq '1') {
12895: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
12896: my %currtimeout;
12897: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12898: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
12899: $changes{'postsubmit'} = 1;
12900: }
12901: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12902: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
12903: }
12904: } else {
12905: $changes{'postsubmit'} = 1;
12906: }
12907: foreach my $type (@types) {
12908: my $timeout = $env{'form.'.$type.'_timeout'};
12909: $timeout =~ s/\D//g;
12910: if ($timeout == $staticdefaults{'postsubmit'}) {
12911: $timeout = '';
12912: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
12913: $timeout = '0';
12914: }
12915: unless ($timeout eq '') {
12916: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
12917: }
12918: if (exists($currtimeout{$type})) {
12919: if ($timeout ne $currtimeout{$type}) {
12920: $changes{'postsubmit'} = 1;
12921: }
12922: } elsif ($timeout ne '') {
12923: $changes{'postsubmit'} = 1;
12924: }
12925: }
12926: } else {
12927: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
12928: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12929: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
12930: $changes{'postsubmit'} = 1;
12931: }
12932: } else {
12933: $changes{'postsubmit'} = 1;
12934: }
1.192 raeburn 12935: }
1.121 raeburn 12936: }
12937: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12938: $dom);
12939: if ($putresult eq 'ok') {
12940: if (keys(%changes) > 0) {
1.213 raeburn 12941: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 12942: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 12943: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.276 raeburn 12944: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.257 raeburn 12945: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
12946: if ($changes{$item}) {
12947: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
12948: }
12949: }
1.192 raeburn 12950: if ($changes{'coursecredits'}) {
12951: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 12952: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
12953: $domdefaults{$type.'credits'} =
12954: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
12955: }
12956: }
12957: }
12958: if ($changes{'postsubmit'}) {
12959: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12960: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
12961: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12962: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
12963: $domdefaults{$type.'postsubtimeout'} =
12964: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
12965: }
12966: }
1.192 raeburn 12967: }
12968: }
1.198 raeburn 12969: if ($changes{'uploadquota'}) {
12970: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
12971: foreach my $type (@types) {
12972: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
12973: }
12974: }
12975: }
1.264 raeburn 12976: if ($changes{'canclone'}) {
12977: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
12978: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
12979: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
12980: if (@clonecodes) {
12981: $domdefaults{'canclone'} = join('+',@clonecodes);
12982: }
12983: }
12984: } else {
12985: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
12986: }
12987: }
1.121 raeburn 12988: my $cachetime = 24*60*60;
12989: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12990: if (ref($lastactref) eq 'HASH') {
12991: $lastactref->{'domdefaults'} = 1;
12992: }
1.121 raeburn 12993: }
12994: $resulttext = &mt('Changes made:').'<ul>';
12995: foreach my $item (sort(keys(%changes))) {
12996: if ($item eq 'canuse_pdfforms') {
12997: if ($env{'form.'.$item} eq '1') {
12998: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
12999: } else {
13000: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
13001: }
1.257 raeburn 13002: } elsif ($item eq 'uselcmath') {
13003: if ($env{'form.'.$item} eq '1') {
13004: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
13005: } else {
13006: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
13007: }
13008: } elsif ($item eq 'usejsme') {
13009: if ($env{'form.'.$item} eq '1') {
13010: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
13011: } else {
13012: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
13013: }
1.139 raeburn 13014: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 13015: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 13016: } elsif ($item eq 'uploadquota') {
13017: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13018: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
13019: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
13020: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 13021: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 13022: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 13023: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
13024: '</ul>'.
13025: '</li>';
13026: } else {
13027: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
13028: }
1.276 raeburn 13029: } elsif ($item eq 'mysqltables') {
13030: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
13031: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
13032: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
13033: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
13034: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
13035: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
13036: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
13037: '</ul>'.
13038: '</li>';
13039: } else {
13040: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
13041: }
1.257 raeburn 13042: } elsif ($item eq 'postsubmit') {
13043: if ($domdefaults{'postsubmit'} eq 'off') {
13044: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
13045: } else {
13046: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
13047: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13048: $resulttext .= &mt('durations:').'<ul>';
13049: foreach my $type (@types) {
13050: $resulttext .= '<li>';
13051: my $timeout;
13052: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13053: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13054: }
13055: my $display;
13056: if ($timeout eq '0') {
13057: $display = &mt('unlimited');
13058: } elsif ($timeout eq '') {
13059: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
13060: } else {
13061: $display = &mt('[quant,_1,second]',$timeout);
13062: }
13063: if ($type eq 'community') {
13064: $resulttext .= &mt('Communities');
13065: } elsif ($type eq 'official') {
13066: $resulttext .= &mt('Official courses');
13067: } elsif ($type eq 'unofficial') {
13068: $resulttext .= &mt('Unofficial courses');
13069: } elsif ($type eq 'textbook') {
13070: $resulttext .= &mt('Textbook courses');
1.271 raeburn 13071: } elsif ($type eq 'placement') {
13072: $resulttext .= &mt('Placement tests');
1.257 raeburn 13073: }
13074: $resulttext .= ' -- '.$display.'</li>';
13075: }
13076: $resulttext .= '</ul>';
13077: }
13078: $resulttext .= '</li>';
13079: }
1.192 raeburn 13080: } elsif ($item eq 'coursecredits') {
13081: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13082: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 13083: ($domdefaults{'unofficialcredits'} eq '') &&
13084: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 13085: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13086: } else {
13087: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
13088: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
13089: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 13090: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 13091: '</ul>'.
13092: '</li>';
13093: }
13094: } else {
13095: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13096: }
1.264 raeburn 13097: } elsif ($item eq 'canclone') {
13098: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13099: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13100: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
13101: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
13102: }
13103: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
13104: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
13105: } else {
13106: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
13107: }
1.140 raeburn 13108: }
1.121 raeburn 13109: }
13110: $resulttext .= '</ul>';
13111: } else {
13112: $resulttext = &mt('No changes made to course defaults');
13113: }
13114: } else {
13115: $resulttext = '<span class="LC_error">'.
13116: &mt('An error occurred: [_1]',$putresult).'</span>';
13117: }
13118: return $resulttext;
13119: }
13120:
1.231 raeburn 13121: sub modify_selfenrollment {
13122: my ($dom,$lastactref,%domconfig) = @_;
13123: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 13124: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 13125: my %titles = &tool_titles();
1.232 raeburn 13126: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
13127: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 13128: $ordered{'default'} = ['types','registered','approval','limit'];
13129:
13130: my (%roles,%shown,%toplevel);
13131: $roles{'0'} = &Apache::lonnet::plaintext('dc');
13132:
13133: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
13134: if ($domconfig{'selfenrollment'} eq '') {
13135: $domconfig{'selfenrollment'} = {};
13136: }
13137: }
13138: %toplevel = (
13139: admin => 'Configuration Rights',
13140: default => 'Default settings',
13141: validation => 'Validation of self-enrollment requests',
13142: );
1.233 raeburn 13143: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 13144:
13145: if (ref($ordered{'admin'}) eq 'ARRAY') {
13146: foreach my $item (@{$ordered{'admin'}}) {
13147: foreach my $type (@types) {
13148: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
13149: $selfenrollhash{'admin'}{$type}{$item} = 1;
13150: } else {
13151: $selfenrollhash{'admin'}{$type}{$item} = 0;
13152: }
13153: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
13154: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
13155: if ($selfenrollhash{'admin'}{$type}{$item} ne
13156: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
13157: push(@{$changes{'admin'}{$type}},$item);
13158: }
13159: } else {
13160: if (!$selfenrollhash{'admin'}{$type}{$item}) {
13161: push(@{$changes{'admin'}{$type}},$item);
13162: }
13163: }
13164: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
13165: push(@{$changes{'admin'}{$type}},$item);
13166: }
13167: }
13168: }
13169: }
13170:
13171: foreach my $item (@{$ordered{'default'}}) {
13172: foreach my $type (@types) {
13173: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
13174: if ($item eq 'types') {
13175: unless (($value eq 'all') || ($value eq 'dom')) {
13176: $value = '';
13177: }
13178: } elsif ($item eq 'registered') {
13179: unless ($value eq '1') {
13180: $value = 0;
13181: }
13182: } elsif ($item eq 'approval') {
13183: unless ($value =~ /^[012]$/) {
13184: $value = 0;
13185: }
13186: } else {
13187: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13188: $value = 'none';
13189: }
13190: }
13191: $selfenrollhash{'default'}{$type}{$item} = $value;
13192: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
13193: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13194: if ($selfenrollhash{'default'}{$type}{$item} ne
13195: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
13196: push(@{$changes{'default'}{$type}},$item);
13197: }
13198: } else {
13199: push(@{$changes{'default'}{$type}},$item);
13200: }
13201: } else {
13202: push(@{$changes{'default'}{$type}},$item);
13203: }
13204: if ($item eq 'limit') {
13205: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13206: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
13207: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
13208: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
13209: }
13210: } else {
13211: $selfenrollhash{'default'}{$type}{'cap'} = '';
13212: }
13213: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13214: if ($selfenrollhash{'default'}{$type}{'cap'} ne
13215: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
13216: push(@{$changes{'default'}{$type}},'cap');
13217: }
13218: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
13219: push(@{$changes{'default'}{$type}},'cap');
13220: }
13221: }
13222: }
13223: }
13224:
13225: foreach my $item (@{$itemsref}) {
13226: if ($item eq 'fields') {
13227: my @changed;
13228: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
13229: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
13230: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
13231: }
13232: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13233: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
13234: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
13235: $domconfig{'selfenrollment'}{'validation'}{$item});
13236: } else {
13237: @changed = @{$selfenrollhash{'validation'}{$item}};
13238: }
13239: } else {
13240: @changed = @{$selfenrollhash{'validation'}{$item}};
13241: }
13242: if (@changed) {
13243: if ($selfenrollhash{'validation'}{$item}) {
13244: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
13245: } else {
13246: $changes{'validation'}{$item} = &mt('None');
13247: }
13248: }
13249: } else {
13250: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
13251: if ($item eq 'markup') {
13252: if ($env{'form.selfenroll_validation_'.$item}) {
13253: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13254: }
13255: }
13256: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13257: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
13258: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
13259: }
13260: }
13261: }
13262: }
13263:
13264: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
13265: $dom);
13266: if ($putresult eq 'ok') {
13267: if (keys(%changes) > 0) {
13268: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13269: $resulttext = &mt('Changes made:').'<ul>';
13270: foreach my $key ('admin','default','validation') {
13271: if (ref($changes{$key}) eq 'HASH') {
13272: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
13273: if ($key eq 'validation') {
13274: foreach my $item (@{$itemsref}) {
13275: if (exists($changes{$key}{$item})) {
13276: if ($item eq 'markup') {
13277: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13278: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
13279: } else {
13280: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13281: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
13282: }
13283: }
13284: }
13285: } else {
13286: foreach my $type (@types) {
13287: if ($type eq 'community') {
13288: $roles{'1'} = &mt('Community personnel');
13289: } else {
13290: $roles{'1'} = &mt('Course personnel');
13291: }
13292: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 13293: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13294: if ($key eq 'admin') {
13295: my @mgrdc = ();
13296: if (ref($ordered{$key}) eq 'ARRAY') {
13297: foreach my $item (@{$ordered{'admin'}}) {
13298: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13299: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
13300: push(@mgrdc,$item);
13301: }
13302: }
13303: }
13304: if (@mgrdc) {
13305: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
13306: } else {
13307: delete($domdefaults{$type.'selfenrolladmdc'});
13308: }
13309: }
13310: } else {
13311: if (ref($ordered{$key}) eq 'ARRAY') {
13312: foreach my $item (@{$ordered{$key}}) {
13313: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13314: $domdefaults{$type.'selfenroll'.$item} =
13315: $selfenrollhash{$key}{$type}{$item};
13316: }
13317: }
13318: }
13319: }
13320: }
1.231 raeburn 13321: $resulttext .= '<li>'.$titles{$type}.'<ul>';
13322: foreach my $item (@{$ordered{$key}}) {
13323: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13324: $resulttext .= '<li>';
13325: if ($key eq 'admin') {
13326: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
13327: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
13328: } else {
13329: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
13330: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
13331: }
13332: $resulttext .= '</li>';
13333: }
13334: }
13335: $resulttext .= '</ul></li>';
13336: }
13337: }
13338: $resulttext .= '</ul></li>';
13339: }
13340: }
1.232 raeburn 13341: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
13342: my $cachetime = 24*60*60;
13343: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13344: if (ref($lastactref) eq 'HASH') {
13345: $lastactref->{'domdefaults'} = 1;
13346: }
13347: }
1.231 raeburn 13348: }
13349: $resulttext .= '</ul>';
13350: } else {
13351: $resulttext = &mt('No changes made to self-enrollment settings');
13352: }
13353: } else {
13354: $resulttext = '<span class="LC_error">'.
13355: &mt('An error occurred: [_1]',$putresult).'</span>';
13356: }
13357: return $resulttext;
13358: }
13359:
1.137 raeburn 13360: sub modify_usersessions {
1.212 raeburn 13361: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 13362: my @hostingtypes = ('version','excludedomain','includedomain');
13363: my @offloadtypes = ('primary','default');
13364: my %types = (
13365: remote => \@hostingtypes,
13366: hosted => \@hostingtypes,
13367: spares => \@offloadtypes,
13368: );
13369: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 13370: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 13371: my (%by_ip,%by_location,@intdoms,@instdoms);
13372: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 13373: my @locations = sort(keys(%by_location));
1.137 raeburn 13374: my (%defaultshash,%changes);
13375: foreach my $prefix (@prefixes) {
13376: $defaultshash{'usersessions'}{$prefix} = {};
13377: }
1.212 raeburn 13378: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 13379: my $resulttext;
1.138 raeburn 13380: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 13381: foreach my $prefix (@prefixes) {
1.145 raeburn 13382: next if ($prefix eq 'spares');
13383: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 13384: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13385: if ($type eq 'version') {
13386: my $value = $env{'form.'.$prefix.'_'.$type};
13387: my $okvalue;
13388: if ($value ne '') {
13389: if (grep(/^\Q$value\E$/,@lcversions)) {
13390: $okvalue = $value;
13391: }
13392: }
13393: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13394: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13395: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
13396: if ($inuse == 0) {
13397: $changes{$prefix}{$type} = 1;
13398: } else {
13399: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
13400: $changes{$prefix}{$type} = 1;
13401: }
13402: if ($okvalue ne '') {
13403: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13404: }
13405: }
13406: } else {
13407: if (($inuse == 1) && ($okvalue ne '')) {
13408: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13409: $changes{$prefix}{$type} = 1;
13410: }
13411: }
13412: } else {
13413: if (($inuse == 1) && ($okvalue ne '')) {
13414: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13415: $changes{$prefix}{$type} = 1;
13416: }
13417: }
13418: } else {
13419: if (($inuse == 1) && ($okvalue ne '')) {
13420: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13421: $changes{$prefix}{$type} = 1;
13422: }
13423: }
13424: } else {
13425: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13426: my @okvals;
13427: foreach my $val (@vals) {
1.138 raeburn 13428: if ($val =~ /:/) {
13429: my @items = split(/:/,$val);
13430: foreach my $item (@items) {
13431: if (ref($by_location{$item}) eq 'ARRAY') {
13432: push(@okvals,$item);
13433: }
13434: }
13435: } else {
13436: if (ref($by_location{$val}) eq 'ARRAY') {
13437: push(@okvals,$val);
13438: }
1.137 raeburn 13439: }
13440: }
13441: @okvals = sort(@okvals);
13442: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13443: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13444: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13445: if ($inuse == 0) {
13446: $changes{$prefix}{$type} = 1;
13447: } else {
13448: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13449: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
13450: if (@changed > 0) {
13451: $changes{$prefix}{$type} = 1;
13452: }
13453: }
13454: } else {
13455: if ($inuse == 1) {
13456: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13457: $changes{$prefix}{$type} = 1;
13458: }
13459: }
13460: } else {
13461: if ($inuse == 1) {
13462: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13463: $changes{$prefix}{$type} = 1;
13464: }
13465: }
13466: } else {
13467: if ($inuse == 1) {
13468: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13469: $changes{$prefix}{$type} = 1;
13470: }
13471: }
13472: }
13473: }
13474: }
1.145 raeburn 13475:
13476: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 13477: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 13478: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
13479: my $savespares;
13480:
13481: foreach my $lonhost (sort(keys(%servers))) {
13482: my $serverhomeID =
13483: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 13484: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 13485: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
13486: my %spareschg;
13487: foreach my $type (@{$types{'spares'}}) {
13488: my @okspares;
13489: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
13490: foreach my $server (@checked) {
1.152 raeburn 13491: if (&Apache::lonnet::hostname($server) ne '') {
13492: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
13493: unless (grep(/^\Q$server\E$/,@okspares)) {
13494: push(@okspares,$server);
13495: }
1.145 raeburn 13496: }
13497: }
13498: }
13499: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
13500: my $newspare;
1.152 raeburn 13501: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
13502: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 13503: $newspare = $new;
13504: }
13505: }
1.152 raeburn 13506: my @spares;
13507: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
13508: @spares = sort(@okspares,$newspare);
13509: } else {
13510: @spares = sort(@okspares);
13511: }
13512: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 13513: if (ref($spareid{$lonhost}) eq 'HASH') {
13514: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 13515: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 13516: if (@diffs > 0) {
13517: $spareschg{$type} = 1;
13518: }
13519: }
13520: }
13521: }
13522: if (keys(%spareschg) > 0) {
13523: $changes{'spares'}{$lonhost} = \%spareschg;
13524: }
13525: }
1.261 raeburn 13526: $defaultshash{'usersessions'}{'offloadnow'} = {};
13527: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
13528: my @okoffload;
13529: if (@offloadnow) {
13530: foreach my $server (@offloadnow) {
13531: if (&Apache::lonnet::hostname($server) ne '') {
13532: unless (grep(/^\Q$server\E$/,@okoffload)) {
13533: push(@okoffload,$server);
13534: }
13535: }
13536: }
13537: if (@okoffload) {
13538: foreach my $lonhost (@okoffload) {
13539: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
13540: }
13541: }
13542: }
1.145 raeburn 13543: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13544: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
13545: if (ref($changes{'spares'}) eq 'HASH') {
13546: if (keys(%{$changes{'spares'}}) > 0) {
13547: $savespares = 1;
13548: }
13549: }
13550: } else {
13551: $savespares = 1;
13552: }
1.261 raeburn 13553: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
13554: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
13555: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
13556: $changes{'offloadnow'} = 1;
13557: last;
13558: }
13559: }
13560: unless ($changes{'offloadnow'}) {
13561: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
13562: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
13563: $changes{'offloadnow'} = 1;
13564: last;
13565: }
13566: }
13567: }
13568: } elsif (@okoffload) {
13569: $changes{'offloadnow'} = 1;
13570: }
13571: } elsif (@okoffload) {
13572: $changes{'offloadnow'} = 1;
1.145 raeburn 13573: }
1.147 raeburn 13574: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
13575: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 13576: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13577: $dom);
13578: if ($putresult eq 'ok') {
13579: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13580: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
13581: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
13582: }
13583: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
13584: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
13585: }
1.261 raeburn 13586: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13587: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
13588: }
1.137 raeburn 13589: }
13590: my $cachetime = 24*60*60;
13591: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13592: if (ref($lastactref) eq 'HASH') {
13593: $lastactref->{'domdefaults'} = 1;
13594: }
1.147 raeburn 13595: if (keys(%changes) > 0) {
13596: my %lt = &usersession_titles();
13597: $resulttext = &mt('Changes made:').'<ul>';
13598: foreach my $prefix (@prefixes) {
13599: if (ref($changes{$prefix}) eq 'HASH') {
13600: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
13601: if ($prefix eq 'spares') {
13602: if (ref($changes{$prefix}) eq 'HASH') {
13603: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
13604: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 13605: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 13606: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
13607: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 13608: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
13609: foreach my $type (@{$types{$prefix}}) {
13610: if ($changes{$prefix}{$lonhost}{$type}) {
13611: my $offloadto = &mt('None');
13612: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
13613: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
13614: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
13615: }
1.145 raeburn 13616: }
1.147 raeburn 13617: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 13618: }
1.137 raeburn 13619: }
13620: }
1.147 raeburn 13621: $resulttext .= '</li>';
1.137 raeburn 13622: }
13623: }
1.147 raeburn 13624: } else {
13625: foreach my $type (@{$types{$prefix}}) {
13626: if (defined($changes{$prefix}{$type})) {
13627: my $newvalue;
13628: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13629: if (ref($defaultshash{'usersessions'}{$prefix})) {
13630: if ($type eq 'version') {
13631: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
13632: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13633: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
13634: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
13635: }
1.145 raeburn 13636: }
13637: }
13638: }
1.147 raeburn 13639: if ($newvalue eq '') {
13640: if ($type eq 'version') {
13641: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
13642: } else {
13643: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
13644: }
1.145 raeburn 13645: } else {
1.147 raeburn 13646: if ($type eq 'version') {
13647: $newvalue .= ' '.&mt('(or later)');
13648: }
13649: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 13650: }
1.137 raeburn 13651: }
13652: }
13653: }
1.147 raeburn 13654: $resulttext .= '</ul>';
1.137 raeburn 13655: }
13656: }
1.261 raeburn 13657: if ($changes{'offloadnow'}) {
13658: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13659: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
13660: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
13661: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
13662: $resulttext .= '<li>'.$lonhost.'</li>';
13663: }
13664: $resulttext .= '</ul>';
13665: } else {
13666: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
13667: }
13668: } else {
13669: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
13670: }
13671: }
1.147 raeburn 13672: $resulttext .= '</ul>';
13673: } else {
13674: $resulttext = $nochgmsg;
1.137 raeburn 13675: }
13676: } else {
13677: $resulttext = '<span class="LC_error">'.
13678: &mt('An error occurred: [_1]',$putresult).'</span>';
13679: }
13680: } else {
1.147 raeburn 13681: $resulttext = $nochgmsg;
1.137 raeburn 13682: }
13683: return $resulttext;
13684: }
13685:
1.275 raeburn 13686: sub modify_ssl {
13687: my ($dom,$lastactref,%domconfig) = @_;
13688: my (%by_ip,%by_location,@intdoms,@instdoms);
13689: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
13690: my @locations = sort(keys(%by_location));
13691: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13692: my (%defaultshash,%changes);
13693: my $action = 'ssl';
13694: my @prefixes = ('connect','replication');
13695: foreach my $prefix (@prefixes) {
13696: $defaultshash{$action}{$prefix} = {};
13697: }
13698: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13699: my $resulttext;
13700: my %iphost = &Apache::lonnet::get_iphost();
13701: my @reptypes = ('certreq','nocertreq');
13702: my @connecttypes = ('dom','intdom','other');
13703: my %types = (
13704: connect => \@connecttypes,
13705: replication => \@reptypes,
13706: );
13707: foreach my $prefix (sort(keys(%types))) {
13708: foreach my $type (@{$types{$prefix}}) {
13709: if ($prefix eq 'connect') {
13710: my $value = 'yes';
13711: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
13712: $value = $env{'form.'.$prefix.'_'.$type};
13713: }
13714: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
13715: if ($domconfig{$action}{$prefix}{$type} ne '') {
13716: if ($value ne $domconfig{$action}{$prefix}{$type}) {
13717: $changes{$prefix}{$type} = 1;
13718: }
13719: $defaultshash{$action}{$prefix}{$type} = $value;
13720: } else {
13721: $defaultshash{$action}{$prefix}{$type} = $value;
13722: $changes{$prefix}{$type} = 1;
13723: }
13724: } else {
13725: $defaultshash{$action}{$prefix}{$type} = $value;
13726: $changes{$prefix}{$type} = 1;
13727: }
13728: if (($type eq 'dom') && (keys(%servers) == 1)) {
13729: delete($changes{$prefix}{$type});
13730: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
13731: delete($changes{$prefix}{$type});
13732: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
13733: delete($changes{$prefix}{$type});
13734: }
13735: } elsif ($prefix eq 'replication') {
13736: if (@locations > 0) {
13737: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13738: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13739: my @okvals;
13740: foreach my $val (@vals) {
13741: if ($val =~ /:/) {
13742: my @items = split(/:/,$val);
13743: foreach my $item (@items) {
13744: if (ref($by_location{$item}) eq 'ARRAY') {
13745: push(@okvals,$item);
13746: }
13747: }
13748: } else {
13749: if (ref($by_location{$val}) eq 'ARRAY') {
13750: push(@okvals,$val);
13751: }
13752: }
13753: }
13754: @okvals = sort(@okvals);
13755: if (ref($domconfig{$action}) eq 'HASH') {
13756: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
13757: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
13758: if ($inuse == 0) {
13759: $changes{$prefix}{$type} = 1;
13760: } else {
13761: $defaultshash{$action}{$prefix}{$type} = \@okvals;
13762: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
13763: if (@changed > 0) {
13764: $changes{$prefix}{$type} = 1;
13765: }
13766: }
13767: } else {
13768: if ($inuse == 1) {
13769: $defaultshash{$action}{$prefix}{$type} = \@okvals;
13770: $changes{$prefix}{$type} = 1;
13771: }
13772: }
13773: } else {
13774: if ($inuse == 1) {
13775: $defaultshash{$action}{$prefix}{$type} = \@okvals;
13776: $changes{$prefix}{$type} = 1;
13777: }
13778: }
13779: } else {
13780: if ($inuse == 1) {
13781: $defaultshash{$action}{$prefix}{$type} = \@okvals;
13782: $changes{$prefix}{$type} = 1;
13783: }
13784: }
13785: }
13786: }
13787: }
13788: }
13789: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
13790: if (keys(%changes) > 0) {
13791: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13792: $dom);
13793: if ($putresult eq 'ok') {
13794: if (ref($defaultshash{$action}) eq 'HASH') {
13795: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
13796: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
13797: }
13798: if (ref($defaultshash{$action}{'connect'}) eq 'HASH') {
13799: $domdefaults{'connect'} = $domconfig{$action}{'connect'};
13800: }
13801: }
13802: my $cachetime = 24*60*60;
13803: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13804: if (ref($lastactref) eq 'HASH') {
13805: $lastactref->{'domdefaults'} = 1;
13806: }
13807: if (keys(%changes) > 0) {
13808: my %titles = &ssl_titles();
13809: $resulttext = &mt('Changes made:').'<ul>';
13810: foreach my $prefix (@prefixes) {
13811: if (ref($changes{$prefix}) eq 'HASH') {
13812: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
13813: foreach my $type (@{$types{$prefix}}) {
13814: if (defined($changes{$prefix}{$type})) {
13815: my $newvalue;
13816: if (ref($defaultshash{$action}) eq 'HASH') {
13817: if (ref($defaultshash{$action}{$prefix})) {
13818: if ($prefix eq 'connect') {
13819: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
13820: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
13821: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
13822: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
13823: }
13824: }
13825: }
13826: if ($newvalue eq '') {
13827: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
13828: } else {
13829: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
13830: }
13831: }
13832: }
13833: }
13834: $resulttext .= '</ul>';
13835: }
13836: }
13837: } else {
13838: $resulttext = $nochgmsg;
13839: }
13840: } else {
13841: $resulttext = '<span class="LC_error">'.
13842: &mt('An error occurred: [_1]',$putresult).'</span>';
13843: }
13844: } else {
13845: $resulttext = $nochgmsg;
13846: }
13847: return $resulttext;
13848: }
13849:
1.279 raeburn 13850: sub modify_trust {
13851: my ($dom,$lastactref,%domconfig) = @_;
13852: my (%by_ip,%by_location,@intdoms,@instdoms);
13853: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
13854: my @locations = sort(keys(%by_location));
13855: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
13856: my @types = ('exc','inc');
13857: my (%defaultshash,%changes);
13858: foreach my $prefix (@prefixes) {
13859: $defaultshash{'trust'}{$prefix} = {};
13860: }
13861: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13862: my $resulttext;
13863: foreach my $prefix (@prefixes) {
13864: foreach my $type (@types) {
13865: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13866: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13867: my @okvals;
13868: foreach my $val (@vals) {
13869: if ($val =~ /:/) {
13870: my @items = split(/:/,$val);
13871: foreach my $item (@items) {
13872: if (ref($by_location{$item}) eq 'ARRAY') {
13873: push(@okvals,$item);
13874: }
13875: }
13876: } else {
13877: if (ref($by_location{$val}) eq 'ARRAY') {
13878: push(@okvals,$val);
13879: }
13880: }
13881: }
13882: @okvals = sort(@okvals);
13883: if (ref($domconfig{'trust'}) eq 'HASH') {
13884: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
13885: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
13886: if ($inuse == 0) {
13887: $changes{$prefix}{$type} = 1;
13888: } else {
13889: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
13890: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
13891: if (@changed > 0) {
13892: $changes{$prefix}{$type} = 1;
13893: }
13894: }
13895: } else {
13896: if ($inuse == 1) {
13897: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
13898: $changes{$prefix}{$type} = 1;
13899: }
13900: }
13901: } else {
13902: if ($inuse == 1) {
13903: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
13904: $changes{$prefix}{$type} = 1;
13905: }
13906: }
13907: } else {
13908: if ($inuse == 1) {
13909: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
13910: $changes{$prefix}{$type} = 1;
13911: }
13912: }
13913: }
13914: }
13915: my $nochgmsg = &mt('No changes made to trust settings.');
13916: if (keys(%changes) > 0) {
13917: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13918: $dom);
13919: if ($putresult eq 'ok') {
13920: if (ref($defaultshash{'trust'}) eq 'HASH') {
13921: foreach my $prefix (@prefixes) {
13922: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
13923: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
13924: }
13925: }
13926: }
13927: my $cachetime = 24*60*60;
13928: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13929: if (ref($lastactref) eq 'HASH') {
13930: $lastactref->{'domdefaults'} = 1;
13931: }
13932: if (keys(%changes) > 0) {
13933: my %lt = &trust_titles();
13934: $resulttext = &mt('Changes made:').'<ul>';
13935: foreach my $prefix (@prefixes) {
13936: if (ref($changes{$prefix}) eq 'HASH') {
13937: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
13938: foreach my $type (@types) {
13939: if (defined($changes{$prefix}{$type})) {
13940: my $newvalue;
13941: if (ref($defaultshash{'trust'}) eq 'HASH') {
13942: if (ref($defaultshash{'trust'}{$prefix})) {
13943: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
13944: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
13945: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
13946: }
13947: }
13948: }
13949: }
13950: if ($newvalue eq '') {
13951: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
13952: } else {
13953: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
13954: }
13955: }
13956: }
13957: $resulttext .= '</ul>';
13958: }
13959: }
13960: $resulttext .= '</ul>';
13961: } else {
13962: $resulttext = $nochgmsg;
13963: }
13964: } else {
13965: $resulttext = '<span class="LC_error">'.
13966: &mt('An error occurred: [_1]',$putresult).'</span>';
13967: }
13968: } else {
13969: $resulttext = $nochgmsg;
13970: }
13971: return $resulttext;
13972: }
13973:
1.150 raeburn 13974: sub modify_loadbalancing {
13975: my ($dom,%domconfig) = @_;
13976: my $primary_id = &Apache::lonnet::domain($dom,'primary');
13977: my $intdom = &Apache::lonnet::internet_dom($primary_id);
13978: my ($othertitle,$usertypes,$types) =
13979: &Apache::loncommon::sorted_inst_types($dom);
13980: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 13981: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 13982: my @sparestypes = ('primary','default');
13983: my %typetitles = &sparestype_titles();
13984: my $resulttext;
1.171 raeburn 13985: my (%currbalancer,%currtargets,%currrules,%existing);
13986: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13987: %existing = %{$domconfig{'loadbalancing'}};
13988: }
13989: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
13990: \%currtargets,\%currrules);
13991: my ($saveloadbalancing,%defaultshash,%changes);
13992: my ($alltypes,$othertypes,$titles) =
13993: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
13994: my %ruletitles = &offloadtype_text();
13995: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
13996: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
13997: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
13998: if ($balancer eq '') {
13999: next;
14000: }
1.210 raeburn 14001: if (!exists($servers{$balancer})) {
1.171 raeburn 14002: if (exists($currbalancer{$balancer})) {
14003: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 14004: }
1.171 raeburn 14005: next;
14006: }
14007: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
14008: push(@{$changes{'delete'}},$balancer);
14009: next;
14010: }
14011: if (!exists($currbalancer{$balancer})) {
14012: push(@{$changes{'add'}},$balancer);
14013: }
14014: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
14015: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
14016: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
14017: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14018: $saveloadbalancing = 1;
14019: }
14020: foreach my $sparetype (@sparestypes) {
14021: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
14022: my @offloadto;
14023: foreach my $target (@targets) {
14024: if (($servers{$target}) && ($target ne $balancer)) {
14025: if ($sparetype eq 'default') {
14026: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
14027: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 14028: }
14029: }
1.171 raeburn 14030: unless(grep(/^\Q$target\E$/,@offloadto)) {
14031: push(@offloadto,$target);
14032: }
1.150 raeburn 14033: }
14034: }
1.284 raeburn 14035: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
14036: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
14037: push(@offloadto,$balancer);
14038: }
14039: }
14040: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 14041: }
1.171 raeburn 14042: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 14043: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14044: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
14045: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 14046: if (@targetdiffs > 0) {
1.171 raeburn 14047: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14048: }
1.171 raeburn 14049: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14050: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14051: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14052: }
14053: }
14054: }
14055: } else {
1.171 raeburn 14056: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 14057: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14058: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14059: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14060: $changes{'curr'}{$balancer}{'targets'} = 1;
14061: }
1.150 raeburn 14062: }
14063: }
1.210 raeburn 14064: }
1.150 raeburn 14065: }
14066: my $ishomedom;
1.171 raeburn 14067: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
14068: $ishomedom = 1;
1.150 raeburn 14069: }
14070: if (ref($alltypes) eq 'ARRAY') {
14071: foreach my $type (@{$alltypes}) {
14072: my $rule;
1.210 raeburn 14073: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 14074: (!$ishomedom)) {
1.171 raeburn 14075: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
14076: }
14077: if ($rule eq 'specific') {
1.255 raeburn 14078: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
14079: if (exists($servers{$specifiedhost})) {
14080: $rule = $specifiedhost;
14081: }
1.150 raeburn 14082: }
1.171 raeburn 14083: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
14084: if (ref($currrules{$balancer}) eq 'HASH') {
14085: if ($rule ne $currrules{$balancer}{$type}) {
14086: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14087: }
14088: } elsif ($rule ne '') {
1.171 raeburn 14089: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14090: }
14091: }
14092: }
1.171 raeburn 14093: }
14094: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
14095: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
14096: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
14097: $defaultshash{'loadbalancing'} = {};
14098: }
14099: my $putresult = &Apache::lonnet::put_dom('configuration',
14100: \%defaultshash,$dom);
14101: if ($putresult eq 'ok') {
14102: if (keys(%changes) > 0) {
1.252 raeburn 14103: my %toupdate;
1.171 raeburn 14104: if (ref($changes{'delete'}) eq 'ARRAY') {
14105: foreach my $balancer (sort(@{$changes{'delete'}})) {
14106: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 14107: $toupdate{$balancer} = 1;
1.150 raeburn 14108: }
1.171 raeburn 14109: }
14110: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 14111: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 14112: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 14113: $toupdate{$balancer} = 1;
1.171 raeburn 14114: }
14115: }
14116: if (ref($changes{'curr'}) eq 'HASH') {
14117: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 14118: $toupdate{$balancer} = 1;
1.171 raeburn 14119: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
14120: if ($changes{'curr'}{$balancer}{'targets'}) {
14121: my %offloadstr;
14122: foreach my $sparetype (@sparestypes) {
14123: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14124: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14125: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14126: }
14127: }
1.150 raeburn 14128: }
1.171 raeburn 14129: if (keys(%offloadstr) == 0) {
14130: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 14131: } else {
1.171 raeburn 14132: my $showoffload;
14133: foreach my $sparetype (@sparestypes) {
14134: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
14135: if (defined($offloadstr{$sparetype})) {
14136: $showoffload .= $offloadstr{$sparetype};
14137: } else {
14138: $showoffload .= &mt('None');
14139: }
14140: $showoffload .= (' 'x3);
14141: }
14142: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 14143: }
14144: }
14145: }
1.171 raeburn 14146: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
14147: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
14148: foreach my $type (@{$alltypes}) {
14149: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
14150: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14151: my $balancetext;
14152: if ($rule eq '') {
14153: $balancetext = $ruletitles{'default'};
1.209 raeburn 14154: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.254 raeburn 14155: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
14156: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 14157: foreach my $sparetype (@sparestypes) {
14158: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14159: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14160: }
14161: }
1.253 raeburn 14162: foreach my $item (@{$alltypes}) {
14163: next if ($item =~ /^_LC_ipchange/);
14164: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
14165: if ($hasrule eq 'homeserver') {
14166: map { $toupdate{$_} = 1; } (keys(%libraryservers));
14167: } else {
14168: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
14169: if ($servers{$hasrule}) {
14170: $toupdate{$hasrule} = 1;
14171: }
14172: }
14173: }
14174: }
1.254 raeburn 14175: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
14176: $balancetext = $ruletitles{$rule};
14177: } else {
14178: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14179: $balancetext = $ruletitles{'particular'}.' '.$receiver;
14180: if ($receiver) {
14181: $toupdate{$receiver};
14182: }
14183: }
14184: } else {
14185: $balancetext = $ruletitles{$rule};
1.252 raeburn 14186: }
1.171 raeburn 14187: } else {
14188: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
14189: }
1.210 raeburn 14190: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 14191: }
14192: }
14193: }
14194: }
1.252 raeburn 14195: if (keys(%toupdate)) {
14196: my %thismachine;
14197: my $updatedhere;
14198: my $cachetime = 60*60*24;
14199: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
14200: foreach my $lonhost (keys(%toupdate)) {
14201: if ($thismachine{$lonhost}) {
14202: unless ($updatedhere) {
14203: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
14204: $defaultshash{'loadbalancing'},
14205: $cachetime);
14206: $updatedhere = 1;
14207: }
14208: } else {
14209: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
14210: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
14211: }
14212: }
14213: }
1.150 raeburn 14214: }
1.171 raeburn 14215: }
14216: if ($resulttext ne '') {
14217: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 14218: } else {
14219: $resulttext = $nochgmsg;
14220: }
14221: } else {
1.171 raeburn 14222: $resulttext = $nochgmsg;
1.150 raeburn 14223: }
14224: } else {
1.171 raeburn 14225: $resulttext = '<span class="LC_error">'.
14226: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 14227: }
14228: } else {
1.171 raeburn 14229: $resulttext = $nochgmsg;
1.150 raeburn 14230: }
14231: return $resulttext;
14232: }
14233:
1.48 raeburn 14234: sub recurse_check {
14235: my ($chkcats,$categories,$depth,$name) = @_;
14236: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
14237: my $chg = 0;
14238: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
14239: my $category = $chkcats->[$depth]{$name}[$j];
14240: my $item;
14241: if ($category eq '') {
14242: $chg ++;
14243: } else {
14244: my $deeper = $depth + 1;
14245: $item = &escape($category).':'.&escape($name).':'.$depth;
14246: if ($chg) {
14247: $categories->{$item} -= $chg;
14248: }
14249: &recurse_check($chkcats,$categories,$deeper,$category);
14250: $deeper --;
14251: }
14252: }
14253: }
14254: return;
14255: }
14256:
14257: sub recurse_cat_deletes {
14258: my ($item,$coursecategories,$deletions) = @_;
14259: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14260: my $subdepth = $depth + 1;
14261: if (ref($coursecategories) eq 'HASH') {
14262: foreach my $subitem (keys(%{$coursecategories})) {
14263: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
14264: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
14265: delete($coursecategories->{$subitem});
14266: $deletions->{$subitem} = 1;
14267: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 14268: }
1.48 raeburn 14269: }
14270: }
14271: return;
14272: }
14273:
1.125 raeburn 14274: sub active_dc_picker {
1.191 raeburn 14275: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 14276: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 14277: my @domcoord = keys(%domcoords);
14278: if (keys(%currhash)) {
14279: foreach my $dc (keys(%currhash)) {
14280: unless (exists($domcoords{$dc})) {
14281: push(@domcoord,$dc);
14282: }
14283: }
14284: }
14285: @domcoord = sort(@domcoord);
1.210 raeburn 14286: my $numdcs = scalar(@domcoord);
1.191 raeburn 14287: my $rows = 0;
14288: my $table;
1.125 raeburn 14289: if ($numdcs > 1) {
1.191 raeburn 14290: $table = '<table>';
14291: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 14292: my $rem = $i%($numinrow);
14293: if ($rem == 0) {
14294: if ($i > 0) {
1.191 raeburn 14295: $table .= '</tr>';
1.125 raeburn 14296: }
1.191 raeburn 14297: $table .= '<tr>';
14298: $rows ++;
1.125 raeburn 14299: }
1.191 raeburn 14300: my $check = '';
14301: if ($inputtype eq 'radio') {
14302: if (keys(%currhash) == 0) {
14303: if (!$i) {
14304: $check = ' checked="checked"';
14305: }
14306: } elsif (exists($currhash{$domcoord[$i]})) {
14307: $check = ' checked="checked"';
14308: }
14309: } else {
14310: if (exists($currhash{$domcoord[$i]})) {
14311: $check = ' checked="checked"';
1.125 raeburn 14312: }
14313: }
1.191 raeburn 14314: if ($i == @domcoord - 1) {
1.125 raeburn 14315: my $colsleft = $numinrow - $rem;
14316: if ($colsleft > 1) {
1.191 raeburn 14317: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 14318: } else {
1.191 raeburn 14319: $table .= '<td class="LC_left_item">';
1.125 raeburn 14320: }
14321: } else {
1.191 raeburn 14322: $table .= '<td class="LC_left_item">';
14323: }
14324: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
14325: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
14326: $table .= '<span class="LC_nobreak"><label>'.
14327: '<input type="'.$inputtype.'" name="'.$name.'"'.
14328: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
14329: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 14330: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 14331: }
1.219 raeburn 14332: $table .= '</label></span></td>';
1.191 raeburn 14333: }
14334: $table .= '</tr></table>';
14335: } elsif ($numdcs == 1) {
1.219 raeburn 14336: my ($dcname,$dcdom) = split(':',$domcoord[0]);
14337: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 14338: if ($inputtype eq 'radio') {
1.247 raeburn 14339: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 14340: if ($user ne $dcname.':'.$dcdom) {
14341: $table .= ' ('.$dcname.':'.$dcdom.')';
14342: }
1.191 raeburn 14343: } else {
14344: my $check;
14345: if (exists($currhash{$domcoord[0]})) {
14346: $check = ' checked="checked"';
1.125 raeburn 14347: }
1.247 raeburn 14348: $table = '<span class="LC_nobreak"><label>'.
14349: '<input type="checkbox" name="'.$name.'" '.
14350: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 14351: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 14352: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 14353: }
1.220 raeburn 14354: $table .= '</label></span>';
1.191 raeburn 14355: $rows ++;
1.125 raeburn 14356: }
14357: }
1.191 raeburn 14358: return ($numdcs,$table,$rows);
1.125 raeburn 14359: }
14360:
1.137 raeburn 14361: sub usersession_titles {
14362: return &Apache::lonlocal::texthash(
14363: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
14364: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 14365: spares => 'Servers offloaded to, when busy',
1.137 raeburn 14366: version => 'LON-CAPA version requirement',
1.138 raeburn 14367: excludedomain => 'Allow all, but exclude specific domains',
14368: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 14369: primary => 'Primary (checked first)',
1.154 raeburn 14370: default => 'Default',
1.137 raeburn 14371: );
14372: }
14373:
1.152 raeburn 14374: sub id_for_thisdom {
14375: my (%servers) = @_;
14376: my %altids;
14377: foreach my $server (keys(%servers)) {
14378: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
14379: if ($serverhome ne $server) {
14380: $altids{$serverhome} = $server;
14381: }
14382: }
14383: return %altids;
14384: }
14385:
1.150 raeburn 14386: sub count_servers {
14387: my ($currbalancer,%servers) = @_;
14388: my (@spares,$numspares);
14389: foreach my $lonhost (sort(keys(%servers))) {
14390: next if ($currbalancer eq $lonhost);
14391: push(@spares,$lonhost);
14392: }
14393: if ($currbalancer) {
14394: $numspares = scalar(@spares);
14395: } else {
14396: $numspares = scalar(@spares) - 1;
14397: }
14398: return ($numspares,@spares);
14399: }
14400:
14401: sub lonbalance_targets_js {
1.171 raeburn 14402: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 14403: my $select = &mt('Select');
14404: my ($alltargets,$allishome,$allinsttypes,@alltypes);
14405: if (ref($servers) eq 'HASH') {
14406: $alltargets = join("','",sort(keys(%{$servers})));
14407: my @homedoms;
14408: foreach my $server (sort(keys(%{$servers}))) {
14409: if (&Apache::lonnet::host_domain($server) eq $dom) {
14410: push(@homedoms,'1');
14411: } else {
14412: push(@homedoms,'0');
14413: }
14414: }
14415: $allishome = join("','",@homedoms);
14416: }
14417: if (ref($types) eq 'ARRAY') {
14418: if (@{$types} > 0) {
14419: @alltypes = @{$types};
14420: }
14421: }
14422: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
14423: $allinsttypes = join("','",@alltypes);
1.171 raeburn 14424: my (%currbalancer,%currtargets,%currrules,%existing);
14425: if (ref($settings) eq 'HASH') {
14426: %existing = %{$settings};
14427: }
14428: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
14429: \%currtargets,\%currrules);
1.210 raeburn 14430: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 14431: return <<"END";
14432:
14433: <script type="text/javascript">
14434: // <![CDATA[
14435:
1.171 raeburn 14436: currBalancers = new Array('$balancers');
14437:
14438: function toggleTargets(balnum) {
14439: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14440: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
14441: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
14442: var prevbalancer = prevhostitem.value;
14443: var baltotal = document.getElementById('loadbalancing_total').value;
14444: prevhostitem.value = balancer;
14445: if (prevbalancer != '') {
14446: var prevIdx = currBalancers.indexOf(prevbalancer);
14447: if (prevIdx != -1) {
14448: currBalancers.splice(prevIdx,1);
14449: }
14450: }
1.150 raeburn 14451: if (balancer == '') {
1.171 raeburn 14452: hideSpares(balnum);
1.150 raeburn 14453: } else {
1.171 raeburn 14454: var currIdx = currBalancers.indexOf(balancer);
14455: if (currIdx == -1) {
14456: currBalancers.push(balancer);
14457: }
1.150 raeburn 14458: var homedoms = new Array('$allishome');
1.171 raeburn 14459: var ishomedom = homedoms[lonhostitem.selectedIndex];
14460: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 14461: }
1.171 raeburn 14462: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 14463: return;
14464: }
14465:
1.171 raeburn 14466: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 14467: var alltargets = new Array('$alltargets');
14468: var insttypes = new Array('$allinsttypes');
1.151 raeburn 14469: var offloadtypes = new Array('primary','default');
14470:
1.171 raeburn 14471: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
14472: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 14473:
1.151 raeburn 14474: for (var i=0; i<offloadtypes.length; i++) {
14475: var count = 0;
14476: for (var j=0; j<alltargets.length; j++) {
14477: if (alltargets[j] != balancer) {
1.171 raeburn 14478: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
14479: item.value = alltargets[j];
14480: item.style.textAlign='left';
14481: item.style.textFace='normal';
14482: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
14483: if (currBalancers.indexOf(alltargets[j]) == -1) {
14484: item.disabled = '';
14485: } else {
14486: item.disabled = 'disabled';
14487: item.checked = false;
14488: }
1.151 raeburn 14489: count ++;
14490: }
1.150 raeburn 14491: }
14492: }
1.151 raeburn 14493: for (var k=0; k<insttypes.length; k++) {
14494: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 14495: if (ishomedom == 1) {
1.171 raeburn 14496: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14497: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14498: } else {
1.171 raeburn 14499: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14500: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 14501: }
14502: } else {
1.171 raeburn 14503: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14504: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14505: }
1.151 raeburn 14506: if ((insttypes[k] != '_LC_external') &&
14507: ((insttypes[k] != '_LC_internetdom') ||
14508: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 14509: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
14510: item.options.length = 0;
14511: item.options[0] = new Option("","",true,true);
1.210 raeburn 14512: var idx = 0;
1.151 raeburn 14513: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 14514: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
14515: idx ++;
14516: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 14517: }
14518: }
14519: }
14520: }
14521: return;
14522: }
14523:
1.171 raeburn 14524: function hideSpares(balnum) {
1.150 raeburn 14525: var alltargets = new Array('$alltargets');
14526: var insttypes = new Array('$allinsttypes');
14527: var offloadtypes = new Array('primary','default');
14528:
1.171 raeburn 14529: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
14530: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 14531:
14532: var total = alltargets.length - 1;
14533: for (var i=0; i<offloadtypes; i++) {
14534: for (var j=0; j<total; j++) {
1.171 raeburn 14535: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
14536: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
14537: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 14538: }
1.150 raeburn 14539: }
14540: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 14541: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14542: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 14543: if (insttypes[k] != '_LC_external') {
1.171 raeburn 14544: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
14545: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 14546: }
14547: }
14548: return;
14549: }
14550:
1.171 raeburn 14551: function checkOffloads(item,balnum,type) {
1.150 raeburn 14552: var alltargets = new Array('$alltargets');
14553: var offloadtypes = new Array('primary','default');
14554: if (item.checked) {
14555: var total = alltargets.length - 1;
14556: var other;
14557: if (type == offloadtypes[0]) {
1.151 raeburn 14558: other = offloadtypes[1];
1.150 raeburn 14559: } else {
1.151 raeburn 14560: other = offloadtypes[0];
1.150 raeburn 14561: }
14562: for (var i=0; i<total; i++) {
1.171 raeburn 14563: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 14564: if (server == item.value) {
1.171 raeburn 14565: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
14566: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 14567: }
14568: }
14569: }
14570: }
14571: return;
14572: }
14573:
1.171 raeburn 14574: function singleServerToggle(balnum,type) {
14575: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 14576: if (offloadtoSelIdx == 0) {
1.171 raeburn 14577: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
14578: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14579:
14580: } else {
1.171 raeburn 14581: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
14582: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 14583: }
14584: return;
14585: }
14586:
1.171 raeburn 14587: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 14588: if (type == '_LC_external') {
1.171 raeburn 14589: return;
1.150 raeburn 14590: }
1.171 raeburn 14591: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 14592: for (var i=0; i<typesRules.length; i++) {
14593: if (formname.elements[typesRules[i]].checked) {
14594: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 14595: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
14596: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14597: } else {
1.171 raeburn 14598: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
14599: }
14600: }
14601: }
14602: return;
14603: }
14604:
14605: function balancerDeleteChange(balnum) {
14606: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14607: var baltotal = document.getElementById('loadbalancing_total').value;
14608: var addtarget;
14609: var removetarget;
14610: var action = 'delete';
14611: if (document.getElementById('loadbalancing_delete_'+balnum)) {
14612: var lonhost = hostitem.value;
14613: var currIdx = currBalancers.indexOf(lonhost);
14614: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
14615: if (currIdx != -1) {
14616: currBalancers.splice(currIdx,1);
14617: }
14618: addtarget = lonhost;
14619: } else {
14620: if (currIdx == -1) {
14621: currBalancers.push(lonhost);
14622: }
14623: removetarget = lonhost;
14624: action = 'undelete';
14625: }
14626: balancerChange(balnum,baltotal,action,addtarget,removetarget);
14627: }
14628: return;
14629: }
14630:
14631: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
14632: if (baltotal > 1) {
14633: var offloadtypes = new Array('primary','default');
14634: var alltargets = new Array('$alltargets');
14635: var insttypes = new Array('$allinsttypes');
14636: for (var i=0; i<baltotal; i++) {
14637: if (i != balnum) {
14638: for (var j=0; j<offloadtypes.length; j++) {
14639: var total = alltargets.length - 1;
14640: for (var k=0; k<total; k++) {
14641: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
14642: var server = serveritem.value;
14643: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14644: if (server == addtarget) {
14645: serveritem.disabled = '';
14646: }
14647: }
14648: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14649: if (server == removetarget) {
14650: serveritem.disabled = 'disabled';
14651: serveritem.checked = false;
14652: }
14653: }
14654: }
14655: }
14656: for (var j=0; j<insttypes.length; j++) {
14657: if (insttypes[j] != '_LC_external') {
14658: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
14659: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
14660: var currSel = singleserver.selectedIndex;
14661: var currVal = singleserver.options[currSel].value;
14662: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14663: var numoptions = singleserver.options.length;
14664: var needsnew = 1;
14665: for (var k=0; k<numoptions; k++) {
14666: if (singleserver.options[k] == addtarget) {
14667: needsnew = 0;
14668: break;
14669: }
14670: }
14671: if (needsnew == 1) {
14672: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
14673: }
14674: }
14675: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14676: singleserver.options.length = 0;
14677: if ((currVal) && (currVal != removetarget)) {
14678: singleserver.options[0] = new Option("","",false,false);
14679: } else {
14680: singleserver.options[0] = new Option("","",true,true);
14681: }
14682: var idx = 0;
14683: for (var m=0; m<alltargets.length; m++) {
14684: if (currBalancers.indexOf(alltargets[m]) == -1) {
14685: idx ++;
14686: if (currVal == alltargets[m]) {
14687: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
14688: } else {
14689: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
14690: }
14691: }
14692: }
14693: }
14694: }
14695: }
14696: }
1.150 raeburn 14697: }
14698: }
14699: }
14700: return;
14701: }
14702:
1.152 raeburn 14703: // ]]>
14704: </script>
14705:
14706: END
14707: }
14708:
14709: sub new_spares_js {
14710: my @sparestypes = ('primary','default');
14711: my $types = join("','",@sparestypes);
14712: my $select = &mt('Select');
14713: return <<"END";
14714:
14715: <script type="text/javascript">
14716: // <![CDATA[
14717:
14718: function updateNewSpares(formname,lonhost) {
14719: var types = new Array('$types');
14720: var include = new Array();
14721: var exclude = new Array();
14722: for (var i=0; i<types.length; i++) {
14723: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
14724: for (var j=0; j<spareboxes.length; j++) {
14725: if (formname.elements[spareboxes[j]].checked) {
14726: exclude.push(formname.elements[spareboxes[j]].value);
14727: } else {
14728: include.push(formname.elements[spareboxes[j]].value);
14729: }
14730: }
14731: }
14732: for (var i=0; i<types.length; i++) {
14733: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
14734: var selIdx = newSpare.selectedIndex;
14735: var currnew = newSpare.options[selIdx].value;
14736: var okSpares = new Array();
14737: for (var j=0; j<newSpare.options.length; j++) {
14738: var possible = newSpare.options[j].value;
14739: if (possible != '') {
14740: if (exclude.indexOf(possible) == -1) {
14741: okSpares.push(possible);
14742: } else {
14743: if (currnew == possible) {
14744: selIdx = 0;
14745: }
14746: }
14747: }
14748: }
14749: for (var k=0; k<include.length; k++) {
14750: if (okSpares.indexOf(include[k]) == -1) {
14751: okSpares.push(include[k]);
14752: }
14753: }
14754: okSpares.sort();
14755: newSpare.options.length = 0;
14756: if (selIdx == 0) {
14757: newSpare.options[0] = new Option("$select","",true,true);
14758: } else {
14759: newSpare.options[0] = new Option("$select","",false,false);
14760: }
14761: for (var m=0; m<okSpares.length; m++) {
14762: var idx = m+1;
14763: var selThis = 0;
14764: if (selIdx != 0) {
14765: if (okSpares[m] == currnew) {
14766: selThis = 1;
14767: }
14768: }
14769: if (selThis == 1) {
14770: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
14771: } else {
14772: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
14773: }
14774: }
14775: }
14776: return;
14777: }
14778:
14779: function checkNewSpares(lonhost,type) {
14780: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
14781: var chosen = newSpare.options[newSpare.selectedIndex].value;
14782: if (chosen != '') {
14783: var othertype;
14784: var othernewSpare;
14785: if (type == 'primary') {
14786: othernewSpare = document.getElementById('newspare_default_'+lonhost);
14787: }
14788: if (type == 'default') {
14789: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
14790: }
14791: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
14792: othernewSpare.selectedIndex = 0;
14793: }
14794: }
14795: return;
14796: }
14797:
14798: // ]]>
14799: </script>
14800:
14801: END
14802:
14803: }
14804:
14805: sub common_domprefs_js {
14806: return <<"END";
14807:
14808: <script type="text/javascript">
14809: // <![CDATA[
14810:
1.150 raeburn 14811: function getIndicesByName(formname,item) {
1.152 raeburn 14812: var group = new Array();
1.150 raeburn 14813: for (var i=0;i<formname.elements.length;i++) {
14814: if (formname.elements[i].name == item) {
1.152 raeburn 14815: group.push(formname.elements[i].id);
1.150 raeburn 14816: }
14817: }
1.152 raeburn 14818: return group;
1.150 raeburn 14819: }
14820:
14821: // ]]>
14822: </script>
14823:
14824: END
1.152 raeburn 14825:
1.150 raeburn 14826: }
14827:
1.165 raeburn 14828: sub recaptcha_js {
14829: my %lt = &captcha_phrases();
14830: return <<"END";
14831:
14832: <script type="text/javascript">
14833: // <![CDATA[
14834:
14835: function updateCaptcha(caller,context) {
14836: var privitem;
14837: var pubitem;
14838: var privtext;
14839: var pubtext;
1.269 raeburn 14840: var versionitem;
14841: var versiontext;
1.165 raeburn 14842: if (document.getElementById(context+'_recaptchapub')) {
14843: pubitem = document.getElementById(context+'_recaptchapub');
14844: } else {
14845: return;
14846: }
14847: if (document.getElementById(context+'_recaptchapriv')) {
14848: privitem = document.getElementById(context+'_recaptchapriv');
14849: } else {
14850: return;
14851: }
14852: if (document.getElementById(context+'_recaptchapubtxt')) {
14853: pubtext = document.getElementById(context+'_recaptchapubtxt');
14854: } else {
14855: return;
14856: }
14857: if (document.getElementById(context+'_recaptchaprivtxt')) {
14858: privtext = document.getElementById(context+'_recaptchaprivtxt');
14859: } else {
14860: return;
14861: }
1.269 raeburn 14862: if (document.getElementById(context+'_recaptchaversion')) {
14863: versionitem = document.getElementById(context+'_recaptchaversion');
14864: } else {
14865: return;
14866: }
14867: if (document.getElementById(context+'_recaptchavertxt')) {
14868: versiontext = document.getElementById(context+'_recaptchavertxt');
14869: } else {
14870: return;
14871: }
1.165 raeburn 14872: if (caller.checked) {
14873: if (caller.value == 'recaptcha') {
14874: pubitem.type = 'text';
14875: privitem.type = 'text';
14876: pubitem.size = '40';
14877: privitem.size = '40';
14878: pubtext.innerHTML = "$lt{'pub'}";
14879: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 14880: versionitem.type = 'text';
14881: versionitem.size = '3';
14882: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 14883: } else {
14884: pubitem.type = 'hidden';
14885: privitem.type = 'hidden';
1.269 raeburn 14886: versionitem.type = 'hidden';
1.165 raeburn 14887: pubtext.innerHTML = '';
14888: privtext.innerHTML = '';
1.269 raeburn 14889: versiontext.innerHTML = '';
1.165 raeburn 14890: }
14891: }
14892: return;
14893: }
14894:
14895: // ]]>
14896: </script>
14897:
14898: END
14899:
14900: }
14901:
1.236 raeburn 14902: sub toggle_display_js {
1.192 raeburn 14903: return <<"END";
14904:
14905: <script type="text/javascript">
14906: // <![CDATA[
14907:
1.236 raeburn 14908: function toggleDisplay(domForm,caller) {
14909: if (document.getElementById(caller)) {
14910: var divitem = document.getElementById(caller);
14911: var optionsElement = domForm.coursecredits;
1.264 raeburn 14912: var checkval = 1;
14913: var dispval = 'block';
1.236 raeburn 14914: if (caller == 'emailoptions') {
14915: optionsElement = domForm.cancreate_email;
14916: }
1.257 raeburn 14917: if (caller == 'studentsubmission') {
14918: optionsElement = domForm.postsubmit;
14919: }
1.264 raeburn 14920: if (caller == 'cloneinstcode') {
14921: optionsElement = domForm.canclone;
14922: checkval = 'instcode';
14923: }
1.236 raeburn 14924: if (optionsElement.length) {
1.192 raeburn 14925: var currval;
1.236 raeburn 14926: for (var i=0; i<optionsElement.length; i++) {
14927: if (optionsElement[i].checked) {
14928: currval = optionsElement[i].value;
1.192 raeburn 14929: }
14930: }
1.264 raeburn 14931: if (currval == checkval) {
14932: divitem.style.display = dispval;
1.192 raeburn 14933: } else {
1.236 raeburn 14934: divitem.style.display = 'none';
1.192 raeburn 14935: }
14936: }
14937: }
14938: return;
14939: }
14940:
14941: // ]]>
14942: </script>
14943:
14944: END
14945:
14946: }
14947:
1.165 raeburn 14948: sub captcha_phrases {
14949: return &Apache::lonlocal::texthash (
14950: priv => 'Private key',
14951: pub => 'Public key',
14952: original => 'original (CAPTCHA)',
14953: recaptcha => 'successor (ReCAPTCHA)',
14954: notused => 'unused',
1.269 raeburn 14955: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 14956: );
14957: }
14958:
1.205 raeburn 14959: sub devalidate_remote_domconfs {
1.212 raeburn 14960: my ($dom,$cachekeys) = @_;
14961: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 14962: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14963: my %thismachine;
14964: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.267 raeburn 14965: my @posscached = ('domainconfig','domdefaults','ltitools');
1.260 raeburn 14966: if (keys(%servers)) {
1.205 raeburn 14967: foreach my $server (keys(%servers)) {
14968: next if ($thismachine{$server});
1.212 raeburn 14969: my @cached;
14970: foreach my $name (@posscached) {
14971: if ($cachekeys->{$name}) {
14972: push(@cached,&escape($name).':'.&escape($dom));
14973: }
14974: }
14975: if (@cached) {
14976: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
14977: }
1.205 raeburn 14978: }
14979: }
14980: return;
14981: }
14982:
1.3 raeburn 14983: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>