Annotation of loncom/interface/domainprefs.pm, revision 1.289
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.289 ! raeburn 4: # $Id: domainprefs.pm,v 1.288 2017/01/23 22:46:44 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 {
1.289 ! raeburn 3027: $maxsize = '1.0';
1.286 raeburn 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" ';
1.289 ! raeburn 3044: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 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]',
1.289 ! raeburn 3120: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
! 3121: &mt('LON-CAPA core group - MSU'),600,500));
1.286 raeburn 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">';
1.289 ! raeburn 3137: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
1.286 raeburn 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') {
1.289 ! raeburn 3191: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 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)/)) {
1.289 ! raeburn 3500: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 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: }
1.289 ! raeburn 3626: $datatable .=
1.257 raeburn 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.289 ! 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: }
1.289 ! raeburn 4051: }
1.264 raeburn 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+$/) {
1.289 ! raeburn 4120: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 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 />'.
1.289 ! raeburn 4935: '<span class="LC_nobreak">'."\n".
1.261 raeburn 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",
1.289 ! raeburn 5429: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
1.286 raeburn 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',
1.289 ! raeburn 5450: 'screenshot' => 'File upload',
1.286 raeburn 5451: );
5452: my @fields = ('username','phone','user','course','section','cc','screenshot');
5453: my %possoptions = (
5454: username => ['yes','no','req'],
1.289 ! raeburn 5455: phone => ['yes','no','req'],
1.286 raeburn 5456: user => ['yes','no'],
1.289 ! raeburn 5457: cc => ['yes','no'],
1.286 raeburn 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.289 ! 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}) {
1.289 ! raeburn 7560: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 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: sub check_exempt_addresses {
7793: my ($iplist) = @_;
7794: $iplist =~ s/^\s+//;
7795: $iplist =~ s/\s+$//;
7796: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7797: my (@okips,$new);
7798: foreach my $ip (@poss_ips) {
7799: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7800: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7801: push(@okips,$ip);
7802: }
7803: }
7804: }
7805: if (@okips > 0) {
7806: $new = join(',',@okips);
7807: } else {
7808: $new = '';
7809: }
7810: return $new;
7811: }
7812:
1.6 raeburn 7813: sub color_font_choices {
7814: my %choices =
7815: &Apache::lonlocal::texthash (
7816: img => "Header",
7817: bgs => "Background colors",
7818: links => "Link colors",
1.55 raeburn 7819: images => "Images",
1.6 raeburn 7820: font => "Font color",
1.201 raeburn 7821: fontmenu => "Font menu",
1.76 raeburn 7822: pgbg => "Page",
1.6 raeburn 7823: tabbg => "Header",
7824: sidebg => "Border",
7825: link => "Link",
7826: alink => "Active link",
7827: vlink => "Visited link",
7828: );
7829: return %choices;
7830: }
7831:
7832: sub modify_rolecolors {
1.205 raeburn 7833: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7834: my ($resulttext,%rolehash);
7835: $rolehash{'rolecolors'} = {};
1.55 raeburn 7836: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7837: if ($domconfig{'rolecolors'} eq '') {
7838: $domconfig{'rolecolors'} = {};
7839: }
7840: }
1.9 raeburn 7841: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7842: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7843: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7844: $dom);
7845: if ($putresult eq 'ok') {
7846: if (keys(%changes) > 0) {
1.41 raeburn 7847: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7848: if (ref($lastactref) eq 'HASH') {
7849: $lastactref->{'domainconfig'} = 1;
7850: }
1.6 raeburn 7851: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7852: $rolehash{'rolecolors'});
7853: } else {
7854: $resulttext = &mt('No changes made to default color schemes');
7855: }
7856: } else {
1.11 albertel 7857: $resulttext = '<span class="LC_error">'.
7858: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7859: }
7860: if ($errors) {
7861: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7862: $errors.'</ul>';
7863: }
7864: return $resulttext;
7865: }
7866:
7867: sub modify_colors {
1.9 raeburn 7868: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7869: my (%changes,%choices);
1.51 raeburn 7870: my @bgs;
1.6 raeburn 7871: my @links = ('link','alink','vlink');
1.41 raeburn 7872: my @logintext;
1.6 raeburn 7873: my @images;
7874: my $servadm = $r->dir_config('lonAdmEMail');
7875: my $errors;
1.200 raeburn 7876: my %defaults;
1.6 raeburn 7877: foreach my $role (@{$roles}) {
7878: if ($role eq 'login') {
1.12 raeburn 7879: %choices = &login_choices();
1.41 raeburn 7880: @logintext = ('textcol','bgcol');
1.12 raeburn 7881: } else {
7882: %choices = &color_font_choices();
7883: }
7884: if ($role eq 'login') {
1.41 raeburn 7885: @images = ('img','logo','domlogo','login');
1.51 raeburn 7886: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7887: } else {
7888: @images = ('img');
1.200 raeburn 7889: @bgs = ('pgbg','tabbg','sidebg');
7890: }
7891: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7892: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7893: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7894: }
7895: if ($role eq 'login') {
7896: foreach my $item (@logintext) {
1.234 raeburn 7897: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7898: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7899: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7900: }
7901: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 7902: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7903: }
7904: }
7905: } else {
1.234 raeburn 7906: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7907: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7908: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7909: }
7910: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 7911: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7912: }
1.6 raeburn 7913: }
1.200 raeburn 7914: foreach my $item (@bgs) {
1.234 raeburn 7915: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7916: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7917: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7918: }
7919: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 7920: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7921: }
7922: }
7923: foreach my $item (@links) {
1.234 raeburn 7924: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7925: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7926: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7927: }
7928: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 7929: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7930: }
1.6 raeburn 7931: }
1.46 raeburn 7932: my ($configuserok,$author_ok,$switchserver) =
7933: &config_check($dom,$confname,$servadm);
1.9 raeburn 7934: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7935: if (ref($domconfig->{$role}) ne 'HASH') {
7936: $domconfig->{$role} = {};
7937: }
1.8 raeburn 7938: foreach my $img (@images) {
1.70 raeburn 7939: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7940: if (defined($env{'form.login_showlogo_'.$img})) {
7941: $confhash->{$role}{'showlogo'}{$img} = 1;
7942: } else {
7943: $confhash->{$role}{'showlogo'}{$img} = 0;
7944: }
7945: }
1.18 albertel 7946: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7947: && !defined($domconfig->{$role}{$img})
7948: && !$env{'form.'.$role.'_del_'.$img}
7949: && $env{'form.'.$role.'_import_'.$img}) {
7950: # import the old configured image from the .tab setting
7951: # if they haven't provided a new one
7952: $domconfig->{$role}{$img} =
7953: $env{'form.'.$role.'_import_'.$img};
7954: }
1.6 raeburn 7955: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7956: my $error;
1.6 raeburn 7957: if ($configuserok eq 'ok') {
1.9 raeburn 7958: if ($switchserver) {
1.12 raeburn 7959: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7960: } else {
7961: if ($author_ok eq 'ok') {
7962: my ($result,$logourl) =
7963: &publishlogo($r,'upload',$role.'_'.$img,
7964: $dom,$confname,$img,$width,$height);
7965: if ($result eq 'ok') {
7966: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7967: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7968: } else {
1.12 raeburn 7969: $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 7970: }
7971: } else {
1.46 raeburn 7972: $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 7973: }
7974: }
7975: } else {
1.46 raeburn 7976: $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 7977: }
7978: if ($error) {
1.8 raeburn 7979: &Apache::lonnet::logthis($error);
1.11 albertel 7980: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7981: }
7982: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7983: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7984: my $error;
7985: if ($configuserok eq 'ok') {
7986: # is confname an author?
7987: if ($switchserver eq '') {
7988: if ($author_ok eq 'ok') {
7989: my ($result,$logourl) =
7990: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7991: $dom,$confname,$img,$width,$height);
7992: if ($result eq 'ok') {
7993: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7994: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7995: }
7996: }
7997: }
7998: }
1.6 raeburn 7999: }
8000: }
8001: }
8002: if (ref($domconfig) eq 'HASH') {
8003: if (ref($domconfig->{$role}) eq 'HASH') {
8004: foreach my $img (@images) {
8005: if ($domconfig->{$role}{$img} ne '') {
8006: if ($env{'form.'.$role.'_del_'.$img}) {
8007: $confhash->{$role}{$img} = '';
1.12 raeburn 8008: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8009: } else {
1.9 raeburn 8010: if ($confhash->{$role}{$img} eq '') {
8011: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8012: }
1.6 raeburn 8013: }
8014: } else {
8015: if ($env{'form.'.$role.'_del_'.$img}) {
8016: $confhash->{$role}{$img} = '';
1.12 raeburn 8017: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8018: }
8019: }
1.70 raeburn 8020: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8021: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8022: if ($confhash->{$role}{'showlogo'}{$img} ne
8023: $domconfig->{$role}{'showlogo'}{$img}) {
8024: $changes{$role}{'showlogo'}{$img} = 1;
8025: }
8026: } else {
8027: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8028: $changes{$role}{'showlogo'}{$img} = 1;
8029: }
8030: }
8031: }
8032: }
1.6 raeburn 8033: if ($domconfig->{$role}{'font'} ne '') {
8034: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8035: $changes{$role}{'font'} = 1;
8036: }
8037: } else {
8038: if ($confhash->{$role}{'font'}) {
8039: $changes{$role}{'font'} = 1;
8040: }
8041: }
1.107 raeburn 8042: if ($role ne 'login') {
8043: if ($domconfig->{$role}{'fontmenu'} ne '') {
8044: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8045: $changes{$role}{'fontmenu'} = 1;
8046: }
8047: } else {
8048: if ($confhash->{$role}{'fontmenu'}) {
8049: $changes{$role}{'fontmenu'} = 1;
8050: }
1.97 tempelho 8051: }
8052: }
1.6 raeburn 8053: foreach my $item (@bgs) {
8054: if ($domconfig->{$role}{$item} ne '') {
8055: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8056: $changes{$role}{'bgs'}{$item} = 1;
8057: }
8058: } else {
8059: if ($confhash->{$role}{$item}) {
8060: $changes{$role}{'bgs'}{$item} = 1;
8061: }
8062: }
8063: }
8064: foreach my $item (@links) {
8065: if ($domconfig->{$role}{$item} ne '') {
8066: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8067: $changes{$role}{'links'}{$item} = 1;
8068: }
8069: } else {
8070: if ($confhash->{$role}{$item}) {
8071: $changes{$role}{'links'}{$item} = 1;
8072: }
8073: }
8074: }
1.41 raeburn 8075: foreach my $item (@logintext) {
8076: if ($domconfig->{$role}{$item} ne '') {
8077: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8078: $changes{$role}{'logintext'}{$item} = 1;
8079: }
8080: } else {
8081: if ($confhash->{$role}{$item}) {
8082: $changes{$role}{'logintext'}{$item} = 1;
8083: }
8084: }
8085: }
1.6 raeburn 8086: } else {
8087: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8088: \@logintext,$confhash,\%changes);
1.6 raeburn 8089: }
8090: } else {
8091: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8092: \@logintext,$confhash,\%changes);
1.6 raeburn 8093: }
8094: }
8095: return ($errors,%changes);
8096: }
8097:
1.46 raeburn 8098: sub config_check {
8099: my ($dom,$confname,$servadm) = @_;
8100: my ($configuserok,$author_ok,$switchserver,%currroles);
8101: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8102: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8103: $confname,$servadm);
8104: if ($configuserok eq 'ok') {
8105: $switchserver = &check_switchserver($dom,$confname);
8106: if ($switchserver eq '') {
8107: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8108: }
8109: }
8110: return ($configuserok,$author_ok,$switchserver);
8111: }
8112:
1.6 raeburn 8113: sub default_change_checker {
1.41 raeburn 8114: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8115: foreach my $item (@{$links}) {
8116: if ($confhash->{$role}{$item}) {
8117: $changes->{$role}{'links'}{$item} = 1;
8118: }
8119: }
8120: foreach my $item (@{$bgs}) {
8121: if ($confhash->{$role}{$item}) {
8122: $changes->{$role}{'bgs'}{$item} = 1;
8123: }
8124: }
1.41 raeburn 8125: foreach my $item (@{$logintext}) {
8126: if ($confhash->{$role}{$item}) {
8127: $changes->{$role}{'logintext'}{$item} = 1;
8128: }
8129: }
1.6 raeburn 8130: foreach my $img (@{$images}) {
8131: if ($env{'form.'.$role.'_del_'.$img}) {
8132: $confhash->{$role}{$img} = '';
1.12 raeburn 8133: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8134: }
1.70 raeburn 8135: if ($role eq 'login') {
8136: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8137: $changes->{$role}{'showlogo'}{$img} = 1;
8138: }
8139: }
1.6 raeburn 8140: }
8141: if ($confhash->{$role}{'font'}) {
8142: $changes->{$role}{'font'} = 1;
8143: }
1.48 raeburn 8144: }
1.6 raeburn 8145:
8146: sub display_colorchgs {
8147: my ($dom,$changes,$roles,$confhash) = @_;
8148: my (%choices,$resulttext);
8149: if (!grep(/^login$/,@{$roles})) {
8150: $resulttext = &mt('Changes made:').'<br />';
8151: }
8152: foreach my $role (@{$roles}) {
8153: if ($role eq 'login') {
8154: %choices = &login_choices();
8155: } else {
8156: %choices = &color_font_choices();
8157: }
8158: if (ref($changes->{$role}) eq 'HASH') {
8159: if ($role ne 'login') {
8160: $resulttext .= '<h4>'.&mt($role).'</h4>';
8161: }
8162: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8163: if ($role ne 'login') {
8164: $resulttext .= '<ul>';
8165: }
8166: if (ref($changes->{$role}{$key}) eq 'HASH') {
8167: if ($role ne 'login') {
8168: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8169: }
8170: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8171: if (($role eq 'login') && ($key eq 'showlogo')) {
8172: if ($confhash->{$role}{$key}{$item}) {
8173: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8174: } else {
8175: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8176: }
8177: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8178: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8179: } else {
1.12 raeburn 8180: my $newitem = $confhash->{$role}{$item};
8181: if ($key eq 'images') {
8182: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
8183: }
8184: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8185: }
8186: }
8187: if ($role ne 'login') {
8188: $resulttext .= '</ul></li>';
8189: }
8190: } else {
8191: if ($confhash->{$role}{$key} eq '') {
8192: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8193: } else {
8194: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8195: }
8196: }
8197: if ($role ne 'login') {
8198: $resulttext .= '</ul>';
8199: }
8200: }
8201: }
8202: }
1.3 raeburn 8203: return $resulttext;
1.1 raeburn 8204: }
8205:
1.9 raeburn 8206: sub thumb_dimensions {
8207: return ('200','50');
8208: }
8209:
1.16 raeburn 8210: sub check_dimensions {
8211: my ($inputfile) = @_;
8212: my ($fullwidth,$fullheight);
8213: if ($inputfile =~ m|^[/\w.\-]+$|) {
8214: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8215: my $imageinfo = <PIPE>;
8216: if (!close(PIPE)) {
8217: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8218: }
8219: chomp($imageinfo);
8220: my ($fullsize) =
1.21 raeburn 8221: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8222: if ($fullsize) {
8223: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8224: }
8225: }
8226: }
8227: return ($fullwidth,$fullheight);
8228: }
8229:
1.9 raeburn 8230: sub check_configuser {
8231: my ($uhome,$dom,$confname,$servadm) = @_;
8232: my ($configuserok,%currroles);
8233: if ($uhome eq 'no_host') {
8234: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
8235: my $configpass = &LONCAPA::Enrollment::create_password();
8236: $configuserok =
8237: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8238: $configpass,'','','','','',undef,$servadm);
8239: } else {
8240: $configuserok = 'ok';
8241: %currroles =
8242: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8243: }
8244: return ($configuserok,%currroles);
8245: }
8246:
8247: sub check_authorstatus {
8248: my ($dom,$confname,%currroles) = @_;
8249: my $author_ok;
1.40 raeburn 8250: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8251: my $start = time;
8252: my $end = 0;
8253: $author_ok =
8254: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8255: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8256: } else {
8257: $author_ok = 'ok';
8258: }
8259: return $author_ok;
8260: }
8261:
8262: sub publishlogo {
1.46 raeburn 8263: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 8264: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 8265: if ($action eq 'upload') {
8266: $fname=$env{'form.'.$formname.'.filename'};
8267: chop($env{'form.'.$formname});
8268: } else {
8269: ($fname) = ($formname =~ /([^\/]+)$/);
8270: }
1.46 raeburn 8271: if ($savefileas ne '') {
8272: $fname = $savefileas;
8273: }
1.9 raeburn 8274: $fname=&Apache::lonnet::clean_filename($fname);
8275: # See if there is anything left
8276: unless ($fname) { return ('error: no uploaded file'); }
8277: $fname="$subdir/$fname";
1.210 raeburn 8278: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 8279: my $filepath="$docroot/priv";
8280: my $relpath = "$dom/$confname";
1.9 raeburn 8281: my ($fnamepath,$file,$fetchthumb);
8282: $file=$fname;
8283: if ($fname=~m|/|) {
8284: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8285: }
1.164 raeburn 8286: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8287: my $count;
1.164 raeburn 8288: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8289: $filepath.="/$parts[$count]";
8290: if ((-e $filepath)!=1) {
8291: mkdir($filepath,02770);
8292: }
8293: }
8294: # Check for bad extension and disallow upload
8295: if ($file=~/\.(\w+)$/ &&
8296: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8297: $output =
1.207 bisitz 8298: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8299: } elsif ($file=~/\.(\w+)$/ &&
8300: !defined(&Apache::loncommon::fileembstyle($1))) {
8301: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8302: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 8303: $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 8304: } elsif (-d "$filepath/$file") {
1.195 bisitz 8305: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8306: } else {
8307: my $source = $filepath.'/'.$file;
8308: my $logfile;
8309: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 8310: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8311: }
8312: print $logfile
8313: "\n================= Publish ".localtime()." ================\n".
8314: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8315: # Save the file
8316: if (!open(FH,'>'.$source)) {
8317: &Apache::lonnet::logthis('Failed to create '.$source);
8318: return (&mt('Failed to create file'));
8319: }
8320: if ($action eq 'upload') {
8321: if (!print FH ($env{'form.'.$formname})) {
8322: &Apache::lonnet::logthis('Failed to write to '.$source);
8323: return (&mt('Failed to write file'));
8324: }
8325: } else {
8326: my $original = &Apache::lonnet::filelocation('',$formname);
8327: if(!copy($original,$source)) {
8328: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8329: return (&mt('Failed to write file'));
8330: }
8331: }
8332: close(FH);
8333: chmod(0660, $source); # Permissions to rw-rw---.
8334:
8335: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8336: my $copyfile=$targetdir.'/'.$file;
8337:
8338: my @parts=split(/\//,$targetdir);
8339: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8340: for (my $count=5;$count<=$#parts;$count++) {
8341: $path.="/$parts[$count]";
8342: if (!-e $path) {
8343: print $logfile "\nCreating directory ".$path;
8344: mkdir($path,02770);
8345: }
8346: }
8347: my $versionresult;
8348: if (-e $copyfile) {
8349: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8350: } else {
8351: $versionresult = 'ok';
8352: }
8353: if ($versionresult eq 'ok') {
8354: if (copy($source,$copyfile)) {
8355: print $logfile "\nCopied original source to ".$copyfile."\n";
8356: $output = 'ok';
8357: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8358: push(@{$modified_urls},[$copyfile,$source]);
8359: my $metaoutput =
8360: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8361: unless ($registered_cleanup) {
8362: my $handlers = $r->get_handlers('PerlCleanupHandler');
8363: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8364: $registered_cleanup=1;
8365: }
1.9 raeburn 8366: } else {
8367: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8368: $output = &mt('Failed to copy file to RES space').", $!";
8369: }
8370: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8371: my $inputfile = $filepath.'/'.$file;
8372: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8373: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8374: if ($fullwidth ne '' && $fullheight ne '') {
8375: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8376: my $thumbsize = $thumbwidth.'x'.$thumbheight;
8377: system("convert -sample $thumbsize $inputfile $outfile");
8378: chmod(0660, $filepath.'/tn-'.$file);
8379: if (-e $outfile) {
8380: my $copyfile=$targetdir.'/tn-'.$file;
8381: if (copy($outfile,$copyfile)) {
8382: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8383: my $thumb_metaoutput =
8384: &write_metadata($dom,$confname,$formname,
8385: $targetdir,'tn-'.$file,$logfile);
8386: push(@{$modified_urls},[$copyfile,$outfile]);
8387: unless ($registered_cleanup) {
8388: my $handlers = $r->get_handlers('PerlCleanupHandler');
8389: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8390: $registered_cleanup=1;
8391: }
1.267 raeburn 8392: $madethumb = 1;
1.16 raeburn 8393: } else {
8394: print $logfile "\nUnable to write ".$copyfile.
8395: ':'.$!."\n";
8396: }
8397: }
1.9 raeburn 8398: }
8399: }
8400: }
8401: } else {
8402: $output = $versionresult;
8403: }
8404: }
1.267 raeburn 8405: return ($output,$logourl,$madethumb);
1.9 raeburn 8406: }
8407:
8408: sub logo_versioning {
8409: my ($targetdir,$file,$logfile) = @_;
8410: my $target = $targetdir.'/'.$file;
8411: my ($maxversion,$fn,$extn,$output);
8412: $maxversion = 0;
8413: if ($file =~ /^(.+)\.(\w+)$/) {
8414: $fn=$1;
8415: $extn=$2;
8416: }
8417: opendir(DIR,$targetdir);
8418: while (my $filename=readdir(DIR)) {
8419: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8420: $maxversion=($1>$maxversion)?$1:$maxversion;
8421: }
8422: }
8423: $maxversion++;
8424: print $logfile "\nCreating old version ".$maxversion."\n";
8425: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8426: if (copy($target,$copyfile)) {
8427: print $logfile "Copied old target to ".$copyfile."\n";
8428: $copyfile=$copyfile.'.meta';
8429: if (copy($target.'.meta',$copyfile)) {
8430: print $logfile "Copied old target metadata to ".$copyfile."\n";
8431: $output = 'ok';
8432: } else {
8433: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8434: $output = &mt('Failed to copy old meta').", $!, ";
8435: }
8436: } else {
8437: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8438: $output = &mt('Failed to copy old target').", $!, ";
8439: }
8440: return $output;
8441: }
8442:
8443: sub write_metadata {
8444: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
8445: my (%metadatafields,%metadatakeys,$output);
8446: $metadatafields{'title'}=$formname;
8447: $metadatafields{'creationdate'}=time;
8448: $metadatafields{'lastrevisiondate'}=time;
8449: $metadatafields{'copyright'}='public';
8450: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
8451: $env{'user.domain'};
8452: $metadatafields{'authorspace'}=$confname.':'.$dom;
8453: $metadatafields{'domain'}=$dom;
8454: {
8455: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
8456: my $mfh;
1.155 raeburn 8457: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 8458: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 8459: unless ($_=~/\./) {
8460: my $unikey=$_;
8461: $unikey=~/^([A-Za-z]+)/;
8462: my $tag=$1;
8463: $tag=~tr/A-Z/a-z/;
8464: print $mfh "\n\<$tag";
8465: foreach (split(/\,/,$metadatakeys{$unikey})) {
8466: my $value=$metadatafields{$unikey.'.'.$_};
8467: $value=~s/\"/\'\'/g;
8468: print $mfh ' '.$_.'="'.$value.'"';
8469: }
8470: print $mfh '>'.
8471: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
8472: .'</'.$tag.'>';
8473: }
8474: }
8475: $output = 'ok';
8476: print $logfile "\nWrote metadata";
8477: close($mfh);
8478: } else {
8479: print $logfile "\nFailed to open metadata file";
1.9 raeburn 8480: $output = &mt('Could not write metadata');
8481: }
8482: }
1.155 raeburn 8483: return $output;
8484: }
8485:
8486: sub notifysubscribed {
8487: foreach my $targetsource (@{$modified_urls}){
8488: next unless (ref($targetsource) eq 'ARRAY');
8489: my ($target,$source)=@{$targetsource};
8490: if ($source ne '') {
8491: if (open(my $logfh,'>>'.$source.'.log')) {
8492: print $logfh "\nCleanup phase: Notifications\n";
8493: my @subscribed=&subscribed_hosts($target);
8494: foreach my $subhost (@subscribed) {
8495: print $logfh "\nNotifying host ".$subhost.':';
8496: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
8497: print $logfh $reply;
8498: }
8499: my @subscribedmeta=&subscribed_hosts("$target.meta");
8500: foreach my $subhost (@subscribedmeta) {
8501: print $logfh "\nNotifying host for metadata only ".$subhost.':';
8502: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
8503: $subhost);
8504: print $logfh $reply;
8505: }
8506: print $logfh "\n============ Done ============\n";
1.160 raeburn 8507: close($logfh);
1.155 raeburn 8508: }
8509: }
8510: }
8511: return OK;
8512: }
8513:
8514: sub subscribed_hosts {
8515: my ($target) = @_;
8516: my @subscribed;
8517: if (open(my $fh,"<$target.subscription")) {
8518: while (my $subline=<$fh>) {
8519: if ($subline =~ /^($match_lonid):/) {
8520: my $host = $1;
8521: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
8522: unless (grep(/^\Q$host\E$/,@subscribed)) {
8523: push(@subscribed,$host);
8524: }
8525: }
8526: }
8527: }
8528: }
8529: return @subscribed;
1.9 raeburn 8530: }
8531:
8532: sub check_switchserver {
8533: my ($dom,$confname) = @_;
8534: my ($allowed,$switchserver);
8535: my $home = &Apache::lonnet::homeserver($confname,$dom);
8536: if ($home eq 'no_host') {
8537: $home = &Apache::lonnet::domain($dom,'primary');
8538: }
8539: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 8540: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
8541: if (!$allowed) {
1.180 raeburn 8542: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 8543: }
8544: return $switchserver;
8545: }
8546:
1.1 raeburn 8547: sub modify_quotas {
1.216 raeburn 8548: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 8549: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 8550: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 8551: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8552: $validationfieldsref);
1.86 raeburn 8553: if ($action eq 'quotas') {
8554: $context = 'tools';
1.163 raeburn 8555: } else {
1.86 raeburn 8556: $context = $action;
8557: }
8558: if ($context eq 'requestcourses') {
1.271 raeburn 8559: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 8560: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 8561: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8562: %titles = &courserequest_titles();
8563: $toolregexp = join('|',@usertools);
8564: %conditions = &courserequest_conditions();
1.216 raeburn 8565: $confname = $dom.'-domainconfig';
8566: my $servadm = $r->dir_config('lonAdmEMail');
8567: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 8568: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8569: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 8570: } elsif ($context eq 'requestauthor') {
8571: @usertools = ('author');
8572: %titles = &authorrequest_titles();
1.86 raeburn 8573: } else {
1.162 raeburn 8574: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 8575: %titles = &tool_titles();
1.86 raeburn 8576: }
1.212 raeburn 8577: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 8578: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8579: foreach my $key (keys(%env)) {
1.101 raeburn 8580: if ($context eq 'requestcourses') {
8581: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8582: my $item = $1;
8583: my $type = $2;
8584: if ($type =~ /^limit_(.+)/) {
8585: $limithash{$item}{$1} = $env{$key};
8586: } else {
8587: $confhash{$item}{$type} = $env{$key};
8588: }
8589: }
1.163 raeburn 8590: } elsif ($context eq 'requestauthor') {
8591: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8592: $confhash{$1} = $env{$key};
8593: }
1.101 raeburn 8594: } else {
1.86 raeburn 8595: if ($key =~ /^form\.quota_(.+)$/) {
8596: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 8597: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8598: $confhash{'authorquota'}{$1} = $env{$key};
8599: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8600: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8601: }
1.72 raeburn 8602: }
8603: }
1.163 raeburn 8604: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 8605: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8606: @approvalnotify = sort(@approvalnotify);
8607: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 8608: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 8609: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8610: foreach my $type (@hasuniquecode) {
8611: if (grep(/^\Q$type\E$/,@crstypes)) {
8612: $confhash{'uniquecode'}{$type} = 1;
8613: }
1.216 raeburn 8614: }
1.242 raeburn 8615: my (%newbook,%allpos);
1.216 raeburn 8616: if ($context eq 'requestcourses') {
1.242 raeburn 8617: foreach my $type ('textbooks','templates') {
8618: @{$allpos{$type}} = ();
8619: my $invalid;
8620: if ($type eq 'textbooks') {
8621: $invalid = &mt('Invalid LON-CAPA course for textbook');
8622: } else {
8623: $invalid = &mt('Invalid LON-CAPA course for template');
8624: }
8625: if ($env{'form.'.$type.'_addbook'}) {
8626: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8627: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8628: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8629: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8630: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8631: } else {
8632: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8633: my $position = $env{'form.'.$type.'_addbook_pos'};
8634: $position =~ s/\D+//g;
8635: if ($position ne '') {
8636: $allpos{$type}[$position] = $newbook{$type};
8637: }
1.216 raeburn 8638: }
1.242 raeburn 8639: } else {
8640: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 8641: }
8642: }
1.242 raeburn 8643: }
1.216 raeburn 8644: }
1.102 raeburn 8645: if (ref($domconfig{$action}) eq 'HASH') {
8646: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8647: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8648: $changes{'notify'}{'approval'} = 1;
8649: }
8650: } else {
1.144 raeburn 8651: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8652: $changes{'notify'}{'approval'} = 1;
8653: }
8654: }
1.218 raeburn 8655: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8656: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8657: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8658: unless ($confhash{'uniquecode'}{$crstype}) {
8659: $changes{'uniquecode'} = 1;
8660: }
8661: }
8662: unless ($changes{'uniquecode'}) {
8663: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8664: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8665: $changes{'uniquecode'} = 1;
8666: }
8667: }
8668: }
8669: } else {
8670: $changes{'uniquecode'} = 1;
8671: }
8672: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8673: $changes{'uniquecode'} = 1;
1.216 raeburn 8674: }
8675: if ($context eq 'requestcourses') {
1.242 raeburn 8676: foreach my $type ('textbooks','templates') {
8677: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8678: my %deletions;
8679: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8680: if (@todelete) {
8681: map { $deletions{$_} = 1; } @todelete;
8682: }
8683: my %imgdeletions;
8684: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8685: if (@todeleteimages) {
8686: map { $imgdeletions{$_} = 1; } @todeleteimages;
8687: }
8688: my $maxnum = $env{'form.'.$type.'_maxnum'};
8689: for (my $i=0; $i<=$maxnum; $i++) {
8690: my $itemid = $env{'form.'.$type.'_id_'.$i};
8691: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8692: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8693: if ($deletions{$key}) {
8694: if ($domconfig{$action}{$type}{$key}{'image'}) {
8695: #FIXME need to obsolete item in RES space
8696: }
8697: next;
8698: } else {
8699: my $newpos = $env{'form.'.$itemid};
8700: $newpos =~ s/\D+//g;
1.243 raeburn 8701: foreach my $item ('subject','title','publisher','author') {
1.289 ! raeburn 8702: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 8703: ($type eq 'templates'));
1.242 raeburn 8704: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8705: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8706: $changes{$type}{$key} = 1;
8707: }
8708: }
8709: $allpos{$type}[$newpos] = $key;
8710: }
8711: if ($imgdeletions{$key}) {
8712: $changes{$type}{$key} = 1;
1.216 raeburn 8713: #FIXME need to obsolete item in RES space
1.242 raeburn 8714: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8715: my ($cdom,$cnum) = split(/_/,$key);
8716: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8717: $cdom,$cnum,$type,$configuserok,
8718: $switchserver,$author_ok);
8719: if ($imgurl) {
8720: $confhash{$type}{$key}{'image'} = $imgurl;
8721: $changes{$type}{$key} = 1;
1.216 raeburn 8722: }
1.242 raeburn 8723: if ($error) {
8724: &Apache::lonnet::logthis($error);
8725: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8726: }
8727: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8728: $confhash{$type}{$key}{'image'} =
8729: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 8730: }
8731: }
8732: }
8733: }
8734: }
8735: }
1.102 raeburn 8736: } else {
1.144 raeburn 8737: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8738: $changes{'notify'}{'approval'} = 1;
8739: }
1.218 raeburn 8740: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 8741: $changes{'uniquecode'} = 1;
8742: }
8743: }
8744: if ($context eq 'requestcourses') {
1.242 raeburn 8745: foreach my $type ('textbooks','templates') {
8746: if ($newbook{$type}) {
8747: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 8748: foreach my $item ('subject','title','publisher','author') {
8749: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8750: ($type eq 'template'));
1.242 raeburn 8751: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8752: if ($env{'form.'.$type.'_addbook_'.$item}) {
8753: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8754: }
8755: }
8756: if ($type eq 'textbooks') {
8757: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8758: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8759: my ($imageurl,$error) =
8760: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8761: $configuserok,$switchserver,$author_ok);
8762: if ($imageurl) {
8763: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8764: }
8765: if ($error) {
8766: &Apache::lonnet::logthis($error);
8767: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8768: }
8769: }
1.216 raeburn 8770: }
8771: }
1.242 raeburn 8772: if (@{$allpos{$type}} > 0) {
8773: my $idx = 0;
8774: foreach my $item (@{$allpos{$type}}) {
8775: if ($item ne '') {
8776: $confhash{$type}{$item}{'order'} = $idx;
8777: if (ref($domconfig{$action}) eq 'HASH') {
8778: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8779: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8780: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8781: $changes{$type}{$item} = 1;
8782: }
1.216 raeburn 8783: }
8784: }
8785: }
1.242 raeburn 8786: $idx ++;
1.216 raeburn 8787: }
8788: }
8789: }
8790: }
1.235 raeburn 8791: if (ref($validationitemsref) eq 'ARRAY') {
8792: foreach my $item (@{$validationitemsref}) {
8793: if ($item eq 'fields') {
8794: my @changed;
8795: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8796: if (@{$confhash{'validation'}{$item}} > 0) {
8797: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8798: }
1.266 raeburn 8799: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8800: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8801: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8802: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8803: $domconfig{'requestcourses'}{'validation'}{$item});
8804: } else {
8805: @changed = @{$confhash{'validation'}{$item}};
8806: }
1.235 raeburn 8807: } else {
8808: @changed = @{$confhash{'validation'}{$item}};
8809: }
8810: } else {
8811: @changed = @{$confhash{'validation'}{$item}};
8812: }
8813: if (@changed) {
8814: if ($confhash{'validation'}{$item}) {
8815: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8816: } else {
8817: $changes{'validation'}{$item} = &mt('None');
8818: }
8819: }
8820: } else {
8821: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8822: if ($item eq 'markup') {
8823: if ($env{'form.requestcourses_validation_'.$item}) {
8824: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8825: }
8826: }
1.266 raeburn 8827: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8828: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8829: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8830: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8831: }
8832: } else {
8833: if ($confhash{'validation'}{$item} ne '') {
8834: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8835: }
1.235 raeburn 8836: }
8837: } else {
8838: if ($confhash{'validation'}{$item} ne '') {
8839: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8840: }
8841: }
8842: }
8843: }
8844: }
8845: if ($env{'form.validationdc'}) {
8846: my $newval = $env{'form.validationdc'};
1.285 raeburn 8847: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 8848: if (exists($domcoords{$newval})) {
8849: $confhash{'validation'}{'dc'} = $newval;
8850: }
8851: }
8852: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 8853: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8854: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8855: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8856: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8857: if ($confhash{'validation'}{'dc'} eq '') {
8858: $changes{'validation'}{'dc'} = &mt('None');
8859: } else {
8860: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8861: }
1.235 raeburn 8862: }
1.266 raeburn 8863: } elsif ($confhash{'validation'}{'dc'} ne '') {
8864: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 8865: }
8866: } elsif ($confhash{'validation'}{'dc'} ne '') {
8867: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8868: }
8869: } elsif ($confhash{'validation'}{'dc'} ne '') {
8870: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 ! raeburn 8871: }
1.266 raeburn 8872: } else {
8873: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8874: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8875: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8876: $changes{'validation'}{'dc'} = &mt('None');
8877: }
8878: }
1.235 raeburn 8879: }
8880: }
1.102 raeburn 8881: }
8882: } else {
1.86 raeburn 8883: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 8884: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8885: }
1.72 raeburn 8886: foreach my $item (@usertools) {
8887: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8888: my $unset;
1.101 raeburn 8889: if ($context eq 'requestcourses') {
1.104 raeburn 8890: $unset = '0';
8891: if ($type eq '_LC_adv') {
8892: $unset = '';
8893: }
1.101 raeburn 8894: if ($confhash{$item}{$type} eq 'autolimit') {
8895: $confhash{$item}{$type} .= '=';
8896: unless ($limithash{$item}{$type} =~ /\D/) {
8897: $confhash{$item}{$type} .= $limithash{$item}{$type};
8898: }
8899: }
1.163 raeburn 8900: } elsif ($context eq 'requestauthor') {
8901: $unset = '0';
8902: if ($type eq '_LC_adv') {
8903: $unset = '';
8904: }
1.72 raeburn 8905: } else {
1.101 raeburn 8906: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8907: $confhash{$item}{$type} = 1;
8908: } else {
8909: $confhash{$item}{$type} = 0;
8910: }
1.72 raeburn 8911: }
1.86 raeburn 8912: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 8913: if ($action eq 'requestauthor') {
8914: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8915: $changes{$type} = 1;
8916: }
8917: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8918: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8919: $changes{$item}{$type} = 1;
8920: }
8921: } else {
8922: if ($context eq 'requestcourses') {
1.104 raeburn 8923: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8924: $changes{$item}{$type} = 1;
8925: }
8926: } else {
8927: if (!$confhash{$item}{$type}) {
8928: $changes{$item}{$type} = 1;
8929: }
8930: }
8931: }
8932: } else {
8933: if ($context eq 'requestcourses') {
1.104 raeburn 8934: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8935: $changes{$item}{$type} = 1;
8936: }
1.163 raeburn 8937: } elsif ($context eq 'requestauthor') {
8938: if ($confhash{$type} ne $unset) {
8939: $changes{$type} = 1;
8940: }
1.72 raeburn 8941: } else {
8942: if (!$confhash{$item}{$type}) {
8943: $changes{$item}{$type} = 1;
8944: }
8945: }
8946: }
1.1 raeburn 8947: }
8948: }
1.163 raeburn 8949: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8950: if (ref($domconfig{'quotas'}) eq 'HASH') {
8951: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8952: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8953: if (exists($confhash{'defaultquota'}{$key})) {
8954: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8955: $changes{'defaultquota'}{$key} = 1;
8956: }
8957: } else {
8958: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8959: }
8960: }
1.86 raeburn 8961: } else {
8962: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8963: if (exists($confhash{'defaultquota'}{$key})) {
8964: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8965: $changes{'defaultquota'}{$key} = 1;
8966: }
8967: } else {
8968: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8969: }
1.1 raeburn 8970: }
8971: }
1.197 raeburn 8972: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8973: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8974: if (exists($confhash{'authorquota'}{$key})) {
8975: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8976: $changes{'authorquota'}{$key} = 1;
8977: }
8978: } else {
8979: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8980: }
8981: }
8982: }
1.1 raeburn 8983: }
1.86 raeburn 8984: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8985: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8986: if (ref($domconfig{'quotas'}) eq 'HASH') {
8987: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8988: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8989: $changes{'defaultquota'}{$key} = 1;
8990: }
8991: } else {
8992: if (!exists($domconfig{'quotas'}{$key})) {
8993: $changes{'defaultquota'}{$key} = 1;
8994: }
1.72 raeburn 8995: }
8996: } else {
1.86 raeburn 8997: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8998: }
1.1 raeburn 8999: }
9000: }
1.197 raeburn 9001: if (ref($confhash{'authorquota'}) eq 'HASH') {
9002: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9003: if (ref($domconfig{'quotas'}) eq 'HASH') {
9004: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9005: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9006: $changes{'authorquota'}{$key} = 1;
9007: }
9008: } else {
9009: $changes{'authorquota'}{$key} = 1;
9010: }
9011: } else {
9012: $changes{'authorquota'}{$key} = 1;
9013: }
9014: }
9015: }
1.1 raeburn 9016: }
1.72 raeburn 9017:
1.163 raeburn 9018: if ($context eq 'requestauthor') {
9019: $domdefaults{'requestauthor'} = \%confhash;
9020: } else {
9021: foreach my $key (keys(%confhash)) {
1.242 raeburn 9022: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 9023: $domdefaults{$key} = $confhash{$key};
9024: }
1.163 raeburn 9025: }
1.72 raeburn 9026: }
1.163 raeburn 9027:
1.1 raeburn 9028: my %quotahash = (
1.86 raeburn 9029: $action => { %confhash }
1.1 raeburn 9030: );
9031: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9032: $dom);
9033: if ($putresult eq 'ok') {
9034: if (keys(%changes) > 0) {
1.72 raeburn 9035: my $cachetime = 24*60*60;
9036: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9037: if (ref($lastactref) eq 'HASH') {
9038: $lastactref->{'domdefaults'} = 1;
9039: }
1.1 raeburn 9040: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 9041: unless (($context eq 'requestcourses') ||
1.163 raeburn 9042: ($context eq 'requestauthor')) {
1.86 raeburn 9043: if (ref($changes{'defaultquota'}) eq 'HASH') {
9044: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9045: foreach my $type (@{$types},'default') {
9046: if (defined($changes{'defaultquota'}{$type})) {
9047: my $typetitle = $usertypes->{$type};
9048: if ($type eq 'default') {
9049: $typetitle = $othertitle;
9050: }
1.213 raeburn 9051: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9052: }
9053: }
1.86 raeburn 9054: $resulttext .= '</ul></li>';
1.72 raeburn 9055: }
1.197 raeburn 9056: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 9057: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 9058: foreach my $type (@{$types},'default') {
9059: if (defined($changes{'authorquota'}{$type})) {
9060: my $typetitle = $usertypes->{$type};
9061: if ($type eq 'default') {
9062: $typetitle = $othertitle;
9063: }
1.213 raeburn 9064: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 9065: }
9066: }
9067: $resulttext .= '</ul></li>';
9068: }
1.72 raeburn 9069: }
1.80 raeburn 9070: my %newenv;
1.72 raeburn 9071: foreach my $item (@usertools) {
1.163 raeburn 9072: my (%haschgs,%inconf);
9073: if ($context eq 'requestauthor') {
9074: %haschgs = %changes;
1.210 raeburn 9075: %inconf = %confhash;
1.163 raeburn 9076: } else {
9077: if (ref($changes{$item}) eq 'HASH') {
9078: %haschgs = %{$changes{$item}};
9079: }
9080: if (ref($confhash{$item}) eq 'HASH') {
9081: %inconf = %{$confhash{$item}};
9082: }
9083: }
9084: if (keys(%haschgs) > 0) {
1.80 raeburn 9085: my $newacc =
9086: &Apache::lonnet::usertools_access($env{'user.name'},
9087: $env{'user.domain'},
1.86 raeburn 9088: $item,'reload',$context);
1.210 raeburn 9089: if (($context eq 'requestcourses') ||
1.163 raeburn 9090: ($context eq 'requestauthor')) {
1.108 raeburn 9091: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9092: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9093: }
9094: } else {
9095: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9096: $newenv{'environment.availabletools.'.$item} = $newacc;
9097: }
1.80 raeburn 9098: }
1.163 raeburn 9099: unless ($context eq 'requestauthor') {
9100: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9101: }
1.72 raeburn 9102: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 9103: if ($haschgs{$type}) {
1.72 raeburn 9104: my $typetitle = $usertypes->{$type};
9105: if ($type eq 'default') {
9106: $typetitle = $othertitle;
9107: } elsif ($type eq '_LC_adv') {
9108: $typetitle = 'LON-CAPA Advanced Users';
9109: }
1.163 raeburn 9110: if ($inconf{$type}) {
1.101 raeburn 9111: if ($context eq 'requestcourses') {
9112: my $cond;
1.163 raeburn 9113: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9114: if ($1 eq '') {
9115: $cond = &mt('(Automatic processing of any request).');
9116: } else {
9117: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9118: }
9119: } else {
1.163 raeburn 9120: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9121: }
9122: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 9123: } elsif ($context eq 'requestauthor') {
9124: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9125: $titles{$inconf{$type}},$typetitle);
9126:
1.101 raeburn 9127: } else {
9128: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9129: }
1.72 raeburn 9130: } else {
1.104 raeburn 9131: if ($type eq '_LC_adv') {
1.163 raeburn 9132: if ($inconf{$type} eq '0') {
1.104 raeburn 9133: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9134: } else {
9135: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9136: }
9137: } else {
9138: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9139: }
1.72 raeburn 9140: }
9141: }
1.26 raeburn 9142: }
1.163 raeburn 9143: unless ($context eq 'requestauthor') {
9144: $resulttext .= '</ul></li>';
9145: }
1.26 raeburn 9146: }
1.1 raeburn 9147: }
1.163 raeburn 9148: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9149: if (ref($changes{'notify'}) eq 'HASH') {
9150: if ($changes{'notify'}{'approval'}) {
9151: if (ref($confhash{'notify'}) eq 'HASH') {
9152: if ($confhash{'notify'}{'approval'}) {
9153: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9154: } else {
1.163 raeburn 9155: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9156: }
9157: }
9158: }
9159: }
9160: }
1.216 raeburn 9161: if ($action eq 'requestcourses') {
9162: my @offon = ('off','on');
9163: if ($changes{'uniquecode'}) {
1.218 raeburn 9164: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9165: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9166: $resulttext .= '<li>'.
9167: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9168: '</li>';
9169: } else {
9170: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9171: '</li>';
9172: }
1.216 raeburn 9173: }
1.242 raeburn 9174: foreach my $type ('textbooks','templates') {
9175: if (ref($changes{$type}) eq 'HASH') {
9176: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9177: foreach my $key (sort(keys(%{$changes{$type}}))) {
9178: my %coursehash = &Apache::lonnet::coursedescription($key);
9179: my $coursetitle = $coursehash{'description'};
9180: my $position = $confhash{$type}{$key}{'order'} + 1;
9181: $resulttext .= '<li>';
1.243 raeburn 9182: foreach my $item ('subject','title','publisher','author') {
9183: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9184: ($type eq 'templates'));
1.242 raeburn 9185: my $name = $item.':';
9186: $name =~ s/^(\w)/\U$1/;
9187: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9188: }
9189: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9190: if ($type eq 'textbooks') {
9191: if ($confhash{$type}{$key}{'image'}) {
9192: $resulttext .= ' '.&mt('Image: [_1]',
9193: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9194: ' alt="Textbook cover" />').'<br />';
9195: }
9196: }
9197: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 9198: }
1.242 raeburn 9199: $resulttext .= '</ul></li>';
1.216 raeburn 9200: }
9201: }
1.235 raeburn 9202: if (ref($changes{'validation'}) eq 'HASH') {
9203: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9204: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9205: foreach my $item (@{$validationitemsref}) {
9206: if (exists($changes{'validation'}{$item})) {
9207: if ($item eq 'markup') {
9208: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9209: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9210: } else {
9211: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9212: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9213: }
9214: }
9215: }
9216: if (exists($changes{'validation'}{'dc'})) {
9217: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9218: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9219: }
9220: }
9221: }
1.216 raeburn 9222: }
1.1 raeburn 9223: $resulttext .= '</ul>';
1.80 raeburn 9224: if (keys(%newenv)) {
9225: &Apache::lonnet::appenv(\%newenv);
9226: }
1.1 raeburn 9227: } else {
1.86 raeburn 9228: if ($context eq 'requestcourses') {
9229: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 9230: } elsif ($context eq 'requestauthor') {
9231: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9232: } else {
1.90 weissno 9233: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9234: }
1.1 raeburn 9235: }
9236: } else {
1.11 albertel 9237: $resulttext = '<span class="LC_error">'.
9238: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9239: }
1.216 raeburn 9240: if ($errors) {
9241: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9242: '<ul>'.$errors.'</ul></p>';
9243: }
1.3 raeburn 9244: return $resulttext;
1.1 raeburn 9245: }
9246:
1.216 raeburn 9247: sub process_textbook_image {
1.242 raeburn 9248: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 9249: my $filename = $env{'form.'.$caller.'.filename'};
9250: my ($error,$url);
9251: my ($width,$height) = (50,50);
9252: if ($configuserok eq 'ok') {
9253: if ($switchserver) {
9254: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9255: $switchserver);
9256: } elsif ($author_ok eq 'ok') {
9257: my ($result,$imageurl) =
9258: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 9259: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 9260: if ($result eq 'ok') {
9261: $url = $imageurl;
9262: } else {
9263: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9264: }
9265: } else {
9266: $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);
9267: }
9268: } else {
9269: $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);
9270: }
9271: return ($url,$error);
9272: }
9273:
1.267 raeburn 9274: sub modify_ltitools {
9275: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
9276: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9277: my ($newid,@allpos,%changes,%confhash,$errors,$resulttext);
9278: my $confname = $dom.'-domainconfig';
9279: my $servadm = $r->dir_config('lonAdmEMail');
9280: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9281: my (%posslti,%possfield);
9282: my @courseroles = ('cc','in','ta','ep','st');
9283: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
9284: map { $posslti{$_} = 1; } @ltiroles;
9285: my @allfields = ('fullname','firstname','lastname','email','user','roles');
9286: map { $possfield{$_} = 1; } @allfields;
9287: my %lt = <itools_names();
9288: if ($env{'form.ltitools_add'}) {
9289: my $title = $env{'form.ltitools_add_title'};
9290: $title =~ s/(`)/'/g;
9291: ($newid,my $error) = &get_ltitools_id($dom,$title);
9292: if ($newid) {
9293: my $position = $env{'form.ltitools_add_pos'};
9294: $position =~ s/\D+//g;
9295: if ($position ne '') {
9296: $allpos[$position] = $newid;
9297: }
9298: $changes{$newid} = 1;
9299: foreach my $item ('title','url','key','secret') {
9300: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
9301: if ($env{'form.ltitools_add_'.$item}) {
9302: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9303: }
9304: }
9305: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
9306: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
9307: }
9308: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
9309: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
9310: }
9311: foreach my $item ('width','height') {
9312: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
9313: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
9314: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
9315: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9316: }
9317: }
9318: if ($env{'form.ltitools_add_target'} eq 'window') {
9319: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
9320: } else {
9321: $confhash{$newid}{'display'}{'target'} = 'iframe';
9322: }
9323: foreach my $item ('passback','roster') {
9324: if ($env{'form.ltitools_add_'.$item}) {
9325: $confhash{$newid}{$item} = 1;
9326: }
9327: }
9328: if ($env{'form.ltitools_add_image.filename'} ne '') {
9329: my ($imageurl,$error) =
9330: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
9331: $configuserok,$switchserver,$author_ok);
9332: if ($imageurl) {
9333: $confhash{$newid}{'image'} = $imageurl;
9334: }
9335: if ($error) {
9336: &Apache::lonnet::logthis($error);
9337: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9338: }
9339: }
9340: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
9341: foreach my $field (@fields) {
9342: if ($possfield{$field}) {
9343: if ($field eq 'roles') {
9344: foreach my $role (@courseroles) {
9345: my $choice = $env{'form.ltitools_add_roles_'.$role};
9346: if (($choice ne '') && ($posslti{$choice})) {
9347: $confhash{$newid}{'roles'}{$role} = $choice;
9348: if ($role eq 'cc') {
9349: $confhash{$newid}{'roles'}{'co'} = $choice;
9350: }
9351: }
9352: }
9353: } else {
9354: $confhash{$newid}{'fields'}{$field} = 1;
9355: }
9356: }
9357: }
1.273 raeburn 9358: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
9359: foreach my $item (@courseconfig) {
9360: $confhash{$newid}{'crsconf'}{$item} = 1;
9361: }
1.267 raeburn 9362: if ($env{'form.ltitools_add_custom'}) {
9363: my $name = $env{'form.ltitools_add_custom_name'};
9364: my $value = $env{'form.ltitools_add_custom_value'};
9365: $value =~ s/(`)/'/g;
9366: $name =~ s/(`)/'/g;
9367: $confhash{$newid}{'custom'}{$name} = $value;
9368: }
9369: } else {
9370: my $error = &mt('Failed to acquire unique ID for new external tool');
9371: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9372: }
9373: }
9374: if (ref($domconfig{$action}) eq 'HASH') {
9375: my %deletions;
9376: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
9377: if (@todelete) {
9378: map { $deletions{$_} = 1; } @todelete;
9379: }
9380: my %customadds;
9381: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
9382: if (@newcustom) {
9383: map { $customadds{$_} = 1; } @newcustom;
9384: }
9385: my %imgdeletions;
9386: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
9387: if (@todeleteimages) {
9388: map { $imgdeletions{$_} = 1; } @todeleteimages;
9389: }
9390: my $maxnum = $env{'form.ltitools_maxnum'};
9391: for (my $i=0; $i<=$maxnum; $i++) {
9392: my $itemid = $env{'form.ltitools_id_'.$i};
9393: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9394: if ($deletions{$itemid}) {
9395: if ($domconfig{$action}{$itemid}{'image'}) {
9396: #FIXME need to obsolete item in RES space
9397: }
9398: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
9399: next;
9400: } else {
9401: my $newpos = $env{'form.ltitools_'.$itemid};
9402: $newpos =~ s/\D+//g;
9403: foreach my $item ('title','url','key','secret') {
9404: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9405: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
9406: $changes{$itemid} = 1;
9407: }
9408: }
9409: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
9410: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
9411: }
9412: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
9413: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
9414: }
9415: foreach my $size ('width','height') {
9416: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
9417: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
9418: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
9419: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
9420: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9421: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
9422: $changes{$itemid} = 1;
9423: }
9424: } else {
9425: $changes{$itemid} = 1;
9426: }
9427: }
9428: }
9429: if ($env{'form.ltitools_target_'.$i} eq 'window') {
9430: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
9431: } else {
9432: $confhash{$itemid}{'display'}{'target'} = 'iframe';
9433: }
9434: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9435: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
9436: $changes{$itemid} = 1;
9437: }
9438: } else {
9439: $changes{$itemid} = 1;
9440: }
9441: foreach my $extra ('passback','roster') {
9442: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
9443: $confhash{$itemid}{$extra} = 1;
9444: }
9445: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
9446: $changes{$itemid} = 1;
9447: }
9448: }
1.273 raeburn 9449: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
9450: foreach my $item ('label','title','target') {
9451: if (grep(/^\Q$item\E$/,@courseconfig)) {
9452: $confhash{$itemid}{'crsconf'}{$item} = 1;
9453: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
9454: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
9455: $changes{$itemid} = 1;
9456: }
9457: } else {
9458: $changes{$itemid} = 1;
9459: }
9460: }
9461: }
1.267 raeburn 9462: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
9463: foreach my $field (@fields) {
9464: if ($possfield{$field}) {
9465: if ($field eq 'roles') {
9466: foreach my $role (@courseroles) {
9467: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
9468: if (($choice ne '') && ($posslti{$choice})) {
9469: $confhash{$itemid}{'roles'}{$role} = $choice;
9470: if ($role eq 'cc') {
9471: $confhash{$itemid}{'roles'}{'co'} = $choice;
9472: }
9473: }
9474: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
9475: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
9476: $changes{$itemid} = 1;
9477: }
9478: } elsif ($confhash{$itemid}{'roles'}{$role}) {
9479: $changes{$itemid} = 1;
9480: }
9481: }
9482: } else {
9483: $confhash{$itemid}{'fields'}{$field} = 1;
9484: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
9485: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
9486: $changes{$itemid} = 1;
9487: }
9488: } else {
9489: $changes{$itemid} = 1;
9490: }
9491: }
9492: }
9493: }
9494: $allpos[$newpos] = $itemid;
9495: }
9496: if ($imgdeletions{$itemid}) {
9497: $changes{$itemid} = 1;
9498: #FIXME need to obsolete item in RES space
9499: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
9500: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
9501: $itemid,$configuserok,$switchserver,
9502: $author_ok);
9503: if ($imgurl) {
9504: $confhash{$itemid}{'image'} = $imgurl;
9505: $changes{$itemid} = 1;
9506: }
9507: if ($error) {
9508: &Apache::lonnet::logthis($error);
9509: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9510: }
9511: } elsif ($domconfig{$action}{$itemid}{'image'}) {
9512: $confhash{$itemid}{'image'} =
9513: $domconfig{$action}{$itemid}{'image'};
9514: }
9515: if ($customadds{$i}) {
9516: my $name = $env{'form.ltitools_custom_name_'.$i};
9517: $name =~ s/(`)/'/g;
9518: $name =~ s/^\s+//;
9519: $name =~ s/\s+$//;
9520: my $value = $env{'form.ltitools_custom_value_'.$i};
9521: $value =~ s/(`)/'/g;
9522: $value =~ s/^\s+//;
9523: $value =~ s/\s+$//;
9524: if ($name ne '') {
9525: $confhash{$itemid}{'custom'}{$name} = $value;
9526: $changes{$itemid} = 1;
9527: }
9528: }
9529: my %customdels;
9530: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
9531: if (@customdeletions) {
9532: $changes{$itemid} = 1;
9533: }
9534: map { $customdels{$_} = 1; } @customdeletions;
9535: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
9536: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
9537: unless ($customdels{$key}) {
9538: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
9539: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
9540: }
9541: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
9542: $changes{$itemid} = 1;
9543: }
9544: }
9545: }
9546: }
9547: unless ($changes{$itemid}) {
9548: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
9549: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
9550: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
9551: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
9552: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
9553: $changes{$itemid} = 1;
9554: last;
9555: }
9556: }
9557: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
9558: $changes{$itemid} = 1;
9559: }
9560: }
9561: last if ($changes{$itemid});
9562: }
9563: }
9564: }
9565: }
9566: }
9567: if (@allpos > 0) {
9568: my $idx = 0;
9569: foreach my $itemid (@allpos) {
9570: if ($itemid ne '') {
9571: $confhash{$itemid}{'order'} = $idx;
9572: if (ref($domconfig{$action}) eq 'HASH') {
9573: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9574: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
9575: $changes{$itemid} = 1;
9576: }
9577: }
9578: }
9579: $idx ++;
9580: }
9581: }
9582: }
9583: my %ltitoolshash = (
9584: $action => { %confhash }
9585: );
9586: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
9587: $dom);
9588: if ($putresult eq 'ok') {
9589: if (keys(%changes) > 0) {
9590: my $cachetime = 24*60*60;
9591: &Apache::lonnet::do_cache_new('ltitools',$dom,\%confhash,$cachetime);
9592: if (ref($lastactref) eq 'HASH') {
9593: $lastactref->{'ltitools'} = 1;
9594: }
9595: $resulttext = &mt('Changes made:').'<ul>';
9596: my %bynum;
9597: foreach my $itemid (sort(keys(%changes))) {
9598: my $position = $confhash{$itemid}{'order'};
9599: $bynum{$position} = $itemid;
9600: }
9601: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9602: my $itemid = $bynum{$pos};
9603: if (ref($confhash{$itemid}) ne 'HASH') {
9604: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9605: } else {
9606: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
9607: if ($confhash{$itemid}{'image'}) {
9608: $resulttext .= ' '.
9609: '<img src="'.$confhash{$itemid}{'image'}.'"'.
9610: ' alt="'.&mt('Tool Provider icon').'" />';
9611: }
9612: $resulttext .= '</li><ul>';
9613: my $position = $pos + 1;
9614: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
9615: foreach my $item ('version','msgtype','url','key') {
9616: if ($confhash{$itemid}{$item} ne '') {
9617: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
9618: }
9619: }
9620: if ($confhash{$itemid}{'secret'} ne '') {
9621: $resulttext .= '<li>'.$lt{'secret'}.': ';
9622: my $num = length($confhash{$itemid}{'secret'});
9623: $resulttext .= ('*'x$num).'</li>';
9624: }
1.273 raeburn 9625: $resulttext .= '<li>'.&mt('Configurable in course:');
9626: my @possconfig = ('label','title','target');
9627: my $numconfig = 0;
9628: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
9629: foreach my $item (@possconfig) {
9630: if ($confhash{$itemid}{'crsconf'}{$item}) {
9631: $numconfig ++;
9632: $resulttext .= ' '.$lt{'crs'.$item};
9633: }
9634: }
9635: }
9636: if (!$numconfig) {
9637: $resulttext .= &mt('None');
9638: }
9639: $resulttext .= '</li>';
1.267 raeburn 9640: foreach my $item ('passback','roster') {
9641: $resulttext .= '<li>'.$lt{$item}.' ';
9642: if ($confhash{$itemid}{$item}) {
9643: $resulttext .= &mt('Yes');
9644: } else {
9645: $resulttext .= &mt('No');
9646: }
9647: $resulttext .= '</li>';
9648: }
9649: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
9650: my $displaylist;
9651: if ($confhash{$itemid}{'display'}{'target'}) {
9652: $displaylist = &mt('Display target').': '.
9653: $confhash{$itemid}{'display'}{'target'}.',';
9654: }
9655: foreach my $size ('width','height') {
9656: if ($confhash{$itemid}{'display'}{$size}) {
9657: $displaylist .= (' 'x2).$lt{$size}.': '.
9658: $confhash{$itemid}{'display'}{$size}.',';
9659: }
9660: }
9661: if ($displaylist) {
9662: $displaylist =~ s/,$//;
9663: $resulttext .= '<li>'.$displaylist.'</li>';
9664: }
9665: }
9666: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
9667: my $fieldlist;
9668: foreach my $field (@allfields) {
9669: if ($confhash{$itemid}{'fields'}{$field}) {
9670: $fieldlist .= (' 'x2).$lt{$field}.',';
9671: }
9672: }
9673: if ($fieldlist) {
9674: $fieldlist =~ s/,$//;
9675: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
9676: }
9677: }
9678: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
9679: my $rolemaps;
9680: foreach my $role (@courseroles) {
9681: if ($confhash{$itemid}{'roles'}{$role}) {
9682: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
9683: $confhash{$itemid}{'roles'}{$role}.',';
9684: }
9685: }
9686: if ($rolemaps) {
9687: $rolemaps =~ s/,$//;
9688: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
9689: }
9690: }
9691: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
9692: my $customlist;
9693: if (keys(%{$confhash{$itemid}{'custom'}})) {
9694: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
9695: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
9696: }
9697: }
9698: if ($customlist) {
9699: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
9700: }
9701: }
9702: $resulttext .= '</ul></li>';
9703: }
9704: }
9705: $resulttext .= '</ul>';
9706: } else {
9707: $resulttext = &mt('No changes made.');
9708: }
9709: } else {
9710: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9711: }
9712: if ($errors) {
9713: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9714: $errors.'</ul>';
9715: }
9716: return $resulttext;
9717: }
9718:
9719: sub process_ltitools_image {
9720: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
9721: my $filename = $env{'form.'.$caller.'.filename'};
9722: my ($error,$url);
9723: my ($width,$height) = (21,21);
9724: if ($configuserok eq 'ok') {
9725: if ($switchserver) {
9726: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
9727: $switchserver);
9728: } elsif ($author_ok eq 'ok') {
9729: my ($result,$imageurl,$madethumb) =
9730: &publishlogo($r,'upload',$caller,$dom,$confname,
9731: "ltitools/$itemid/icon",$width,$height);
9732: if ($result eq 'ok') {
9733: if ($madethumb) {
9734: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
9735: my $imagethumb = "$path/tn-".$imagefile;
9736: $url = $imagethumb;
9737: } else {
9738: $url = $imageurl;
9739: }
9740: } else {
9741: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9742: }
9743: } else {
9744: $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);
9745: }
9746: } else {
9747: $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);
9748: }
9749: return ($url,$error);
9750: }
9751:
9752: sub get_ltitools_id {
9753: my ($cdom,$title) = @_;
9754: # get lock on ltitools db
9755: my $lockhash = {
9756: lock => $env{'user.name'}.
9757: ':'.$env{'user.domain'},
9758: };
9759: my $tries = 0;
9760: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9761: my ($id,$error);
9762:
9763: while (($gotlock ne 'ok') && ($tries<10)) {
9764: $tries ++;
9765: sleep (0.1);
9766: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9767: }
9768: if ($gotlock eq 'ok') {
9769: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
9770: if ($currids{'lock'}) {
9771: delete($currids{'lock'});
9772: if (keys(%currids)) {
9773: my @curr = sort { $a <=> $b } keys(%currids);
9774: if ($curr[-1] =~ /^\d+$/) {
9775: $id = 1 + $curr[-1];
9776: }
9777: } else {
9778: $id = 1;
9779: }
9780: if ($id) {
9781: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
9782: $error = 'nostore';
9783: }
9784: } else {
9785: $error = 'nonumber';
9786: }
9787: }
9788: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
9789: } else {
9790: $error = 'nolock';
9791: }
9792: return ($id,$error);
9793: }
9794:
1.3 raeburn 9795: sub modify_autoenroll {
1.205 raeburn 9796: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 9797: my ($resulttext,%changes);
9798: my %currautoenroll;
9799: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9800: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9801: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9802: }
9803: }
9804: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9805: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 9806: sender => 'Sender for notification messages',
1.274 raeburn 9807: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9808: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 9809: my @offon = ('off','on');
1.17 raeburn 9810: my $sender_uname = $env{'form.sender_uname'};
9811: my $sender_domain = $env{'form.sender_domain'};
9812: if ($sender_domain eq '') {
9813: $sender_uname = '';
9814: } elsif ($sender_uname eq '') {
9815: $sender_domain = '';
9816: }
1.129 raeburn 9817: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 9818: my $failsafe = $env{'form.autoenroll_failsafe'};
9819: $failsafe =~ s{^\s+|\s+$}{}g;
9820: if ($failsafe =~ /\D/) {
9821: undef($failsafe);
9822: }
1.1 raeburn 9823: my %autoenrollhash = (
1.129 raeburn 9824: autoenroll => { 'run' => $env{'form.autoenroll_run'},
9825: 'sender_uname' => $sender_uname,
9826: 'sender_domain' => $sender_domain,
9827: 'co-owners' => $coowners,
1.274 raeburn 9828: 'autofailsafe' => $failsafe,
1.1 raeburn 9829: }
9830: );
1.4 raeburn 9831: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
9832: $dom);
1.1 raeburn 9833: if ($putresult eq 'ok') {
9834: if (exists($currautoenroll{'run'})) {
9835: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
9836: $changes{'run'} = 1;
9837: }
9838: } elsif ($autorun) {
9839: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 9840: $changes{'run'} = 1;
1.1 raeburn 9841: }
9842: }
1.17 raeburn 9843: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 9844: $changes{'sender'} = 1;
9845: }
1.17 raeburn 9846: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 9847: $changes{'sender'} = 1;
9848: }
1.129 raeburn 9849: if ($currautoenroll{'co-owners'} ne '') {
9850: if ($currautoenroll{'co-owners'} ne $coowners) {
9851: $changes{'coowners'} = 1;
9852: }
9853: } elsif ($coowners) {
9854: $changes{'coowners'} = 1;
1.274 raeburn 9855: }
9856: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
9857: $changes{'autofailsafe'} = 1;
9858: }
1.1 raeburn 9859: if (keys(%changes) > 0) {
9860: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 9861: if ($changes{'run'}) {
1.1 raeburn 9862: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
9863: }
9864: if ($changes{'sender'}) {
1.17 raeburn 9865: if ($sender_uname eq '' || $sender_domain eq '') {
9866: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
9867: } else {
9868: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
9869: }
1.1 raeburn 9870: }
1.129 raeburn 9871: if ($changes{'coowners'}) {
9872: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
9873: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9874: if (ref($lastactref) eq 'HASH') {
9875: $lastactref->{'domainconfig'} = 1;
9876: }
1.129 raeburn 9877: }
1.274 raeburn 9878: if ($changes{'autofailsafe'}) {
9879: if ($failsafe ne '') {
9880: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
9881: } else {
9882: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
9883: }
9884: &Apache::lonnet::get_domain_defaults($dom,1);
9885: if (ref($lastactref) eq 'HASH') {
9886: $lastactref->{'domdefaults'} = 1;
9887: }
9888: }
1.1 raeburn 9889: $resulttext .= '</ul>';
9890: } else {
9891: $resulttext = &mt('No changes made to auto-enrollment settings');
9892: }
9893: } else {
1.11 albertel 9894: $resulttext = '<span class="LC_error">'.
9895: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9896: }
1.3 raeburn 9897: return $resulttext;
1.1 raeburn 9898: }
9899:
9900: sub modify_autoupdate {
1.3 raeburn 9901: my ($dom,%domconfig) = @_;
1.1 raeburn 9902: my ($resulttext,%currautoupdate,%fields,%changes);
9903: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
9904: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
9905: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
9906: }
9907: }
9908: my @offon = ('off','on');
9909: my %title = &Apache::lonlocal::texthash (
9910: run => 'Auto-update:',
9911: classlists => 'Updates to user information in classlists?'
9912: );
1.44 raeburn 9913: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9914: my %fieldtitles = &Apache::lonlocal::texthash (
9915: id => 'Student/Employee ID',
1.20 raeburn 9916: permanentemail => 'E-mail address',
1.1 raeburn 9917: lastname => 'Last Name',
9918: firstname => 'First Name',
9919: middlename => 'Middle Name',
1.132 raeburn 9920: generation => 'Generation',
1.1 raeburn 9921: );
1.142 raeburn 9922: $othertitle = &mt('All users');
1.1 raeburn 9923: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 9924: $othertitle = &mt('Other users');
1.1 raeburn 9925: }
9926: foreach my $key (keys(%env)) {
9927: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 9928: my ($usertype,$item) = ($1,$2);
9929: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
9930: if ($usertype eq 'default') {
9931: push(@{$fields{$1}},$2);
9932: } elsif (ref($types) eq 'ARRAY') {
9933: if (grep(/^\Q$usertype\E$/,@{$types})) {
9934: push(@{$fields{$1}},$2);
9935: }
9936: }
9937: }
1.1 raeburn 9938: }
9939: }
1.131 raeburn 9940: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
9941: @lockablenames = sort(@lockablenames);
9942: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
9943: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9944: if (@changed) {
9945: $changes{'lockablenames'} = 1;
9946: }
9947: } else {
9948: if (@lockablenames) {
9949: $changes{'lockablenames'} = 1;
9950: }
9951: }
1.1 raeburn 9952: my %updatehash = (
9953: autoupdate => { run => $env{'form.autoupdate_run'},
9954: classlists => $env{'form.classlists'},
9955: fields => {%fields},
1.131 raeburn 9956: lockablenames => \@lockablenames,
1.1 raeburn 9957: }
9958: );
9959: foreach my $key (keys(%currautoupdate)) {
9960: if (($key eq 'run') || ($key eq 'classlists')) {
9961: if (exists($updatehash{autoupdate}{$key})) {
9962: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
9963: $changes{$key} = 1;
9964: }
9965: }
9966: } elsif ($key eq 'fields') {
9967: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 9968: foreach my $item (@{$types},'default') {
1.1 raeburn 9969: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
9970: my $change = 0;
9971: foreach my $type (@{$currautoupdate{$key}{$item}}) {
9972: if (!exists($fields{$item})) {
9973: $change = 1;
1.132 raeburn 9974: last;
1.1 raeburn 9975: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 9976: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 9977: $change = 1;
1.132 raeburn 9978: last;
1.1 raeburn 9979: }
9980: }
9981: }
9982: if ($change) {
9983: push(@{$changes{$key}},$item);
9984: }
1.26 raeburn 9985: }
1.1 raeburn 9986: }
9987: }
1.131 raeburn 9988: } elsif ($key eq 'lockablenames') {
9989: if (ref($currautoupdate{$key}) eq 'ARRAY') {
9990: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9991: if (@changed) {
9992: $changes{'lockablenames'} = 1;
9993: }
9994: } else {
9995: if (@lockablenames) {
9996: $changes{'lockablenames'} = 1;
9997: }
9998: }
9999: }
10000: }
10001: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10002: if (@lockablenames) {
10003: $changes{'lockablenames'} = 1;
1.1 raeburn 10004: }
10005: }
1.26 raeburn 10006: foreach my $item (@{$types},'default') {
10007: if (defined($fields{$item})) {
10008: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 10009: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10010: my $change = 0;
10011: if (ref($fields{$item}) eq 'ARRAY') {
10012: foreach my $type (@{$fields{$item}}) {
10013: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10014: $change = 1;
10015: last;
10016: }
10017: }
10018: }
10019: if ($change) {
10020: push(@{$changes{'fields'}},$item);
10021: }
10022: } else {
1.26 raeburn 10023: push(@{$changes{'fields'}},$item);
10024: }
10025: } else {
10026: push(@{$changes{'fields'}},$item);
1.1 raeburn 10027: }
10028: }
10029: }
10030: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10031: $dom);
10032: if ($putresult eq 'ok') {
10033: if (keys(%changes) > 0) {
10034: $resulttext = &mt('Changes made:').'<ul>';
10035: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 10036: if ($key eq 'lockablenames') {
10037: $resulttext .= '<li>';
10038: if (@lockablenames) {
10039: $usertypes->{'default'} = $othertitle;
10040: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10041: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10042: } else {
10043: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10044: }
10045: $resulttext .= '</li>';
10046: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 10047: foreach my $item (@{$changes{$key}}) {
10048: my @newvalues;
10049: foreach my $type (@{$fields{$item}}) {
10050: push(@newvalues,$fieldtitles{$type});
10051: }
1.3 raeburn 10052: my $newvaluestr;
10053: if (@newvalues > 0) {
10054: $newvaluestr = join(', ',@newvalues);
10055: } else {
10056: $newvaluestr = &mt('none');
1.6 raeburn 10057: }
1.1 raeburn 10058: if ($item eq 'default') {
1.26 raeburn 10059: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 10060: } else {
1.26 raeburn 10061: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 10062: }
10063: }
10064: } else {
10065: my $newvalue;
10066: if ($key eq 'run') {
10067: $newvalue = $offon[$env{'form.autoupdate_run'}];
10068: } else {
10069: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 10070: }
1.1 raeburn 10071: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
10072: }
10073: }
10074: $resulttext .= '</ul>';
10075: } else {
1.3 raeburn 10076: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 10077: }
10078: } else {
1.11 albertel 10079: $resulttext = '<span class="LC_error">'.
10080: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10081: }
1.3 raeburn 10082: return $resulttext;
1.1 raeburn 10083: }
10084:
1.125 raeburn 10085: sub modify_autocreate {
10086: my ($dom,%domconfig) = @_;
10087: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10088: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10089: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10090: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10091: }
10092: }
10093: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10094: req => 'Auto-creation of validated requests for official courses',
10095: xmldc => 'Identity of course creator of courses from XML files',
10096: );
10097: my @types = ('xml','req');
10098: foreach my $item (@types) {
10099: $newvals{$item} = $env{'form.autocreate_'.$item};
10100: $newvals{$item} =~ s/\D//g;
10101: $newvals{$item} = 0 if ($newvals{$item} eq '');
10102: }
10103: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 10104: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 10105: unless (exists($domcoords{$newvals{'xmldc'}})) {
10106: $newvals{'xmldc'} = '';
10107: }
10108: %autocreatehash = (
10109: autocreate => { xml => $newvals{'xml'},
10110: req => $newvals{'req'},
10111: }
10112: );
10113: if ($newvals{'xmldc'} ne '') {
10114: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10115: }
10116: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10117: $dom);
10118: if ($putresult eq 'ok') {
10119: my @items = @types;
10120: if ($newvals{'xml'}) {
10121: push(@items,'xmldc');
10122: }
10123: foreach my $item (@items) {
10124: if (exists($currautocreate{$item})) {
10125: if ($currautocreate{$item} ne $newvals{$item}) {
10126: $changes{$item} = 1;
10127: }
10128: } elsif ($newvals{$item}) {
10129: $changes{$item} = 1;
10130: }
10131: }
10132: if (keys(%changes) > 0) {
10133: my @offon = ('off','on');
10134: $resulttext = &mt('Changes made:').'<ul>';
10135: foreach my $item (@types) {
10136: if ($changes{$item}) {
10137: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 10138: $resulttext .= '<li>'.
10139: &mt("$title{$item} set to [_1]$newtxt [_2]",
10140: '<b>','</b>').
10141: '</li>';
1.125 raeburn 10142: }
10143: }
10144: if ($changes{'xmldc'}) {
10145: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10146: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 10147: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 10148: }
10149: $resulttext .= '</ul>';
10150: } else {
10151: $resulttext = &mt('No changes made to auto-creation settings');
10152: }
10153: } else {
10154: $resulttext = '<span class="LC_error">'.
10155: &mt('An error occurred: [_1]',$putresult).'</span>';
10156: }
10157: return $resulttext;
10158: }
10159:
1.23 raeburn 10160: sub modify_directorysrch {
10161: my ($dom,%domconfig) = @_;
10162: my ($resulttext,%changes);
10163: my %currdirsrch;
10164: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10165: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10166: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10167: }
10168: }
1.277 raeburn 10169: my %title = ( available => 'Institutional directory search available',
10170: localonly => 'Other domains can search institution',
10171: lcavailable => 'LON-CAPA directory search available',
1.289 ! raeburn 10172: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 10173: searchby => 'Search types',
10174: searchtypes => 'Search latitude');
10175: my @offon = ('off','on');
1.24 raeburn 10176: my @otherdoms = ('Yes','No');
1.23 raeburn 10177:
1.25 raeburn 10178: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 10179: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10180: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10181:
1.44 raeburn 10182: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 10183: if (keys(%{$usertypes}) == 0) {
10184: @cansearch = ('default');
10185: } else {
10186: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10187: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10188: if (!grep(/^\Q$type\E$/,@cansearch)) {
10189: push(@{$changes{'cansearch'}},$type);
10190: }
1.23 raeburn 10191: }
1.26 raeburn 10192: foreach my $type (@cansearch) {
10193: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10194: push(@{$changes{'cansearch'}},$type);
10195: }
1.23 raeburn 10196: }
1.26 raeburn 10197: } else {
10198: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 10199: }
10200: }
10201:
10202: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10203: foreach my $by (@{$currdirsrch{'searchby'}}) {
10204: if (!grep(/^\Q$by\E$/,@searchby)) {
10205: push(@{$changes{'searchby'}},$by);
10206: }
10207: }
10208: foreach my $by (@searchby) {
10209: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10210: push(@{$changes{'searchby'}},$by);
10211: }
10212: }
10213: } else {
10214: push(@{$changes{'searchby'}},@searchby);
10215: }
1.25 raeburn 10216:
10217: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10218: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10219: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10220: push(@{$changes{'searchtypes'}},$type);
10221: }
10222: }
10223: foreach my $type (@searchtypes) {
10224: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10225: push(@{$changes{'searchtypes'}},$type);
10226: }
10227: }
10228: } else {
10229: if (exists($currdirsrch{'searchtypes'})) {
10230: foreach my $type (@searchtypes) {
10231: if ($type ne $currdirsrch{'searchtypes'}) {
10232: push(@{$changes{'searchtypes'}},$type);
10233: }
10234: }
10235: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10236: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10237: }
10238: } else {
10239: push(@{$changes{'searchtypes'}},@searchtypes);
10240: }
10241: }
10242:
1.23 raeburn 10243: my %dirsrch_hash = (
10244: directorysrch => { available => $env{'form.dirsrch_available'},
10245: cansearch => \@cansearch,
1.277 raeburn 10246: localonly => $env{'form.dirsrch_instlocalonly'},
10247: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10248: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 10249: searchby => \@searchby,
1.25 raeburn 10250: searchtypes => \@searchtypes,
1.23 raeburn 10251: }
10252: );
10253: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10254: $dom);
10255: if ($putresult eq 'ok') {
10256: if (exists($currdirsrch{'available'})) {
10257: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10258: $changes{'available'} = 1;
10259: }
10260: } else {
10261: if ($env{'form.dirsrch_available'} eq '1') {
10262: $changes{'available'} = 1;
10263: }
10264: }
1.277 raeburn 10265: if (exists($currdirsrch{'lcavailable'})) {
1.289 ! raeburn 10266: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
! 10267: $changes{'lcavailable'} = 1;
! 10268: }
1.277 raeburn 10269: } else {
10270: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10271: $changes{'lcavailable'} = 1;
10272: }
10273: }
1.24 raeburn 10274: if (exists($currdirsrch{'localonly'})) {
1.289 ! raeburn 10275: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
! 10276: $changes{'localonly'} = 1;
! 10277: }
1.24 raeburn 10278: } else {
1.277 raeburn 10279: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 10280: $changes{'localonly'} = 1;
10281: }
10282: }
1.277 raeburn 10283: if (exists($currdirsrch{'lclocalonly'})) {
1.289 ! raeburn 10284: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
! 10285: $changes{'lclocalonly'} = 1;
! 10286: }
1.277 raeburn 10287: } else {
10288: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10289: $changes{'lclocalonly'} = 1;
10290: }
10291: }
1.23 raeburn 10292: if (keys(%changes) > 0) {
10293: $resulttext = &mt('Changes made:').'<ul>';
10294: if ($changes{'available'}) {
10295: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10296: }
1.277 raeburn 10297: if ($changes{'lcavailable'}) {
10298: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10299: }
1.24 raeburn 10300: if ($changes{'localonly'}) {
1.277 raeburn 10301: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 10302: }
1.277 raeburn 10303: if ($changes{'lclocalonly'}) {
10304: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 ! raeburn 10305: }
1.23 raeburn 10306: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10307: my $chgtext;
1.26 raeburn 10308: if (ref($usertypes) eq 'HASH') {
10309: if (keys(%{$usertypes}) > 0) {
10310: foreach my $type (@{$types}) {
10311: if (grep(/^\Q$type\E$/,@cansearch)) {
10312: $chgtext .= $usertypes->{$type}.'; ';
10313: }
10314: }
10315: if (grep(/^default$/,@cansearch)) {
10316: $chgtext .= $othertitle;
10317: } else {
10318: $chgtext =~ s/\; $//;
10319: }
1.210 raeburn 10320: $resulttext .=
1.178 raeburn 10321: '<li>'.
10322: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10323: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10324: '</li>';
1.23 raeburn 10325: }
10326: }
10327: }
10328: if (ref($changes{'searchby'}) eq 'ARRAY') {
10329: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10330: my $chgtext;
10331: foreach my $type (@{$titleorder}) {
10332: if (grep(/^\Q$type\E$/,@searchby)) {
10333: if (defined($searchtitles->{$type})) {
10334: $chgtext .= $searchtitles->{$type}.'; ';
10335: }
10336: }
10337: }
10338: $chgtext =~ s/\; $//;
10339: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10340: }
1.25 raeburn 10341: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10342: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10343: my $chgtext;
10344: foreach my $type (@{$srchtypeorder}) {
10345: if (grep(/^\Q$type\E$/,@searchtypes)) {
10346: if (defined($srchtypes_desc->{$type})) {
10347: $chgtext .= $srchtypes_desc->{$type}.'; ';
10348: }
10349: }
10350: }
10351: $chgtext =~ s/\; $//;
1.178 raeburn 10352: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 10353: }
10354: $resulttext .= '</ul>';
10355: } else {
1.277 raeburn 10356: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 10357: }
10358: } else {
10359: $resulttext = '<span class="LC_error">'.
1.27 raeburn 10360: &mt('An error occurred: [_1]',$putresult).'</span>';
10361: }
10362: return $resulttext;
10363: }
10364:
1.28 raeburn 10365: sub modify_contacts {
1.205 raeburn 10366: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 10367: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10368: if (ref($domconfig{'contacts'}) eq 'HASH') {
10369: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10370: $currsetting{$key} = $domconfig{'contacts'}{$key};
10371: }
10372: }
1.286 raeburn 10373: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 10374: my @contacts = ('supportemail','adminemail');
1.286 raeburn 10375: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
10376: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 10377: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 10378: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 10379: foreach my $type (@mailings) {
10380: @{$newsetting{$type}} =
10381: &Apache::loncommon::get_env_multiple('form.'.$type);
10382: foreach my $item (@contacts) {
10383: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
10384: $contacts_hash{contacts}{$type}{$item} = 1;
10385: } else {
10386: $contacts_hash{contacts}{$type}{$item} = 0;
10387: }
1.289 ! raeburn 10388: }
1.28 raeburn 10389: $others{$type} = $env{'form.'.$type.'_others'};
10390: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 10391: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10392: $bcc{$type} = $env{'form.'.$type.'_bcc'};
10393: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 10394: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
10395: $includestr{$type} = $env{'form.'.$type.'_includestr'};
10396: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
10397: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10398: }
1.134 raeburn 10399: }
1.28 raeburn 10400: }
10401: foreach my $item (@contacts) {
10402: $to{$item} = $env{'form.'.$item};
10403: $contacts_hash{'contacts'}{$item} = $to{$item};
10404: }
1.203 raeburn 10405: foreach my $item (@toggles) {
10406: if ($env{'form.'.$item} =~ /^(0|1)$/) {
10407: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
10408: }
10409: }
1.286 raeburn 10410: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
10411: foreach my $field (@{$fields}) {
10412: if (ref($possoptions->{$field}) eq 'ARRAY') {
10413: my $value = $env{'form.helpform_'.$field};
10414: $value =~ s/^\s+|\s+$//g;
10415: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
10416: $contacts_hash{contacts}{'helpform'}{$field} = $value;
10417: if ($field eq 'screenshot') {
10418: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
10419: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
10420: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
10421: }
10422: }
10423: }
10424: }
10425: }
10426: }
1.28 raeburn 10427: if (keys(%currsetting) > 0) {
10428: foreach my $item (@contacts) {
10429: if ($to{$item} ne $currsetting{$item}) {
10430: $changes{$item} = 1;
10431: }
10432: }
10433: foreach my $type (@mailings) {
10434: foreach my $item (@contacts) {
10435: if (ref($currsetting{$type}) eq 'HASH') {
10436: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
10437: push(@{$changes{$type}},$item);
10438: }
10439: } else {
10440: push(@{$changes{$type}},@{$newsetting{$type}});
10441: }
10442: }
10443: if ($others{$type} ne $currsetting{$type}{'others'}) {
10444: push(@{$changes{$type}},'others');
10445: }
1.289 ! raeburn 10446: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10447: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
10448: push(@{$changes{$type}},'bcc');
10449: }
1.286 raeburn 10450: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
10451: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
10452: push(@{$changes{$type}},'include');
10453: }
10454: }
10455: }
10456: if (ref($fields) eq 'ARRAY') {
10457: if (ref($currsetting{'helpform'}) eq 'HASH') {
10458: foreach my $field (@{$fields}) {
10459: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
10460: push(@{$changes{'helpform'}},$field);
10461: }
10462: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10463: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
10464: push(@{$changes{'helpform'}},'maxsize');
10465: }
10466: }
10467: }
10468: } else {
10469: foreach my $field (@{$fields}) {
10470: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10471: push(@{$changes{'helpform'}},$field);
10472: }
10473: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10474: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10475: push(@{$changes{'helpform'}},'maxsize');
10476: }
10477: }
10478: }
1.134 raeburn 10479: }
1.28 raeburn 10480: }
10481: } else {
10482: my %default;
10483: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
10484: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
10485: $default{'errormail'} = 'adminemail';
10486: $default{'packagesmail'} = 'adminemail';
10487: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 10488: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 10489: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 10490: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 10491: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 10492: foreach my $item (@contacts) {
10493: if ($to{$item} ne $default{$item}) {
1.286 raeburn 10494: $changes{$item} = 1;
1.203 raeburn 10495: }
1.28 raeburn 10496: }
10497: foreach my $type (@mailings) {
10498: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
10499: push(@{$changes{$type}},@{$newsetting{$type}});
10500: }
10501: if ($others{$type} ne '') {
10502: push(@{$changes{$type}},'others');
1.134 raeburn 10503: }
1.286 raeburn 10504: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10505: if ($bcc{$type} ne '') {
10506: push(@{$changes{$type}},'bcc');
10507: }
1.286 raeburn 10508: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
10509: push(@{$changes{$type}},'include');
10510: }
1.134 raeburn 10511: }
1.28 raeburn 10512: }
1.286 raeburn 10513: if (ref($fields) eq 'ARRAY') {
10514: foreach my $field (@{$fields}) {
10515: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10516: push(@{$changes{'helpform'}},$field);
10517: }
10518: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10519: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10520: push(@{$changes{'helpform'}},'maxsize');
10521: }
10522: }
10523: }
1.289 ! raeburn 10524: }
1.28 raeburn 10525: }
1.203 raeburn 10526: foreach my $item (@toggles) {
10527: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
10528: $changes{$item} = 1;
10529: } elsif ((!$env{'form.'.$item}) &&
10530: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
10531: $changes{$item} = 1;
10532: }
10533: }
1.28 raeburn 10534: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
10535: $dom);
10536: if ($putresult eq 'ok') {
10537: if (keys(%changes) > 0) {
1.205 raeburn 10538: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10539: if (ref($lastactref) eq 'HASH') {
10540: $lastactref->{'domainconfig'} = 1;
10541: }
1.28 raeburn 10542: my ($titles,$short_titles) = &contact_titles();
10543: $resulttext = &mt('Changes made:').'<ul>';
10544: foreach my $item (@contacts) {
10545: if ($changes{$item}) {
10546: $resulttext .= '<li>'.$titles->{$item}.
10547: &mt(' set to: ').
10548: '<span class="LC_cusr_emph">'.
10549: $to{$item}.'</span></li>';
10550: }
10551: }
10552: foreach my $type (@mailings) {
10553: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 10554: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 ! raeburn 10555: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 10556: } else {
10557: $resulttext .= '<li>'.$titles->{$type}.': ';
10558: }
1.28 raeburn 10559: my @text;
10560: foreach my $item (@{$newsetting{$type}}) {
10561: push(@text,$short_titles->{$item});
10562: }
10563: if ($others{$type} ne '') {
10564: push(@text,$others{$type});
10565: }
1.286 raeburn 10566: if (@text) {
10567: $resulttext .= '<span class="LC_cusr_emph">'.
10568: join(', ',@text).'</span>';
10569: }
10570: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10571: if ($bcc{$type} ne '') {
1.286 raeburn 10572: my $bcctext;
10573: if (@text) {
1.289 ! raeburn 10574: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 10575: } else {
10576: $bcctext = '(Bcc)';
10577: }
10578: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10579: } elsif (!@text) {
10580: $resulttext .= &mt('No one');
10581: }
1.289 ! raeburn 10582: if ($includestr{$type} ne '') {
1.286 raeburn 10583: if ($includeloc{$type} eq 'b') {
10584: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
10585: } elsif ($includeloc{$type} eq 's') {
10586: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
10587: }
1.134 raeburn 10588: }
1.286 raeburn 10589: } elsif (!@text) {
10590: $resulttext .= &mt('No recipients');
1.134 raeburn 10591: }
10592: $resulttext .= '</li>';
1.28 raeburn 10593: }
10594: }
1.203 raeburn 10595: my @offon = ('off','on');
10596: if ($changes{'reporterrors'}) {
10597: $resulttext .= '<li>'.
10598: &mt('E-mail error reports to [_1] set to "'.
10599: $offon[$env{'form.reporterrors'}].'".',
10600: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10601: &mt('LON-CAPA core group - MSU'),600,500)).
10602: '</li>';
10603: }
10604: if ($changes{'reportupdates'}) {
10605: $resulttext .= '<li>'.
10606: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
10607: $offon[$env{'form.reportupdates'}].'".',
10608: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10609: &mt('LON-CAPA core group - MSU'),600,500)).
10610: '</li>';
10611: }
1.286 raeburn 10612: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
10613: my (@optional,@required,@unused,$maxsizechg);
10614: foreach my $field (@{$changes{'helpform'}}) {
10615: if ($field eq 'maxsize') {
10616: $maxsizechg = 1;
10617: next;
10618: }
10619: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 ! raeburn 10620: push(@optional,$field);
1.286 raeburn 10621: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
10622: push(@unused,$field);
10623: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 ! raeburn 10624: push(@required,$field);
1.286 raeburn 10625: }
10626: }
10627: if (@optional) {
10628: $resulttext .= '<li>'.
10629: &mt('Help form fields changed to "Optional": [_1].',
10630: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
10631: '</li>';
10632: }
10633: if (@required) {
10634: $resulttext .= '<li>'.
10635: &mt('Help form fields changed to "Required": [_1].',
10636: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
10637: '</li>';
10638: }
10639: if (@unused) {
10640: $resulttext .= '<li>'.
10641: &mt('Help form fields changed to "Not shown": [_1].',
10642: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
10643: '</li>';
10644: }
10645: if ($maxsizechg) {
10646: $resulttext .= '<li>'.
10647: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
10648: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
10649: '</li>';
10650:
10651: }
10652: }
1.28 raeburn 10653: $resulttext .= '</ul>';
10654: } else {
1.288 raeburn 10655: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 10656: }
10657: } else {
10658: $resulttext = '<span class="LC_error">'.
10659: &mt('An error occurred: [_1].',$putresult).'</span>';
10660: }
10661: return $resulttext;
10662: }
10663:
10664: sub modify_usercreation {
1.27 raeburn 10665: my ($dom,%domconfig) = @_;
1.224 raeburn 10666: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 10667: my $warningmsg;
1.27 raeburn 10668: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10669: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 10670: if ($key eq 'cancreate') {
10671: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10672: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10673: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269 raeburn 10674: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
10675: ($item eq 'recaptchaversion')) {
1.224 raeburn 10676: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10677: } else {
10678: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10679: }
10680: }
10681: }
10682: } elsif ($key eq 'email_rule') {
10683: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10684: } else {
10685: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10686: }
1.27 raeburn 10687: }
10688: }
10689: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 10690: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 10691: my @contexts = ('author','course','requestcrs');
1.34 raeburn 10692: foreach my $item(@contexts) {
1.224 raeburn 10693: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 10694: }
1.34 raeburn 10695: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10696: foreach my $item (@contexts) {
1.224 raeburn 10697: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
10698: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 10699: }
1.27 raeburn 10700: }
1.34 raeburn 10701: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
10702: foreach my $item (@contexts) {
1.43 raeburn 10703: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 10704: if ($cancreate{$item} ne 'any') {
10705: push(@{$changes{'cancreate'}},$item);
10706: }
10707: } else {
10708: if ($cancreate{$item} ne 'none') {
10709: push(@{$changes{'cancreate'}},$item);
10710: }
1.27 raeburn 10711: }
10712: }
10713: } else {
1.43 raeburn 10714: foreach my $item (@contexts) {
1.34 raeburn 10715: push(@{$changes{'cancreate'}},$item);
10716: }
1.27 raeburn 10717: }
1.34 raeburn 10718:
1.27 raeburn 10719: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
10720: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
10721: if (!grep(/^\Q$type\E$/,@username_rule)) {
10722: push(@{$changes{'username_rule'}},$type);
10723: }
10724: }
10725: foreach my $type (@username_rule) {
10726: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
10727: push(@{$changes{'username_rule'}},$type);
10728: }
10729: }
10730: } else {
10731: push(@{$changes{'username_rule'}},@username_rule);
10732: }
10733:
1.32 raeburn 10734: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
10735: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
10736: if (!grep(/^\Q$type\E$/,@id_rule)) {
10737: push(@{$changes{'id_rule'}},$type);
10738: }
10739: }
10740: foreach my $type (@id_rule) {
10741: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
10742: push(@{$changes{'id_rule'}},$type);
10743: }
10744: }
10745: } else {
10746: push(@{$changes{'id_rule'}},@id_rule);
10747: }
10748:
1.43 raeburn 10749: my @authen_contexts = ('author','course','domain');
1.28 raeburn 10750: my @authtypes = ('int','krb4','krb5','loc');
10751: my %authhash;
1.43 raeburn 10752: foreach my $item (@authen_contexts) {
1.28 raeburn 10753: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
10754: foreach my $auth (@authtypes) {
10755: if (grep(/^\Q$auth\E$/,@authallowed)) {
10756: $authhash{$item}{$auth} = 1;
10757: } else {
10758: $authhash{$item}{$auth} = 0;
10759: }
10760: }
10761: }
10762: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 10763: foreach my $item (@authen_contexts) {
1.28 raeburn 10764: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
10765: foreach my $auth (@authtypes) {
10766: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
10767: push(@{$changes{'authtypes'}},$item);
10768: last;
10769: }
10770: }
10771: }
10772: }
10773: } else {
1.43 raeburn 10774: foreach my $item (@authen_contexts) {
1.28 raeburn 10775: push(@{$changes{'authtypes'}},$item);
10776: }
10777: }
10778:
1.224 raeburn 10779: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
10780: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
10781: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
10782: $save_usercreate{'id_rule'} = \@id_rule;
10783: $save_usercreate{'username_rule'} = \@username_rule,
10784: $save_usercreate{'authtypes'} = \%authhash;
10785:
1.27 raeburn 10786: my %usercreation_hash = (
1.224 raeburn 10787: usercreation => \%save_usercreate,
10788: );
1.27 raeburn 10789:
10790: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
10791: $dom);
1.50 raeburn 10792:
1.224 raeburn 10793: if ($putresult eq 'ok') {
10794: if (keys(%changes) > 0) {
10795: $resulttext = &mt('Changes made:').'<ul>';
10796: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10797: my %lt = &usercreation_types();
10798: foreach my $type (@{$changes{'cancreate'}}) {
10799: my $chgtext = $lt{$type}.', ';
10800: if ($cancreate{$type} eq 'none') {
10801: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
10802: } elsif ($cancreate{$type} eq 'any') {
10803: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
10804: } elsif ($cancreate{$type} eq 'official') {
10805: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
10806: } elsif ($cancreate{$type} eq 'unofficial') {
10807: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
10808: }
10809: $resulttext .= '<li>'.$chgtext.'</li>';
10810: }
10811: }
10812: if (ref($changes{'username_rule'}) eq 'ARRAY') {
10813: my ($rules,$ruleorder) =
10814: &Apache::lonnet::inst_userrules($dom,'username');
10815: my $chgtext = '<ul>';
10816: foreach my $type (@username_rule) {
10817: if (ref($rules->{$type}) eq 'HASH') {
10818: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
10819: }
10820: }
10821: $chgtext .= '</ul>';
10822: if (@username_rule > 0) {
10823: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10824: } else {
10825: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
10826: }
10827: }
10828: if (ref($changes{'id_rule'}) eq 'ARRAY') {
10829: my ($idrules,$idruleorder) =
10830: &Apache::lonnet::inst_userrules($dom,'id');
10831: my $chgtext = '<ul>';
10832: foreach my $type (@id_rule) {
10833: if (ref($idrules->{$type}) eq 'HASH') {
10834: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
10835: }
10836: }
10837: $chgtext .= '</ul>';
10838: if (@id_rule > 0) {
10839: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10840: } else {
10841: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
10842: }
10843: }
10844: my %authname = &authtype_names();
10845: my %context_title = &context_names();
10846: if (ref($changes{'authtypes'}) eq 'ARRAY') {
10847: my $chgtext = '<ul>';
10848: foreach my $type (@{$changes{'authtypes'}}) {
10849: my @allowed;
10850: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
10851: foreach my $auth (@authtypes) {
10852: if ($authhash{$type}{$auth}) {
10853: push(@allowed,$authname{$auth});
10854: }
10855: }
10856: if (@allowed > 0) {
10857: $chgtext .= join(', ',@allowed).'</li>';
10858: } else {
10859: $chgtext .= &mt('none').'</li>';
10860: }
10861: }
10862: $chgtext .= '</ul>';
10863: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
10864: $resulttext .= '</li>';
10865: }
10866: $resulttext .= '</ul>';
10867: } else {
10868: $resulttext = &mt('No changes made to user creation settings');
10869: }
10870: } else {
10871: $resulttext = '<span class="LC_error">'.
10872: &mt('An error occurred: [_1]',$putresult).'</span>';
10873: }
10874: if ($warningmsg ne '') {
10875: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10876: }
10877: return $resulttext;
10878: }
10879:
10880: sub modify_selfcreation {
10881: my ($dom,%domconfig) = @_;
10882: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
10883: my (%save_usercreate,%save_usermodify);
1.228 raeburn 10884: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10885: if (ref($types) eq 'ARRAY') {
10886: $usertypes->{'default'} = $othertitle;
10887: push(@{$types},'default');
10888: }
1.224 raeburn 10889: #
10890: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
10891: #
10892: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10893: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
10894: if ($key eq 'cancreate') {
10895: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10896: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10897: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
10898: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.269 raeburn 10899: ($item eq 'recaptchaversion') ||
1.236 raeburn 10900: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 10901: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 10902: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10903: } else {
10904: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10905: }
10906: }
10907: }
10908: } elsif ($key eq 'email_rule') {
10909: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10910: } else {
10911: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10912: }
10913: }
10914: }
10915: #
10916: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
10917: #
10918: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10919: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
10920: if ($key eq 'selfcreate') {
10921: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
10922: } else {
10923: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
10924: }
10925: }
10926: }
10927:
10928: my @contexts = ('selfcreate');
10929: @{$cancreate{'selfcreate'}} = ();
10930: %{$cancreate{'emailusername'}} = ();
10931: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 10932: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 10933: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 10934: my %selfcreatetypes = (
10935: sso => 'users authenticated by institutional single sign on',
10936: login => 'users authenticated by institutional log-in',
1.236 raeburn 10937: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 10938: );
1.224 raeburn 10939: #
10940: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
10941: # is permitted.
10942: #
1.236 raeburn 10943:
10944: my @statuses;
10945: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10946: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
10947: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
10948: }
10949: }
10950: push(@statuses,'default');
10951:
1.228 raeburn 10952: foreach my $item ('login','sso','email') {
1.224 raeburn 10953: if ($item eq 'email') {
1.236 raeburn 10954: if ($env{'form.cancreate_email'}) {
1.224 raeburn 10955: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 10956: push(@contexts,'selfcreateprocessing');
10957: foreach my $type (@statuses) {
10958: if ($type eq 'default') {
10959: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
10960: } else {
10961: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
10962: }
10963: }
1.224 raeburn 10964: }
10965: } else {
10966: if ($env{'form.cancreate_'.$item}) {
10967: push(@{$cancreate{'selfcreate'}},$item);
10968: }
10969: }
10970: }
10971: my (@email_rule,%userinfo,%savecaptcha);
10972: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
10973: #
1.228 raeburn 10974: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
10975: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 10976: #
1.236 raeburn 10977:
1.244 raeburn 10978: if ($env{'form.cancreate_email'}) {
1.228 raeburn 10979: push(@contexts,'emailusername');
10980: if (ref($types) eq 'ARRAY') {
10981: foreach my $type (@{$types}) {
10982: if (ref($infofields) eq 'ARRAY') {
10983: foreach my $field (@{$infofields}) {
10984: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
10985: $cancreate{'emailusername'}{$type}{$field} = $1;
10986: }
10987: }
1.224 raeburn 10988: }
10989: }
10990: }
10991: #
10992: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
10993: # queued requests for self-creation of account using e-mail address as username
10994: #
10995:
10996: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
10997: @approvalnotify = sort(@approvalnotify);
10998: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
10999: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11000: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11001: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11002: push(@{$changes{'cancreate'}},'notify');
11003: }
11004: } else {
11005: if ($cancreate{'notify'}{'approval'}) {
11006: push(@{$changes{'cancreate'}},'notify');
11007: }
11008: }
11009: } elsif ($cancreate{'notify'}{'approval'}) {
11010: push(@{$changes{'cancreate'}},'notify');
11011: }
11012:
11013: #
11014: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
11015: #
11016: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
11017: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11018: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11019: if (@{$curr_usercreation{'email_rule'}} > 0) {
11020: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
11021: if (!grep(/^\Q$type\E$/,@email_rule)) {
11022: push(@{$changes{'email_rule'}},$type);
11023: }
11024: }
11025: }
11026: if (@email_rule > 0) {
11027: foreach my $type (@email_rule) {
11028: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
11029: push(@{$changes{'email_rule'}},$type);
11030: }
11031: }
11032: }
11033: } elsif (@email_rule > 0) {
11034: push(@{$changes{'email_rule'}},@email_rule);
11035: }
11036: }
11037: #
1.236 raeburn 11038: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 11039: # institutional log-in.
11040: #
11041: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11042: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11043: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11044: ($domdefaults{'auth_def'} eq 'localauth'))) {
11045: $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.').' '.
11046: &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.');
11047: }
11048: }
11049: my @fields = ('lastname','firstname','middlename','generation',
11050: 'permanentemail','id');
1.240 raeburn 11051: my @shibfields = (@fields,'inststatus');
1.224 raeburn 11052: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11053: #
11054: # Where usernames may created for institutional log-in and/or institutional single sign on:
11055: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11056: # may self-create accounts
11057: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11058: # which the user may supply, if institutional data is unavailable.
11059: #
11060: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
11061: if (ref($types) eq 'ARRAY') {
1.228 raeburn 11062: if (@{$types} > 1) {
1.224 raeburn 11063: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11064: push(@contexts,'statustocreate');
11065: } else {
11066: undef($cancreate{'statustocreate'});
11067: }
11068: foreach my $type (@{$types}) {
11069: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11070: foreach my $field (@fields) {
11071: if (grep(/^\Q$field\E$/,@modifiable)) {
11072: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11073: } else {
11074: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11075: }
11076: }
11077: }
11078: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
11079: foreach my $type (@{$types}) {
11080: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11081: foreach my $field (@fields) {
11082: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11083: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11084: push(@{$changes{'selfcreate'}},$type);
11085: last;
11086: }
11087: }
11088: }
11089: }
11090: } else {
11091: foreach my $type (@{$types}) {
11092: push(@{$changes{'selfcreate'}},$type);
11093: }
11094: }
11095: }
1.240 raeburn 11096: foreach my $field (@shibfields) {
11097: if ($env{'form.shibenv_'.$field} ne '') {
11098: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11099: }
11100: }
11101: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11102: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11103: foreach my $field (@shibfields) {
11104: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11105: push(@{$changes{'cancreate'}},'shibenv');
11106: }
11107: }
11108: } else {
11109: foreach my $field (@shibfields) {
11110: if ($env{'form.shibenv_'.$field}) {
11111: push(@{$changes{'cancreate'}},'shibenv');
11112: last;
11113: }
11114: }
11115: }
11116: }
1.224 raeburn 11117: }
11118: foreach my $item (@contexts) {
11119: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11120: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11121: if (ref($cancreate{$item}) eq 'ARRAY') {
11122: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11123: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11124: push(@{$changes{'cancreate'}},$item);
11125: }
11126: }
11127: }
11128: }
11129: if (ref($cancreate{$item}) eq 'ARRAY') {
11130: foreach my $type (@{$cancreate{$item}}) {
11131: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11132: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11133: push(@{$changes{'cancreate'}},$item);
11134: }
11135: }
11136: }
11137: }
11138: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11139: if (ref($cancreate{$item}) eq 'HASH') {
11140: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 11141: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
11142: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
11143: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
11144: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11145: push(@{$changes{'cancreate'}},$item);
11146: }
11147: }
11148: }
1.236 raeburn 11149: } elsif ($item eq 'selfcreateprocessing') {
11150: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
11151: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11152: push(@{$changes{'cancreate'}},$item);
11153: }
11154: }
1.228 raeburn 11155: } else {
11156: if (!$cancreate{$item}{$curr}) {
11157: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11158: push(@{$changes{'cancreate'}},$item);
11159: }
1.224 raeburn 11160: }
11161: }
11162: }
11163: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 11164: if (ref($cancreate{$item}{$field}) eq 'HASH') {
11165: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
11166: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
11167: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
11168: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11169: push(@{$changes{'cancreate'}},$item);
11170: }
11171: }
11172: } else {
11173: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11174: push(@{$changes{'cancreate'}},$item);
11175: }
11176: }
11177: }
1.236 raeburn 11178: } elsif ($item eq 'selfcreateprocessing') {
11179: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
11180: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11181: push(@{$changes{'cancreate'}},$item);
11182: }
11183: }
1.228 raeburn 11184: } else {
11185: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
11186: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11187: push(@{$changes{'cancreate'}},$item);
11188: }
1.224 raeburn 11189: }
11190: }
11191: }
11192: }
11193: } elsif ($curr_usercreation{'cancreate'}{$item}) {
11194: if (ref($cancreate{$item}) eq 'ARRAY') {
11195: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
11196: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11197: push(@{$changes{'cancreate'}},$item);
11198: }
11199: }
11200: } elsif (ref($cancreate{$item}) eq 'HASH') {
11201: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
11202: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11203: push(@{$changes{'cancreate'}},$item);
11204: }
11205: }
11206: }
11207: } elsif ($item eq 'emailusername') {
1.228 raeburn 11208: if (ref($cancreate{$item}) eq 'HASH') {
11209: foreach my $type (keys(%{$cancreate{$item}})) {
11210: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11211: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11212: if ($cancreate{$item}{$type}{$field}) {
11213: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11214: push(@{$changes{'cancreate'}},$item);
11215: }
11216: last;
11217: }
11218: }
11219: }
11220: }
1.224 raeburn 11221: }
11222: }
11223: }
11224: #
11225: # Populate %save_usercreate hash with updates to self-creation configuration.
11226: #
11227: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
11228: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 11229: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 11230: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
11231: if (ref($cancreate{'notify'}) eq 'HASH') {
11232: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
11233: }
1.236 raeburn 11234: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
11235: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
11236: }
1.224 raeburn 11237: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11238: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
11239: }
1.240 raeburn 11240: if (ref($cancreate{'shibenv'}) eq 'HASH') {
11241: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
11242: }
1.224 raeburn 11243: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
11244: $save_usercreate{'emailrule'} = \@email_rule;
11245:
11246: my %userconfig_hash = (
11247: usercreation => \%save_usercreate,
11248: usermodification => \%save_usermodify,
11249: );
11250: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
11251: $dom);
11252: #
11253: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
11254: #
1.27 raeburn 11255: if ($putresult eq 'ok') {
11256: if (keys(%changes) > 0) {
11257: $resulttext = &mt('Changes made:').'<ul>';
11258: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 11259: my %lt = &selfcreation_types();
1.34 raeburn 11260: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 11261: my $chgtext;
1.45 raeburn 11262: if ($type eq 'selfcreate') {
1.50 raeburn 11263: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 11264: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 11265: } else {
1.224 raeburn 11266: $chgtext .= &mt('Self-creation of a new account is permitted for:').
11267: '<ul>';
1.50 raeburn 11268: foreach my $case (@{$cancreate{$type}}) {
11269: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
11270: }
11271: $chgtext .= '</ul>';
1.100 raeburn 11272: if (ref($cancreate{$type}) eq 'ARRAY') {
11273: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
11274: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11275: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 11276: $chgtext .= '<br />'.
11277: '<span class="LC_warning">'.
11278: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11279: '</span>';
1.100 raeburn 11280: }
11281: }
11282: }
11283: }
1.43 raeburn 11284: }
1.240 raeburn 11285: } elsif ($type eq 'shibenv') {
11286: if (keys(%{$cancreate{$type}}) == 0) {
11287: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
11288: } else {
11289: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
11290: '<ul>';
11291: foreach my $field (@shibfields) {
11292: next if ($cancreate{$type}{$field} eq '');
11293: if ($field eq 'inststatus') {
11294: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
11295: } else {
11296: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
11297: }
11298: }
11299: $chgtext .= '</ul>';
11300: }
1.93 raeburn 11301: } elsif ($type eq 'statustocreate') {
1.96 raeburn 11302: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
11303: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
11304: if (@{$cancreate{'selfcreate'}} > 0) {
11305: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 11306: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 11307: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 11308: $chgtext .= '<br />'.
11309: '<span class="LC_warning">'.
11310: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11311: '</span>';
11312: }
1.96 raeburn 11313: } elsif (ref($usertypes) eq 'HASH') {
11314: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 11315: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
11316: } else {
11317: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
11318: }
11319: $chgtext .= '<ul>';
11320: foreach my $case (@{$cancreate{$type}}) {
11321: if ($case eq 'default') {
11322: $chgtext .= '<li>'.$othertitle.'</li>';
11323: } else {
11324: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 11325: }
11326: }
1.100 raeburn 11327: $chgtext .= '</ul>';
11328: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 11329: $chgtext .= '<br /><span class="LC_warning">'.
11330: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
11331: '</span>';
1.100 raeburn 11332: }
11333: }
11334: } else {
11335: if (@{$cancreate{$type}} == 0) {
11336: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
11337: } else {
11338: $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 11339: }
11340: }
11341: }
1.236 raeburn 11342: } elsif ($type eq 'selfcreateprocessing') {
11343: my %choices = &Apache::lonlocal::texthash (
11344: automatic => 'Automatic approval',
11345: approval => 'Queued for approval',
11346: );
11347: if (@statuses > 1) {
11348: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
11349: '<ul>';
11350: foreach my $type (@statuses) {
11351: if ($type eq 'default') {
11352: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11353: } else {
11354: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11355: }
11356: }
11357: $chgtext .= '</ul>';
11358: } else {
11359: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
11360: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
11361: }
1.165 raeburn 11362: } elsif ($type eq 'captcha') {
1.224 raeburn 11363: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 11364: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
11365: } else {
11366: my %captchas = &captcha_phrases();
1.224 raeburn 11367: if ($captchas{$savecaptcha{$type}}) {
11368: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 11369: } else {
1.210 raeburn 11370: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 11371: }
11372: }
11373: } elsif ($type eq 'recaptchakeys') {
11374: my ($privkey,$pubkey);
1.224 raeburn 11375: if (ref($savecaptcha{$type}) eq 'HASH') {
11376: $pubkey = $savecaptcha{$type}{'public'};
11377: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 11378: }
11379: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
11380: if (!$pubkey) {
11381: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
11382: } else {
11383: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11384: }
11385: if (!$privkey) {
11386: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
11387: } else {
11388: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
11389: }
11390: $chgtext .= '</ul>';
1.269 raeburn 11391: } elsif ($type eq 'recaptchaversion') {
11392: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 11393: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 11394: }
1.224 raeburn 11395: } elsif ($type eq 'emailusername') {
11396: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 11397: if (ref($types) eq 'ARRAY') {
11398: foreach my $type (@{$types}) {
11399: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
11400: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 11401: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 11402: '<ul>';
11403: foreach my $field (@{$infofields}) {
11404: if ($cancreate{'emailusername'}{$type}{$field}) {
11405: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
11406: }
11407: }
1.245 raeburn 11408: $chgtext .= '</ul>';
11409: } else {
11410: $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 11411: }
11412: } else {
1.245 raeburn 11413: $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 11414: }
11415: }
11416: }
11417: }
11418: } elsif ($type eq 'notify') {
11419: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
11420: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11421: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
11422: if ($cancreate{'notify'}{'approval'}) {
11423: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
11424: }
11425: }
1.43 raeburn 11426: }
1.34 raeburn 11427: }
1.224 raeburn 11428: if ($chgtext) {
11429: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 11430: }
11431: }
11432: }
1.43 raeburn 11433: if (ref($changes{'email_rule'}) eq 'ARRAY') {
11434: my ($emailrules,$emailruleorder) =
11435: &Apache::lonnet::inst_userrules($dom,'email');
11436: my $chgtext = '<ul>';
11437: foreach my $type (@email_rule) {
11438: if (ref($emailrules->{$type}) eq 'HASH') {
11439: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
11440: }
11441: }
11442: $chgtext .= '</ul>';
11443: if (@email_rule > 0) {
1.224 raeburn 11444: $resulttext .= '<li>'.
11445: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
11446: $chgtext.
11447: '</li>';
1.43 raeburn 11448: } else {
1.224 raeburn 11449: $resulttext .= '<li>'.
11450: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
11451: '</li>';
1.43 raeburn 11452: }
11453: }
1.224 raeburn 11454: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
11455: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
11456: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11457: foreach my $type (@{$changes{'selfcreate'}}) {
11458: my $typename = $type;
11459: if (ref($usertypes) eq 'HASH') {
11460: if ($usertypes->{$type} ne '') {
11461: $typename = $usertypes->{$type};
11462: }
11463: }
11464: my @modifiable;
11465: $resulttext .= '<li>'.
11466: &mt('Self-creation of account by users with status: [_1]',
11467: '<span class="LC_cusr_emph">'.$typename.'</span>').
11468: ' - '.&mt('modifiable fields (if institutional data blank): ');
11469: foreach my $field (@fields) {
11470: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
11471: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 11472: }
11473: }
1.224 raeburn 11474: if (@modifiable > 0) {
11475: $resulttext .= join(', ',@modifiable);
1.43 raeburn 11476: } else {
1.224 raeburn 11477: $resulttext .= &mt('none');
1.43 raeburn 11478: }
1.224 raeburn 11479: $resulttext .= '</li>';
1.28 raeburn 11480: }
1.224 raeburn 11481: $resulttext .= '</ul></li>';
1.28 raeburn 11482: }
1.27 raeburn 11483: $resulttext .= '</ul>';
11484: } else {
1.224 raeburn 11485: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 11486: }
11487: } else {
11488: $resulttext = '<span class="LC_error">'.
1.23 raeburn 11489: &mt('An error occurred: [_1]',$putresult).'</span>';
11490: }
1.43 raeburn 11491: if ($warningmsg ne '') {
11492: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11493: }
1.23 raeburn 11494: return $resulttext;
11495: }
11496:
1.165 raeburn 11497: sub process_captcha {
11498: my ($container,$changes,$newsettings,$current) = @_;
11499: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
11500: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
11501: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
11502: $newsettings->{'captcha'} = 'original';
11503: }
11504: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 11505: if ($container eq 'cancreate') {
1.169 raeburn 11506: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11507: push(@{$changes->{'cancreate'}},'captcha');
11508: } elsif (!defined($changes->{'cancreate'})) {
11509: $changes->{'cancreate'} = ['captcha'];
11510: }
11511: } else {
11512: $changes->{'captcha'} = 1;
1.165 raeburn 11513: }
11514: }
1.269 raeburn 11515: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 11516: if ($newsettings->{'captcha'} eq 'recaptcha') {
11517: $newpub = $env{'form.'.$container.'_recaptchapub'};
11518: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 11519: $newpub =~ s/[^\w\-]//g;
11520: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 11521: $newsettings->{'recaptchakeys'} = {
11522: public => $newpub,
11523: private => $newpriv,
11524: };
1.269 raeburn 11525: $newversion = $env{'form.'.$container.'_recaptchaversion'};
11526: $newversion =~ s/\D//g;
11527: if ($newversion ne '2') {
11528: $newversion = 1;
11529: }
11530: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 11531: }
11532: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
11533: $currpub = $current->{'recaptchakeys'}{'public'};
11534: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 11535: unless ($newsettings->{'captcha'} eq 'recaptcha') {
11536: $newsettings->{'recaptchakeys'} = {
11537: public => '',
11538: private => '',
11539: }
11540: }
1.165 raeburn 11541: }
1.269 raeburn 11542: if ($current->{'captcha'} eq 'recaptcha') {
11543: $currversion = $current->{'recaptchaversion'};
11544: if ($currversion ne '2') {
11545: $currversion = 1;
11546: }
11547: }
11548: if ($currversion ne $newversion) {
11549: if ($container eq 'cancreate') {
11550: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11551: push(@{$changes->{'cancreate'}},'recaptchaversion');
11552: } elsif (!defined($changes->{'cancreate'})) {
11553: $changes->{'cancreate'} = ['recaptchaversion'];
11554: }
11555: } else {
11556: $changes->{'recaptchaversion'} = 1;
11557: }
11558: }
1.165 raeburn 11559: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 11560: if ($container eq 'cancreate') {
11561: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11562: push(@{$changes->{'cancreate'}},'recaptchakeys');
11563: } elsif (!defined($changes->{'cancreate'})) {
11564: $changes->{'cancreate'} = ['recaptchakeys'];
11565: }
11566: } else {
1.210 raeburn 11567: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 11568: }
11569: }
11570: return;
11571: }
11572:
1.33 raeburn 11573: sub modify_usermodification {
11574: my ($dom,%domconfig) = @_;
1.224 raeburn 11575: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 11576: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11577: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 11578: if ($key eq 'selfcreate') {
11579: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
11580: } else {
11581: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
11582: }
1.33 raeburn 11583: }
11584: }
1.224 raeburn 11585: my @contexts = ('author','course');
1.33 raeburn 11586: my %context_title = (
11587: author => 'In author context',
11588: course => 'In course context',
11589: );
11590: my @fields = ('lastname','firstname','middlename','generation',
11591: 'permanentemail','id');
11592: my %roles = (
11593: author => ['ca','aa'],
11594: course => ['st','ep','ta','in','cr'],
11595: );
11596: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11597: foreach my $context (@contexts) {
11598: foreach my $role (@{$roles{$context}}) {
11599: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
11600: foreach my $item (@fields) {
11601: if (grep(/^\Q$item\E$/,@modifiable)) {
11602: $modifyhash{$context}{$role}{$item} = 1;
11603: } else {
11604: $modifyhash{$context}{$role}{$item} = 0;
11605: }
11606: }
11607: }
11608: if (ref($curr_usermodification{$context}) eq 'HASH') {
11609: foreach my $role (@{$roles{$context}}) {
11610: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
11611: foreach my $field (@fields) {
11612: if ($modifyhash{$context}{$role}{$field} ne
11613: $curr_usermodification{$context}{$role}{$field}) {
11614: push(@{$changes{$context}},$role);
11615: last;
11616: }
11617: }
11618: }
11619: }
11620: } else {
11621: foreach my $context (@contexts) {
11622: foreach my $role (@{$roles{$context}}) {
11623: push(@{$changes{$context}},$role);
11624: }
11625: }
11626: }
11627: }
11628: my %usermodification_hash = (
11629: usermodification => \%modifyhash,
11630: );
11631: my $putresult = &Apache::lonnet::put_dom('configuration',
11632: \%usermodification_hash,$dom);
11633: if ($putresult eq 'ok') {
11634: if (keys(%changes) > 0) {
11635: $resulttext = &mt('Changes made: ').'<ul>';
11636: foreach my $context (@contexts) {
11637: if (ref($changes{$context}) eq 'ARRAY') {
11638: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
11639: if (ref($changes{$context}) eq 'ARRAY') {
11640: foreach my $role (@{$changes{$context}}) {
11641: my $rolename;
1.224 raeburn 11642: if ($role eq 'cr') {
11643: $rolename = &mt('Custom');
1.33 raeburn 11644: } else {
1.224 raeburn 11645: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 11646: }
11647: my @modifiable;
1.224 raeburn 11648: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 11649: foreach my $field (@fields) {
11650: if ($modifyhash{$context}{$role}{$field}) {
11651: push(@modifiable,$fieldtitles{$field});
11652: }
11653: }
11654: if (@modifiable > 0) {
11655: $resulttext .= join(', ',@modifiable);
11656: } else {
11657: $resulttext .= &mt('none');
11658: }
11659: $resulttext .= '</li>';
11660: }
11661: $resulttext .= '</ul></li>';
11662: }
11663: }
11664: }
11665: $resulttext .= '</ul>';
11666: } else {
11667: $resulttext = &mt('No changes made to user modification settings');
11668: }
11669: } else {
11670: $resulttext = '<span class="LC_error">'.
11671: &mt('An error occurred: [_1]',$putresult).'</span>';
11672: }
11673: return $resulttext;
11674: }
11675:
1.43 raeburn 11676: sub modify_defaults {
1.212 raeburn 11677: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 11678: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 11679: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 11680: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 11681: my @authtypes = ('internal','krb4','krb5','localauth');
11682: foreach my $item (@items) {
11683: $newvalues{$item} = $env{'form.'.$item};
11684: if ($item eq 'auth_def') {
11685: if ($newvalues{$item} ne '') {
11686: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
11687: push(@errors,$item);
11688: }
11689: }
11690: } elsif ($item eq 'lang_def') {
11691: if ($newvalues{$item} ne '') {
11692: if ($newvalues{$item} =~ /^(\w+)/) {
11693: my $langcode = $1;
1.103 raeburn 11694: if ($langcode ne 'x_chef') {
11695: if (code2language($langcode) eq '') {
11696: push(@errors,$item);
11697: }
1.43 raeburn 11698: }
11699: } else {
11700: push(@errors,$item);
11701: }
11702: }
1.54 raeburn 11703: } elsif ($item eq 'timezone_def') {
11704: if ($newvalues{$item} ne '') {
1.62 raeburn 11705: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 11706: push(@errors,$item);
11707: }
11708: }
1.68 raeburn 11709: } elsif ($item eq 'datelocale_def') {
11710: if ($newvalues{$item} ne '') {
11711: my @datelocale_ids = DateTime::Locale->ids();
11712: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
11713: push(@errors,$item);
11714: }
11715: }
1.141 raeburn 11716: } elsif ($item eq 'portal_def') {
11717: if ($newvalues{$item} ne '') {
11718: 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])\/?$/) {
11719: push(@errors,$item);
11720: }
11721: }
1.43 raeburn 11722: }
11723: if (grep(/^\Q$item\E$/,@errors)) {
11724: $newvalues{$item} = $domdefaults{$item};
11725: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
11726: $changes{$item} = 1;
11727: }
1.72 raeburn 11728: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 11729: }
11730: my %defaults_hash = (
1.72 raeburn 11731: defaults => \%newvalues,
11732: );
1.43 raeburn 11733: my $title = &defaults_titles();
1.236 raeburn 11734:
11735: my $currinststatus;
11736: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11737: $currinststatus = $domconfig{'inststatus'};
11738: } else {
11739: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11740: $currinststatus = {
11741: inststatustypes => $usertypes,
11742: inststatusorder => $types,
11743: inststatusguest => [],
11744: };
11745: }
11746: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
11747: my @allpos;
11748: my %guests;
11749: my %alltypes;
11750: my ($currtitles,$currguests,$currorder);
11751: if (ref($currinststatus) eq 'HASH') {
11752: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
11753: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
11754: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
11755: if ($currinststatus->{inststatustypes}->{$type} ne '') {
11756: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
11757: }
11758: }
11759: unless (grep(/^\Q$type\E$/,@todelete)) {
11760: my $position = $env{'form.inststatus_pos_'.$type};
11761: $position =~ s/\D+//g;
11762: $allpos[$position] = $type;
11763: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
11764: $alltypes{$type} =~ s/`//g;
11765: if ($env{'form.inststatus_guest_'.$type}) {
11766: $guests{$type} = 1;
11767: }
11768: }
11769: }
11770: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
11771: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
11772: }
11773: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
11774: $currtitles =~ s/,$//;
11775: }
11776: }
11777: if ($env{'form.addinststatus'}) {
11778: my $newtype = $env{'form.addinststatus'};
11779: $newtype =~ s/\W//g;
11780: unless (exists($alltypes{$newtype})) {
11781: if ($env{'form.addinststatus_guest'}) {
11782: $guests{$newtype} = 1;
11783: }
11784: $alltypes{$newtype} = $env{'form.addinststatus_title'};
11785: $alltypes{$newtype} =~ s/`//g;
11786: my $position = $env{'form.addinststatus_pos'};
11787: $position =~ s/\D+//g;
11788: if ($position ne '') {
11789: $allpos[$position] = $newtype;
11790: }
11791: }
11792: }
11793: my (@orderedstatus,@orderedguests);
11794: foreach my $type (@allpos) {
11795: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
11796: push(@orderedstatus,$type);
11797: if ($guests{$type}) {
11798: push(@orderedguests,$type);
11799: }
11800: }
11801: }
11802: foreach my $type (keys(%alltypes)) {
11803: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
11804: delete($alltypes{$type});
11805: }
11806: }
11807: $defaults_hash{'inststatus'} = {
11808: inststatustypes => \%alltypes,
11809: inststatusorder => \@orderedstatus,
11810: inststatusguest => \@orderedguests,
11811: };
11812: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
11813: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
11814: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
11815: }
11816: }
11817: if ($currorder ne join(',',@orderedstatus)) {
11818: $changes{'inststatus'}{'inststatusorder'} = 1;
11819: }
11820: if ($currguests ne join(',',@orderedguests)) {
11821: $changes{'inststatus'}{'inststatusguest'} = 1;
11822: }
11823: my $newtitles;
11824: foreach my $item (@orderedstatus) {
11825: $newtitles .= $alltypes{$item}.',';
11826: }
11827: $newtitles =~ s/,$//;
11828: if ($currtitles ne $newtitles) {
11829: $changes{'inststatus'}{'inststatustypes'} = 1;
11830: }
1.43 raeburn 11831: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
11832: $dom);
11833: if ($putresult eq 'ok') {
11834: if (keys(%changes) > 0) {
11835: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 11836: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 11837: 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";
11838: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 11839: if ($item eq 'inststatus') {
11840: if (ref($changes{'inststatus'}) eq 'HASH') {
11841: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
11842: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
11843: foreach my $type (@orderedstatus) {
11844: $resulttext .= $alltypes{$type}.', ';
11845: }
11846: $resulttext =~ s/, $//;
11847: $resulttext .= '</li>';
11848: }
11849: if ($changes{'inststatus'}{'inststatusguest'}) {
11850: $resulttext .= '<li>';
11851: if (@orderedguests) {
11852: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
11853: foreach my $type (@orderedguests) {
11854: $resulttext .= $alltypes{$type}.', ';
11855: }
11856: $resulttext =~ s/, $//;
11857: } else {
11858: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
11859: }
11860: $resulttext .= '</li>';
11861: }
11862: }
11863: } else {
11864: my $value = $env{'form.'.$item};
11865: if ($value eq '') {
11866: $value = &mt('none');
11867: } elsif ($item eq 'auth_def') {
11868: my %authnames = &authtype_names();
11869: my %shortauth = (
11870: internal => 'int',
11871: krb4 => 'krb4',
11872: krb5 => 'krb5',
11873: localauth => 'loc',
11874: );
11875: $value = $authnames{$shortauth{$value}};
11876: }
11877: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
11878: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 11879: }
11880: }
11881: $resulttext .= '</ul>';
11882: $mailmsgtext .= "\n";
11883: my $cachetime = 24*60*60;
1.72 raeburn 11884: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11885: if (ref($lastactref) eq 'HASH') {
11886: $lastactref->{'domdefaults'} = 1;
11887: }
1.68 raeburn 11888: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 11889: my $notify = 1;
11890: if (ref($domconfig{'contacts'}) eq 'HASH') {
11891: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
11892: $notify = 0;
11893: }
11894: }
11895: if ($notify) {
11896: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
11897: "LON-CAPA Domain Settings Change - $dom",
11898: $mailmsgtext);
11899: }
1.54 raeburn 11900: }
1.43 raeburn 11901: } else {
1.54 raeburn 11902: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 11903: }
11904: } else {
11905: $resulttext = '<span class="LC_error">'.
11906: &mt('An error occurred: [_1]',$putresult).'</span>';
11907: }
11908: if (@errors > 0) {
11909: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
11910: foreach my $item (@errors) {
11911: $resulttext .= ' "'.$title->{$item}.'",';
11912: }
11913: $resulttext =~ s/,$//;
11914: }
11915: return $resulttext;
11916: }
11917:
1.46 raeburn 11918: sub modify_scantron {
1.205 raeburn 11919: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 11920: my ($resulttext,%confhash,%changes,$errors);
11921: my $custom = 'custom.tab';
11922: my $default = 'default.tab';
11923: my $servadm = $r->dir_config('lonAdmEMail');
11924: my ($configuserok,$author_ok,$switchserver) =
11925: &config_check($dom,$confname,$servadm);
11926: if ($env{'form.scantronformat.filename'} ne '') {
11927: my $error;
11928: if ($configuserok eq 'ok') {
11929: if ($switchserver) {
1.130 raeburn 11930: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 11931: } else {
11932: if ($author_ok eq 'ok') {
11933: my ($result,$scantronurl) =
11934: &publishlogo($r,'upload','scantronformat',$dom,
11935: $confname,'scantron','','',$custom);
11936: if ($result eq 'ok') {
11937: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 11938: $changes{'scantronformat'} = 1;
1.46 raeburn 11939: } else {
11940: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
11941: }
11942: } else {
11943: $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);
11944: }
11945: }
11946: } else {
11947: $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);
11948: }
11949: if ($error) {
11950: &Apache::lonnet::logthis($error);
11951: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11952: }
11953: }
1.48 raeburn 11954: if (ref($domconfig{'scantron'}) eq 'HASH') {
11955: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
11956: if ($env{'form.scantronformat_del'}) {
11957: $confhash{'scantron'}{'scantronformat'} = '';
11958: $changes{'scantronformat'} = 1;
1.46 raeburn 11959: }
11960: }
11961: }
11962: if (keys(%confhash) > 0) {
11963: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
11964: $dom);
11965: if ($putresult eq 'ok') {
11966: if (keys(%changes) > 0) {
1.48 raeburn 11967: if (ref($confhash{'scantron'}) eq 'HASH') {
11968: $resulttext = &mt('Changes made:').'<ul>';
11969: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 11970: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 11971: } else {
1.130 raeburn 11972: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 11973: }
1.48 raeburn 11974: $resulttext .= '</ul>';
11975: } else {
1.130 raeburn 11976: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 11977: }
11978: $resulttext .= '</ul>';
11979: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11980: if (ref($lastactref) eq 'HASH') {
11981: $lastactref->{'domainconfig'} = 1;
11982: }
1.46 raeburn 11983: } else {
1.130 raeburn 11984: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11985: }
11986: } else {
11987: $resulttext = '<span class="LC_error">'.
11988: &mt('An error occurred: [_1]',$putresult).'</span>';
11989: }
11990: } else {
1.130 raeburn 11991: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11992: }
11993: if ($errors) {
11994: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11995: $errors.'</ul>';
11996: }
11997: return $resulttext;
11998: }
11999:
1.48 raeburn 12000: sub modify_coursecategories {
1.239 raeburn 12001: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 12002: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
12003: $cathash);
1.48 raeburn 12004: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 12005: my @catitems = ('unauth','auth');
12006: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 12007: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 12008: $cathash = $domconfig{'coursecategories'}{'cats'};
12009: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
12010: $changes{'togglecats'} = 1;
12011: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
12012: }
12013: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
12014: $changes{'categorize'} = 1;
12015: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
12016: }
1.120 raeburn 12017: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
12018: $changes{'togglecatscomm'} = 1;
12019: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
12020: }
12021: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
12022: $changes{'categorizecomm'} = 1;
12023: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 12024:
12025: }
12026: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
12027: $changes{'togglecatsplace'} = 1;
12028: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
12029: }
12030: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
12031: $changes{'categorizeplace'} = 1;
12032: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 12033: }
1.238 raeburn 12034: foreach my $item (@catitems) {
12035: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12036: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
12037: $changes{$item} = 1;
12038: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12039: }
12040: }
12041: }
1.57 raeburn 12042: } else {
12043: $changes{'togglecats'} = 1;
12044: $changes{'categorize'} = 1;
1.124 raeburn 12045: $changes{'togglecatscomm'} = 1;
12046: $changes{'categorizecomm'} = 1;
1.272 raeburn 12047: $changes{'togglecatsplace'} = 1;
12048: $changes{'categorizeplace'} = 1;
1.87 raeburn 12049: $domconfig{'coursecategories'} = {
12050: togglecats => $env{'form.togglecats'},
12051: categorize => $env{'form.categorize'},
1.124 raeburn 12052: togglecatscomm => $env{'form.togglecatscomm'},
12053: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 12054: togglecatsplace => $env{'form.togglecatsplace'},
12055: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 12056: };
1.238 raeburn 12057: foreach my $item (@catitems) {
12058: if ($env{'form.coursecat_'.$item} ne 'std') {
12059: $changes{$item} = 1;
12060: }
12061: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12062: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12063: }
12064: }
1.57 raeburn 12065: }
12066: if (ref($cathash) eq 'HASH') {
12067: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 12068: push (@deletecategory,'instcode::0');
12069: }
1.120 raeburn 12070: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
12071: push(@deletecategory,'communities::0');
12072: }
1.272 raeburn 12073: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
12074: push(@deletecategory,'placement::0');
12075: }
1.48 raeburn 12076: }
1.57 raeburn 12077: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
12078: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12079: if (@deletecategory > 0) {
12080: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 12081: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 12082: foreach my $item (@deletecategory) {
1.57 raeburn 12083: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
12084: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 12085: $deletions{$item} = 1;
1.57 raeburn 12086: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 12087: }
12088: }
12089: }
1.57 raeburn 12090: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 12091: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 12092: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 12093: $reorderings{$item} = 1;
1.57 raeburn 12094: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 12095: }
12096: if ($env{'form.addcategory_name_'.$item} ne '') {
12097: my $newcat = $env{'form.addcategory_name_'.$item};
12098: my $newdepth = $depth+1;
12099: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12100: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 12101: $adds{$newitem} = 1;
12102: }
12103: if ($env{'form.subcat_'.$item} ne '') {
12104: my $newcat = $env{'form.subcat_'.$item};
12105: my $newdepth = $depth+1;
12106: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12107: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 12108: $adds{$newitem} = 1;
12109: }
12110: }
12111: }
12112: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 12113: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12114: my $newitem = 'instcode::0';
1.57 raeburn 12115: if ($cathash->{$newitem} eq '') {
12116: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12117: $adds{$newitem} = 1;
12118: }
12119: } else {
12120: my $newitem = 'instcode::0';
1.57 raeburn 12121: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12122: $adds{$newitem} = 1;
12123: }
12124: }
1.120 raeburn 12125: if ($env{'form.communities'} eq '1') {
12126: if (ref($cathash) eq 'HASH') {
12127: my $newitem = 'communities::0';
12128: if ($cathash->{$newitem} eq '') {
12129: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12130: $adds{$newitem} = 1;
12131: }
12132: } else {
12133: my $newitem = 'communities::0';
12134: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12135: $adds{$newitem} = 1;
12136: }
12137: }
1.272 raeburn 12138: if ($env{'form.placement'} eq '1') {
12139: if (ref($cathash) eq 'HASH') {
12140: my $newitem = 'placement::0';
12141: if ($cathash->{$newitem} eq '') {
12142: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12143: $adds{$newitem} = 1;
12144: }
12145: } else {
12146: my $newitem = 'placement::0';
12147: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12148: $adds{$newitem} = 1;
12149: }
12150: }
1.48 raeburn 12151: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 12152: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 12153: ($env{'form.addcategory_name'} ne 'communities') &&
12154: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 12155: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
12156: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
12157: $adds{$newitem} = 1;
12158: }
1.48 raeburn 12159: }
1.57 raeburn 12160: my $putresult;
1.48 raeburn 12161: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12162: if (keys(%deletions) > 0) {
12163: foreach my $key (keys(%deletions)) {
12164: if ($predelallitems{$key} ne '') {
12165: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
12166: }
12167: }
12168: }
12169: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 12170: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 12171: if (ref($chkcats[0]) eq 'ARRAY') {
12172: my $depth = 0;
12173: my $chg = 0;
12174: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
12175: my $name = $chkcats[0][$i];
12176: my $item;
12177: if ($name eq '') {
12178: $chg ++;
12179: } else {
12180: $item = &escape($name).'::0';
12181: if ($chg) {
1.57 raeburn 12182: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 12183: }
12184: $depth ++;
1.57 raeburn 12185: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 12186: $depth --;
12187: }
12188: }
12189: }
1.57 raeburn 12190: }
12191: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12192: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 12193: if ($putresult eq 'ok') {
1.57 raeburn 12194: my %title = (
1.120 raeburn 12195: togglecats => 'Show/Hide a course in catalog',
12196: categorize => 'Assign a category to a course',
12197: togglecatscomm => 'Show/Hide a community in catalog',
12198: categorizecomm => 'Assign a category to a community',
1.57 raeburn 12199: );
12200: my %level = (
1.120 raeburn 12201: dom => 'set in Domain ("Modify Course/Community")',
12202: crs => 'set in Course ("Course Configuration")',
12203: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 12204: none => 'No catalog',
12205: std => 'Standard catalog',
12206: domonly => 'Domain-only catalog',
12207: codesrch => 'Code search form',
1.57 raeburn 12208: );
1.48 raeburn 12209: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 12210: if ($changes{'togglecats'}) {
12211: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
12212: }
12213: if ($changes{'categorize'}) {
12214: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 12215: }
1.120 raeburn 12216: if ($changes{'togglecatscomm'}) {
12217: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
12218: }
12219: if ($changes{'categorizecomm'}) {
12220: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
12221: }
1.238 raeburn 12222: if ($changes{'unauth'}) {
12223: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
12224: }
12225: if ($changes{'auth'}) {
12226: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
12227: }
1.57 raeburn 12228: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12229: my $cathash;
12230: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
12231: $cathash = $domconfig{'coursecategories'}{'cats'};
12232: } else {
12233: $cathash = {};
12234: }
12235: my (@cats,@trails,%allitems);
12236: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
12237: if (keys(%deletions) > 0) {
12238: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
12239: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
12240: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
12241: }
12242: $resulttext .= '</ul></li>';
12243: }
12244: if (keys(%reorderings) > 0) {
12245: my %sort_by_trail;
12246: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
12247: foreach my $key (keys(%reorderings)) {
12248: if ($allitems{$key} ne '') {
12249: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12250: }
1.48 raeburn 12251: }
1.57 raeburn 12252: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12253: $resulttext .= '<li>'.$trails[$trail].'</li>';
12254: }
12255: $resulttext .= '</ul></li>';
1.48 raeburn 12256: }
1.57 raeburn 12257: if (keys(%adds) > 0) {
12258: my %sort_by_trail;
12259: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
12260: foreach my $key (keys(%adds)) {
12261: if ($allitems{$key} ne '') {
12262: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12263: }
12264: }
12265: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12266: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 12267: }
1.57 raeburn 12268: $resulttext .= '</ul></li>';
1.48 raeburn 12269: }
12270: }
12271: $resulttext .= '</ul>';
1.239 raeburn 12272: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 12273: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12274: if ($changes{'auth'}) {
12275: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
12276: }
12277: if ($changes{'unauth'}) {
12278: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
12279: }
12280: my $cachetime = 24*60*60;
12281: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 12282: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 12283: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 12284: }
12285: }
1.48 raeburn 12286: } else {
12287: $resulttext = '<span class="LC_error">'.
1.57 raeburn 12288: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 12289: }
12290: } else {
1.120 raeburn 12291: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 12292: }
12293: return $resulttext;
12294: }
12295:
1.69 raeburn 12296: sub modify_serverstatuses {
12297: my ($dom,%domconfig) = @_;
12298: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
12299: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
12300: %currserverstatus = %{$domconfig{'serverstatuses'}};
12301: }
12302: my @pages = &serverstatus_pages();
12303: foreach my $type (@pages) {
12304: $newserverstatus{$type}{'namedusers'} = '';
12305: $newserverstatus{$type}{'machines'} = '';
12306: if (defined($env{'form.'.$type.'_namedusers'})) {
12307: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
12308: my @okusers;
12309: foreach my $user (@users) {
12310: my ($uname,$udom) = split(/:/,$user);
12311: if (($udom =~ /^$match_domain$/) &&
12312: (&Apache::lonnet::domain($udom)) &&
12313: ($uname =~ /^$match_username$/)) {
12314: if (!grep(/^\Q$user\E/,@okusers)) {
12315: push(@okusers,$user);
12316: }
12317: }
12318: }
12319: if (@okusers > 0) {
12320: @okusers = sort(@okusers);
12321: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
12322: }
12323: }
12324: if (defined($env{'form.'.$type.'_machines'})) {
12325: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
12326: my @okmachines;
12327: foreach my $ip (@machines) {
12328: my @parts = split(/\./,$ip);
12329: next if (@parts < 4);
12330: my $badip = 0;
12331: for (my $i=0; $i<4; $i++) {
12332: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
12333: $badip = 1;
12334: last;
12335: }
12336: }
12337: if (!$badip) {
12338: push(@okmachines,$ip);
12339: }
12340: }
12341: @okmachines = sort(@okmachines);
12342: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
12343: }
12344: }
12345: my %serverstatushash = (
12346: serverstatuses => \%newserverstatus,
12347: );
12348: foreach my $type (@pages) {
1.83 raeburn 12349: foreach my $setting ('namedusers','machines') {
1.84 raeburn 12350: my (@current,@new);
1.83 raeburn 12351: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 12352: if ($currserverstatus{$type}{$setting} ne '') {
12353: @current = split(/,/,$currserverstatus{$type}{$setting});
12354: }
12355: }
12356: if ($newserverstatus{$type}{$setting} ne '') {
12357: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 12358: }
12359: if (@current > 0) {
12360: if (@new > 0) {
12361: foreach my $item (@current) {
12362: if (!grep(/^\Q$item\E$/,@new)) {
12363: $changes{$type}{$setting} = 1;
1.82 raeburn 12364: last;
12365: }
12366: }
1.84 raeburn 12367: foreach my $item (@new) {
12368: if (!grep(/^\Q$item\E$/,@current)) {
12369: $changes{$type}{$setting} = 1;
12370: last;
1.82 raeburn 12371: }
12372: }
12373: } else {
1.83 raeburn 12374: $changes{$type}{$setting} = 1;
1.69 raeburn 12375: }
1.83 raeburn 12376: } elsif (@new > 0) {
12377: $changes{$type}{$setting} = 1;
1.69 raeburn 12378: }
12379: }
12380: }
12381: if (keys(%changes) > 0) {
1.81 raeburn 12382: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 12383: my $putresult = &Apache::lonnet::put_dom('configuration',
12384: \%serverstatushash,$dom);
12385: if ($putresult eq 'ok') {
12386: $resulttext .= &mt('Changes made:').'<ul>';
12387: foreach my $type (@pages) {
1.84 raeburn 12388: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 12389: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 12390: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 12391: if ($newserverstatus{$type}{'namedusers'} eq '') {
12392: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
12393: } else {
12394: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
12395: }
1.84 raeburn 12396: }
12397: if ($changes{$type}{'machines'}) {
1.69 raeburn 12398: if ($newserverstatus{$type}{'machines'} eq '') {
12399: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
12400: } else {
12401: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
12402: }
12403:
12404: }
12405: $resulttext .= '</ul></li>';
12406: }
12407: }
12408: $resulttext .= '</ul>';
12409: } else {
12410: $resulttext = '<span class="LC_error">'.
12411: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
12412:
12413: }
12414: } else {
12415: $resulttext = &mt('No changes made to access to server status pages');
12416: }
12417: return $resulttext;
12418: }
12419:
1.118 jms 12420: sub modify_helpsettings {
1.285 raeburn 12421: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 12422: my ($resulttext,$errors,%changes,%helphash);
12423: my %defaultchecked = ('submitbugs' => 'on');
12424: my @offon = ('off','on');
1.118 jms 12425: my @toggles = ('submitbugs');
1.285 raeburn 12426: my %current = ('submitbugs' => '',
12427: 'adhoc' => {},
12428: );
1.118 jms 12429: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 12430: %current = %{$domconfig{'helpsettings'}};
12431: }
1.285 raeburn 12432: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 12433: foreach my $item (@toggles) {
12434: if ($defaultchecked{$item} eq 'on') {
12435: if ($current{$item} eq '') {
12436: if ($env{'form.'.$item} eq '0') {
12437: $changes{$item} = 1;
12438: }
12439: } elsif ($current{$item} ne $env{'form.'.$item}) {
12440: $changes{$item} = 1;
12441: }
12442: } elsif ($defaultchecked{$item} eq 'off') {
12443: if ($current{$item} eq '') {
12444: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 12445: $changes{$item} = 1;
12446: }
1.282 raeburn 12447: } elsif ($current{$item} ne $env{'form.'.$item}) {
12448: $changes{$item} = 1;
12449: }
12450: }
12451: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
12452: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
12453: }
12454: }
1.285 raeburn 12455: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 12456: my $confname = $dom.'-domainconfig';
12457: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 12458: my (@allpos,%newsettings,%changedprivs,$newrole);
12459: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12460: my @accesstypes = ('all','none','status','inc','exc');
12461: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh']);
12462: my %lt = &Apache::lonlocal::texthash(
12463: s => 'system',
12464: d => 'domain',
12465: order => 'Display order',
12466: access => 'Role usage',
12467: all => 'All',
12468: none => 'None',
12469: status => 'Determined based on institutional status',
12470: inc => 'Include all, but exclude specific personnel',
12471: exc => 'Exclude all, but include specific personnel',
12472: );
12473: for (my $num=0; $num<=$maxnum; $num++) {
12474: my ($prefix,$identifier,$rolename,%curr);
12475: if ($num == $maxnum) {
12476: next unless ($env{'form.newcusthelp'} == $maxnum);
12477: $identifier = 'custhelp'.$num;
12478: $prefix = 'helproles_'.$num;
12479: $rolename = $env{'form.custhelpname'.$num};
12480: $rolename=~s/[^A-Za-z0-9]//gs;
12481: next if ($rolename eq '');
12482: next if (exists($existing{'rolesdef_'.$rolename}));
12483: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12484: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12485: $newprivs{'c'},$confname,$dom);
12486: if ($result ne 'ok') {
12487: $errors .= '<li><span class="LC_error">'.
12488: &mt('An error occurred storing the new custom role: [_1]',
12489: $result).'</span></li>';
12490: next;
12491: } else {
12492: $changedprivs{$rolename} = \%newprivs;
12493: $newrole = $rolename;
12494: }
12495: } else {
12496: $prefix = 'helproles_'.$num;
12497: $rolename = $env{'form.'.$prefix};
12498: next if ($rolename eq '');
12499: next unless (exists($existing{'rolesdef_'.$rolename}));
12500: $identifier = 'custhelp'.$num;
12501: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12502: my %currprivs;
1.289 ! raeburn 12503: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 12504: split(/\_/,$existing{'rolesdef_'.$rolename});
12505: foreach my $level ('c','d','s') {
12506: if ($newprivs{$level} ne $currprivs{$level}) {
12507: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12508: $newprivs{'c'},$confname,$dom);
12509: if ($result ne 'ok') {
12510: $errors .= '<li><span class="LC_error">'.
12511: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
12512: $rolename,$result).'</span></li>';
12513: } else {
12514: $changedprivs{$rolename} = \%newprivs;
12515: }
12516: last;
12517: }
12518: }
12519: if (ref($current{'adhoc'}) eq 'HASH') {
12520: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12521: %curr = %{$current{'adhoc'}{$rolename}};
12522: }
12523: }
12524: }
12525: my $newpos = $env{'form.'.$prefix.'_pos'};
12526: $newpos =~ s/\D+//g;
12527: $allpos[$newpos] = $rolename;
12528: my $newdesc = $env{'form.'.$prefix.'_desc'};
12529: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
12530: if ($curr{'desc'}) {
12531: if ($curr{'desc'} ne $newdesc) {
12532: $changes{'customrole'}{$rolename}{'desc'} = 1;
12533: $newsettings{$rolename}{'desc'} = $newdesc;
12534: }
12535: } elsif ($newdesc ne '') {
12536: $changes{'customrole'}{$rolename}{'desc'} = 1;
12537: $newsettings{$rolename}{'desc'} = $newdesc;
12538: }
12539: my $access = $env{'form.'.$prefix.'_access'};
12540: if (grep(/^\Q$access\E$/,@accesstypes)) {
12541: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
12542: if ($access eq 'status') {
12543: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
12544: if (scalar(@statuses) == 0) {
1.289 ! raeburn 12545: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 12546: } else {
12547: my (@shownstatus,$numtypes);
12548: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12549: if (ref($types) eq 'ARRAY') {
12550: $numtypes = scalar(@{$types});
12551: foreach my $type (sort(@statuses)) {
12552: if ($type eq 'default') {
12553: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12554: } elsif (grep(/^\Q$type\E$/,@{$types})) {
12555: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12556: push(@shownstatus,$usertypes->{$type});
12557: }
12558: }
12559: }
12560: if (grep(/^default$/,@statuses)) {
12561: push(@shownstatus,$othertitle);
12562: }
12563: if (scalar(@shownstatus) == 1+$numtypes) {
12564: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
12565: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
12566: } else {
12567: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
12568: if (ref($curr{'status'}) eq 'ARRAY') {
12569: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12570: if (@diffs) {
12571: $changes{'customrole'}{$rolename}{$access} = 1;
12572: }
12573: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12574: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 12575: }
1.166 raeburn 12576: }
12577: }
1.285 raeburn 12578: } elsif (($access eq 'inc') || ($access eq 'exc')) {
12579: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
12580: my @newspecstaff;
12581: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12582: foreach my $person (sort(@personnel)) {
12583: if ($domhelpdesk{$person}) {
12584: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
12585: }
12586: }
12587: if (ref($curr{$access}) eq 'ARRAY') {
12588: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12589: if (@diffs) {
12590: $changes{'customrole'}{$rolename}{$access} = 1;
12591: }
12592: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12593: $changes{'customrole'}{$rolename}{$access} = 1;
12594: }
12595: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12596: my ($uname,$udom) = split(/:/,$person);
12597: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
12598: }
12599: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 12600: }
1.285 raeburn 12601: } else {
12602: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
12603: }
12604: unless ($curr{'access'} eq $access) {
12605: $changes{'customrole'}{$rolename}{'access'} = 1;
12606: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 12607: }
12608: }
1.285 raeburn 12609: if (@allpos > 0) {
12610: my $idx = 0;
12611: foreach my $rolename (@allpos) {
12612: if ($rolename ne '') {
12613: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
12614: if (ref($current{'adhoc'}) eq 'HASH') {
12615: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12616: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
12617: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 ! raeburn 12618: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 12619: }
12620: }
1.282 raeburn 12621: }
1.285 raeburn 12622: $idx ++;
1.166 raeburn 12623: }
12624: }
1.118 jms 12625: }
1.123 jms 12626: my $putresult;
12627: if (keys(%changes) > 0) {
1.166 raeburn 12628: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 12629: if ($putresult eq 'ok') {
1.285 raeburn 12630: if (ref($helphash{'helpsettings'}) eq 'HASH') {
12631: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
12632: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
12633: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
12634: }
12635: }
12636: my $cachetime = 24*60*60;
12637: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12638: if (ref($lastactref) eq 'HASH') {
12639: $lastactref->{'domdefaults'} = 1;
12640: }
12641: } else {
12642: $errors .= '<li><span class="LC_error">'.
12643: &mt('An error occurred storing the settings: [_1]',
12644: $putresult).'</span></li>';
12645: }
12646: }
12647: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
12648: $resulttext = &mt('Changes made:').'<ul>';
12649: my (%shownprivs,@levelorder);
12650: @levelorder = ('c','d','s');
12651: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 12652: foreach my $item (sort(keys(%changes))) {
12653: if ($item eq 'submitbugs') {
12654: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
12655: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
12656: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 12657: } elsif ($item eq 'customrole') {
12658: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 12659: my @keyorder = ('order','desc','access','status','exc','inc');
12660: my %keytext = &Apache::lonlocal::texthash(
12661: order => 'Order',
12662: desc => 'Role description',
12663: access => 'Role usage',
12664: status => 'Allowed instituional types',
12665: exc => 'Allowed personnel',
12666: inc => 'Disallowed personnel',
12667: );
1.282 raeburn 12668: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 12669: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
12670: if ($role eq $newrole) {
12671: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
12672: $role).'<ul>';
12673: } else {
12674: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12675: $role).'<ul>';
12676: }
12677: foreach my $key (@keyorder) {
12678: if ($changes{'customrole'}{$role}{$key}) {
12679: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
12680: $keytext{$key},$newsettings{$role}{$key}).
12681: '</li>';
12682: }
12683: }
12684: if (ref($changedprivs{$role}) eq 'HASH') {
12685: $shownprivs{$role} = 1;
12686: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
12687: foreach my $level (@levelorder) {
12688: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12689: next if ($item eq '');
12690: my ($priv) = split(/\&/,$item,2);
12691: if (&Apache::lonnet::plaintext($priv)) {
12692: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12693: unless ($level eq 'c') {
12694: $resulttext .= ' ('.$lt{$level}.')';
12695: }
12696: $resulttext .= '</li>';
12697: }
12698: }
12699: }
12700: $resulttext .= '</ul>';
12701: }
12702: $resulttext .= '</ul></li>';
12703: }
12704: }
12705: }
12706: }
12707: }
12708: }
12709: if (keys(%changedprivs)) {
12710: foreach my $role (sort(keys(%changedprivs))) {
12711: unless ($shownprivs{$role}) {
12712: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12713: $role).'<ul>'.
12714: '<li>'.&mt('Privileges set to :').'<ul>';
12715: foreach my $level (@levelorder) {
12716: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12717: next if ($item eq '');
12718: my ($priv) = split(/\&/,$item,2);
12719: if (&Apache::lonnet::plaintext($priv)) {
12720: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12721: unless ($level eq 'c') {
12722: $resulttext .= ' ('.$lt{$level}.')';
12723: }
12724: $resulttext .= '</li>';
12725: }
1.282 raeburn 12726: }
12727: }
1.285 raeburn 12728: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 12729: }
12730: }
12731: }
1.285 raeburn 12732: $resulttext .= '</ul>';
12733: } else {
12734: $resulttext = &mt('No changes made to help settings');
1.118 jms 12735: }
12736: if ($errors) {
1.168 raeburn 12737: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 12738: $errors.'</ul>';
1.118 jms 12739: }
12740: return $resulttext;
12741: }
12742:
1.121 raeburn 12743: sub modify_coursedefaults {
1.212 raeburn 12744: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 12745: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 12746: my %defaultchecked = (
12747: 'canuse_pdfforms' => 'off',
12748: 'uselcmath' => 'on',
12749: 'usejsme' => 'on'
12750: );
12751: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 12752: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 12753: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
12754: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
12755: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 12756: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 12757: my %staticdefaults = (
12758: anonsurvey_threshold => 10,
12759: uploadquota => 500,
1.257 raeburn 12760: postsubmit => 60,
1.276 raeburn 12761: mysqltables => 172800,
1.198 raeburn 12762: );
1.121 raeburn 12763:
12764: $defaultshash{'coursedefaults'} = {};
12765:
12766: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
12767: if ($domconfig{'coursedefaults'} eq '') {
12768: $domconfig{'coursedefaults'} = {};
12769: }
12770: }
12771:
12772: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
12773: foreach my $item (@toggles) {
12774: if ($defaultchecked{$item} eq 'on') {
12775: if (($domconfig{'coursedefaults'}{$item} eq '') &&
12776: ($env{'form.'.$item} eq '0')) {
12777: $changes{$item} = 1;
1.192 raeburn 12778: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 12779: $changes{$item} = 1;
12780: }
12781: } elsif ($defaultchecked{$item} eq 'off') {
12782: if (($domconfig{'coursedefaults'}{$item} eq '') &&
12783: ($env{'form.'.$item} eq '1')) {
12784: $changes{$item} = 1;
12785: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
12786: $changes{$item} = 1;
12787: }
12788: }
12789: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
12790: }
1.198 raeburn 12791: foreach my $item (@numbers) {
12792: my ($currdef,$newdef);
1.208 raeburn 12793: $newdef = $env{'form.'.$item};
1.198 raeburn 12794: if ($item eq 'anonsurvey_threshold') {
12795: $currdef = $domconfig{'coursedefaults'}{$item};
12796: $newdef =~ s/\D//g;
12797: if ($newdef eq '' || $newdef < 1) {
12798: $newdef = 1;
12799: }
12800: $defaultshash{'coursedefaults'}{$item} = $newdef;
12801: } else {
1.276 raeburn 12802: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
12803: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
12804: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 12805: }
12806: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 12807: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 12808: }
12809: if ($currdef ne $newdef) {
12810: my $staticdef;
12811: if ($item eq 'anonsurvey_threshold') {
12812: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
12813: $changes{$item} = 1;
12814: }
1.276 raeburn 12815: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 ! raeburn 12816: my $setting = $1;
1.276 raeburn 12817: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
12818: $changes{$setting} = 1;
1.198 raeburn 12819: }
12820: }
1.139 raeburn 12821: }
12822: }
1.264 raeburn 12823: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
12824: my @currclonecode;
12825: if (ref($currclone) eq 'HASH') {
12826: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
12827: @currclonecode = @{$currclone->{'instcode'}};
12828: }
12829: }
12830: my $newclone;
1.289 ! raeburn 12831: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 12832: $newclone = $env{'form.canclone'};
12833: }
12834: if ($newclone eq 'instcode') {
12835: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
12836: my (%codedefaults,@code_order,@clonecode);
12837: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
12838: \@code_order);
12839: foreach my $item (@code_order) {
12840: if (grep(/^\Q$item\E$/,@newcodes)) {
12841: push(@clonecode,$item);
12842: }
12843: }
12844: if (@clonecode) {
12845: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
12846: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
12847: if (@diffs) {
12848: $changes{'canclone'} = 1;
12849: }
12850: } else {
12851: $newclone eq '';
12852: }
12853: } elsif ($newclone ne '') {
1.289 ! raeburn 12854: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
! 12855: }
1.264 raeburn 12856: if ($newclone ne $currclone) {
12857: $changes{'canclone'} = 1;
12858: }
1.257 raeburn 12859: my %credits;
12860: foreach my $type (@types) {
12861: unless ($type eq 'community') {
12862: $credits{$type} = $env{'form.'.$type.'_credits'};
12863: $credits{$type} =~ s/[^\d.]+//g;
12864: }
12865: }
12866: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
12867: ($env{'form.coursecredits'} eq '1')) {
12868: $changes{'coursecredits'} = 1;
12869: foreach my $type (keys(%credits)) {
12870: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
12871: }
12872: } else {
1.289 ! raeburn 12873: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 12874: foreach my $type (@types) {
12875: unless ($type eq 'community') {
1.289 ! raeburn 12876: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 12877: $changes{'coursecredits'} = 1;
12878: }
12879: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
12880: }
12881: }
12882: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
12883: foreach my $type (@types) {
12884: unless ($type eq 'community') {
12885: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
12886: $changes{'coursecredits'} = 1;
12887: last;
12888: }
12889: }
12890: }
12891: }
12892: }
12893: if ($env{'form.postsubmit'} eq '1') {
12894: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
12895: my %currtimeout;
12896: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12897: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
12898: $changes{'postsubmit'} = 1;
12899: }
12900: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12901: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
12902: }
12903: } else {
12904: $changes{'postsubmit'} = 1;
12905: }
12906: foreach my $type (@types) {
12907: my $timeout = $env{'form.'.$type.'_timeout'};
12908: $timeout =~ s/\D//g;
12909: if ($timeout == $staticdefaults{'postsubmit'}) {
12910: $timeout = '';
12911: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
12912: $timeout = '0';
12913: }
12914: unless ($timeout eq '') {
12915: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
12916: }
12917: if (exists($currtimeout{$type})) {
12918: if ($timeout ne $currtimeout{$type}) {
1.289 ! raeburn 12919: $changes{'postsubmit'} = 1;
1.257 raeburn 12920: }
12921: } elsif ($timeout ne '') {
12922: $changes{'postsubmit'} = 1;
12923: }
12924: }
12925: } else {
12926: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
12927: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12928: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
12929: $changes{'postsubmit'} = 1;
12930: }
12931: } else {
12932: $changes{'postsubmit'} = 1;
12933: }
1.192 raeburn 12934: }
1.121 raeburn 12935: }
12936: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12937: $dom);
12938: if ($putresult eq 'ok') {
12939: if (keys(%changes) > 0) {
1.213 raeburn 12940: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 12941: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 12942: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.276 raeburn 12943: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.257 raeburn 12944: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
12945: if ($changes{$item}) {
12946: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
12947: }
1.289 ! raeburn 12948: }
1.192 raeburn 12949: if ($changes{'coursecredits'}) {
12950: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 12951: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
12952: $domdefaults{$type.'credits'} =
12953: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
12954: }
12955: }
12956: }
12957: if ($changes{'postsubmit'}) {
12958: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12959: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
12960: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12961: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
12962: $domdefaults{$type.'postsubtimeout'} =
12963: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
12964: }
12965: }
1.192 raeburn 12966: }
12967: }
1.198 raeburn 12968: if ($changes{'uploadquota'}) {
12969: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
12970: foreach my $type (@types) {
12971: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
12972: }
12973: }
12974: }
1.264 raeburn 12975: if ($changes{'canclone'}) {
12976: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
12977: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
12978: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
12979: if (@clonecodes) {
12980: $domdefaults{'canclone'} = join('+',@clonecodes);
12981: }
12982: }
12983: } else {
12984: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
12985: }
12986: }
1.121 raeburn 12987: my $cachetime = 24*60*60;
12988: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12989: if (ref($lastactref) eq 'HASH') {
12990: $lastactref->{'domdefaults'} = 1;
12991: }
1.121 raeburn 12992: }
12993: $resulttext = &mt('Changes made:').'<ul>';
12994: foreach my $item (sort(keys(%changes))) {
12995: if ($item eq 'canuse_pdfforms') {
12996: if ($env{'form.'.$item} eq '1') {
12997: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
12998: } else {
12999: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
13000: }
1.257 raeburn 13001: } elsif ($item eq 'uselcmath') {
13002: if ($env{'form.'.$item} eq '1') {
13003: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
13004: } else {
13005: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
13006: }
13007: } elsif ($item eq 'usejsme') {
13008: if ($env{'form.'.$item} eq '1') {
13009: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
13010: } else {
1.289 ! raeburn 13011: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 13012: }
1.139 raeburn 13013: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 13014: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 13015: } elsif ($item eq 'uploadquota') {
13016: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13017: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
13018: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
13019: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 13020: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 13021: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 13022: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
13023: '</ul>'.
13024: '</li>';
13025: } else {
13026: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
13027: }
1.276 raeburn 13028: } elsif ($item eq 'mysqltables') {
13029: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
13030: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
13031: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
13032: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
13033: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
13034: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
13035: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
13036: '</ul>'.
13037: '</li>';
13038: } else {
13039: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
13040: }
1.257 raeburn 13041: } elsif ($item eq 'postsubmit') {
13042: if ($domdefaults{'postsubmit'} eq 'off') {
13043: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
13044: } else {
13045: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 ! raeburn 13046: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 13047: $resulttext .= &mt('durations:').'<ul>';
13048: foreach my $type (@types) {
13049: $resulttext .= '<li>';
13050: my $timeout;
13051: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13052: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13053: }
13054: my $display;
13055: if ($timeout eq '0') {
13056: $display = &mt('unlimited');
13057: } elsif ($timeout eq '') {
13058: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
13059: } else {
13060: $display = &mt('[quant,_1,second]',$timeout);
13061: }
13062: if ($type eq 'community') {
13063: $resulttext .= &mt('Communities');
13064: } elsif ($type eq 'official') {
13065: $resulttext .= &mt('Official courses');
13066: } elsif ($type eq 'unofficial') {
13067: $resulttext .= &mt('Unofficial courses');
13068: } elsif ($type eq 'textbook') {
13069: $resulttext .= &mt('Textbook courses');
1.271 raeburn 13070: } elsif ($type eq 'placement') {
13071: $resulttext .= &mt('Placement tests');
1.257 raeburn 13072: }
13073: $resulttext .= ' -- '.$display.'</li>';
13074: }
13075: $resulttext .= '</ul>';
13076: }
1.289 ! raeburn 13077: $resulttext .= '</li>';
1.257 raeburn 13078: }
1.192 raeburn 13079: } elsif ($item eq 'coursecredits') {
13080: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13081: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 13082: ($domdefaults{'unofficialcredits'} eq '') &&
13083: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 13084: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13085: } else {
13086: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
13087: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
13088: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 13089: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 13090: '</ul>'.
13091: '</li>';
13092: }
13093: } else {
13094: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13095: }
1.264 raeburn 13096: } elsif ($item eq 'canclone') {
13097: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13098: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13099: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
13100: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
13101: }
13102: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
13103: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
13104: } else {
1.289 ! raeburn 13105: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 13106: }
1.140 raeburn 13107: }
1.121 raeburn 13108: }
13109: $resulttext .= '</ul>';
13110: } else {
13111: $resulttext = &mt('No changes made to course defaults');
13112: }
13113: } else {
13114: $resulttext = '<span class="LC_error">'.
13115: &mt('An error occurred: [_1]',$putresult).'</span>';
13116: }
13117: return $resulttext;
13118: }
13119:
1.231 raeburn 13120: sub modify_selfenrollment {
13121: my ($dom,$lastactref,%domconfig) = @_;
13122: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 13123: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 13124: my %titles = &tool_titles();
1.232 raeburn 13125: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
13126: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 13127: $ordered{'default'} = ['types','registered','approval','limit'];
13128:
13129: my (%roles,%shown,%toplevel);
13130: $roles{'0'} = &Apache::lonnet::plaintext('dc');
13131:
13132: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
13133: if ($domconfig{'selfenrollment'} eq '') {
13134: $domconfig{'selfenrollment'} = {};
13135: }
13136: }
13137: %toplevel = (
13138: admin => 'Configuration Rights',
13139: default => 'Default settings',
13140: validation => 'Validation of self-enrollment requests',
13141: );
1.233 raeburn 13142: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 13143:
13144: if (ref($ordered{'admin'}) eq 'ARRAY') {
13145: foreach my $item (@{$ordered{'admin'}}) {
13146: foreach my $type (@types) {
13147: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
13148: $selfenrollhash{'admin'}{$type}{$item} = 1;
13149: } else {
13150: $selfenrollhash{'admin'}{$type}{$item} = 0;
13151: }
13152: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
13153: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
13154: if ($selfenrollhash{'admin'}{$type}{$item} ne
13155: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
13156: push(@{$changes{'admin'}{$type}},$item);
13157: }
13158: } else {
13159: if (!$selfenrollhash{'admin'}{$type}{$item}) {
13160: push(@{$changes{'admin'}{$type}},$item);
13161: }
13162: }
13163: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
13164: push(@{$changes{'admin'}{$type}},$item);
13165: }
13166: }
13167: }
13168: }
13169:
13170: foreach my $item (@{$ordered{'default'}}) {
13171: foreach my $type (@types) {
13172: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
13173: if ($item eq 'types') {
13174: unless (($value eq 'all') || ($value eq 'dom')) {
13175: $value = '';
13176: }
13177: } elsif ($item eq 'registered') {
13178: unless ($value eq '1') {
13179: $value = 0;
13180: }
13181: } elsif ($item eq 'approval') {
13182: unless ($value =~ /^[012]$/) {
13183: $value = 0;
13184: }
13185: } else {
13186: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13187: $value = 'none';
13188: }
13189: }
13190: $selfenrollhash{'default'}{$type}{$item} = $value;
13191: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
13192: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13193: if ($selfenrollhash{'default'}{$type}{$item} ne
13194: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
13195: push(@{$changes{'default'}{$type}},$item);
13196: }
13197: } else {
13198: push(@{$changes{'default'}{$type}},$item);
13199: }
13200: } else {
13201: push(@{$changes{'default'}{$type}},$item);
13202: }
13203: if ($item eq 'limit') {
13204: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13205: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
13206: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
13207: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
13208: }
13209: } else {
13210: $selfenrollhash{'default'}{$type}{'cap'} = '';
13211: }
13212: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13213: if ($selfenrollhash{'default'}{$type}{'cap'} ne
13214: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
13215: push(@{$changes{'default'}{$type}},'cap');
13216: }
13217: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
13218: push(@{$changes{'default'}{$type}},'cap');
13219: }
13220: }
13221: }
13222: }
13223:
13224: foreach my $item (@{$itemsref}) {
13225: if ($item eq 'fields') {
13226: my @changed;
13227: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
13228: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
13229: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
13230: }
13231: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13232: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
13233: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
13234: $domconfig{'selfenrollment'}{'validation'}{$item});
13235: } else {
13236: @changed = @{$selfenrollhash{'validation'}{$item}};
13237: }
13238: } else {
13239: @changed = @{$selfenrollhash{'validation'}{$item}};
13240: }
13241: if (@changed) {
13242: if ($selfenrollhash{'validation'}{$item}) {
13243: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
13244: } else {
13245: $changes{'validation'}{$item} = &mt('None');
13246: }
13247: }
13248: } else {
13249: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
13250: if ($item eq 'markup') {
13251: if ($env{'form.selfenroll_validation_'.$item}) {
13252: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13253: }
13254: }
13255: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13256: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
13257: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
13258: }
13259: }
13260: }
13261: }
13262:
13263: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
13264: $dom);
13265: if ($putresult eq 'ok') {
13266: if (keys(%changes) > 0) {
13267: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13268: $resulttext = &mt('Changes made:').'<ul>';
13269: foreach my $key ('admin','default','validation') {
13270: if (ref($changes{$key}) eq 'HASH') {
13271: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
13272: if ($key eq 'validation') {
13273: foreach my $item (@{$itemsref}) {
13274: if (exists($changes{$key}{$item})) {
13275: if ($item eq 'markup') {
13276: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13277: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
13278: } else {
13279: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13280: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
13281: }
13282: }
13283: }
13284: } else {
13285: foreach my $type (@types) {
13286: if ($type eq 'community') {
13287: $roles{'1'} = &mt('Community personnel');
13288: } else {
13289: $roles{'1'} = &mt('Course personnel');
13290: }
13291: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 13292: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13293: if ($key eq 'admin') {
13294: my @mgrdc = ();
13295: if (ref($ordered{$key}) eq 'ARRAY') {
13296: foreach my $item (@{$ordered{'admin'}}) {
13297: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13298: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
13299: push(@mgrdc,$item);
13300: }
13301: }
13302: }
13303: if (@mgrdc) {
13304: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
13305: } else {
13306: delete($domdefaults{$type.'selfenrolladmdc'});
13307: }
13308: }
13309: } else {
13310: if (ref($ordered{$key}) eq 'ARRAY') {
13311: foreach my $item (@{$ordered{$key}}) {
13312: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13313: $domdefaults{$type.'selfenroll'.$item} =
13314: $selfenrollhash{$key}{$type}{$item};
13315: }
13316: }
13317: }
13318: }
13319: }
1.231 raeburn 13320: $resulttext .= '<li>'.$titles{$type}.'<ul>';
13321: foreach my $item (@{$ordered{$key}}) {
13322: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13323: $resulttext .= '<li>';
13324: if ($key eq 'admin') {
13325: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
13326: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
13327: } else {
13328: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
13329: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
13330: }
13331: $resulttext .= '</li>';
13332: }
13333: }
13334: $resulttext .= '</ul></li>';
13335: }
13336: }
13337: $resulttext .= '</ul></li>';
13338: }
13339: }
1.232 raeburn 13340: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
13341: my $cachetime = 24*60*60;
13342: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13343: if (ref($lastactref) eq 'HASH') {
13344: $lastactref->{'domdefaults'} = 1;
13345: }
13346: }
1.231 raeburn 13347: }
13348: $resulttext .= '</ul>';
13349: } else {
13350: $resulttext = &mt('No changes made to self-enrollment settings');
13351: }
13352: } else {
13353: $resulttext = '<span class="LC_error">'.
13354: &mt('An error occurred: [_1]',$putresult).'</span>';
13355: }
13356: return $resulttext;
13357: }
13358:
1.137 raeburn 13359: sub modify_usersessions {
1.212 raeburn 13360: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 13361: my @hostingtypes = ('version','excludedomain','includedomain');
13362: my @offloadtypes = ('primary','default');
13363: my %types = (
13364: remote => \@hostingtypes,
13365: hosted => \@hostingtypes,
13366: spares => \@offloadtypes,
13367: );
13368: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 13369: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 13370: my (%by_ip,%by_location,@intdoms,@instdoms);
13371: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 13372: my @locations = sort(keys(%by_location));
1.137 raeburn 13373: my (%defaultshash,%changes);
13374: foreach my $prefix (@prefixes) {
13375: $defaultshash{'usersessions'}{$prefix} = {};
13376: }
1.212 raeburn 13377: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 13378: my $resulttext;
1.138 raeburn 13379: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 13380: foreach my $prefix (@prefixes) {
1.145 raeburn 13381: next if ($prefix eq 'spares');
13382: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 13383: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13384: if ($type eq 'version') {
13385: my $value = $env{'form.'.$prefix.'_'.$type};
13386: my $okvalue;
13387: if ($value ne '') {
13388: if (grep(/^\Q$value\E$/,@lcversions)) {
13389: $okvalue = $value;
13390: }
13391: }
13392: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13393: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13394: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
13395: if ($inuse == 0) {
13396: $changes{$prefix}{$type} = 1;
13397: } else {
13398: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
13399: $changes{$prefix}{$type} = 1;
13400: }
13401: if ($okvalue ne '') {
13402: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13403: }
13404: }
13405: } else {
13406: if (($inuse == 1) && ($okvalue ne '')) {
13407: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13408: $changes{$prefix}{$type} = 1;
13409: }
13410: }
13411: } else {
13412: if (($inuse == 1) && ($okvalue ne '')) {
13413: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13414: $changes{$prefix}{$type} = 1;
13415: }
13416: }
13417: } else {
13418: if (($inuse == 1) && ($okvalue ne '')) {
13419: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13420: $changes{$prefix}{$type} = 1;
13421: }
13422: }
13423: } else {
13424: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13425: my @okvals;
13426: foreach my $val (@vals) {
1.138 raeburn 13427: if ($val =~ /:/) {
13428: my @items = split(/:/,$val);
13429: foreach my $item (@items) {
13430: if (ref($by_location{$item}) eq 'ARRAY') {
13431: push(@okvals,$item);
13432: }
13433: }
13434: } else {
13435: if (ref($by_location{$val}) eq 'ARRAY') {
13436: push(@okvals,$val);
13437: }
1.137 raeburn 13438: }
13439: }
13440: @okvals = sort(@okvals);
13441: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13442: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13443: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13444: if ($inuse == 0) {
13445: $changes{$prefix}{$type} = 1;
13446: } else {
13447: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13448: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
13449: if (@changed > 0) {
13450: $changes{$prefix}{$type} = 1;
13451: }
13452: }
13453: } else {
13454: if ($inuse == 1) {
13455: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13456: $changes{$prefix}{$type} = 1;
13457: }
13458: }
13459: } else {
13460: if ($inuse == 1) {
13461: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13462: $changes{$prefix}{$type} = 1;
13463: }
13464: }
13465: } else {
13466: if ($inuse == 1) {
13467: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13468: $changes{$prefix}{$type} = 1;
13469: }
13470: }
13471: }
13472: }
13473: }
1.145 raeburn 13474:
13475: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 13476: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 13477: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
13478: my $savespares;
13479:
13480: foreach my $lonhost (sort(keys(%servers))) {
13481: my $serverhomeID =
13482: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 13483: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 13484: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
13485: my %spareschg;
13486: foreach my $type (@{$types{'spares'}}) {
13487: my @okspares;
13488: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
13489: foreach my $server (@checked) {
1.152 raeburn 13490: if (&Apache::lonnet::hostname($server) ne '') {
13491: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
13492: unless (grep(/^\Q$server\E$/,@okspares)) {
13493: push(@okspares,$server);
13494: }
1.145 raeburn 13495: }
13496: }
13497: }
13498: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
13499: my $newspare;
1.152 raeburn 13500: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
13501: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 13502: $newspare = $new;
13503: }
13504: }
1.152 raeburn 13505: my @spares;
13506: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
13507: @spares = sort(@okspares,$newspare);
13508: } else {
13509: @spares = sort(@okspares);
13510: }
13511: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 13512: if (ref($spareid{$lonhost}) eq 'HASH') {
13513: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 13514: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 13515: if (@diffs > 0) {
13516: $spareschg{$type} = 1;
13517: }
13518: }
13519: }
13520: }
13521: if (keys(%spareschg) > 0) {
13522: $changes{'spares'}{$lonhost} = \%spareschg;
13523: }
13524: }
1.261 raeburn 13525: $defaultshash{'usersessions'}{'offloadnow'} = {};
13526: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
13527: my @okoffload;
13528: if (@offloadnow) {
13529: foreach my $server (@offloadnow) {
13530: if (&Apache::lonnet::hostname($server) ne '') {
13531: unless (grep(/^\Q$server\E$/,@okoffload)) {
13532: push(@okoffload,$server);
13533: }
13534: }
13535: }
13536: if (@okoffload) {
13537: foreach my $lonhost (@okoffload) {
13538: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
13539: }
13540: }
13541: }
1.145 raeburn 13542: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13543: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
13544: if (ref($changes{'spares'}) eq 'HASH') {
13545: if (keys(%{$changes{'spares'}}) > 0) {
13546: $savespares = 1;
13547: }
13548: }
13549: } else {
13550: $savespares = 1;
13551: }
1.261 raeburn 13552: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
13553: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
13554: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
13555: $changes{'offloadnow'} = 1;
13556: last;
13557: }
13558: }
13559: unless ($changes{'offloadnow'}) {
1.289 ! raeburn 13560: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 13561: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
13562: $changes{'offloadnow'} = 1;
13563: last;
13564: }
13565: }
13566: }
13567: } elsif (@okoffload) {
13568: $changes{'offloadnow'} = 1;
13569: }
13570: } elsif (@okoffload) {
13571: $changes{'offloadnow'} = 1;
1.145 raeburn 13572: }
1.147 raeburn 13573: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
13574: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 13575: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13576: $dom);
13577: if ($putresult eq 'ok') {
13578: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13579: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
13580: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
13581: }
13582: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
13583: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
13584: }
1.261 raeburn 13585: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13586: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
13587: }
1.137 raeburn 13588: }
13589: my $cachetime = 24*60*60;
13590: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13591: if (ref($lastactref) eq 'HASH') {
13592: $lastactref->{'domdefaults'} = 1;
13593: }
1.147 raeburn 13594: if (keys(%changes) > 0) {
13595: my %lt = &usersession_titles();
13596: $resulttext = &mt('Changes made:').'<ul>';
13597: foreach my $prefix (@prefixes) {
13598: if (ref($changes{$prefix}) eq 'HASH') {
13599: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
13600: if ($prefix eq 'spares') {
13601: if (ref($changes{$prefix}) eq 'HASH') {
13602: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
13603: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 13604: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 13605: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
13606: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 13607: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
13608: foreach my $type (@{$types{$prefix}}) {
13609: if ($changes{$prefix}{$lonhost}{$type}) {
13610: my $offloadto = &mt('None');
13611: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
13612: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
13613: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
13614: }
1.145 raeburn 13615: }
1.147 raeburn 13616: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 13617: }
1.137 raeburn 13618: }
13619: }
1.147 raeburn 13620: $resulttext .= '</li>';
1.137 raeburn 13621: }
13622: }
1.147 raeburn 13623: } else {
13624: foreach my $type (@{$types{$prefix}}) {
13625: if (defined($changes{$prefix}{$type})) {
13626: my $newvalue;
13627: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13628: if (ref($defaultshash{'usersessions'}{$prefix})) {
13629: if ($type eq 'version') {
13630: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
13631: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13632: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
13633: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
13634: }
1.145 raeburn 13635: }
13636: }
13637: }
1.147 raeburn 13638: if ($newvalue eq '') {
13639: if ($type eq 'version') {
13640: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
13641: } else {
13642: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
13643: }
1.145 raeburn 13644: } else {
1.147 raeburn 13645: if ($type eq 'version') {
13646: $newvalue .= ' '.&mt('(or later)');
13647: }
13648: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 13649: }
1.137 raeburn 13650: }
13651: }
13652: }
1.147 raeburn 13653: $resulttext .= '</ul>';
1.137 raeburn 13654: }
13655: }
1.261 raeburn 13656: if ($changes{'offloadnow'}) {
13657: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13658: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
13659: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
13660: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
13661: $resulttext .= '<li>'.$lonhost.'</li>';
13662: }
13663: $resulttext .= '</ul>';
13664: } else {
13665: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
13666: }
13667: } else {
13668: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
13669: }
13670: }
1.147 raeburn 13671: $resulttext .= '</ul>';
13672: } else {
13673: $resulttext = $nochgmsg;
1.137 raeburn 13674: }
13675: } else {
13676: $resulttext = '<span class="LC_error">'.
13677: &mt('An error occurred: [_1]',$putresult).'</span>';
13678: }
13679: } else {
1.147 raeburn 13680: $resulttext = $nochgmsg;
1.137 raeburn 13681: }
13682: return $resulttext;
13683: }
13684:
1.275 raeburn 13685: sub modify_ssl {
13686: my ($dom,$lastactref,%domconfig) = @_;
13687: my (%by_ip,%by_location,@intdoms,@instdoms);
13688: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
13689: my @locations = sort(keys(%by_location));
13690: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13691: my (%defaultshash,%changes);
13692: my $action = 'ssl';
13693: my @prefixes = ('connect','replication');
13694: foreach my $prefix (@prefixes) {
13695: $defaultshash{$action}{$prefix} = {};
13696: }
13697: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13698: my $resulttext;
13699: my %iphost = &Apache::lonnet::get_iphost();
13700: my @reptypes = ('certreq','nocertreq');
13701: my @connecttypes = ('dom','intdom','other');
13702: my %types = (
13703: connect => \@connecttypes,
13704: replication => \@reptypes,
13705: );
13706: foreach my $prefix (sort(keys(%types))) {
13707: foreach my $type (@{$types{$prefix}}) {
13708: if ($prefix eq 'connect') {
13709: my $value = 'yes';
13710: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
13711: $value = $env{'form.'.$prefix.'_'.$type};
13712: }
13713: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
13714: if ($domconfig{$action}{$prefix}{$type} ne '') {
13715: if ($value ne $domconfig{$action}{$prefix}{$type}) {
13716: $changes{$prefix}{$type} = 1;
13717: }
13718: $defaultshash{$action}{$prefix}{$type} = $value;
13719: } else {
13720: $defaultshash{$action}{$prefix}{$type} = $value;
13721: $changes{$prefix}{$type} = 1;
13722: }
13723: } else {
13724: $defaultshash{$action}{$prefix}{$type} = $value;
13725: $changes{$prefix}{$type} = 1;
13726: }
13727: if (($type eq 'dom') && (keys(%servers) == 1)) {
13728: delete($changes{$prefix}{$type});
13729: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
13730: delete($changes{$prefix}{$type});
13731: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
13732: delete($changes{$prefix}{$type});
13733: }
13734: } elsif ($prefix eq 'replication') {
13735: if (@locations > 0) {
13736: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13737: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13738: my @okvals;
13739: foreach my $val (@vals) {
13740: if ($val =~ /:/) {
13741: my @items = split(/:/,$val);
13742: foreach my $item (@items) {
13743: if (ref($by_location{$item}) eq 'ARRAY') {
13744: push(@okvals,$item);
13745: }
13746: }
13747: } else {
13748: if (ref($by_location{$val}) eq 'ARRAY') {
13749: push(@okvals,$val);
13750: }
13751: }
13752: }
13753: @okvals = sort(@okvals);
13754: if (ref($domconfig{$action}) eq 'HASH') {
13755: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
13756: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
13757: if ($inuse == 0) {
13758: $changes{$prefix}{$type} = 1;
13759: } else {
13760: $defaultshash{$action}{$prefix}{$type} = \@okvals;
13761: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
13762: if (@changed > 0) {
13763: $changes{$prefix}{$type} = 1;
13764: }
13765: }
13766: } else {
13767: if ($inuse == 1) {
13768: $defaultshash{$action}{$prefix}{$type} = \@okvals;
13769: $changes{$prefix}{$type} = 1;
13770: }
13771: }
13772: } else {
13773: if ($inuse == 1) {
13774: $defaultshash{$action}{$prefix}{$type} = \@okvals;
13775: $changes{$prefix}{$type} = 1;
13776: }
13777: }
13778: } else {
13779: if ($inuse == 1) {
13780: $defaultshash{$action}{$prefix}{$type} = \@okvals;
13781: $changes{$prefix}{$type} = 1;
13782: }
13783: }
13784: }
13785: }
13786: }
13787: }
13788: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
13789: if (keys(%changes) > 0) {
13790: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13791: $dom);
13792: if ($putresult eq 'ok') {
13793: if (ref($defaultshash{$action}) eq 'HASH') {
13794: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
13795: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
13796: }
13797: if (ref($defaultshash{$action}{'connect'}) eq 'HASH') {
13798: $domdefaults{'connect'} = $domconfig{$action}{'connect'};
13799: }
13800: }
13801: my $cachetime = 24*60*60;
13802: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13803: if (ref($lastactref) eq 'HASH') {
13804: $lastactref->{'domdefaults'} = 1;
13805: }
13806: if (keys(%changes) > 0) {
13807: my %titles = &ssl_titles();
13808: $resulttext = &mt('Changes made:').'<ul>';
13809: foreach my $prefix (@prefixes) {
13810: if (ref($changes{$prefix}) eq 'HASH') {
13811: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
13812: foreach my $type (@{$types{$prefix}}) {
13813: if (defined($changes{$prefix}{$type})) {
13814: my $newvalue;
13815: if (ref($defaultshash{$action}) eq 'HASH') {
13816: if (ref($defaultshash{$action}{$prefix})) {
13817: if ($prefix eq 'connect') {
13818: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
13819: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
13820: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
13821: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
13822: }
13823: }
13824: }
13825: if ($newvalue eq '') {
13826: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
13827: } else {
13828: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
13829: }
13830: }
13831: }
13832: }
13833: $resulttext .= '</ul>';
13834: }
13835: }
13836: } else {
13837: $resulttext = $nochgmsg;
13838: }
13839: } else {
13840: $resulttext = '<span class="LC_error">'.
13841: &mt('An error occurred: [_1]',$putresult).'</span>';
13842: }
13843: } else {
13844: $resulttext = $nochgmsg;
13845: }
13846: return $resulttext;
13847: }
13848:
1.279 raeburn 13849: sub modify_trust {
13850: my ($dom,$lastactref,%domconfig) = @_;
13851: my (%by_ip,%by_location,@intdoms,@instdoms);
13852: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
13853: my @locations = sort(keys(%by_location));
13854: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
13855: my @types = ('exc','inc');
13856: my (%defaultshash,%changes);
13857: foreach my $prefix (@prefixes) {
13858: $defaultshash{'trust'}{$prefix} = {};
13859: }
13860: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13861: my $resulttext;
13862: foreach my $prefix (@prefixes) {
13863: foreach my $type (@types) {
13864: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13865: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13866: my @okvals;
13867: foreach my $val (@vals) {
13868: if ($val =~ /:/) {
13869: my @items = split(/:/,$val);
13870: foreach my $item (@items) {
13871: if (ref($by_location{$item}) eq 'ARRAY') {
13872: push(@okvals,$item);
13873: }
13874: }
13875: } else {
13876: if (ref($by_location{$val}) eq 'ARRAY') {
13877: push(@okvals,$val);
13878: }
13879: }
13880: }
13881: @okvals = sort(@okvals);
13882: if (ref($domconfig{'trust'}) eq 'HASH') {
13883: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
13884: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
13885: if ($inuse == 0) {
13886: $changes{$prefix}{$type} = 1;
13887: } else {
13888: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
13889: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
13890: if (@changed > 0) {
13891: $changes{$prefix}{$type} = 1;
13892: }
13893: }
13894: } else {
13895: if ($inuse == 1) {
13896: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
13897: $changes{$prefix}{$type} = 1;
13898: }
13899: }
13900: } else {
13901: if ($inuse == 1) {
13902: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
13903: $changes{$prefix}{$type} = 1;
13904: }
13905: }
13906: } else {
13907: if ($inuse == 1) {
13908: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
13909: $changes{$prefix}{$type} = 1;
13910: }
13911: }
13912: }
13913: }
13914: my $nochgmsg = &mt('No changes made to trust settings.');
13915: if (keys(%changes) > 0) {
13916: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13917: $dom);
13918: if ($putresult eq 'ok') {
13919: if (ref($defaultshash{'trust'}) eq 'HASH') {
13920: foreach my $prefix (@prefixes) {
13921: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
13922: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
13923: }
13924: }
13925: }
13926: my $cachetime = 24*60*60;
13927: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13928: if (ref($lastactref) eq 'HASH') {
13929: $lastactref->{'domdefaults'} = 1;
13930: }
13931: if (keys(%changes) > 0) {
13932: my %lt = &trust_titles();
13933: $resulttext = &mt('Changes made:').'<ul>';
13934: foreach my $prefix (@prefixes) {
13935: if (ref($changes{$prefix}) eq 'HASH') {
13936: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
13937: foreach my $type (@types) {
13938: if (defined($changes{$prefix}{$type})) {
13939: my $newvalue;
13940: if (ref($defaultshash{'trust'}) eq 'HASH') {
13941: if (ref($defaultshash{'trust'}{$prefix})) {
13942: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
13943: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
13944: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
13945: }
13946: }
13947: }
13948: }
13949: if ($newvalue eq '') {
13950: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
13951: } else {
13952: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
13953: }
13954: }
13955: }
13956: $resulttext .= '</ul>';
13957: }
13958: }
13959: $resulttext .= '</ul>';
13960: } else {
13961: $resulttext = $nochgmsg;
13962: }
13963: } else {
13964: $resulttext = '<span class="LC_error">'.
13965: &mt('An error occurred: [_1]',$putresult).'</span>';
13966: }
13967: } else {
13968: $resulttext = $nochgmsg;
13969: }
13970: return $resulttext;
13971: }
13972:
1.150 raeburn 13973: sub modify_loadbalancing {
13974: my ($dom,%domconfig) = @_;
13975: my $primary_id = &Apache::lonnet::domain($dom,'primary');
13976: my $intdom = &Apache::lonnet::internet_dom($primary_id);
13977: my ($othertitle,$usertypes,$types) =
13978: &Apache::loncommon::sorted_inst_types($dom);
13979: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 13980: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 13981: my @sparestypes = ('primary','default');
13982: my %typetitles = &sparestype_titles();
13983: my $resulttext;
1.171 raeburn 13984: my (%currbalancer,%currtargets,%currrules,%existing);
13985: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13986: %existing = %{$domconfig{'loadbalancing'}};
13987: }
13988: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
13989: \%currtargets,\%currrules);
13990: my ($saveloadbalancing,%defaultshash,%changes);
13991: my ($alltypes,$othertypes,$titles) =
13992: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
13993: my %ruletitles = &offloadtype_text();
13994: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
13995: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
13996: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
13997: if ($balancer eq '') {
13998: next;
13999: }
1.210 raeburn 14000: if (!exists($servers{$balancer})) {
1.171 raeburn 14001: if (exists($currbalancer{$balancer})) {
14002: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 14003: }
1.171 raeburn 14004: next;
14005: }
14006: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
14007: push(@{$changes{'delete'}},$balancer);
14008: next;
14009: }
14010: if (!exists($currbalancer{$balancer})) {
14011: push(@{$changes{'add'}},$balancer);
14012: }
14013: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
14014: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
14015: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
14016: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14017: $saveloadbalancing = 1;
14018: }
14019: foreach my $sparetype (@sparestypes) {
14020: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
14021: my @offloadto;
14022: foreach my $target (@targets) {
14023: if (($servers{$target}) && ($target ne $balancer)) {
14024: if ($sparetype eq 'default') {
14025: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
14026: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 14027: }
14028: }
1.171 raeburn 14029: unless(grep(/^\Q$target\E$/,@offloadto)) {
14030: push(@offloadto,$target);
14031: }
1.150 raeburn 14032: }
14033: }
1.284 raeburn 14034: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
14035: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
14036: push(@offloadto,$balancer);
14037: }
14038: }
14039: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 14040: }
1.171 raeburn 14041: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 14042: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14043: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
14044: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 14045: if (@targetdiffs > 0) {
1.171 raeburn 14046: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14047: }
1.171 raeburn 14048: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14049: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14050: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14051: }
14052: }
14053: }
14054: } else {
1.171 raeburn 14055: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 14056: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14057: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14058: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14059: $changes{'curr'}{$balancer}{'targets'} = 1;
14060: }
1.150 raeburn 14061: }
14062: }
1.210 raeburn 14063: }
1.150 raeburn 14064: }
14065: my $ishomedom;
1.171 raeburn 14066: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
14067: $ishomedom = 1;
1.150 raeburn 14068: }
14069: if (ref($alltypes) eq 'ARRAY') {
14070: foreach my $type (@{$alltypes}) {
14071: my $rule;
1.210 raeburn 14072: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 14073: (!$ishomedom)) {
1.171 raeburn 14074: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
14075: }
14076: if ($rule eq 'specific') {
1.255 raeburn 14077: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 ! raeburn 14078: if (exists($servers{$specifiedhost})) {
1.255 raeburn 14079: $rule = $specifiedhost;
14080: }
1.150 raeburn 14081: }
1.171 raeburn 14082: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
14083: if (ref($currrules{$balancer}) eq 'HASH') {
14084: if ($rule ne $currrules{$balancer}{$type}) {
14085: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14086: }
14087: } elsif ($rule ne '') {
1.171 raeburn 14088: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14089: }
14090: }
14091: }
1.171 raeburn 14092: }
14093: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
14094: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
14095: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
14096: $defaultshash{'loadbalancing'} = {};
14097: }
14098: my $putresult = &Apache::lonnet::put_dom('configuration',
14099: \%defaultshash,$dom);
14100: if ($putresult eq 'ok') {
14101: if (keys(%changes) > 0) {
1.252 raeburn 14102: my %toupdate;
1.171 raeburn 14103: if (ref($changes{'delete'}) eq 'ARRAY') {
14104: foreach my $balancer (sort(@{$changes{'delete'}})) {
14105: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 14106: $toupdate{$balancer} = 1;
1.150 raeburn 14107: }
1.171 raeburn 14108: }
14109: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 14110: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 14111: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 14112: $toupdate{$balancer} = 1;
1.171 raeburn 14113: }
14114: }
14115: if (ref($changes{'curr'}) eq 'HASH') {
14116: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 14117: $toupdate{$balancer} = 1;
1.171 raeburn 14118: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
14119: if ($changes{'curr'}{$balancer}{'targets'}) {
14120: my %offloadstr;
14121: foreach my $sparetype (@sparestypes) {
14122: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14123: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14124: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14125: }
14126: }
1.150 raeburn 14127: }
1.171 raeburn 14128: if (keys(%offloadstr) == 0) {
14129: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 14130: } else {
1.171 raeburn 14131: my $showoffload;
14132: foreach my $sparetype (@sparestypes) {
14133: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
14134: if (defined($offloadstr{$sparetype})) {
14135: $showoffload .= $offloadstr{$sparetype};
14136: } else {
14137: $showoffload .= &mt('None');
14138: }
14139: $showoffload .= (' 'x3);
14140: }
14141: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 14142: }
14143: }
14144: }
1.171 raeburn 14145: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
14146: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
14147: foreach my $type (@{$alltypes}) {
14148: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
14149: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14150: my $balancetext;
14151: if ($rule eq '') {
14152: $balancetext = $ruletitles{'default'};
1.209 raeburn 14153: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 ! raeburn 14154: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 14155: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 14156: foreach my $sparetype (@sparestypes) {
14157: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14158: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14159: }
14160: }
1.253 raeburn 14161: foreach my $item (@{$alltypes}) {
14162: next if ($item =~ /^_LC_ipchange/);
14163: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
14164: if ($hasrule eq 'homeserver') {
14165: map { $toupdate{$_} = 1; } (keys(%libraryservers));
14166: } else {
14167: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
14168: if ($servers{$hasrule}) {
14169: $toupdate{$hasrule} = 1;
14170: }
14171: }
14172: }
14173: }
1.254 raeburn 14174: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
14175: $balancetext = $ruletitles{$rule};
14176: } else {
14177: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14178: $balancetext = $ruletitles{'particular'}.' '.$receiver;
14179: if ($receiver) {
14180: $toupdate{$receiver};
14181: }
14182: }
14183: } else {
14184: $balancetext = $ruletitles{$rule};
1.252 raeburn 14185: }
1.171 raeburn 14186: } else {
14187: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
14188: }
1.210 raeburn 14189: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 14190: }
14191: }
14192: }
14193: }
1.252 raeburn 14194: if (keys(%toupdate)) {
14195: my %thismachine;
14196: my $updatedhere;
14197: my $cachetime = 60*60*24;
14198: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
14199: foreach my $lonhost (keys(%toupdate)) {
14200: if ($thismachine{$lonhost}) {
14201: unless ($updatedhere) {
14202: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
14203: $defaultshash{'loadbalancing'},
14204: $cachetime);
14205: $updatedhere = 1;
14206: }
14207: } else {
14208: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
14209: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
14210: }
14211: }
14212: }
1.150 raeburn 14213: }
1.171 raeburn 14214: }
14215: if ($resulttext ne '') {
14216: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 14217: } else {
14218: $resulttext = $nochgmsg;
14219: }
14220: } else {
1.171 raeburn 14221: $resulttext = $nochgmsg;
1.150 raeburn 14222: }
14223: } else {
1.171 raeburn 14224: $resulttext = '<span class="LC_error">'.
14225: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 14226: }
14227: } else {
1.171 raeburn 14228: $resulttext = $nochgmsg;
1.150 raeburn 14229: }
14230: return $resulttext;
14231: }
14232:
1.48 raeburn 14233: sub recurse_check {
14234: my ($chkcats,$categories,$depth,$name) = @_;
14235: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
14236: my $chg = 0;
14237: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
14238: my $category = $chkcats->[$depth]{$name}[$j];
14239: my $item;
14240: if ($category eq '') {
14241: $chg ++;
14242: } else {
14243: my $deeper = $depth + 1;
14244: $item = &escape($category).':'.&escape($name).':'.$depth;
14245: if ($chg) {
14246: $categories->{$item} -= $chg;
14247: }
14248: &recurse_check($chkcats,$categories,$deeper,$category);
14249: $deeper --;
14250: }
14251: }
14252: }
14253: return;
14254: }
14255:
14256: sub recurse_cat_deletes {
14257: my ($item,$coursecategories,$deletions) = @_;
14258: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14259: my $subdepth = $depth + 1;
14260: if (ref($coursecategories) eq 'HASH') {
14261: foreach my $subitem (keys(%{$coursecategories})) {
14262: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
14263: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
14264: delete($coursecategories->{$subitem});
14265: $deletions->{$subitem} = 1;
14266: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 14267: }
1.48 raeburn 14268: }
14269: }
14270: return;
14271: }
14272:
1.125 raeburn 14273: sub active_dc_picker {
1.191 raeburn 14274: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 14275: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 14276: my @domcoord = keys(%domcoords);
14277: if (keys(%currhash)) {
14278: foreach my $dc (keys(%currhash)) {
14279: unless (exists($domcoords{$dc})) {
14280: push(@domcoord,$dc);
14281: }
14282: }
14283: }
14284: @domcoord = sort(@domcoord);
1.210 raeburn 14285: my $numdcs = scalar(@domcoord);
1.191 raeburn 14286: my $rows = 0;
14287: my $table;
1.125 raeburn 14288: if ($numdcs > 1) {
1.191 raeburn 14289: $table = '<table>';
14290: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 14291: my $rem = $i%($numinrow);
14292: if ($rem == 0) {
14293: if ($i > 0) {
1.191 raeburn 14294: $table .= '</tr>';
1.125 raeburn 14295: }
1.191 raeburn 14296: $table .= '<tr>';
14297: $rows ++;
1.125 raeburn 14298: }
1.191 raeburn 14299: my $check = '';
14300: if ($inputtype eq 'radio') {
14301: if (keys(%currhash) == 0) {
14302: if (!$i) {
14303: $check = ' checked="checked"';
14304: }
14305: } elsif (exists($currhash{$domcoord[$i]})) {
14306: $check = ' checked="checked"';
14307: }
14308: } else {
14309: if (exists($currhash{$domcoord[$i]})) {
14310: $check = ' checked="checked"';
1.125 raeburn 14311: }
14312: }
1.191 raeburn 14313: if ($i == @domcoord - 1) {
1.125 raeburn 14314: my $colsleft = $numinrow - $rem;
14315: if ($colsleft > 1) {
1.191 raeburn 14316: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 14317: } else {
1.191 raeburn 14318: $table .= '<td class="LC_left_item">';
1.125 raeburn 14319: }
14320: } else {
1.191 raeburn 14321: $table .= '<td class="LC_left_item">';
14322: }
14323: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
14324: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
14325: $table .= '<span class="LC_nobreak"><label>'.
14326: '<input type="'.$inputtype.'" name="'.$name.'"'.
14327: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
14328: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 14329: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 14330: }
1.219 raeburn 14331: $table .= '</label></span></td>';
1.191 raeburn 14332: }
14333: $table .= '</tr></table>';
14334: } elsif ($numdcs == 1) {
1.219 raeburn 14335: my ($dcname,$dcdom) = split(':',$domcoord[0]);
14336: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 14337: if ($inputtype eq 'radio') {
1.247 raeburn 14338: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 14339: if ($user ne $dcname.':'.$dcdom) {
14340: $table .= ' ('.$dcname.':'.$dcdom.')';
14341: }
1.191 raeburn 14342: } else {
14343: my $check;
14344: if (exists($currhash{$domcoord[0]})) {
14345: $check = ' checked="checked"';
1.125 raeburn 14346: }
1.247 raeburn 14347: $table = '<span class="LC_nobreak"><label>'.
14348: '<input type="checkbox" name="'.$name.'" '.
14349: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 14350: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 14351: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 14352: }
1.220 raeburn 14353: $table .= '</label></span>';
1.191 raeburn 14354: $rows ++;
1.125 raeburn 14355: }
14356: }
1.191 raeburn 14357: return ($numdcs,$table,$rows);
1.125 raeburn 14358: }
14359:
1.137 raeburn 14360: sub usersession_titles {
14361: return &Apache::lonlocal::texthash(
14362: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
14363: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 14364: spares => 'Servers offloaded to, when busy',
1.137 raeburn 14365: version => 'LON-CAPA version requirement',
1.138 raeburn 14366: excludedomain => 'Allow all, but exclude specific domains',
14367: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 14368: primary => 'Primary (checked first)',
1.154 raeburn 14369: default => 'Default',
1.137 raeburn 14370: );
14371: }
14372:
1.152 raeburn 14373: sub id_for_thisdom {
14374: my (%servers) = @_;
14375: my %altids;
14376: foreach my $server (keys(%servers)) {
14377: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
14378: if ($serverhome ne $server) {
14379: $altids{$serverhome} = $server;
14380: }
14381: }
14382: return %altids;
14383: }
14384:
1.150 raeburn 14385: sub count_servers {
14386: my ($currbalancer,%servers) = @_;
14387: my (@spares,$numspares);
14388: foreach my $lonhost (sort(keys(%servers))) {
14389: next if ($currbalancer eq $lonhost);
14390: push(@spares,$lonhost);
14391: }
14392: if ($currbalancer) {
14393: $numspares = scalar(@spares);
14394: } else {
14395: $numspares = scalar(@spares) - 1;
14396: }
14397: return ($numspares,@spares);
14398: }
14399:
14400: sub lonbalance_targets_js {
1.171 raeburn 14401: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 14402: my $select = &mt('Select');
14403: my ($alltargets,$allishome,$allinsttypes,@alltypes);
14404: if (ref($servers) eq 'HASH') {
14405: $alltargets = join("','",sort(keys(%{$servers})));
14406: my @homedoms;
14407: foreach my $server (sort(keys(%{$servers}))) {
14408: if (&Apache::lonnet::host_domain($server) eq $dom) {
14409: push(@homedoms,'1');
14410: } else {
14411: push(@homedoms,'0');
14412: }
14413: }
14414: $allishome = join("','",@homedoms);
14415: }
14416: if (ref($types) eq 'ARRAY') {
14417: if (@{$types} > 0) {
14418: @alltypes = @{$types};
14419: }
14420: }
14421: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
14422: $allinsttypes = join("','",@alltypes);
1.171 raeburn 14423: my (%currbalancer,%currtargets,%currrules,%existing);
14424: if (ref($settings) eq 'HASH') {
14425: %existing = %{$settings};
14426: }
14427: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
14428: \%currtargets,\%currrules);
1.210 raeburn 14429: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 14430: return <<"END";
14431:
14432: <script type="text/javascript">
14433: // <![CDATA[
14434:
1.171 raeburn 14435: currBalancers = new Array('$balancers');
14436:
14437: function toggleTargets(balnum) {
14438: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14439: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
14440: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
14441: var prevbalancer = prevhostitem.value;
14442: var baltotal = document.getElementById('loadbalancing_total').value;
14443: prevhostitem.value = balancer;
14444: if (prevbalancer != '') {
14445: var prevIdx = currBalancers.indexOf(prevbalancer);
14446: if (prevIdx != -1) {
14447: currBalancers.splice(prevIdx,1);
14448: }
14449: }
1.150 raeburn 14450: if (balancer == '') {
1.171 raeburn 14451: hideSpares(balnum);
1.150 raeburn 14452: } else {
1.171 raeburn 14453: var currIdx = currBalancers.indexOf(balancer);
14454: if (currIdx == -1) {
14455: currBalancers.push(balancer);
14456: }
1.150 raeburn 14457: var homedoms = new Array('$allishome');
1.171 raeburn 14458: var ishomedom = homedoms[lonhostitem.selectedIndex];
14459: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 14460: }
1.171 raeburn 14461: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 14462: return;
14463: }
14464:
1.171 raeburn 14465: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 14466: var alltargets = new Array('$alltargets');
14467: var insttypes = new Array('$allinsttypes');
1.151 raeburn 14468: var offloadtypes = new Array('primary','default');
14469:
1.171 raeburn 14470: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
14471: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 14472:
1.151 raeburn 14473: for (var i=0; i<offloadtypes.length; i++) {
14474: var count = 0;
14475: for (var j=0; j<alltargets.length; j++) {
14476: if (alltargets[j] != balancer) {
1.171 raeburn 14477: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
14478: item.value = alltargets[j];
14479: item.style.textAlign='left';
14480: item.style.textFace='normal';
14481: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
14482: if (currBalancers.indexOf(alltargets[j]) == -1) {
14483: item.disabled = '';
14484: } else {
14485: item.disabled = 'disabled';
14486: item.checked = false;
14487: }
1.151 raeburn 14488: count ++;
14489: }
1.150 raeburn 14490: }
14491: }
1.151 raeburn 14492: for (var k=0; k<insttypes.length; k++) {
14493: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 14494: if (ishomedom == 1) {
1.171 raeburn 14495: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14496: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14497: } else {
1.171 raeburn 14498: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14499: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 14500: }
14501: } else {
1.171 raeburn 14502: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14503: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14504: }
1.151 raeburn 14505: if ((insttypes[k] != '_LC_external') &&
14506: ((insttypes[k] != '_LC_internetdom') ||
14507: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 14508: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
14509: item.options.length = 0;
14510: item.options[0] = new Option("","",true,true);
1.210 raeburn 14511: var idx = 0;
1.151 raeburn 14512: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 14513: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
14514: idx ++;
14515: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 14516: }
14517: }
14518: }
14519: }
14520: return;
14521: }
14522:
1.171 raeburn 14523: function hideSpares(balnum) {
1.150 raeburn 14524: var alltargets = new Array('$alltargets');
14525: var insttypes = new Array('$allinsttypes');
14526: var offloadtypes = new Array('primary','default');
14527:
1.171 raeburn 14528: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
14529: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 14530:
14531: var total = alltargets.length - 1;
14532: for (var i=0; i<offloadtypes; i++) {
14533: for (var j=0; j<total; j++) {
1.171 raeburn 14534: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
14535: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
14536: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 14537: }
1.150 raeburn 14538: }
14539: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 14540: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14541: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 14542: if (insttypes[k] != '_LC_external') {
1.171 raeburn 14543: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
14544: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 14545: }
14546: }
14547: return;
14548: }
14549:
1.171 raeburn 14550: function checkOffloads(item,balnum,type) {
1.150 raeburn 14551: var alltargets = new Array('$alltargets');
14552: var offloadtypes = new Array('primary','default');
14553: if (item.checked) {
14554: var total = alltargets.length - 1;
14555: var other;
14556: if (type == offloadtypes[0]) {
1.151 raeburn 14557: other = offloadtypes[1];
1.150 raeburn 14558: } else {
1.151 raeburn 14559: other = offloadtypes[0];
1.150 raeburn 14560: }
14561: for (var i=0; i<total; i++) {
1.171 raeburn 14562: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 14563: if (server == item.value) {
1.171 raeburn 14564: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
14565: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 14566: }
14567: }
14568: }
14569: }
14570: return;
14571: }
14572:
1.171 raeburn 14573: function singleServerToggle(balnum,type) {
14574: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 14575: if (offloadtoSelIdx == 0) {
1.171 raeburn 14576: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
14577: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14578:
14579: } else {
1.171 raeburn 14580: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
14581: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 14582: }
14583: return;
14584: }
14585:
1.171 raeburn 14586: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 14587: if (type == '_LC_external') {
1.171 raeburn 14588: return;
1.150 raeburn 14589: }
1.171 raeburn 14590: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 14591: for (var i=0; i<typesRules.length; i++) {
14592: if (formname.elements[typesRules[i]].checked) {
14593: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 14594: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
14595: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14596: } else {
1.171 raeburn 14597: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
14598: }
14599: }
14600: }
14601: return;
14602: }
14603:
14604: function balancerDeleteChange(balnum) {
14605: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14606: var baltotal = document.getElementById('loadbalancing_total').value;
14607: var addtarget;
14608: var removetarget;
14609: var action = 'delete';
14610: if (document.getElementById('loadbalancing_delete_'+balnum)) {
14611: var lonhost = hostitem.value;
14612: var currIdx = currBalancers.indexOf(lonhost);
14613: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
14614: if (currIdx != -1) {
14615: currBalancers.splice(currIdx,1);
14616: }
14617: addtarget = lonhost;
14618: } else {
14619: if (currIdx == -1) {
14620: currBalancers.push(lonhost);
14621: }
14622: removetarget = lonhost;
14623: action = 'undelete';
14624: }
14625: balancerChange(balnum,baltotal,action,addtarget,removetarget);
14626: }
14627: return;
14628: }
14629:
14630: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
14631: if (baltotal > 1) {
14632: var offloadtypes = new Array('primary','default');
14633: var alltargets = new Array('$alltargets');
14634: var insttypes = new Array('$allinsttypes');
14635: for (var i=0; i<baltotal; i++) {
14636: if (i != balnum) {
14637: for (var j=0; j<offloadtypes.length; j++) {
14638: var total = alltargets.length - 1;
14639: for (var k=0; k<total; k++) {
14640: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
14641: var server = serveritem.value;
14642: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14643: if (server == addtarget) {
14644: serveritem.disabled = '';
14645: }
14646: }
14647: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14648: if (server == removetarget) {
14649: serveritem.disabled = 'disabled';
14650: serveritem.checked = false;
14651: }
14652: }
14653: }
14654: }
14655: for (var j=0; j<insttypes.length; j++) {
14656: if (insttypes[j] != '_LC_external') {
14657: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
14658: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
14659: var currSel = singleserver.selectedIndex;
14660: var currVal = singleserver.options[currSel].value;
14661: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14662: var numoptions = singleserver.options.length;
14663: var needsnew = 1;
14664: for (var k=0; k<numoptions; k++) {
14665: if (singleserver.options[k] == addtarget) {
14666: needsnew = 0;
14667: break;
14668: }
14669: }
14670: if (needsnew == 1) {
14671: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
14672: }
14673: }
14674: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14675: singleserver.options.length = 0;
14676: if ((currVal) && (currVal != removetarget)) {
14677: singleserver.options[0] = new Option("","",false,false);
14678: } else {
14679: singleserver.options[0] = new Option("","",true,true);
14680: }
14681: var idx = 0;
14682: for (var m=0; m<alltargets.length; m++) {
14683: if (currBalancers.indexOf(alltargets[m]) == -1) {
14684: idx ++;
14685: if (currVal == alltargets[m]) {
14686: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
14687: } else {
14688: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
14689: }
14690: }
14691: }
14692: }
14693: }
14694: }
14695: }
1.150 raeburn 14696: }
14697: }
14698: }
14699: return;
14700: }
14701:
1.152 raeburn 14702: // ]]>
14703: </script>
14704:
14705: END
14706: }
14707:
14708: sub new_spares_js {
14709: my @sparestypes = ('primary','default');
14710: my $types = join("','",@sparestypes);
14711: my $select = &mt('Select');
14712: return <<"END";
14713:
14714: <script type="text/javascript">
14715: // <![CDATA[
14716:
14717: function updateNewSpares(formname,lonhost) {
14718: var types = new Array('$types');
14719: var include = new Array();
14720: var exclude = new Array();
14721: for (var i=0; i<types.length; i++) {
14722: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
14723: for (var j=0; j<spareboxes.length; j++) {
14724: if (formname.elements[spareboxes[j]].checked) {
14725: exclude.push(formname.elements[spareboxes[j]].value);
14726: } else {
14727: include.push(formname.elements[spareboxes[j]].value);
14728: }
14729: }
14730: }
14731: for (var i=0; i<types.length; i++) {
14732: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
14733: var selIdx = newSpare.selectedIndex;
14734: var currnew = newSpare.options[selIdx].value;
14735: var okSpares = new Array();
14736: for (var j=0; j<newSpare.options.length; j++) {
14737: var possible = newSpare.options[j].value;
14738: if (possible != '') {
14739: if (exclude.indexOf(possible) == -1) {
14740: okSpares.push(possible);
14741: } else {
14742: if (currnew == possible) {
14743: selIdx = 0;
14744: }
14745: }
14746: }
14747: }
14748: for (var k=0; k<include.length; k++) {
14749: if (okSpares.indexOf(include[k]) == -1) {
14750: okSpares.push(include[k]);
14751: }
14752: }
14753: okSpares.sort();
14754: newSpare.options.length = 0;
14755: if (selIdx == 0) {
14756: newSpare.options[0] = new Option("$select","",true,true);
14757: } else {
14758: newSpare.options[0] = new Option("$select","",false,false);
14759: }
14760: for (var m=0; m<okSpares.length; m++) {
14761: var idx = m+1;
14762: var selThis = 0;
14763: if (selIdx != 0) {
14764: if (okSpares[m] == currnew) {
14765: selThis = 1;
14766: }
14767: }
14768: if (selThis == 1) {
14769: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
14770: } else {
14771: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
14772: }
14773: }
14774: }
14775: return;
14776: }
14777:
14778: function checkNewSpares(lonhost,type) {
14779: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
14780: var chosen = newSpare.options[newSpare.selectedIndex].value;
14781: if (chosen != '') {
14782: var othertype;
14783: var othernewSpare;
14784: if (type == 'primary') {
14785: othernewSpare = document.getElementById('newspare_default_'+lonhost);
14786: }
14787: if (type == 'default') {
14788: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
14789: }
14790: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
14791: othernewSpare.selectedIndex = 0;
14792: }
14793: }
14794: return;
14795: }
14796:
14797: // ]]>
14798: </script>
14799:
14800: END
14801:
14802: }
14803:
14804: sub common_domprefs_js {
14805: return <<"END";
14806:
14807: <script type="text/javascript">
14808: // <![CDATA[
14809:
1.150 raeburn 14810: function getIndicesByName(formname,item) {
1.152 raeburn 14811: var group = new Array();
1.150 raeburn 14812: for (var i=0;i<formname.elements.length;i++) {
14813: if (formname.elements[i].name == item) {
1.152 raeburn 14814: group.push(formname.elements[i].id);
1.150 raeburn 14815: }
14816: }
1.152 raeburn 14817: return group;
1.150 raeburn 14818: }
14819:
14820: // ]]>
14821: </script>
14822:
14823: END
1.152 raeburn 14824:
1.150 raeburn 14825: }
14826:
1.165 raeburn 14827: sub recaptcha_js {
14828: my %lt = &captcha_phrases();
14829: return <<"END";
14830:
14831: <script type="text/javascript">
14832: // <![CDATA[
14833:
14834: function updateCaptcha(caller,context) {
14835: var privitem;
14836: var pubitem;
14837: var privtext;
14838: var pubtext;
1.269 raeburn 14839: var versionitem;
14840: var versiontext;
1.165 raeburn 14841: if (document.getElementById(context+'_recaptchapub')) {
14842: pubitem = document.getElementById(context+'_recaptchapub');
14843: } else {
14844: return;
14845: }
14846: if (document.getElementById(context+'_recaptchapriv')) {
14847: privitem = document.getElementById(context+'_recaptchapriv');
14848: } else {
14849: return;
14850: }
14851: if (document.getElementById(context+'_recaptchapubtxt')) {
14852: pubtext = document.getElementById(context+'_recaptchapubtxt');
14853: } else {
14854: return;
14855: }
14856: if (document.getElementById(context+'_recaptchaprivtxt')) {
14857: privtext = document.getElementById(context+'_recaptchaprivtxt');
14858: } else {
14859: return;
14860: }
1.269 raeburn 14861: if (document.getElementById(context+'_recaptchaversion')) {
14862: versionitem = document.getElementById(context+'_recaptchaversion');
14863: } else {
14864: return;
14865: }
14866: if (document.getElementById(context+'_recaptchavertxt')) {
14867: versiontext = document.getElementById(context+'_recaptchavertxt');
14868: } else {
14869: return;
14870: }
1.165 raeburn 14871: if (caller.checked) {
14872: if (caller.value == 'recaptcha') {
14873: pubitem.type = 'text';
14874: privitem.type = 'text';
14875: pubitem.size = '40';
14876: privitem.size = '40';
14877: pubtext.innerHTML = "$lt{'pub'}";
14878: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 14879: versionitem.type = 'text';
14880: versionitem.size = '3';
1.289 ! raeburn 14881: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 14882: } else {
14883: pubitem.type = 'hidden';
14884: privitem.type = 'hidden';
1.269 raeburn 14885: versionitem.type = 'hidden';
1.165 raeburn 14886: pubtext.innerHTML = '';
14887: privtext.innerHTML = '';
1.269 raeburn 14888: versiontext.innerHTML = '';
1.165 raeburn 14889: }
14890: }
14891: return;
14892: }
14893:
14894: // ]]>
14895: </script>
14896:
14897: END
14898:
14899: }
14900:
1.236 raeburn 14901: sub toggle_display_js {
1.192 raeburn 14902: return <<"END";
14903:
14904: <script type="text/javascript">
14905: // <![CDATA[
14906:
1.236 raeburn 14907: function toggleDisplay(domForm,caller) {
14908: if (document.getElementById(caller)) {
14909: var divitem = document.getElementById(caller);
14910: var optionsElement = domForm.coursecredits;
1.264 raeburn 14911: var checkval = 1;
14912: var dispval = 'block';
1.236 raeburn 14913: if (caller == 'emailoptions') {
14914: optionsElement = domForm.cancreate_email;
14915: }
1.257 raeburn 14916: if (caller == 'studentsubmission') {
14917: optionsElement = domForm.postsubmit;
14918: }
1.264 raeburn 14919: if (caller == 'cloneinstcode') {
14920: optionsElement = domForm.canclone;
14921: checkval = 'instcode';
14922: }
1.236 raeburn 14923: if (optionsElement.length) {
1.192 raeburn 14924: var currval;
1.236 raeburn 14925: for (var i=0; i<optionsElement.length; i++) {
14926: if (optionsElement[i].checked) {
14927: currval = optionsElement[i].value;
1.192 raeburn 14928: }
14929: }
1.264 raeburn 14930: if (currval == checkval) {
14931: divitem.style.display = dispval;
1.192 raeburn 14932: } else {
1.236 raeburn 14933: divitem.style.display = 'none';
1.192 raeburn 14934: }
14935: }
14936: }
14937: return;
14938: }
14939:
14940: // ]]>
14941: </script>
14942:
14943: END
14944:
14945: }
14946:
1.165 raeburn 14947: sub captcha_phrases {
14948: return &Apache::lonlocal::texthash (
14949: priv => 'Private key',
14950: pub => 'Public key',
14951: original => 'original (CAPTCHA)',
14952: recaptcha => 'successor (ReCAPTCHA)',
14953: notused => 'unused',
1.289 ! raeburn 14954: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 14955: );
14956: }
14957:
1.205 raeburn 14958: sub devalidate_remote_domconfs {
1.212 raeburn 14959: my ($dom,$cachekeys) = @_;
14960: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 14961: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14962: my %thismachine;
14963: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.267 raeburn 14964: my @posscached = ('domainconfig','domdefaults','ltitools');
1.260 raeburn 14965: if (keys(%servers)) {
1.205 raeburn 14966: foreach my $server (keys(%servers)) {
14967: next if ($thismachine{$server});
1.212 raeburn 14968: my @cached;
14969: foreach my $name (@posscached) {
14970: if ($cachekeys->{$name}) {
14971: push(@cached,&escape($name).':'.&escape($dom));
14972: }
14973: }
14974: if (@cached) {
14975: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
14976: }
1.205 raeburn 14977: }
14978: }
14979: return;
14980: }
14981:
1.3 raeburn 14982: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>