Annotation of loncom/interface/domainprefs.pm, revision 1.291
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.291 ! raeburn 4: # $Id: domainprefs.pm,v 1.290 2017/01/28 03:48: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);
1.291 ! raeburn 3253: my @accesstypes = ('all','anydh','anyda','none');
1.285 raeburn 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.290 raeburn 3262: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 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: }
1.291 ! raeburn 3471: if ((curraccess == 'all') || (curraccess == 'anydh') || (curraccess == 'anyda')) {
1.285 raeburn 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?',
1.291 ! raeburn 3528: 'all' => "All with domain helpdesk or helpdesk assistant role',
! 3529: 'anydh' => "All with domain helpdesk role',
! 3530: 'anyda' => "All with domain helpdesk assistant role',
1.285 raeburn 3531: 'none' => 'None',
3532: 'status' => 'Determined based on institutional status',
3533: 'inc' => 'Include all, but exclude specific personnel',
3534: 'exc' => 'Exclude all, but include specific personnel',
3535: );
3536: my %usecheck = (
3537: all => ' checked="checked"',
3538: );
3539: my %displaydiv = (
3540: status => 'none',
3541: inc => 'none',
3542: exc => 'none',
3543: priv => 'block',
3544: );
3545: my $output;
3546: if (ref($current) eq 'HASH') {
3547: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3548: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3549: $usecheck{$current->{access}} = $usecheck{'all'};
3550: delete($usecheck{'all'});
3551: if ($current->{access} =~ /^(status|inc|exc)$/) {
3552: my $access = $1;
3553: $displaydiv{$access} = 'inline';
3554: } elsif ($current->{access} eq 'none') {
3555: $displaydiv{'priv'} = 'none';
3556: }
3557: }
3558: }
3559: }
3560: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3561: '<p>'.$lt{'whi'}.'</p>';
3562: foreach my $access (@{$accesstypes}) {
3563: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3564: ' onclick="helpdeskAccess('."'$num'".');" />'.
3565: $lt{$access}.'</label>';
3566: if ($access eq 'status') {
3567: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3568: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3569: $othertitle,$usertypes,$types).
3570: '</div>';
3571: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3572: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3573: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3574: '</div>';
3575: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3576: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3577: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3578: '</div>';
3579: }
3580: $output .= '</p>';
3581: }
3582: $output .= '</fieldset>';
3583: return $output;
3584: }
3585:
1.121 raeburn 3586: sub radiobutton_prefs {
1.192 raeburn 3587: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 3588: $additional,$align) = @_;
1.121 raeburn 3589: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3590: (ref($choices) eq 'HASH'));
3591:
1.170 raeburn 3592: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 3593:
3594: foreach my $item (@{$toggles}) {
3595: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3596: $checkedon{$item} = ' checked="checked" ';
3597: $checkedoff{$item} = ' ';
1.121 raeburn 3598: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3599: $checkedoff{$item} = ' checked="checked" ';
3600: $checkedon{$item} = ' ';
3601: }
3602: }
3603: if (ref($settings) eq 'HASH') {
1.121 raeburn 3604: foreach my $item (@{$toggles}) {
1.118 jms 3605: if ($settings->{$item} eq '1') {
3606: $checkedon{$item} = ' checked="checked" ';
3607: $checkedoff{$item} = ' ';
3608: } elsif ($settings->{$item} eq '0') {
3609: $checkedoff{$item} = ' checked="checked" ';
3610: $checkedon{$item} = ' ';
3611: }
3612: }
1.121 raeburn 3613: }
1.192 raeburn 3614: if ($onclick) {
3615: $onclick = ' onclick="'.$onclick.'"';
3616: }
1.121 raeburn 3617: foreach my $item (@{$toggles}) {
1.118 jms 3618: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3619: $datatable .=
1.192 raeburn 3620: '<tr'.$css_class.'><td valign="top">'.
3621: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 3622: '</span></td>';
3623: if ($align eq 'left') {
3624: $datatable .= '<td class="LC_left_item">';
3625: } else {
3626: $datatable .= '<td class="LC_right_item">';
3627: }
1.289 raeburn 3628: $datatable .=
1.257 raeburn 3629: '<span class="LC_nobreak">'.
1.118 jms 3630: '<label><input type="radio" name="'.
1.192 raeburn 3631: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3632: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 3633: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3634: '</span>'.$additional.
3635: '</td>'.
1.118 jms 3636: '</tr>';
3637: $itemcount ++;
1.121 raeburn 3638: }
3639: return ($datatable,$itemcount);
3640: }
3641:
1.267 raeburn 3642: sub print_ltitools {
3643: my ($dom,$settings,$rowtotal) = @_;
3644: my $rownum = 0;
3645: my $css_class;
3646: my $itemcount = 1;
3647: my $maxnum = 0;
3648: my %ordered;
3649: if (ref($settings) eq 'HASH') {
3650: foreach my $item (keys(%{$settings})) {
3651: if (ref($settings->{$item}) eq 'HASH') {
3652: my $num = $settings->{$item}{'order'};
3653: $ordered{$num} = $item;
3654: }
3655: }
3656: }
3657: my $confname = $dom.'-domainconfig';
3658: my $switchserver = &check_switchserver($dom,$confname);
3659: my $maxnum = scalar(keys(%ordered));
3660: my $datatable = <itools_javascript($settings);
3661: my %lt = <itools_names();
3662: my @courseroles = ('cc','in','ta','ep','st');
3663: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3664: my @fields = ('fullname','firstname','lastname','email','user','roles');
3665: if (keys(%ordered)) {
3666: my @items = sort { $a <=> $b } keys(%ordered);
3667: for (my $i=0; $i<@items; $i++) {
3668: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3669: my $item = $ordered{$items[$i]};
3670: my ($title,$key,$secret,$url,$imgsrc,$version);
3671: if (ref($settings->{$item}) eq 'HASH') {
3672: $title = $settings->{$item}->{'title'};
3673: $url = $settings->{$item}->{'url'};
3674: $key = $settings->{$item}->{'key'};
3675: $secret = $settings->{$item}->{'secret'};
3676: my $image = $settings->{$item}->{'image'};
3677: if ($image ne '') {
3678: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3679: }
3680: }
3681: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3682: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3683: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3684: for (my $k=0; $k<=$maxnum; $k++) {
3685: my $vpos = $k+1;
3686: my $selstr;
3687: if ($k == $i) {
3688: $selstr = ' selected="selected" ';
3689: }
3690: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3691: }
3692: $datatable .= '</select>'.(' 'x2).
3693: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3694: &mt('Delete?').'</label></span></td>'.
3695: '<td colspan="2">'.
3696: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3697: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3698: (' 'x2).
3699: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3700: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3701: (' 'x2).
3702: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3703: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3704: '<br /><br />'.
3705: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3706: ' value="'.$url.'" /></span>'.
3707: (' 'x2).
3708: '<span class="LC_nobreak">'.$lt{'key'}.
3709: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3710: (' 'x2).
3711: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3712: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3713: '<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>'.
3714: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3715: '</fieldset>'.
3716: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3717: '<span class="LC_nobreak">'.&mt('Display target:');
3718: my %currdisp;
3719: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3720: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3721: $currdisp{'window'} = ' checked="checked"';
3722: } else {
3723: $currdisp{'iframe'} = ' checked="checked"';
3724: }
3725: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3726: $currdisp{'width'} = $1;
3727: }
3728: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3729: $currdisp{'height'} = $1;
3730: }
3731: } else {
3732: $currdisp{'iframe'} = ' checked="checked"';
3733: }
3734: foreach my $disp ('iframe','window') {
3735: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3736: $lt{$disp}.'</label>'.(' 'x2);
3737: }
3738: $datatable .= (' 'x4);
3739: foreach my $dimen ('width','height') {
3740: $datatable .= '<label>'.$lt{$dimen}.' '.
3741: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3742: (' 'x2);
3743: }
3744: $datatable .= '<br />';
3745: foreach my $extra ('passback','roster') {
3746: my $checkedon = '';
3747: my $checkedoff = ' checked="checked"';
3748: if ($settings->{$item}->{$extra}) {
3749: $checkedon = $checkedoff;
3750: $checkedoff = '';
3751: }
3752: $datatable .= $lt{$extra}.' '.
3753: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3754: &mt('Yes').'</label>'.(' 'x2).
3755: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3756: &mt('No').'</label>'.(' 'x4);
3757: }
3758: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3759: if ($imgsrc) {
3760: $datatable .= $imgsrc.
3761: '<label><input type="checkbox" name="ltitools_image_del"'.
3762: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3763: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3764: } else {
3765: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3766: }
3767: if ($switchserver) {
3768: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3769: } else {
3770: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3771: }
3772: $datatable .= '</span></fieldset>';
3773: my (%checkedfields,%rolemaps);
3774: if (ref($settings->{$item}) eq 'HASH') {
3775: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3776: %checkedfields = %{$settings->{$item}->{'fields'}};
3777: }
3778: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3779: %rolemaps = %{$settings->{$item}->{'roles'}};
3780: $checkedfields{'roles'} = 1;
3781: }
3782: }
3783: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3784: '<span class="LC_nobreak">';
3785: foreach my $field (@fields) {
3786: my $checked;
3787: if ($checkedfields{$field}) {
3788: $checked = ' checked="checked"';
3789: }
3790: $datatable .= '<label>'.
3791: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3792: $lt{$field}.'</label>'.(' ' x2);
3793: }
3794: $datatable .= '</span></fieldset>'.
3795: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3796: foreach my $role (@courseroles) {
3797: my ($selected,$selectnone);
3798: if (!$rolemaps{$role}) {
3799: $selectnone = ' selected="selected"';
3800: }
3801: $datatable .= '<td align="center">'.
3802: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3803: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3804: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3805: foreach my $ltirole (@ltiroles) {
3806: unless ($selectnone) {
3807: if ($rolemaps{$role} eq $ltirole) {
3808: $selected = ' selected="selected"';
3809: } else {
3810: $selected = '';
3811: }
3812: }
3813: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3814: }
3815: $datatable .= '</select></td>';
3816: }
1.273 raeburn 3817: $datatable .= '</tr></table></fieldset>';
3818: my %courseconfig;
3819: if (ref($settings->{$item}) eq 'HASH') {
3820: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3821: %courseconfig = %{$settings->{$item}->{'crsconf'}};
3822: }
3823: }
3824: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3825: foreach my $item ('label','title','target') {
3826: my $checked;
3827: if ($courseconfig{$item}) {
3828: $checked = ' checked="checked"';
3829: }
3830: $datatable .= '<label>'.
3831: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3832: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3833: }
3834: $datatable .= '</span></fieldset>'.
1.267 raeburn 3835: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3836: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3837: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3838: my %custom = %{$settings->{$item}->{'custom'}};
3839: if (keys(%custom) > 0) {
3840: foreach my $key (sort(keys(%custom))) {
3841: $datatable .= '<tr><td><span class="LC_nobreak">'.
3842: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3843: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3844: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3845: ' value="'.$custom{$key}.'" /></td></tr>';
3846: }
3847: }
3848: }
3849: $datatable .= '<tr><td><span class="LC_nobreak">'.
3850: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3851: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3852: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3853: $datatable .= '</table></fieldset></td></tr>'."\n";
3854: $itemcount ++;
3855: }
3856: }
3857: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3858: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3859: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3860: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3861: '<select name="ltitools_add_pos"'.$chgstr.'>';
3862: for (my $k=0; $k<$maxnum+1; $k++) {
3863: my $vpos = $k+1;
3864: my $selstr;
3865: if ($k == $maxnum) {
3866: $selstr = ' selected="selected" ';
3867: }
3868: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3869: }
3870: $datatable .= '</select> '."\n".
3871: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3872: '<td colspan="2">'.
3873: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3874: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3875: (' 'x2).
3876: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3877: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3878: (' 'x2).
3879: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3880: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3881: '<br />'.
3882: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3883: (' 'x2).
3884: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3885: (' 'x2).
3886: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3887: '<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".
3888: '</fieldset>'.
3889: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3890: '<span class="LC_nobreak">'.&mt('Display target:');
3891: my %defaultdisp;
3892: $defaultdisp{'iframe'} = ' checked="checked"';
3893: foreach my $disp ('iframe','window') {
3894: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3895: $lt{$disp}.'</label>'.(' 'x2);
3896: }
3897: $datatable .= (' 'x4);
3898: foreach my $dimen ('width','height') {
3899: $datatable .= '<label>'.$lt{$dimen}.' '.
3900: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3901: (' 'x2);
3902: }
3903: $datatable .= '<br />';
3904: foreach my $extra ('passback','roster') {
3905: $datatable .= $lt{$extra}.' '.
3906: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
3907: &mt('Yes').'</label>'.(' 'x2).
3908: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
3909: &mt('No').'</label>'.(' 'x4);
3910: }
3911: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
3912: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3913: if ($switchserver) {
3914: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3915: } else {
3916: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3917: }
3918: $datatable .= '</span></fieldset>'.
3919: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3920: '<span class="LC_nobreak">';
3921: foreach my $field (@fields) {
3922: $datatable .= '<label>'.
3923: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
3924: $lt{$field}.'</label>'.(' ' x2);
3925: }
3926: $datatable .= '</span></fieldset>'.
3927: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3928: foreach my $role (@courseroles) {
3929: my ($checked,$checkednone);
3930: $datatable .= '<td align="center">'.
3931: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3932: '<select name="ltitools_add_roles_'.$role.'">'.
3933: '<option value="" selected="selected">'.&mt('Select').'</option>';
3934: foreach my $ltirole (@ltiroles) {
3935: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
3936: }
3937: $datatable .= '</select></td>';
3938: }
3939: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 3940: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3941: foreach my $item ('label','title','target') {
3942: $datatable .= '<label>'.
3943: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
3944: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3945: }
3946: $datatable .= '</span></fieldset>'.
1.267 raeburn 3947: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3948: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
3949: '<tr><td><span class="LC_nobreak">'.
3950: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
3951: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
3952: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
3953: '</table></fieldset></td></tr>'."\n".
3954: '</td>'."\n".
3955: '</tr>'."\n";
3956: $itemcount ++;
3957: return $datatable;
3958: }
3959:
3960: sub ltitools_names {
3961: my %lt = &Apache::lonlocal::texthash(
3962: 'title' => 'Title',
3963: 'version' => 'Version',
3964: 'msgtype' => 'Message Type',
3965: 'url' => 'URL',
3966: 'key' => 'Key',
3967: 'secret' => 'Secret',
3968: 'icon' => 'Icon',
3969: 'user' => 'Username:domain',
3970: 'fullname' => 'Full Name',
3971: 'firstname' => 'First Name',
3972: 'lastname' => 'Last Name',
3973: 'email' => 'E-mail',
3974: 'roles' => 'Role',
3975: 'window' => 'Window/Tab',
3976: 'iframe' => 'iFrame',
3977: 'height' => 'Height',
3978: 'width' => 'Width',
3979: 'passback' => 'Tool can return grades:',
3980: 'roster' => 'Tool can retrieve roster:',
1.273 raeburn 3981: 'crstarget' => 'Display target',
3982: 'crslabel' => 'Course label',
3983: 'crstitle' => 'Course title',
1.267 raeburn 3984: );
3985: return %lt;
3986: }
3987:
1.121 raeburn 3988: sub print_coursedefaults {
1.139 raeburn 3989: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 3990: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3991: my $itemcount = 1;
1.192 raeburn 3992: my %choices = &Apache::lonlocal::texthash (
3993: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 3994: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 3995: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3996: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 3997: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3998: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
3999: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 4000: canclone => "People who may clone a course (besides course's owner and coordinators)",
4001: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 4002: );
1.198 raeburn 4003: my %staticdefaults = (
4004: anonsurvey_threshold => 10,
4005: uploadquota => 500,
1.257 raeburn 4006: postsubmit => 60,
1.276 raeburn 4007: mysqltables => 172800,
1.198 raeburn 4008: );
1.139 raeburn 4009: if ($position eq 'top') {
1.257 raeburn 4010: %defaultchecked = (
4011: 'canuse_pdfforms' => 'off',
4012: 'uselcmath' => 'on',
4013: 'usejsme' => 'on',
1.289 raeburn 4014: 'canclone' => 'none',
1.257 raeburn 4015: );
4016: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139 raeburn 4017: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 4018: \%choices,$itemcount);
1.264 raeburn 4019: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4020: $datatable .=
4021: '<tr'.$css_class.'><td valign="top">'.
4022: '<span class="LC_nobreak">'.$choices{'canclone'}.
4023: '</span></td><td class="LC_left_item">';
4024: my $currcanclone = 'none';
4025: my $onclick;
4026: my @cloneoptions = ('none','domain');
4027: my %clonetitles = (
4028: none => 'No additional course requesters',
4029: domain => "Any course requester in course's domain",
4030: instcode => 'Course requests for official courses ...',
4031: );
4032: my (%codedefaults,@code_order,@posscodes);
4033: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4034: \@code_order) eq 'ok') {
4035: if (@code_order > 0) {
4036: push(@cloneoptions,'instcode');
4037: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4038: }
4039: }
4040: if (ref($settings) eq 'HASH') {
4041: if ($settings->{'canclone'}) {
4042: if (ref($settings->{'canclone'}) eq 'HASH') {
4043: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4044: if (@code_order > 0) {
4045: $currcanclone = 'instcode';
4046: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4047: }
4048: }
4049: } elsif ($settings->{'canclone'} eq 'domain') {
4050: $currcanclone = $settings->{'canclone'};
4051: }
4052: }
1.289 raeburn 4053: }
1.264 raeburn 4054: foreach my $option (@cloneoptions) {
4055: my ($checked,$additional);
4056: if ($currcanclone eq $option) {
4057: $checked = ' checked="checked"';
4058: }
4059: if ($option eq 'instcode') {
4060: if (@code_order) {
4061: my $show = 'none';
4062: if ($checked) {
4063: $show = 'block';
4064: }
4065: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4066: &mt('Institutional codes for new and cloned course have identical:').
4067: '<br />';
4068: foreach my $item (@code_order) {
4069: my $codechk;
4070: if ($checked) {
4071: if (grep(/^\Q$item\E$/,@posscodes)) {
4072: $codechk = ' checked="checked"';
4073: }
4074: }
4075: $additional .= '<label>'.
4076: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4077: $item.'</label>';
4078: }
4079: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4080: }
4081: }
4082: $datatable .=
4083: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4084: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4085: '</label> '.$additional.'</span><br />';
4086: }
4087: $datatable .= '</td>'.
4088: '</tr>';
4089: $itemcount ++;
1.139 raeburn 4090: } else {
4091: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 4092: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 4093: my $currusecredits = 0;
1.257 raeburn 4094: my $postsubmitclient = 1;
1.271 raeburn 4095: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 4096: if (ref($settings) eq 'HASH') {
4097: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 4098: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4099: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4100: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4101: }
4102: }
1.192 raeburn 4103: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 4104: foreach my $type (@types) {
4105: next if ($type eq 'community');
4106: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4107: if ($defcredits{$type} ne '') {
4108: $currusecredits = 1;
4109: }
4110: }
4111: }
4112: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4113: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4114: $postsubmitclient = 0;
4115: foreach my $type (@types) {
4116: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4117: }
4118: } else {
4119: foreach my $type (@types) {
4120: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4121: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 4122: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 4123: } else {
4124: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4125: }
4126: } else {
4127: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4128: }
4129: }
4130: }
4131: } else {
4132: foreach my $type (@types) {
4133: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 4134: }
4135: }
1.276 raeburn 4136: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4137: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4138: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4139: }
4140: } else {
4141: foreach my $type (@types) {
4142: $currmysql{$type} = $staticdefaults{'mysqltables'};
4143: }
4144: }
1.258 raeburn 4145: } else {
4146: foreach my $type (@types) {
4147: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4148: }
1.139 raeburn 4149: }
4150: if (!$currdefresponder) {
1.198 raeburn 4151: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4152: } elsif ($currdefresponder < 1) {
4153: $currdefresponder = 1;
4154: }
1.198 raeburn 4155: foreach my $type (@types) {
4156: if ($curruploadquota{$type} eq '') {
4157: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4158: }
4159: }
1.139 raeburn 4160: $datatable .=
1.192 raeburn 4161: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4162: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4163: '</span></td>'.
4164: '<td class="LC_right_item"><span class="LC_nobreak">'.
4165: '<input type="text" name="anonsurvey_threshold"'.
4166: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 4167: '</td></tr>'."\n";
4168: $itemcount ++;
4169: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4170: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4171: $choices{'uploadquota'}.
4172: '</span></td>'.
4173: '<td align="right" class="LC_right_item">'.
4174: '<table><tr>';
1.198 raeburn 4175: foreach my $type (@types) {
4176: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4177: '<input type="text" name="uploadquota_'.$type.'"'.
4178: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4179: }
4180: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 4181: $itemcount ++;
1.236 raeburn 4182: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 4183: my $display = 'none';
1.192 raeburn 4184: if ($currusecredits) {
4185: $display = 'block';
4186: }
4187: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 4188: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4189: foreach my $type (@types) {
4190: next if ($type eq 'community');
4191: $additional .= '<td align="center">'.&mt($type).'<br />'.
4192: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 4193: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 4194: }
4195: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 4196: %defaultchecked = ('coursecredits' => 'off');
4197: @toggles = ('coursecredits');
4198: my $current = {
4199: 'coursecredits' => $currusecredits,
4200: };
4201: (my $table,$itemcount) =
4202: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 4203: \%choices,$itemcount,$onclick,$additional,'left');
4204: $datatable .= $table;
4205: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4206: my $display = 'none';
4207: if ($postsubmitclient) {
4208: $display = 'block';
4209: }
4210: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 4211: &mt('Number of seconds submit is disabled').'<br />'.
4212: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4213: '<table><tr>';
1.257 raeburn 4214: foreach my $type (@types) {
4215: $additional .= '<td align="center">'.&mt($type).'<br />'.
4216: '<input type="text" name="'.$type.'_timeout" value="'.
4217: $deftimeout{$type}.'" size="5" /></td>';
4218: }
4219: $additional .= '</tr></table></div>'."\n";
4220: %defaultchecked = ('postsubmit' => 'on');
4221: @toggles = ('postsubmit');
1.280 raeburn 4222: $current = {
4223: 'postsubmit' => $postsubmitclient,
4224: };
1.257 raeburn 4225: ($table,$itemcount) =
4226: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4227: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 4228: $datatable .= $table;
1.276 raeburn 4229: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4230: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4231: $choices{'mysqltables'}.
4232: '</span></td>'.
4233: '<td align="right" class="LC_right_item">'.
4234: '<table><tr>';
4235: foreach my $type (@types) {
4236: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4237: '<input type="text" name="mysqltables_'.$type.'"'.
4238: ' value="'.$currmysql{$type}.'" size="5" /></td>';
4239: }
4240: $datatable .= '</tr></table></td></tr>'."\n";
4241: $itemcount ++;
4242:
1.139 raeburn 4243: }
1.192 raeburn 4244: $$rowtotal += $itemcount;
1.121 raeburn 4245: return $datatable;
1.118 jms 4246: }
4247:
1.231 raeburn 4248: sub print_selfenrollment {
4249: my ($position,$dom,$settings,$rowtotal) = @_;
4250: my ($css_class,$datatable);
4251: my $itemcount = 1;
1.271 raeburn 4252: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 4253: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 4254: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4255: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 4256: my @rows;
4257: my $key;
4258: if ($position eq 'top') {
4259: $key = 'admin';
4260: if (ref($rowsref) eq 'ARRAY') {
4261: @rows = @{$rowsref};
4262: }
4263: } elsif ($position eq 'middle') {
4264: $key = 'default';
4265: @rows = ('types','registered','approval','limit');
4266: }
4267: foreach my $row (@rows) {
4268: if (defined($titlesref->{$row})) {
4269: $itemcount ++;
4270: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4271: $datatable .= '<tr'.$css_class.'>'.
4272: '<td>'.$titlesref->{$row}.'</td>'.
4273: '<td class="LC_left_item">'.
4274: '<table><tr>';
4275: my (%current,%currentcap);
4276: if (ref($settings) eq 'HASH') {
4277: if (ref($settings->{$key}) eq 'HASH') {
4278: foreach my $type (@types) {
4279: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4280: $current{$type} = $settings->{$key}->{$type}->{$row};
4281: }
4282: if (($row eq 'limit') && ($key eq 'default')) {
4283: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4284: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4285: }
4286: }
4287: }
4288: }
4289: }
4290: my %roles = (
4291: '0' => &Apache::lonnet::plaintext('dc'),
4292: );
4293:
4294: foreach my $type (@types) {
4295: unless (($row eq 'registered') && ($key eq 'default')) {
4296: $datatable .= '<th>'.&mt($type).'</th>';
4297: }
4298: }
4299: unless (($row eq 'registered') && ($key eq 'default')) {
4300: $datatable .= '</tr><tr>';
4301: }
4302: foreach my $type (@types) {
4303: if ($type eq 'community') {
4304: $roles{'1'} = &mt('Community personnel');
4305: } else {
4306: $roles{'1'} = &mt('Course personnel');
4307: }
4308: $datatable .= '<td style="vertical-align: top">';
4309: if ($position eq 'top') {
4310: my %checked;
4311: if ($current{$type} eq '0') {
4312: $checked{'0'} = ' checked="checked"';
4313: } else {
4314: $checked{'1'} = ' checked="checked"';
4315: }
4316: foreach my $role ('1','0') {
4317: $datatable .= '<span class="LC_nobreak"><label>'.
4318: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4319: 'value="'.$role.'"'.$checked{$role}.' />'.
4320: $roles{$role}.'</label></span> ';
4321: }
4322: } else {
4323: if ($row eq 'types') {
4324: my %checked;
4325: if ($current{$type} =~ /^(all|dom)$/) {
4326: $checked{$1} = ' checked="checked"';
4327: } else {
4328: $checked{''} = ' checked="checked"';
4329: }
4330: foreach my $val ('','dom','all') {
4331: $datatable .= '<span class="LC_nobreak"><label>'.
4332: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4333: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4334: }
4335: } elsif ($row eq 'registered') {
4336: my %checked;
4337: if ($current{$type} eq '1') {
4338: $checked{'1'} = ' checked="checked"';
4339: } else {
4340: $checked{'0'} = ' checked="checked"';
4341: }
4342: foreach my $val ('0','1') {
4343: $datatable .= '<span class="LC_nobreak"><label>'.
4344: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4345: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4346: }
4347: } elsif ($row eq 'approval') {
4348: my %checked;
4349: if ($current{$type} =~ /^([12])$/) {
4350: $checked{$1} = ' checked="checked"';
4351: } else {
4352: $checked{'0'} = ' checked="checked"';
4353: }
4354: for my $val (0..2) {
4355: $datatable .= '<span class="LC_nobreak"><label>'.
4356: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4357: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4358: }
4359: } elsif ($row eq 'limit') {
4360: my %checked;
4361: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4362: $checked{$1} = ' checked="checked"';
4363: } else {
4364: $checked{'none'} = ' checked="checked"';
4365: }
4366: my $cap;
4367: if ($currentcap{$type} =~ /^\d+$/) {
4368: $cap = $currentcap{$type};
4369: }
4370: foreach my $val ('none','allstudents','selfenrolled') {
4371: $datatable .= '<span class="LC_nobreak"><label>'.
4372: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4373: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4374: }
4375: $datatable .= '<br />'.
4376: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4377: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4378: '</span>';
4379: }
4380: }
4381: $datatable .= '</td>';
4382: }
4383: $datatable .= '</tr>';
4384: }
4385: $datatable .= '</table></td></tr>';
4386: }
4387: } elsif ($position eq 'bottom') {
1.235 raeburn 4388: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4389: }
4390: $$rowtotal += $itemcount;
4391: return $datatable;
4392: }
4393:
4394: sub print_validation_rows {
4395: my ($caller,$dom,$settings,$rowtotal) = @_;
4396: my ($itemsref,$namesref,$fieldsref);
4397: if ($caller eq 'selfenroll') {
4398: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4399: } elsif ($caller eq 'requestcourses') {
4400: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4401: }
4402: my %currvalidation;
4403: if (ref($settings) eq 'HASH') {
4404: if (ref($settings->{'validation'}) eq 'HASH') {
4405: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 4406: }
1.235 raeburn 4407: }
4408: my $datatable;
4409: my $itemcount = 0;
4410: foreach my $item (@{$itemsref}) {
4411: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4412: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4413: $namesref->{$item}.
4414: '</span></td>'.
4415: '<td class="LC_left_item">';
4416: if (($item eq 'url') || ($item eq 'button')) {
4417: $datatable .= '<span class="LC_nobreak">'.
4418: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4419: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4420: } elsif ($item eq 'fields') {
4421: my @currfields;
4422: if (ref($currvalidation{$item}) eq 'ARRAY') {
4423: @currfields = @{$currvalidation{$item}};
4424: }
4425: foreach my $field (@{$fieldsref}) {
4426: my $check = '';
4427: if (grep(/^\Q$field\E$/,@currfields)) {
4428: $check = ' checked="checked"';
4429: }
4430: $datatable .= '<span class="LC_nobreak"><label>'.
4431: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4432: ' value="'.$field.'"'.$check.' />'.$field.
4433: '</label></span> ';
4434: }
4435: } elsif ($item eq 'markup') {
4436: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
4437: $currvalidation{$item}.
1.231 raeburn 4438: '</textarea>';
1.235 raeburn 4439: }
4440: $datatable .= '</td></tr>'."\n";
4441: if (ref($rowtotal)) {
1.231 raeburn 4442: $itemcount ++;
4443: }
4444: }
1.235 raeburn 4445: if ($caller eq 'requestcourses') {
4446: my %currhash;
1.248 raeburn 4447: if (ref($settings) eq 'HASH') {
4448: if (ref($settings->{'validation'}) eq 'HASH') {
4449: if ($settings->{'validation'}{'dc'} ne '') {
4450: $currhash{$settings->{'validation'}{'dc'}} = 1;
4451: }
1.235 raeburn 4452: }
4453: }
4454: my $numinrow = 2;
4455: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4456: 'validationdc',%currhash);
1.247 raeburn 4457: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4458: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 4459: if ($numdc > 1) {
1.247 raeburn 4460: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 4461: } else {
1.247 raeburn 4462: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 4463: }
1.247 raeburn 4464: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 4465: $itemcount ++;
4466: }
4467: if (ref($rowtotal)) {
4468: $$rowtotal += $itemcount;
4469: }
1.231 raeburn 4470: return $datatable;
4471: }
4472:
1.137 raeburn 4473: sub print_usersessions {
4474: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 4475: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 4476: my (%by_ip,%by_location,@intdoms,@instdoms);
4477: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 4478:
4479: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4480: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4481: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4482: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4483: if ($position eq 'top') {
1.152 raeburn 4484: if (keys(%serverhomes) > 1) {
1.145 raeburn 4485: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 4486: my $curroffloadnow;
4487: if (ref($settings) eq 'HASH') {
4488: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4489: $curroffloadnow = $settings->{'offloadnow'};
4490: }
4491: }
4492: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4493: } else {
1.140 raeburn 4494: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 4495: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
4496: '</td></tr>';
1.140 raeburn 4497: }
1.137 raeburn 4498: } else {
1.279 raeburn 4499: my %titles = &usersession_titles();
4500: my ($prefix,@types);
4501: if ($position eq 'bottom') {
4502: $prefix = 'remote';
4503: @types = ('version','excludedomain','includedomain');
1.145 raeburn 4504: } else {
1.279 raeburn 4505: $prefix = 'hosted';
4506: @types = ('excludedomain','includedomain');
4507: }
4508: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4509: }
4510: $$rowtotal += $itemcount;
4511: return $datatable;
4512: }
4513:
4514: sub rules_by_location {
4515: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
4516: my ($datatable,$itemcount,$css_class);
4517: if (keys(%{$by_location}) == 0) {
4518: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4519: $datatable = '<tr'.$css_class.'><td colspan="2">'.
4520: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
4521: '</td></tr>';
4522: $itemcount = 1;
4523: } else {
4524: $itemcount = 0;
4525: my $numinrow = 5;
4526: my (%current,%checkedon,%checkedoff);
4527: my @locations = sort(keys(%{$by_location}));
4528: foreach my $type (@{$types}) {
4529: $checkedon{$type} = '';
4530: $checkedoff{$type} = ' checked="checked"';
4531: }
4532: if (ref($settings) eq 'HASH') {
4533: if (ref($settings->{$prefix}) eq 'HASH') {
4534: foreach my $key (keys(%{$settings->{$prefix}})) {
4535: $current{$key} = $settings->{$prefix}{$key};
4536: if ($key eq 'version') {
4537: if ($current{$key} ne '') {
1.145 raeburn 4538: $checkedon{$key} = ' checked="checked"';
4539: $checkedoff{$key} = '';
4540: }
1.279 raeburn 4541: } elsif (ref($current{$key}) eq 'ARRAY') {
4542: $checkedon{$key} = ' checked="checked"';
4543: $checkedoff{$key} = '';
1.137 raeburn 4544: }
4545: }
4546: }
1.279 raeburn 4547: }
4548: foreach my $type (@{$types}) {
4549: next if ($type ne 'version' && !@locations);
4550: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4551: $datatable .= '<tr'.$css_class.'>
4552: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
4553: <span class="LC_nobreak">
4554: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4555: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4556: if ($type eq 'version') {
4557: my @lcversions = &Apache::lonnet::all_loncaparevs();
4558: my $selector = '<select name="'.$prefix.'_version">';
4559: foreach my $version (@lcversions) {
4560: my $selected = '';
4561: if ($current{'version'} eq $version) {
4562: $selected = ' selected="selected"';
1.145 raeburn 4563: }
1.279 raeburn 4564: $selector .= ' <option value="'.$version.'"'.
4565: $selected.'>'.$version.'</option>';
4566: }
4567: $selector .= '</select> ';
4568: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4569: } else {
4570: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4571: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4572: ' />'.(' 'x2).
4573: '<input type="button" value="'.&mt('uncheck all').'" '.
4574: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4575: "\n".
4576: '</div><div><table>';
4577: my $rem;
4578: for (my $i=0; $i<@locations; $i++) {
4579: my ($showloc,$value,$checkedtype);
4580: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
4581: my $ip = $by_location->{$locations[$i]}->[0];
4582: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4583: $value = join(':',@{$by_ip->{$ip}});
4584: $showloc = join(', ',@{$by_ip->{$ip}});
4585: if (ref($current{$type}) eq 'ARRAY') {
4586: foreach my $loc (@{$by_ip->{$ip}}) {
4587: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4588: $checkedtype = ' checked="checked"';
4589: last;
1.145 raeburn 4590: }
1.138 raeburn 4591: }
4592: }
4593: }
1.137 raeburn 4594: }
1.279 raeburn 4595: $rem = $i%($numinrow);
4596: if ($rem == 0) {
4597: if ($i > 0) {
4598: $datatable .= '</tr>';
4599: }
4600: $datatable .= '<tr>';
4601: }
4602: $datatable .= '<td class="LC_left_item">'.
4603: '<span class="LC_nobreak"><label>'.
4604: '<input type="checkbox" name="'.$prefix.'_'.$type.
4605: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4606: '</label></span></td>';
4607: }
4608: $rem = @locations%($numinrow);
4609: my $colsleft = $numinrow - $rem;
4610: if ($colsleft > 1 ) {
4611: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4612: ' </td>';
4613: } elsif ($colsleft == 1) {
4614: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4615: }
1.279 raeburn 4616: $datatable .= '</tr></table>';
1.137 raeburn 4617: }
1.279 raeburn 4618: $datatable .= '</td></tr>';
4619: $itemcount ++;
1.137 raeburn 4620: }
4621: }
1.279 raeburn 4622: return ($datatable,$itemcount);
1.137 raeburn 4623: }
4624:
1.275 raeburn 4625: sub print_ssl {
4626: my ($position,$dom,$settings,$rowtotal) = @_;
4627: my ($css_class,$datatable);
4628: my $itemcount = 1;
4629: if ($position eq 'top') {
1.281 raeburn 4630: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4631: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4632: my $same_institution;
4633: if ($intdom ne '') {
4634: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
4635: if (ref($internet_names) eq 'ARRAY') {
4636: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4637: $same_institution = 1;
4638: }
4639: }
4640: }
1.275 raeburn 4641: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 4642: $datatable = '<tr'.$css_class.'><td colspan="2">';
4643: if ($same_institution) {
4644: my %domservers = &Apache::lonnet::get_servers($dom);
4645: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
4646: } else {
4647: $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.");
4648: }
4649: $datatable .= '</td></tr>';
1.275 raeburn 4650: $itemcount ++;
4651: } else {
4652: my %titles = &ssl_titles();
4653: my (%by_ip,%by_location,@intdoms,@instdoms);
4654: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4655: my @alldoms = &Apache::lonnet::all_domains();
4656: my %serverhomes = %Apache::lonnet::serverhomeIDs;
4657: my @domservers = &Apache::lonnet::get_servers($dom);
4658: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4659: my %altids = &id_for_thisdom(%servers);
4660: if ($position eq 'middle') {
4661: foreach my $type ('dom','intdom','other') {
4662: my %checked;
4663: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4664: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
4665: '<td class="LC_right_item">';
4666: my $skip;
4667: if ($type eq 'dom') {
4668: unless (keys(%servers) > 1) {
4669: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
4670: $skip = 1;
4671: }
4672: }
4673: if ($type eq 'intdom') {
4674: unless (@instdoms > 1) {
4675: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
4676: $skip = 1;
4677: }
4678: } elsif ($type eq 'other') {
4679: if (keys(%by_location) == 0) {
4680: $datatable .= &mt('Nothing to set here, as there are no other institutions');
4681: $skip = 1;
4682: }
4683: }
4684: unless ($skip) {
4685: $checked{'yes'} = ' checked="checked"';
4686: if (ref($settings) eq 'HASH') {
4687: if (ref($settings->{'connect'}) eq 'HASH') {
4688: if ($settings->{'connect'}->{$type} =~ /^(no|req)$/) {
4689: $checked{$1} = $checked{'yes'};
4690: delete($checked{'yes'});
4691: }
4692: }
4693: }
4694: foreach my $option ('no','yes','req') {
4695: $datatable .= '<span class="LC_nobreak"><label>'.
4696: '<input type="radio" name="connect_'.$type.'" '.
4697: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
4698: '</label></span>'.(' 'x2);
4699: }
4700: }
4701: $datatable .= '</td></tr>';
4702: $itemcount ++;
4703: }
4704: } else {
4705: my $prefix = 'replication';
4706: my @types = ('certreq','nocertreq');
1.279 raeburn 4707: if (keys(%by_location) == 0) {
4708: $datatable .= '<tr'.$css_class.'><td>'.
4709: &mt('Nothing to set here, as there are no other institutions').
4710: '</td></tr>';
4711: $itemcount ++;
1.275 raeburn 4712: } else {
1.279 raeburn 4713: ($datatable,$itemcount) =
4714: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 4715: }
4716: }
4717: }
4718: $$rowtotal += $itemcount;
4719: return $datatable;
4720: }
4721:
4722: sub ssl_titles {
4723: return &Apache::lonlocal::texthash (
4724: dom => 'LON-CAPA servers/VMs from same domain',
4725: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
4726: other => 'External LON-CAPA servers/VMs',
4727: connect => 'Connections to other servers',
4728: replication => 'Replicating content to other institutions',
4729: certreq => 'Client certificate required, but specific domains exempt',
4730: nocertreq => 'No client certificate required, except for specific domains',
4731: no => 'SSL not used',
4732: yes => 'SSL Optional (used if available)',
4733: req => 'SSL Required',
4734: );
1.279 raeburn 4735: }
4736:
4737: sub print_trust {
4738: my ($prefix,$dom,$settings,$rowtotal) = @_;
4739: my ($css_class,$datatable,%checked,%choices);
4740: my (%by_ip,%by_location,@intdoms,@instdoms);
4741: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4742: my $itemcount = 1;
4743: my %titles = &trust_titles();
4744: my @types = ('exc','inc');
4745: if ($prefix eq 'top') {
4746: $prefix = 'content';
4747: } elsif ($prefix eq 'bottom') {
4748: $prefix = 'msg';
4749: }
4750: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4751: $$rowtotal += $itemcount;
4752: return $datatable;
4753: }
4754:
4755: sub trust_titles {
4756: return &Apache::lonlocal::texthash(
4757: content => "Access to this domain's content by others",
4758: shared => "Access to other domain's content by this domain",
4759: enroll => "Enrollment in this domain's courses by others",
4760: othcoau => "Co-author roles in this domain for others",
4761: coaurem => "Co-author roles for this domain's users elsewhere",
4762: domroles => "Domain roles in this domain assignable to others",
4763: catalog => "Course Catalog for this domain displayed elsewhere",
4764: reqcrs => "Requests for creation of courses in this domain by others",
4765: msg => "Users in other domains can send messages to this domain",
4766: exc => "Allow all, but exclude specific domains",
4767: inc => "Deny all, but include specific domains",
4768: );
1.275 raeburn 4769: }
4770:
1.138 raeburn 4771: sub build_location_hashes {
1.275 raeburn 4772: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 4773: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 4774: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 4775: my %iphost = &Apache::lonnet::get_iphost();
4776: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4777: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4778: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4779: foreach my $id (@{$iphost{$primary_ip}}) {
4780: my $intdom = &Apache::lonnet::internet_dom($id);
4781: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4782: push(@{$intdoms},$intdom);
4783: }
4784: }
4785: }
4786: foreach my $ip (keys(%iphost)) {
4787: if (ref($iphost{$ip}) eq 'ARRAY') {
4788: foreach my $id (@{$iphost{$ip}}) {
4789: my $location = &Apache::lonnet::internet_dom($id);
4790: if ($location) {
1.275 raeburn 4791: if (grep(/^\Q$location\E$/,@{$intdoms})) {
4792: my $dom = &Apache::lonnet::host_domain($id);
4793: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
4794: push(@{$instdoms},$dom);
4795: }
4796: next;
4797: }
1.138 raeburn 4798: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4799: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4800: push(@{$by_ip->{$ip}},$location);
4801: }
4802: } else {
4803: $by_ip->{$ip} = [$location];
4804: }
4805: }
4806: }
4807: }
4808: }
4809: foreach my $ip (sort(keys(%{$by_ip}))) {
4810: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4811: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4812: my $first = $by_ip->{$ip}->[0];
4813: if (ref($by_location->{$first}) eq 'ARRAY') {
4814: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4815: push(@{$by_location->{$first}},$ip);
4816: }
4817: } else {
4818: $by_location->{$first} = [$ip];
4819: }
4820: }
4821: }
4822: return;
4823: }
4824:
1.145 raeburn 4825: sub current_offloads_to {
4826: my ($dom,$settings,$servers) = @_;
4827: my (%spareid,%otherdomconfigs);
1.152 raeburn 4828: if (ref($servers) eq 'HASH') {
1.145 raeburn 4829: foreach my $lonhost (sort(keys(%{$servers}))) {
4830: my $gotspares;
1.152 raeburn 4831: if (ref($settings) eq 'HASH') {
4832: if (ref($settings->{'spares'}) eq 'HASH') {
4833: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4834: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4835: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4836: $gotspares = 1;
4837: }
1.145 raeburn 4838: }
4839: }
4840: unless ($gotspares) {
4841: my $gotspares;
4842: my $serverhomeID =
4843: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4844: my $serverhomedom =
4845: &Apache::lonnet::host_domain($serverhomeID);
4846: if ($serverhomedom ne $dom) {
4847: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4848: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4849: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4850: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4851: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4852: $gotspares = 1;
4853: }
4854: }
4855: } else {
4856: $otherdomconfigs{$serverhomedom} =
4857: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4858: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4859: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4860: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4861: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4862: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4863: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4864: $gotspares = 1;
4865: }
4866: }
4867: }
4868: }
4869: }
4870: }
4871: }
4872: unless ($gotspares) {
4873: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4874: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4875: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4876: } else {
4877: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4878: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4879: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4880: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4881: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4882: } else {
1.150 raeburn 4883: my %what = (
4884: spareid => 1,
4885: );
4886: my ($result,$returnhash) =
4887: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4888: if ($result eq 'ok') {
4889: if (ref($returnhash) eq 'HASH') {
4890: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4891: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4892: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4893: }
4894: }
1.145 raeburn 4895: }
4896: }
4897: }
4898: }
4899: }
4900: }
4901: return %spareid;
4902: }
4903:
4904: sub spares_row {
1.261 raeburn 4905: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4906: my $css_class;
4907: my $numinrow = 4;
4908: my $itemcount = 1;
4909: my $datatable;
1.152 raeburn 4910: my %typetitles = &sparestype_titles();
4911: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4912: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4913: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4914: my ($othercontrol,$serverdom);
4915: if ($serverhome ne $server) {
4916: $serverdom = &Apache::lonnet::host_domain($serverhome);
4917: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4918: } else {
4919: $serverdom = &Apache::lonnet::host_domain($server);
4920: if ($serverdom ne $dom) {
4921: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4922: }
4923: }
4924: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 4925: my $checkednow;
4926: if (ref($curroffloadnow) eq 'HASH') {
4927: if ($curroffloadnow->{$server}) {
4928: $checkednow = ' checked="checked"';
4929: }
4930: }
1.145 raeburn 4931: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4932: $datatable .= '<tr'.$css_class.'>
4933: <td rowspan="2">
1.183 bisitz 4934: <span class="LC_nobreak">'.
4935: &mt('[_1] when busy, offloads to:'
1.261 raeburn 4936: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 4937: '<span class="LC_nobreak">'."\n".
1.261 raeburn 4938: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4939: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 4940: "\n";
1.145 raeburn 4941: my (%current,%canselect);
1.152 raeburn 4942: my @choices =
4943: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4944: foreach my $type ('primary','default') {
4945: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4946: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4947: my @spares = @{$spareid->{$server}{$type}};
4948: if (@spares > 0) {
1.152 raeburn 4949: if ($othercontrol) {
4950: $current{$type} = join(', ',@spares);
4951: } else {
4952: $current{$type} .= '<table>';
4953: my $numspares = scalar(@spares);
4954: for (my $i=0; $i<@spares; $i++) {
4955: my $rem = $i%($numinrow);
4956: if ($rem == 0) {
4957: if ($i > 0) {
4958: $current{$type} .= '</tr>';
4959: }
4960: $current{$type} .= '<tr>';
1.145 raeburn 4961: }
1.152 raeburn 4962: $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'".');" /> '.
4963: $spareid->{$server}{$type}[$i].
4964: '</label></td>'."\n";
4965: }
4966: my $rem = @spares%($numinrow);
4967: my $colsleft = $numinrow - $rem;
4968: if ($colsleft > 1 ) {
4969: $current{$type} .= '<td colspan="'.$colsleft.
4970: '" class="LC_left_item">'.
4971: ' </td>';
4972: } elsif ($colsleft == 1) {
4973: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4974: }
1.152 raeburn 4975: $current{$type} .= '</tr></table>';
1.150 raeburn 4976: }
1.145 raeburn 4977: }
4978: }
4979: if ($current{$type} eq '') {
4980: $current{$type} = &mt('None specified');
4981: }
1.152 raeburn 4982: if ($othercontrol) {
4983: if ($type eq 'primary') {
4984: $canselect{$type} = $othercontrol;
4985: }
4986: } else {
4987: $canselect{$type} =
4988: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4989: '<select name="newspare_'.$type.'_'.$server.'" '.
4990: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4991: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4992: if (@choices > 0) {
4993: foreach my $lonhost (@choices) {
4994: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4995: }
4996: }
4997: $canselect{$type} .= '</select>'."\n";
4998: }
4999: } else {
5000: $current{$type} = &mt('Could not be determined');
5001: if ($type eq 'primary') {
5002: $canselect{$type} = $othercontrol;
5003: }
1.145 raeburn 5004: }
1.152 raeburn 5005: if ($type eq 'default') {
5006: $datatable .= '<tr'.$css_class.'>';
5007: }
5008: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5009: '<td>'.$current{$type}.'</td>'."\n".
5010: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 5011: }
5012: $itemcount ++;
5013: }
5014: }
5015: $$rowtotal += $itemcount;
5016: return $datatable;
5017: }
5018:
1.152 raeburn 5019: sub possible_newspares {
5020: my ($server,$currspares,$serverhomes,$altids) = @_;
5021: my $serverhostname = &Apache::lonnet::hostname($server);
5022: my %excluded;
5023: if ($serverhostname ne '') {
5024: %excluded = (
5025: $serverhostname => 1,
5026: );
5027: }
5028: if (ref($currspares) eq 'HASH') {
5029: foreach my $type (keys(%{$currspares})) {
5030: if (ref($currspares->{$type}) eq 'ARRAY') {
5031: if (@{$currspares->{$type}} > 0) {
5032: foreach my $curr (@{$currspares->{$type}}) {
5033: my $hostname = &Apache::lonnet::hostname($curr);
5034: $excluded{$hostname} = 1;
5035: }
5036: }
5037: }
5038: }
5039: }
5040: my @choices;
5041: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5042: if (keys(%{$serverhomes}) > 1) {
5043: foreach my $name (sort(keys(%{$serverhomes}))) {
5044: unless ($excluded{$name}) {
5045: if (exists($altids->{$serverhomes->{$name}})) {
5046: push(@choices,$altids->{$serverhomes->{$name}});
5047: } else {
5048: push(@choices,$serverhomes->{$name});
1.145 raeburn 5049: }
5050: }
5051: }
5052: }
5053: }
1.152 raeburn 5054: return sort(@choices);
1.145 raeburn 5055: }
5056:
1.150 raeburn 5057: sub print_loadbalancing {
5058: my ($dom,$settings,$rowtotal) = @_;
5059: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5060: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5061: my $numinrow = 1;
5062: my $datatable;
5063: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 5064: my (%currbalancer,%currtargets,%currrules,%existing);
5065: if (ref($settings) eq 'HASH') {
5066: %existing = %{$settings};
5067: }
5068: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5069: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
5070: \%currtargets,\%currrules);
1.150 raeburn 5071: } else {
5072: return;
5073: }
5074: my ($othertitle,$usertypes,$types) =
5075: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 5076: my $rownum = 8;
1.150 raeburn 5077: if (ref($types) eq 'ARRAY') {
5078: $rownum += scalar(@{$types});
5079: }
1.171 raeburn 5080: my @css_class = ('LC_odd_row','LC_even_row');
5081: my $balnum = 0;
5082: my $islast;
5083: my (@toshow,$disabledtext);
5084: if (keys(%currbalancer) > 0) {
5085: @toshow = sort(keys(%currbalancer));
5086: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5087: push(@toshow,'');
5088: }
5089: } else {
5090: @toshow = ('');
5091: $disabledtext = &mt('No existing load balancer');
5092: }
5093: foreach my $lonhost (@toshow) {
5094: if ($balnum == scalar(@toshow)-1) {
5095: $islast = 1;
5096: } else {
5097: $islast = 0;
5098: }
5099: my $cssidx = $balnum%2;
5100: my $targets_div_style = 'display: none';
5101: my $disabled_div_style = 'display: block';
5102: my $homedom_div_style = 'display: none';
5103: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
5104: '<td rowspan="'.$rownum.'" valign="top">'.
5105: '<p>';
5106: if ($lonhost eq '') {
1.210 raeburn 5107: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 5108: if (keys(%currbalancer) > 0) {
5109: $datatable .= &mt('Add balancer:');
5110: } else {
5111: $datatable .= &mt('Enable balancer:');
5112: }
5113: $datatable .= ' '.
5114: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5115: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5116: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5117: '<option value="" selected="selected">'.&mt('None').
5118: '</option>'."\n";
5119: foreach my $server (sort(keys(%servers))) {
5120: next if ($currbalancer{$server});
5121: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5122: }
1.210 raeburn 5123: $datatable .=
1.171 raeburn 5124: '</select>'."\n".
5125: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5126: } else {
5127: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5128: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5129: &mt('Stop balancing').'</label>'.
5130: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5131: $targets_div_style = 'display: block';
5132: $disabled_div_style = 'display: none';
5133: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5134: $homedom_div_style = 'display: block';
5135: }
5136: }
5137: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
5138: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5139: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5140: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5141: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5142: my @sparestypes = ('primary','default');
5143: my %typetitles = &sparestype_titles();
1.284 raeburn 5144: my %hostherechecked = (
5145: no => ' checked="checked"',
5146: );
1.171 raeburn 5147: foreach my $sparetype (@sparestypes) {
5148: my $targettable;
5149: for (my $i=0; $i<$numspares; $i++) {
5150: my $checked;
5151: if (ref($currtargets{$lonhost}) eq 'HASH') {
5152: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5153: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5154: $checked = ' checked="checked"';
5155: }
5156: }
5157: }
5158: my ($chkboxval,$disabled);
5159: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5160: $chkboxval = $spares[$i];
5161: }
5162: if (exists($currbalancer{$spares[$i]})) {
5163: $disabled = ' disabled="disabled"';
5164: }
1.210 raeburn 5165: $targettable .=
1.253 raeburn 5166: '<td><span class="LC_nobreak"><label>'.
5167: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 5168: $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 5169: '</span></label></span></td>';
1.171 raeburn 5170: my $rem = $i%($numinrow);
5171: if ($rem == 0) {
5172: if (($i > 0) && ($i < $numspares-1)) {
5173: $targettable .= '</tr>';
5174: }
5175: if ($i < $numspares-1) {
5176: $targettable .= '<tr>';
1.150 raeburn 5177: }
5178: }
5179: }
1.171 raeburn 5180: if ($targettable ne '') {
5181: my $rem = $numspares%($numinrow);
5182: my $colsleft = $numinrow - $rem;
5183: if ($colsleft > 1 ) {
5184: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5185: ' </td>';
5186: } elsif ($colsleft == 1) {
5187: $targettable .= '<td class="LC_left_item"> </td>';
5188: }
5189: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5190: '<table><tr>'.$targettable.'</tr></table><br />';
5191: }
1.284 raeburn 5192: $hostherechecked{$sparetype} = '';
5193: if (ref($currtargets{$lonhost}) eq 'HASH') {
5194: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5195: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5196: $hostherechecked{$sparetype} = ' checked="checked"';
5197: $hostherechecked{'no'} = '';
5198: }
5199: }
5200: }
5201: }
5202: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5203: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5204: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5205: foreach my $sparetype (@sparestypes) {
5206: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5207: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5208: '</i></label><br />';
1.171 raeburn 5209: }
5210: $datatable .= '</div></td></tr>'.
5211: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5212: $othertitle,$usertypes,$types,\%servers,
5213: \%currbalancer,$lonhost,
5214: $targets_div_style,$homedom_div_style,
5215: $css_class[$cssidx],$balnum,$islast);
5216: $$rowtotal += $rownum;
5217: $balnum ++;
5218: }
5219: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5220: return $datatable;
5221: }
5222:
5223: sub get_loadbalancers_config {
5224: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
5225: return unless ((ref($servers) eq 'HASH') &&
5226: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
5227: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
5228: if (keys(%{$existing}) > 0) {
5229: my $oldlonhost;
5230: foreach my $key (sort(keys(%{$existing}))) {
5231: if ($key eq 'lonhost') {
5232: $oldlonhost = $existing->{'lonhost'};
5233: $currbalancer->{$oldlonhost} = 1;
5234: } elsif ($key eq 'targets') {
5235: if ($oldlonhost) {
5236: $currtargets->{$oldlonhost} = $existing->{'targets'};
5237: }
5238: } elsif ($key eq 'rules') {
5239: if ($oldlonhost) {
5240: $currrules->{$oldlonhost} = $existing->{'rules'};
5241: }
5242: } elsif (ref($existing->{$key}) eq 'HASH') {
5243: $currbalancer->{$key} = 1;
5244: $currtargets->{$key} = $existing->{$key}{'targets'};
5245: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 5246: }
5247: }
1.171 raeburn 5248: } else {
5249: my ($balancerref,$targetsref) =
5250: &Apache::lonnet::get_lonbalancer_config($servers);
5251: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5252: foreach my $server (sort(keys(%{$balancerref}))) {
5253: $currbalancer->{$server} = 1;
5254: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5255: }
5256: }
5257: }
1.171 raeburn 5258: return;
1.150 raeburn 5259: }
5260:
5261: sub loadbalancing_rules {
5262: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 5263: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5264: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5265: my $output;
1.171 raeburn 5266: my $num = 0;
1.210 raeburn 5267: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5268: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5269: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5270: foreach my $type (@{$alltypes}) {
1.171 raeburn 5271: $num ++;
1.150 raeburn 5272: my $current;
5273: if (ref($currrules) eq 'HASH') {
5274: $current = $currrules->{$type};
5275: }
1.253 raeburn 5276: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 5277: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5278: $current = '';
5279: }
5280: }
5281: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 5282: $servers,$currbalancer,$lonhost,$dom,
5283: $targets_div_style,$homedom_div_style,
5284: $css_class,$balnum,$num,$islast);
1.150 raeburn 5285: }
5286: }
5287: return $output;
5288: }
5289:
5290: sub loadbalancing_titles {
5291: my ($dom,$intdom,$usertypes,$types) = @_;
5292: my %othertypes = (
5293: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5294: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5295: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5296: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 5297: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5298: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5299: );
1.209 raeburn 5300: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 5301: if (ref($types) eq 'ARRAY') {
5302: unshift(@alltypes,@{$types},'default');
5303: }
5304: my %titles;
5305: foreach my $type (@alltypes) {
5306: if ($type =~ /^_LC_/) {
5307: $titles{$type} = $othertypes{$type};
5308: } elsif ($type eq 'default') {
5309: $titles{$type} = &mt('All users from [_1]',$dom);
5310: if (ref($types) eq 'ARRAY') {
5311: if (@{$types} > 0) {
5312: $titles{$type} = &mt('Other users from [_1]',$dom);
5313: }
5314: }
5315: } elsif (ref($usertypes) eq 'HASH') {
5316: $titles{$type} = $usertypes->{$type};
5317: }
5318: }
5319: return (\@alltypes,\%othertypes,\%titles);
5320: }
5321:
5322: sub loadbalance_rule_row {
1.171 raeburn 5323: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5324: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 5325: my @rulenames;
1.150 raeburn 5326: my %ruletitles = &offloadtype_text();
1.209 raeburn 5327: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 5328: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 5329: } else {
1.209 raeburn 5330: @rulenames = ('default','homeserver');
5331: if ($type eq '_LC_external') {
5332: push(@rulenames,'externalbalancer');
5333: } else {
5334: push(@rulenames,'specific');
5335: }
5336: push(@rulenames,'none');
1.150 raeburn 5337: }
5338: my $style = $targets_div_style;
1.253 raeburn 5339: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 5340: $style = $homedom_div_style;
5341: }
1.171 raeburn 5342: my $space;
5343: if ($islast && $num == 1) {
5344: $space = '<div display="inline-block"> </div>';
5345: }
1.210 raeburn 5346: my $output =
1.171 raeburn 5347: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
5348: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5349: '<td valaign="top">'.$space.
5350: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 5351: for (my $i=0; $i<@rulenames; $i++) {
5352: my $rule = $rulenames[$i];
5353: my ($checked,$extra);
5354: if ($rulenames[$i] eq 'default') {
5355: $rule = '';
5356: }
5357: if ($rulenames[$i] eq 'specific') {
5358: if (ref($servers) eq 'HASH') {
5359: my $default;
5360: if (($current ne '') && (exists($servers->{$current}))) {
5361: $checked = ' checked="checked"';
5362: }
5363: unless ($checked) {
5364: $default = ' selected="selected"';
5365: }
1.210 raeburn 5366: $extra =
1.171 raeburn 5367: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5368: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5369: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5370: '<option value=""'.$default.'></option>'."\n";
5371: foreach my $server (sort(keys(%{$servers}))) {
5372: if (ref($currbalancer) eq 'HASH') {
5373: next if (exists($currbalancer->{$server}));
5374: }
1.150 raeburn 5375: my $selected;
1.171 raeburn 5376: if ($server eq $current) {
1.150 raeburn 5377: $selected = ' selected="selected"';
5378: }
1.171 raeburn 5379: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 5380: }
5381: $extra .= '</select>';
5382: }
5383: } elsif ($rule eq $current) {
5384: $checked = ' checked="checked"';
5385: }
5386: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 5387: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5388: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5389: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 5390: ')"'.$checked.' /> ';
5391: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
5392: $output .= $ruletitles{'particular'};
5393: } else {
5394: $output .= $ruletitles{$rulenames[$i]};
5395: }
5396: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 5397: }
5398: $output .= '</div></td></tr>'."\n";
5399: return $output;
5400: }
5401:
5402: sub offloadtype_text {
5403: my %ruletitles = &Apache::lonlocal::texthash (
5404: 'default' => 'Offloads to default destinations',
5405: 'homeserver' => "Offloads to user's home server",
5406: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5407: 'specific' => 'Offloads to specific server',
1.161 raeburn 5408: 'none' => 'No offload',
1.209 raeburn 5409: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5410: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 5411: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 5412: );
5413: return %ruletitles;
5414: }
5415:
5416: sub sparestype_titles {
5417: my %typestitles = &Apache::lonlocal::texthash (
5418: 'primary' => 'primary',
5419: 'default' => 'default',
5420: );
5421: return %typestitles;
5422: }
5423:
1.28 raeburn 5424: sub contact_titles {
5425: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 5426: 'supportemail' => 'Support E-mail address',
5427: 'adminemail' => 'Default Server Admin E-mail address',
5428: 'errormail' => 'Error reports to be e-mailed to',
5429: 'packagesmail' => 'Package update alerts to be e-mailed to',
5430: 'helpdeskmail' => "Helpdesk requests for this domain's users",
1.289 raeburn 5431: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
1.286 raeburn 5432: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5433: 'requestsmail' => 'E-mail from course requests requiring approval',
5434: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 5435: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 5436: );
5437: my %short_titles = &Apache::lonlocal::texthash (
5438: adminemail => 'Admin E-mail address',
5439: supportemail => 'Support E-mail',
5440: );
5441: return (\%titles,\%short_titles);
5442: }
5443:
1.286 raeburn 5444: sub helpform_fields {
5445: my %titles = &Apache::lonlocal::texthash (
5446: 'username' => 'Name',
5447: 'user' => 'Username/domain',
5448: 'phone' => 'Phone',
5449: 'cc' => 'Cc e-mail',
5450: 'course' => 'Course Details',
5451: 'section' => 'Sections',
1.289 raeburn 5452: 'screenshot' => 'File upload',
1.286 raeburn 5453: );
5454: my @fields = ('username','phone','user','course','section','cc','screenshot');
5455: my %possoptions = (
5456: username => ['yes','no','req'],
1.289 raeburn 5457: phone => ['yes','no','req'],
1.286 raeburn 5458: user => ['yes','no'],
1.289 raeburn 5459: cc => ['yes','no'],
1.286 raeburn 5460: course => ['yes','no'],
5461: section => ['yes','no'],
5462: screenshot => ['yes','no'],
5463: );
5464: my %fieldoptions = &Apache::lonlocal::texthash (
5465: 'yes' => 'Optional',
5466: 'req' => 'Required',
5467: 'no' => "Not shown",
5468: );
5469: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5470: }
5471:
1.72 raeburn 5472: sub tool_titles {
5473: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 5474: aboutme => 'Personal web page',
1.86 raeburn 5475: blog => 'Blog',
1.162 raeburn 5476: webdav => 'WebDAV',
1.86 raeburn 5477: portfolio => 'Portfolio',
1.88 bisitz 5478: official => 'Official courses (with institutional codes)',
5479: unofficial => 'Unofficial courses',
1.98 raeburn 5480: community => 'Communities',
1.216 raeburn 5481: textbook => 'Textbook courses',
1.271 raeburn 5482: placement => 'Placement tests',
1.86 raeburn 5483: );
1.72 raeburn 5484: return %titles;
5485: }
5486:
1.101 raeburn 5487: sub courserequest_titles {
5488: my %titles = &Apache::lonlocal::texthash (
5489: official => 'Official',
5490: unofficial => 'Unofficial',
5491: community => 'Communities',
1.216 raeburn 5492: textbook => 'Textbook',
1.271 raeburn 5493: placement => 'Placement tests',
1.101 raeburn 5494: norequest => 'Not allowed',
1.104 raeburn 5495: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5496: validate => 'With validation',
5497: autolimit => 'Numerical limit',
1.103 raeburn 5498: unlimited => '(blank for unlimited)',
1.101 raeburn 5499: );
5500: return %titles;
5501: }
5502:
1.163 raeburn 5503: sub authorrequest_titles {
5504: my %titles = &Apache::lonlocal::texthash (
5505: norequest => 'Not allowed',
5506: approval => 'Approval by Dom. Coord.',
5507: automatic => 'Automatic approval',
5508: );
5509: return %titles;
1.210 raeburn 5510: }
1.163 raeburn 5511:
1.101 raeburn 5512: sub courserequest_conditions {
5513: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5514: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 5515: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 5516: );
5517: return %conditions;
5518: }
5519:
5520:
1.27 raeburn 5521: sub print_usercreation {
1.30 raeburn 5522: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 5523: my $numinrow = 4;
1.28 raeburn 5524: my $datatable;
5525: if ($position eq 'top') {
1.30 raeburn 5526: $$rowtotal ++;
1.34 raeburn 5527: my $rowcount = 0;
1.32 raeburn 5528: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 5529: if (ref($rules) eq 'HASH') {
5530: if (keys(%{$rules}) > 0) {
1.32 raeburn 5531: $datatable .= &user_formats_row('username',$settings,$rules,
5532: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 5533: $$rowtotal ++;
1.32 raeburn 5534: $rowcount ++;
5535: }
5536: }
5537: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5538: if (ref($idrules) eq 'HASH') {
5539: if (keys(%{$idrules}) > 0) {
5540: $datatable .= &user_formats_row('id',$settings,$idrules,
5541: $idruleorder,$numinrow,$rowcount);
5542: $$rowtotal ++;
5543: $rowcount ++;
1.28 raeburn 5544: }
5545: }
1.39 raeburn 5546: if ($rowcount == 0) {
5547: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5548: $$rowtotal ++;
5549: $rowcount ++;
5550: }
1.34 raeburn 5551: } elsif ($position eq 'middle') {
1.224 raeburn 5552: my @creators = ('author','course','requestcrs');
1.37 raeburn 5553: my ($rules,$ruleorder) =
5554: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 5555: my %lt = &usercreation_types();
5556: my %checked;
5557: if (ref($settings) eq 'HASH') {
5558: if (ref($settings->{'cancreate'}) eq 'HASH') {
5559: foreach my $item (@creators) {
5560: $checked{$item} = $settings->{'cancreate'}{$item};
5561: }
5562: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5563: foreach my $item (@creators) {
5564: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5565: $checked{$item} = 'none';
5566: }
5567: }
5568: }
5569: }
5570: my $rownum = 0;
5571: foreach my $item (@creators) {
5572: $rownum ++;
1.224 raeburn 5573: if ($checked{$item} eq '') {
5574: $checked{$item} = 'any';
1.34 raeburn 5575: }
5576: my $css_class;
5577: if ($rownum%2) {
5578: $css_class = '';
5579: } else {
5580: $css_class = ' class="LC_odd_row" ';
5581: }
5582: $datatable .= '<tr'.$css_class.'>'.
5583: '<td><span class="LC_nobreak">'.$lt{$item}.
5584: '</span></td><td align="right">';
1.224 raeburn 5585: my @options = ('any');
5586: if (ref($rules) eq 'HASH') {
5587: if (keys(%{$rules}) > 0) {
5588: push(@options,('official','unofficial'));
1.37 raeburn 5589: }
5590: }
1.224 raeburn 5591: push(@options,'none');
1.37 raeburn 5592: foreach my $option (@options) {
1.50 raeburn 5593: my $type = 'radio';
1.34 raeburn 5594: my $check = ' ';
1.224 raeburn 5595: if ($checked{$item} eq $option) {
5596: $check = ' checked="checked" ';
1.34 raeburn 5597: }
5598: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5599: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5600: $item.'" value="'.$option.'"'.$check.'/> '.
5601: $lt{$option}.'</label> </span>';
5602: }
5603: $datatable .= '</td></tr>';
5604: }
1.28 raeburn 5605: } else {
5606: my @contexts = ('author','course','domain');
5607: my @authtypes = ('int','krb4','krb5','loc');
5608: my %checked;
5609: if (ref($settings) eq 'HASH') {
5610: if (ref($settings->{'authtypes'}) eq 'HASH') {
5611: foreach my $item (@contexts) {
5612: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5613: foreach my $auth (@authtypes) {
5614: if ($settings->{'authtypes'}{$item}{$auth}) {
5615: $checked{$item}{$auth} = ' checked="checked" ';
5616: }
5617: }
5618: }
5619: }
1.27 raeburn 5620: }
1.35 raeburn 5621: } else {
5622: foreach my $item (@contexts) {
1.36 raeburn 5623: foreach my $auth (@authtypes) {
1.35 raeburn 5624: $checked{$item}{$auth} = ' checked="checked" ';
5625: }
5626: }
1.27 raeburn 5627: }
1.28 raeburn 5628: my %title = &context_names();
5629: my %authname = &authtype_names();
5630: my $rownum = 0;
5631: my $css_class;
5632: foreach my $item (@contexts) {
5633: if ($rownum%2) {
5634: $css_class = '';
5635: } else {
5636: $css_class = ' class="LC_odd_row" ';
5637: }
1.30 raeburn 5638: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5639: '<td>'.$title{$item}.
5640: '</td><td class="LC_left_item">'.
5641: '<span class="LC_nobreak">';
5642: foreach my $auth (@authtypes) {
5643: $datatable .= '<label>'.
5644: '<input type="checkbox" name="'.$item.'_auth" '.
5645: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5646: $authname{$auth}.'</label> ';
5647: }
5648: $datatable .= '</span></td></tr>';
5649: $rownum ++;
1.27 raeburn 5650: }
1.30 raeburn 5651: $$rowtotal += $rownum;
1.27 raeburn 5652: }
5653: return $datatable;
5654: }
5655:
1.224 raeburn 5656: sub print_selfcreation {
5657: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 5658: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 5659: if (ref($settings) eq 'HASH') {
5660: if (ref($settings->{'cancreate'}) eq 'HASH') {
5661: $createsettings = $settings->{'cancreate'};
1.236 raeburn 5662: if (ref($createsettings) eq 'HASH') {
5663: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5664: @selfcreate = @{$createsettings->{'selfcreate'}};
5665: } elsif ($createsettings->{'selfcreate'} ne '') {
5666: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5667: @selfcreate = ('email','login','sso');
5668: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5669: @selfcreate = ($createsettings->{'selfcreate'});
5670: }
5671: }
5672: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5673: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 5674: }
5675: }
5676: }
5677: }
5678: my %radiohash;
5679: my $numinrow = 4;
5680: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5681: if ($position eq 'top') {
5682: my %choices = &Apache::lonlocal::texthash (
5683: cancreate_login => 'Institutional Login',
5684: cancreate_sso => 'Institutional Single Sign On',
5685: );
5686: my @toggles = sort(keys(%choices));
5687: my %defaultchecked = (
5688: 'cancreate_login' => 'off',
5689: 'cancreate_sso' => 'off',
5690: );
1.228 raeburn 5691: my ($onclick,$itemcount);
1.224 raeburn 5692: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5693: \%choices,$itemcount,$onclick);
1.228 raeburn 5694: $$rowtotal += $itemcount;
5695:
1.224 raeburn 5696: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5697:
5698: if (ref($usertypes) eq 'HASH') {
5699: if (keys(%{$usertypes}) > 0) {
5700: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5701: $dom,$numinrow,$othertitle,
1.228 raeburn 5702: 'statustocreate',$$rowtotal);
1.224 raeburn 5703: $$rowtotal ++;
5704: }
5705: }
1.240 raeburn 5706: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5707: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5708: $fieldtitles{'inststatus'} = &mt('Institutional status');
5709: my $rem;
5710: my $numperrow = 2;
5711: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5712: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 5713: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 5714: '<td class="LC_left_item">'."\n".
5715: '<table><tr><td>'."\n";
5716: for (my $i=0; $i<@fields; $i++) {
5717: $rem = $i%($numperrow);
5718: if ($rem == 0) {
5719: if ($i > 0) {
5720: $datatable .= '</tr>';
5721: }
5722: $datatable .= '<tr>';
5723: }
5724: my $currval;
1.248 raeburn 5725: if (ref($createsettings) eq 'HASH') {
5726: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5727: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5728: }
1.240 raeburn 5729: }
5730: $datatable .= '<td class="LC_left_item">'.
5731: '<span class="LC_nobreak">'.
5732: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5733: 'value="'.$currval.'" size="10" /> '.
5734: $fieldtitles{$fields[$i]}.'</span></td>';
5735: }
5736: my $colsleft = $numperrow - $rem;
5737: if ($colsleft > 1 ) {
5738: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5739: ' </td>';
5740: } elsif ($colsleft == 1) {
5741: $datatable .= '<td class="LC_left_item"> </td>';
5742: }
5743: $datatable .= '</tr></table></td></tr>';
5744: $$rowtotal ++;
1.224 raeburn 5745: } elsif ($position eq 'middle') {
5746: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5747: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5748: $usertypes->{'default'} = $othertitle;
5749: if (ref($types) eq 'ARRAY') {
5750: push(@{$types},'default');
5751: $usertypes->{'default'} = $othertitle;
5752: foreach my $status (@{$types}) {
5753: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 5754: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 5755: $$rowtotal ++;
1.224 raeburn 5756: }
5757: }
5758: } else {
1.236 raeburn 5759: my %choices = &Apache::lonlocal::texthash (
5760: cancreate_email => 'E-mail address as username',
5761: );
5762: my @toggles = sort(keys(%choices));
5763: my %defaultchecked = (
5764: 'cancreate_email' => 'off',
5765: );
5766: my $itemcount = 0;
5767: my $display = 'none';
5768: if (grep(/^\Qemail\E$/,@selfcreate)) {
5769: $display = 'block';
5770: }
5771: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5772: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5773: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5774: my $usertypes = {};
5775: my $order = [];
5776: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
5777: $usertypes = $domdefaults{'inststatustypes'};
5778: $order = $domdefaults{'inststatusguest'};
5779: }
5780: if (ref($order) eq 'ARRAY') {
5781: push(@{$order},'default');
5782: if (@{$order} > 1) {
5783: $usertypes->{'default'} = &mt('Other users');
5784: $additional .= '<table><tr>';
5785: foreach my $status (@{$order}) {
5786: $additional .= '<th>'.$usertypes->{$status}.'</th>';
5787: }
5788: $additional .= '</tr><tr>';
5789: foreach my $status (@{$order}) {
5790: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 5791: }
1.236 raeburn 5792: $additional .= '</tr></table>';
1.224 raeburn 5793: } else {
1.236 raeburn 5794: $usertypes->{'default'} = &mt('All users');
5795: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 5796: }
5797: }
1.236 raeburn 5798: $additional .= '</div>'."\n";
5799:
5800: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 5801: \%choices,$$rowtotal,$onclick,$additional);
5802: $$rowtotal ++;
1.236 raeburn 5803: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 5804: $$rowtotal ++;
1.224 raeburn 5805: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 5806: $numinrow = 1;
1.236 raeburn 5807: if (ref($order) eq 'ARRAY') {
5808: foreach my $status (@{$order}) {
1.228 raeburn 5809: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5810: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
5811: $$rowtotal ++;
5812: }
5813: }
1.224 raeburn 5814: my ($emailrules,$emailruleorder) =
5815: &Apache::lonnet::inst_userrules($dom,'email');
5816: if (ref($emailrules) eq 'HASH') {
5817: if (keys(%{$emailrules}) > 0) {
5818: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 5819: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 5820: $$rowtotal ++;
5821: }
5822: }
1.228 raeburn 5823: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 5824: }
5825: return $datatable;
5826: }
5827:
1.236 raeburn 5828: sub email_as_username {
5829: my ($rowtotal,$processing,$type) = @_;
5830: my %choices =
5831: &Apache::lonlocal::texthash (
5832: automatic => 'Automatic approval',
5833: approval => 'Queued for approval',
5834: );
5835: my $output;
5836: foreach my $option ('automatic','approval') {
5837: my $checked;
5838: if (ref($processing) eq 'HASH') {
5839: if ($type eq '') {
5840: if (!exists($processing->{'default'})) {
5841: if ($option eq 'automatic') {
5842: $checked = ' checked="checked"';
5843: }
5844: } else {
5845: if ($processing->{'default'} eq $option) {
5846: $checked = ' checked="checked"';
5847: }
5848: }
5849: } else {
5850: if (!exists($processing->{$type})) {
5851: if ($option eq 'automatic') {
5852: $checked = ' checked="checked"';
5853: }
5854: } else {
5855: if ($processing->{$type} eq $option) {
5856: $checked = ' checked="checked"';
5857: }
5858: }
5859: }
5860: } elsif ($option eq 'automatic') {
5861: $checked = ' checked="checked"';
5862: }
5863: my $name = 'cancreate_emailprocess';
5864: if (($type ne '') && ($type ne 'default')) {
5865: $name .= '_'.$type;
5866: }
5867: $output .= '<span class="LC_nobreak"><label>'.
5868: '<input type="radio" name="'.$name.'"'.
5869: $checked.' value="'.$option.'" />'.
5870: $choices{$option}.'</label></span>';
5871: if ($type eq '') {
5872: $output .= ' ';
5873: } else {
5874: $output .= '<br />';
5875: }
5876: }
5877: $$rowtotal ++;
5878: return $output;
5879: }
5880:
1.165 raeburn 5881: sub captcha_choice {
1.169 raeburn 5882: my ($context,$settings,$itemcount) = @_;
1.269 raeburn 5883: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5884: $vertext,$currver);
1.165 raeburn 5885: my %lt = &captcha_phrases();
5886: $keyentry = 'hidden';
5887: if ($context eq 'cancreate') {
1.224 raeburn 5888: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 5889: } elsif ($context eq 'login') {
5890: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 5891: }
5892: if (ref($settings) eq 'HASH') {
5893: if ($settings->{'captcha'}) {
5894: $checked{$settings->{'captcha'}} = ' checked="checked"';
5895: } else {
5896: $checked{'original'} = ' checked="checked"';
5897: }
5898: if ($settings->{'captcha'} eq 'recaptcha') {
5899: $pubtext = $lt{'pub'};
5900: $privtext = $lt{'priv'};
5901: $keyentry = 'text';
1.269 raeburn 5902: $vertext = $lt{'ver'};
5903: $currver = $settings->{'recaptchaversion'};
5904: if ($currver ne '2') {
5905: $currver = 1;
5906: }
1.165 raeburn 5907: }
5908: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5909: $currpub = $settings->{'recaptchakeys'}{'public'};
5910: $currpriv = $settings->{'recaptchakeys'}{'private'};
5911: }
5912: } else {
5913: $checked{'original'} = ' checked="checked"';
5914: }
1.169 raeburn 5915: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5916: my $output = '<tr'.$css_class.'>'.
5917: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 5918: '<table><tr><td>'."\n";
5919: foreach my $option ('original','recaptcha','notused') {
5920: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5921: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5922: $lt{$option}.'</label></span>';
5923: unless ($option eq 'notused') {
5924: $output .= (' 'x2)."\n";
5925: }
5926: }
5927: #
5928: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5929: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 5930: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 5931: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 5932: #
1.165 raeburn 5933: $output .= '</td></tr>'."\n".
5934: '<tr><td>'."\n".
5935: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5936: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5937: $currpub.'" size="40" /></span><br />'."\n".
5938: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5939: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 5940: $currpriv.'" size="40" /></span><br />'.
5941: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5942: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5943: $currver.'" size="3" /></span><br />'.
5944: '</td></tr></table>'."\n".
1.165 raeburn 5945: '</td></tr>';
5946: return $output;
5947: }
5948:
1.32 raeburn 5949: sub user_formats_row {
5950: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5951: my $output;
5952: my %text = (
5953: 'username' => 'new usernames',
5954: 'id' => 'IDs',
1.45 raeburn 5955: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5956: );
5957: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5958: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5959: '<td><span class="LC_nobreak">';
5960: if ($type eq 'email') {
5961: $output .= &mt("Formats disallowed for $text{$type}: ");
5962: } else {
5963: $output .= &mt("Format rules to check for $text{$type}: ");
5964: }
5965: $output .= '</span></td>'.
5966: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5967: my $rem;
5968: if (ref($ruleorder) eq 'ARRAY') {
5969: for (my $i=0; $i<@{$ruleorder}; $i++) {
5970: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5971: my $rem = $i%($numinrow);
5972: if ($rem == 0) {
5973: if ($i > 0) {
5974: $output .= '</tr>';
5975: }
5976: $output .= '<tr>';
5977: }
5978: my $check = ' ';
1.39 raeburn 5979: if (ref($settings) eq 'HASH') {
5980: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5981: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5982: $check = ' checked="checked" ';
5983: }
1.27 raeburn 5984: }
5985: }
5986: $output .= '<td class="LC_left_item">'.
5987: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5988: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5989: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5990: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5991: }
5992: }
5993: $rem = @{$ruleorder}%($numinrow);
5994: }
5995: my $colsleft = $numinrow - $rem;
5996: if ($colsleft > 1 ) {
5997: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5998: ' </td>';
5999: } elsif ($colsleft == 1) {
6000: $output .= '<td class="LC_left_item"> </td>';
6001: }
6002: $output .= '</tr></table></td></tr>';
6003: return $output;
6004: }
6005:
1.34 raeburn 6006: sub usercreation_types {
6007: my %lt = &Apache::lonlocal::texthash (
6008: author => 'When adding a co-author',
6009: course => 'When adding a user to a course',
1.100 raeburn 6010: requestcrs => 'When requesting a course',
1.34 raeburn 6011: any => 'Any',
6012: official => 'Institutional only ',
6013: unofficial => 'Non-institutional only',
6014: none => 'None',
6015: );
6016: return %lt;
1.48 raeburn 6017: }
1.34 raeburn 6018:
1.224 raeburn 6019: sub selfcreation_types {
6020: my %lt = &Apache::lonlocal::texthash (
6021: selfcreate => 'User creates own account',
6022: any => 'Any',
6023: official => 'Institutional only ',
6024: unofficial => 'Non-institutional only',
6025: email => 'E-mail address',
6026: login => 'Institutional Login',
6027: sso => 'SSO',
6028: );
6029: }
6030:
1.28 raeburn 6031: sub authtype_names {
6032: my %lt = &Apache::lonlocal::texthash(
6033: int => 'Internal',
6034: krb4 => 'Kerberos 4',
6035: krb5 => 'Kerberos 5',
6036: loc => 'Local',
6037: );
6038: return %lt;
6039: }
6040:
6041: sub context_names {
6042: my %context_title = &Apache::lonlocal::texthash(
6043: author => 'Creating users when an Author',
6044: course => 'Creating users when in a course',
6045: domain => 'Creating users when a Domain Coordinator',
6046: );
6047: return %context_title;
6048: }
6049:
1.33 raeburn 6050: sub print_usermodification {
6051: my ($position,$dom,$settings,$rowtotal) = @_;
6052: my $numinrow = 4;
6053: my ($context,$datatable,$rowcount);
6054: if ($position eq 'top') {
6055: $rowcount = 0;
6056: $context = 'author';
6057: foreach my $role ('ca','aa') {
6058: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6059: $numinrow,$rowcount);
6060: $$rowtotal ++;
6061: $rowcount ++;
6062: }
1.230 raeburn 6063: } elsif ($position eq 'bottom') {
1.33 raeburn 6064: $context = 'course';
6065: $rowcount = 0;
6066: foreach my $role ('st','ep','ta','in','cr') {
6067: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6068: $numinrow,$rowcount);
6069: $$rowtotal ++;
6070: $rowcount ++;
6071: }
6072: }
6073: return $datatable;
6074: }
6075:
1.43 raeburn 6076: sub print_defaults {
1.236 raeburn 6077: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 6078: my $rownum = 0;
6079: my ($datatable,$css_class);
1.236 raeburn 6080: if ($position eq 'top') {
6081: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6082: 'datelocale_def','portal_def');
6083: my %defaults;
6084: if (ref($settings) eq 'HASH') {
6085: %defaults = %{$settings};
1.43 raeburn 6086: } else {
1.236 raeburn 6087: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6088: foreach my $item (@items) {
6089: $defaults{$item} = $domdefaults{$item};
6090: }
1.43 raeburn 6091: }
1.236 raeburn 6092: my $titles = &defaults_titles($dom);
6093: foreach my $item (@items) {
6094: if ($rownum%2) {
6095: $css_class = '';
6096: } else {
6097: $css_class = ' class="LC_odd_row" ';
6098: }
6099: $datatable .= '<tr'.$css_class.'>'.
6100: '<td><span class="LC_nobreak">'.$titles->{$item}.
6101: '</span></td><td class="LC_right_item" colspan="3">';
6102: if ($item eq 'auth_def') {
6103: my @authtypes = ('internal','krb4','krb5','localauth');
6104: my %shortauth = (
6105: internal => 'int',
6106: krb4 => 'krb4',
6107: krb5 => 'krb5',
6108: localauth => 'loc'
6109: );
6110: my %authnames = &authtype_names();
6111: foreach my $auth (@authtypes) {
6112: my $checked = ' ';
6113: if ($defaults{$item} eq $auth) {
6114: $checked = ' checked="checked" ';
6115: }
6116: $datatable .= '<label><input type="radio" name="'.$item.
6117: '" value="'.$auth.'"'.$checked.'/>'.
6118: $authnames{$shortauth{$auth}}.'</label> ';
6119: }
6120: } elsif ($item eq 'timezone_def') {
6121: my $includeempty = 1;
6122: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6123: } elsif ($item eq 'datelocale_def') {
6124: my $includeempty = 1;
6125: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
6126: } elsif ($item eq 'lang_def') {
1.263 raeburn 6127: my $includeempty = 1;
6128: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 6129: } else {
6130: my $size;
6131: if ($item eq 'portal_def') {
6132: $size = ' size="25"';
6133: }
6134: $datatable .= '<input type="text" name="'.$item.'" value="'.
6135: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 6136: }
1.236 raeburn 6137: $datatable .= '</td></tr>';
6138: $rownum ++;
6139: }
6140: } else {
6141: my (%defaults);
6142: if (ref($settings) eq 'HASH') {
6143: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
6144: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
6145: my $maxnum = @{$settings->{'inststatusorder'}};
6146: for (my $i=0; $i<$maxnum; $i++) {
6147: $css_class = $rownum%2?' class="LC_odd_row"':'';
6148: my $item = $settings->{'inststatusorder'}->[$i];
6149: my $title = $settings->{'inststatustypes'}->{$item};
6150: my $guestok;
6151: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
6152: $guestok = 1;
6153: }
6154: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6155: $datatable .= '<tr'.$css_class.'>'.
6156: '<td><span class="LC_nobreak">'.
6157: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6158: for (my $k=0; $k<=$maxnum; $k++) {
6159: my $vpos = $k+1;
6160: my $selstr;
6161: if ($k == $i) {
6162: $selstr = ' selected="selected" ';
6163: }
6164: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6165: }
6166: my ($checkedon,$checkedoff);
6167: $checkedoff = ' checked="checked"';
6168: if ($guestok) {
6169: $checkedon = $checkedoff;
6170: $checkedoff = '';
6171: }
6172: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6173: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6174: &mt('delete').'</span></td>'.
6175: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
6176: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
6177: '</span></td>'.
6178: '<td class="LC_right_item"><span class="LC_nobreak">'.
6179: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
6180: &mt('Yes').'</label>'.(' 'x2).
6181: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
6182: &mt('No').'</label></span></td></tr>';
6183: }
6184: $css_class = $rownum%2?' class="LC_odd_row"':'';
6185: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6186: $datatable .= '<tr '.$css_class.'>'.
6187: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6188: for (my $k=0; $k<=$maxnum; $k++) {
6189: my $vpos = $k+1;
6190: my $selstr;
6191: if ($k == $maxnum) {
6192: $selstr = ' selected="selected" ';
6193: }
6194: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6195: }
6196: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 6197: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 6198: ' '.&mt('(new)').
6199: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
6200: &mt('Name displayed:').
6201: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6202: '<td class="LC_right_item"><span class="LC_nobreak">'.
6203: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
6204: &mt('Yes').'</label>'.(' 'x2).
6205: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
6206: &mt('No').'</label></span></td></tr>';
6207: '</tr>'."\n";
6208: $rownum ++;
1.141 raeburn 6209: }
1.43 raeburn 6210: }
6211: }
6212: $$rowtotal += $rownum;
6213: return $datatable;
6214: }
6215:
1.168 raeburn 6216: sub get_languages_hash {
6217: my %langchoices;
6218: foreach my $id (&Apache::loncommon::languageids()) {
6219: my $code = &Apache::loncommon::supportedlanguagecode($id);
6220: if ($code ne '') {
6221: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6222: }
6223: }
6224: return %langchoices;
6225: }
6226:
1.43 raeburn 6227: sub defaults_titles {
1.141 raeburn 6228: my ($dom) = @_;
1.43 raeburn 6229: my %titles = &Apache::lonlocal::texthash (
6230: 'auth_def' => 'Default authentication type',
6231: 'auth_arg_def' => 'Default authentication argument',
6232: 'lang_def' => 'Default language',
1.54 raeburn 6233: 'timezone_def' => 'Default timezone',
1.68 raeburn 6234: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6235: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 6236: );
1.141 raeburn 6237: if ($dom) {
6238: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6239: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6240: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6241: $protocol = 'http' if ($protocol ne 'https');
6242: if ($uint_dom) {
6243: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6244: $uint_dom);
6245: }
6246: }
1.43 raeburn 6247: return (\%titles);
6248: }
6249:
1.46 raeburn 6250: sub print_scantronformat {
6251: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6252: my $itemcount = 1;
1.60 raeburn 6253: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6254: %confhash);
1.46 raeburn 6255: my $switchserver = &check_switchserver($dom,$confname);
6256: my %lt = &Apache::lonlocal::texthash (
1.95 www 6257: default => 'Default bubblesheet format file error',
6258: custom => 'Custom bubblesheet format file error',
1.46 raeburn 6259: );
6260: my %scantronfiles = (
6261: default => 'default.tab',
6262: custom => 'custom.tab',
6263: );
6264: foreach my $key (keys(%scantronfiles)) {
6265: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6266: .$scantronfiles{$key};
6267: }
6268: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6269: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6270: if (!$switchserver) {
6271: my $servadm = $r->dir_config('lonAdmEMail');
6272: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6273: if ($configuserok eq 'ok') {
6274: if ($author_ok eq 'ok') {
6275: my %legacyfile = (
6276: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6277: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
6278: );
6279: my %md5chk;
6280: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6281: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6282: chomp($md5chk{$type});
1.46 raeburn 6283: }
6284: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6285: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6286: ($scantronurls{$type},my $error) =
1.46 raeburn 6287: &legacy_scantronformat($r,$dom,$confname,
6288: $type,$legacyfile{$type},
6289: $scantronurls{$type},
6290: $scantronfiles{$type});
1.60 raeburn 6291: if ($error ne '') {
6292: $error{$type} = $error;
6293: }
6294: }
6295: if (keys(%error) == 0) {
6296: $is_custom = 1;
6297: $confhash{'scantron'}{'scantronformat'} =
6298: $scantronurls{'custom'};
6299: my $putresult =
6300: &Apache::lonnet::put_dom('configuration',
6301: \%confhash,$dom);
6302: if ($putresult ne 'ok') {
6303: $error{'custom'} =
6304: '<span class="LC_error">'.
6305: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6306: }
1.46 raeburn 6307: }
6308: } else {
1.60 raeburn 6309: ($scantronurls{'default'},my $error) =
1.46 raeburn 6310: &legacy_scantronformat($r,$dom,$confname,
6311: 'default',$legacyfile{'default'},
6312: $scantronurls{'default'},
6313: $scantronfiles{'default'});
1.60 raeburn 6314: if ($error eq '') {
6315: $confhash{'scantron'}{'scantronformat'} = '';
6316: my $putresult =
6317: &Apache::lonnet::put_dom('configuration',
6318: \%confhash,$dom);
6319: if ($putresult ne 'ok') {
6320: $error{'default'} =
6321: '<span class="LC_error">'.
6322: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6323: }
6324: } else {
6325: $error{'default'} = $error;
6326: }
1.46 raeburn 6327: }
6328: }
6329: }
6330: } else {
1.95 www 6331: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 6332: }
6333: }
6334: if (ref($settings) eq 'HASH') {
6335: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6336: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
6337: if ((!@info) || ($info[0] eq 'no_such_dir')) {
6338: $scantronurl = '';
6339: } else {
6340: $scantronurl = $settings->{'scantronformat'};
6341: }
6342: $is_custom = 1;
6343: } else {
6344: $scantronurl = $scantronurls{'default'};
6345: }
6346: } else {
1.60 raeburn 6347: if ($is_custom) {
6348: $scantronurl = $scantronurls{'custom'};
6349: } else {
6350: $scantronurl = $scantronurls{'default'};
6351: }
1.46 raeburn 6352: }
6353: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6354: $datatable .= '<tr'.$css_class.'>';
6355: if (!$is_custom) {
1.65 raeburn 6356: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6357: '<span class="LC_nobreak">';
1.46 raeburn 6358: if ($scantronurl) {
1.199 raeburn 6359: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6360: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 6361: } else {
6362: $datatable = &mt('File unavailable for display');
6363: }
1.65 raeburn 6364: $datatable .= '</span></td>';
1.60 raeburn 6365: if (keys(%error) == 0) {
6366: $datatable .= '<td valign="bottom">';
6367: if (!$switchserver) {
6368: $datatable .= &mt('Upload:').'<br />';
6369: }
6370: } else {
6371: my $errorstr;
6372: foreach my $key (sort(keys(%error))) {
6373: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6374: }
6375: $datatable .= '<td>'.$errorstr;
6376: }
1.46 raeburn 6377: } else {
6378: if (keys(%error) > 0) {
6379: my $errorstr;
6380: foreach my $key (sort(keys(%error))) {
6381: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6382: }
1.60 raeburn 6383: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 6384: } elsif ($scantronurl) {
1.199 raeburn 6385: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
6386: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 6387: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 6388: $link.
6389: '<label><input type="checkbox" name="scantronformat_del"'.
6390: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 6391: '<td><span class="LC_nobreak"> '.
6392: &mt('Replace:').'</span><br />';
1.46 raeburn 6393: }
6394: }
6395: if (keys(%error) == 0) {
6396: if ($switchserver) {
6397: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6398: } else {
1.65 raeburn 6399: $datatable .='<span class="LC_nobreak"> '.
6400: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 6401: }
6402: }
6403: $datatable .= '</td></tr>';
6404: $$rowtotal ++;
6405: return $datatable;
6406: }
6407:
6408: sub legacy_scantronformat {
6409: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6410: my ($url,$error);
6411: my @statinfo = &Apache::lonnet::stat_file($newurl);
6412: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6413: (my $result,$url) =
6414: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6415: '','',$newfile);
6416: if ($result ne 'ok') {
1.130 raeburn 6417: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 6418: }
6419: }
6420: return ($url,$error);
6421: }
1.43 raeburn 6422:
1.49 raeburn 6423: sub print_coursecategories {
1.57 raeburn 6424: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6425: my $datatable;
6426: if ($position eq 'top') {
1.238 raeburn 6427: my (%checked);
6428: my @catitems = ('unauth','auth');
6429: my @cattypes = ('std','domonly','codesrch','none');
6430: $checked{'unauth'} = 'std';
6431: $checked{'auth'} = 'std';
6432: if (ref($settings) eq 'HASH') {
6433: foreach my $type (@cattypes) {
6434: if ($type eq $settings->{'unauth'}) {
6435: $checked{'unauth'} = $type;
6436: }
6437: if ($type eq $settings->{'auth'}) {
6438: $checked{'auth'} = $type;
6439: }
6440: }
6441: }
6442: my %lt = &Apache::lonlocal::texthash (
6443: unauth => 'Catalog type for unauthenticated users',
6444: auth => 'Catalog type for authenticated users',
6445: none => 'No catalog',
6446: std => 'Standard catalog',
6447: domonly => 'Domain-only catalog',
6448: codesrch => "Code search form",
6449: );
6450: my $itemcount = 0;
6451: foreach my $item (@catitems) {
6452: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6453: $datatable .= '<tr '.$css_class.'>'.
6454: '<td>'.$lt{$item}.'</td>'.
6455: '<td class="LC_right_item"><span class="LC_nobreak">';
6456: foreach my $type (@cattypes) {
6457: my $ischecked;
6458: if ($checked{$item} eq $type) {
6459: $ischecked=' checked="checked"';
6460: }
6461: $datatable .= '<label>'.
6462: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6463: ' />'.$lt{$type}.'</label> ';
6464: }
6465: $datatable .= '</td></tr>';
6466: $itemcount ++;
6467: }
6468: $$rowtotal += $itemcount;
6469: } elsif ($position eq 'middle') {
1.57 raeburn 6470: my $toggle_cats_crs = ' ';
6471: my $toggle_cats_dom = ' checked="checked" ';
6472: my $can_cat_crs = ' ';
6473: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 6474: my $toggle_catscomm_comm = ' ';
6475: my $toggle_catscomm_dom = ' checked="checked" ';
6476: my $can_catcomm_comm = ' ';
6477: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 6478: my $toggle_catsplace_place = ' ';
6479: my $toggle_catsplace_dom = ' checked="checked" ';
6480: my $can_catplace_place = ' ';
6481: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 6482:
1.57 raeburn 6483: if (ref($settings) eq 'HASH') {
6484: if ($settings->{'togglecats'} eq 'crs') {
6485: $toggle_cats_crs = $toggle_cats_dom;
6486: $toggle_cats_dom = ' ';
6487: }
6488: if ($settings->{'categorize'} eq 'crs') {
6489: $can_cat_crs = $can_cat_dom;
6490: $can_cat_dom = ' ';
6491: }
1.120 raeburn 6492: if ($settings->{'togglecatscomm'} eq 'comm') {
6493: $toggle_catscomm_comm = $toggle_catscomm_dom;
6494: $toggle_catscomm_dom = ' ';
6495: }
6496: if ($settings->{'categorizecomm'} eq 'comm') {
6497: $can_catcomm_comm = $can_catcomm_dom;
6498: $can_catcomm_dom = ' ';
6499: }
1.272 raeburn 6500: if ($settings->{'togglecatsplace'} eq 'place') {
6501: $toggle_catsplace_place = $toggle_catsplace_dom;
6502: $toggle_catsplace_dom = ' ';
6503: }
6504: if ($settings->{'categorizeplace'} eq 'place') {
6505: $can_catplace_place = $can_catplace_dom;
6506: $can_catplace_dom = ' ';
6507: }
1.57 raeburn 6508: }
6509: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 6510: togglecats => 'Show/Hide a course in catalog',
6511: togglecatscomm => 'Show/Hide a community in catalog',
6512: togglecatsplace => 'Show/Hide a placement test in catalog',
6513: categorize => 'Assign a category to a course',
6514: categorizecomm => 'Assign a category to a community',
6515: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 6516: );
6517: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 6518: dom => 'Set in Domain',
6519: crs => 'Set in Course',
6520: comm => 'Set in Community',
6521: place => 'Set in Placement Test',
1.57 raeburn 6522: );
6523: $datatable = '<tr class="LC_odd_row">'.
6524: '<td>'.$title{'togglecats'}.'</td>'.
6525: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6526: '<input type="radio" name="togglecats"'.
6527: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6528: '<label><input type="radio" name="togglecats"'.
6529: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
6530: '</tr><tr>'.
6531: '<td>'.$title{'categorize'}.'</td>'.
6532: '<td class="LC_right_item"><span class="LC_nobreak">'.
6533: '<label><input type="radio" name="categorize"'.
6534: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6535: '<label><input type="radio" name="categorize"'.
6536: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 6537: '</tr><tr class="LC_odd_row">'.
6538: '<td>'.$title{'togglecatscomm'}.'</td>'.
6539: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6540: '<input type="radio" name="togglecatscomm"'.
6541: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6542: '<label><input type="radio" name="togglecatscomm"'.
6543: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
6544: '</tr><tr>'.
6545: '<td>'.$title{'categorizecomm'}.'</td>'.
6546: '<td class="LC_right_item"><span class="LC_nobreak">'.
6547: '<label><input type="radio" name="categorizecomm"'.
6548: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6549: '<label><input type="radio" name="categorizecomm"'.
6550: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 6551: '</tr><tr>'.
6552: '<td>'.$title{'togglecatsplace'}.'</td>'.
6553: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6554: '<input type="radio" name="togglecatsplace"'.
6555: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6556: '<label><input type="radio" name="togglecatscomm"'.
6557: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
6558: '</tr><tr>'.
6559: '<td>'.$title{'categorizeplace'}.'</td>'.
6560: '<td class="LC_right_item"><span class="LC_nobreak">'.
6561: '<label><input type="radio" name="categorizeplace"'.
6562: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6563: '<label><input type="radio" name="categorizeplace"'.
6564: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 6565: '</tr>';
1.272 raeburn 6566: $$rowtotal += 6;
1.57 raeburn 6567: } else {
6568: my $css_class;
6569: my $itemcount = 1;
6570: my $cathash;
6571: if (ref($settings) eq 'HASH') {
6572: $cathash = $settings->{'cats'};
6573: }
6574: if (ref($cathash) eq 'HASH') {
6575: my (@cats,@trails,%allitems,%idx,@jsarray);
6576: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
6577: \%allitems,\%idx,\@jsarray);
6578: my $maxdepth = scalar(@cats);
6579: my $colattrib = '';
6580: if ($maxdepth > 2) {
6581: $colattrib = ' colspan="2" ';
6582: }
6583: my @path;
6584: if (@cats > 0) {
6585: if (ref($cats[0]) eq 'ARRAY') {
6586: my $numtop = @{$cats[0]};
6587: my $maxnum = $numtop;
1.120 raeburn 6588: my %default_names = (
6589: instcode => &mt('Official courses'),
6590: communities => &mt('Communities'),
1.272 raeburn 6591: placement => &mt('Placement Tests'),
1.120 raeburn 6592: );
6593:
6594: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6595: ($cathash->{'instcode::0'} eq '') ||
6596: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 6597: ($cathash->{'communities::0'} eq '') ||
6598: (!grep(/^placement$/,@{$cats[0]})) ||
6599: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 6600: $maxnum ++;
6601: }
6602: my $lastidx;
6603: for (my $i=0; $i<$numtop; $i++) {
6604: my $parent = $cats[0][$i];
6605: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6606: my $item = &escape($parent).'::0';
6607: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6608: $lastidx = $idx{$item};
6609: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6610: .'<select name="'.$item.'"'.$chgstr.'>';
6611: for (my $k=0; $k<=$maxnum; $k++) {
6612: my $vpos = $k+1;
6613: my $selstr;
6614: if ($k == $i) {
6615: $selstr = ' selected="selected" ';
6616: }
6617: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6618: }
1.214 raeburn 6619: $datatable .= '</select></span></td><td>';
1.272 raeburn 6620: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 6621: $datatable .= '<span class="LC_nobreak">'
6622: .$default_names{$parent}.'</span>';
6623: if ($parent eq 'instcode') {
6624: $datatable .= '<br /><span class="LC_nobreak">('
6625: .&mt('with institutional codes')
6626: .')</span></td><td'.$colattrib.'>';
6627: } else {
6628: $datatable .= '<table><tr><td>';
6629: }
6630: $datatable .= '<span class="LC_nobreak">'
6631: .'<label><input type="radio" name="'
6632: .$parent.'" value="1" checked="checked" />'
6633: .&mt('Display').'</label>';
6634: if ($parent eq 'instcode') {
6635: $datatable .= ' ';
6636: } else {
6637: $datatable .= '</span></td></tr><tr><td>'
6638: .'<span class="LC_nobreak">';
6639: }
6640: $datatable .= '<label><input type="radio" name="'
6641: .$parent.'" value="0" />'
6642: .&mt('Do not display').'</label></span>';
1.272 raeburn 6643: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 6644: $datatable .= '</td></tr></table>';
6645: }
6646: $datatable .= '</td>';
1.57 raeburn 6647: } else {
6648: $datatable .= $parent
1.214 raeburn 6649: .' <span class="LC_nobreak"><label>'
6650: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6651: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6652: }
6653: my $depth = 1;
6654: push(@path,$parent);
6655: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6656: pop(@path);
6657: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6658: $itemcount ++;
6659: }
1.48 raeburn 6660: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6661: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6662: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6663: for (my $k=0; $k<=$maxnum; $k++) {
6664: my $vpos = $k+1;
6665: my $selstr;
1.57 raeburn 6666: if ($k == $numtop) {
1.48 raeburn 6667: $selstr = ' selected="selected" ';
6668: }
6669: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6670: }
1.59 bisitz 6671: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6672: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6673: .'</tr>'."\n";
1.48 raeburn 6674: $itemcount ++;
1.272 raeburn 6675: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6676: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6677: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6678: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6679: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6680: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6681: for (my $k=0; $k<=$maxnum; $k++) {
6682: my $vpos = $k+1;
6683: my $selstr;
6684: if ($k == $maxnum) {
6685: $selstr = ' selected="selected" ';
6686: }
6687: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6688: }
1.120 raeburn 6689: $datatable .= '</select></span></td>'.
6690: '<td><span class="LC_nobreak">'.
6691: $default_names{$default}.'</span>';
6692: if ($default eq 'instcode') {
6693: $datatable .= '<br /><span class="LC_nobreak">('
6694: .&mt('with institutional codes').')</span>';
6695: }
6696: $datatable .= '</td>'
6697: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6698: .&mt('Display').'</label> '
6699: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6700: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6701: }
6702: }
6703: }
1.57 raeburn 6704: } else {
6705: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6706: }
6707: } else {
1.238 raeburn 6708: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6709: .&initialize_categories($itemcount);
1.48 raeburn 6710: }
1.57 raeburn 6711: $$rowtotal += $itemcount;
1.48 raeburn 6712: }
6713: return $datatable;
6714: }
6715:
1.69 raeburn 6716: sub print_serverstatuses {
6717: my ($dom,$settings,$rowtotal) = @_;
6718: my $datatable;
6719: my @pages = &serverstatus_pages();
6720: my (%namedaccess,%machineaccess);
6721: foreach my $type (@pages) {
6722: $namedaccess{$type} = '';
6723: $machineaccess{$type}= '';
6724: }
6725: if (ref($settings) eq 'HASH') {
6726: foreach my $type (@pages) {
6727: if (exists($settings->{$type})) {
6728: if (ref($settings->{$type}) eq 'HASH') {
6729: foreach my $key (keys(%{$settings->{$type}})) {
6730: if ($key eq 'namedusers') {
6731: $namedaccess{$type} = $settings->{$type}->{$key};
6732: } elsif ($key eq 'machines') {
6733: $machineaccess{$type} = $settings->{$type}->{$key};
6734: }
6735: }
6736: }
6737: }
6738: }
6739: }
1.81 raeburn 6740: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6741: my $rownum = 0;
6742: my $css_class;
6743: foreach my $type (@pages) {
6744: $rownum ++;
6745: $css_class = $rownum%2?' class="LC_odd_row"':'';
6746: $datatable .= '<tr'.$css_class.'>'.
6747: '<td><span class="LC_nobreak">'.
6748: $titles->{$type}.'</span></td>'.
6749: '<td class="LC_left_item">'.
6750: '<input type="text" name="'.$type.'_namedusers" '.
6751: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6752: '<td class="LC_right_item">'.
6753: '<span class="LC_nobreak">'.
6754: '<input type="text" name="'.$type.'_machines" '.
6755: 'value="'.$machineaccess{$type}.'" size="10" />'.
6756: '</td></tr>'."\n";
6757: }
6758: $$rowtotal += $rownum;
6759: return $datatable;
6760: }
6761:
6762: sub serverstatus_pages {
6763: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 6764: 'checksums','clusterstatus','certstatus','metadata_keywords',
6765: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
6766: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6767: }
6768:
1.236 raeburn 6769: sub defaults_javascript {
6770: my ($settings) = @_;
1.289 raeburn 6771: return unless (ref($settings) eq 'HASH');
1.236 raeburn 6772: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6773: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6774: if ($maxnum eq '') {
6775: $maxnum = 0;
6776: }
6777: $maxnum ++;
1.249 raeburn 6778: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 6779: return <<"ENDSCRIPT";
6780: <script type="text/javascript">
6781: // <![CDATA[
6782: function reorderTypes(form,caller) {
6783: var changedVal;
6784: $jstext
6785: var newpos = 'addinststatus_pos';
6786: var current = new Array;
6787: var maxh = $maxnum;
6788: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6789: var oldVal;
6790: if (caller == newpos) {
6791: changedVal = newitemVal;
6792: } else {
6793: var curritem = 'inststatus_pos_'+caller;
6794: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6795: current[newitemVal] = newpos;
6796: }
6797: for (var i=0; i<inststatuses.length; i++) {
6798: if (inststatuses[i] != caller) {
6799: var elementName = 'inststatus_pos_'+inststatuses[i];
6800: if (form.elements[elementName]) {
6801: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6802: current[currVal] = elementName;
6803: }
6804: }
6805: }
6806: for (var j=0; j<maxh; j++) {
6807: if (current[j] == undefined) {
6808: oldVal = j;
6809: }
6810: }
6811: if (oldVal < changedVal) {
6812: for (var k=oldVal+1; k<=changedVal ; k++) {
6813: var elementName = current[k];
6814: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6815: }
6816: } else {
6817: for (var k=changedVal; k<oldVal; k++) {
6818: var elementName = current[k];
6819: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6820: }
6821: }
6822: return;
6823: }
6824:
6825: // ]]>
6826: </script>
6827:
6828: ENDSCRIPT
6829: }
6830: }
6831:
1.49 raeburn 6832: sub coursecategories_javascript {
6833: my ($settings) = @_;
1.57 raeburn 6834: my ($output,$jstext,$cathash);
1.49 raeburn 6835: if (ref($settings) eq 'HASH') {
1.57 raeburn 6836: $cathash = $settings->{'cats'};
6837: }
6838: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6839: my (@cats,@jsarray,%idx);
1.57 raeburn 6840: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6841: if (@jsarray > 0) {
6842: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6843: for (my $i=0; $i<@jsarray; $i++) {
6844: if (ref($jsarray[$i]) eq 'ARRAY') {
6845: my $catstr = join('","',@{$jsarray[$i]});
6846: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6847: }
6848: }
6849: }
6850: } else {
6851: $jstext = ' var categories = Array(1);'."\n".
6852: ' categories[0] = Array("instcode_pos");'."\n";
6853: }
1.237 bisitz 6854: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6855: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 6856: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 6857: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6858: &js_escape(\$instcode_reserved);
6859: &js_escape(\$communities_reserved);
1.272 raeburn 6860: &js_escape(\$placement_reserved);
1.265 damieng 6861: &js_escape(\$choose_again);
1.49 raeburn 6862: $output = <<"ENDSCRIPT";
6863: <script type="text/javascript">
1.109 raeburn 6864: // <![CDATA[
1.49 raeburn 6865: function reorderCats(form,parent,item,idx) {
6866: var changedVal;
6867: $jstext
6868: var newpos = 'addcategory_pos';
6869: if (parent == '') {
6870: var has_instcode = 0;
6871: var maxtop = categories[idx].length;
6872: for (var j=0; j<maxtop; j++) {
6873: if (categories[idx][j] == 'instcode::0') {
6874: has_instcode == 1;
6875: }
6876: }
6877: if (has_instcode == 0) {
6878: categories[idx][maxtop] = 'instcode_pos';
6879: }
6880: } else {
6881: newpos += '_'+parent;
6882: }
6883: var maxh = 1 + categories[idx].length;
6884: var current = new Array;
6885: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6886: if (item == newpos) {
6887: changedVal = newitemVal;
6888: } else {
6889: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6890: current[newitemVal] = newpos;
6891: }
6892: for (var i=0; i<categories[idx].length; i++) {
6893: var elementName = categories[idx][i];
6894: if (elementName != item) {
6895: if (form.elements[elementName]) {
6896: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6897: current[currVal] = elementName;
6898: }
6899: }
6900: }
6901: var oldVal;
6902: for (var j=0; j<maxh; j++) {
6903: if (current[j] == undefined) {
6904: oldVal = j;
6905: }
6906: }
6907: if (oldVal < changedVal) {
6908: for (var k=oldVal+1; k<=changedVal ; k++) {
6909: var elementName = current[k];
6910: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6911: }
6912: } else {
6913: for (var k=changedVal; k<oldVal; k++) {
6914: var elementName = current[k];
6915: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6916: }
6917: }
6918: return;
6919: }
1.120 raeburn 6920:
6921: function categoryCheck(form) {
6922: if (form.elements['addcategory_name'].value == 'instcode') {
6923: alert('$instcode_reserved\\n$choose_again');
6924: return false;
6925: }
6926: if (form.elements['addcategory_name'].value == 'communities') {
6927: alert('$communities_reserved\\n$choose_again');
6928: return false;
6929: }
1.272 raeburn 6930: if (form.elements['addcategory_name'].value == 'placement') {
6931: alert('$placement_reserved\\n$choose_again');
6932: return false;
6933: }
1.120 raeburn 6934: return true;
6935: }
6936:
1.109 raeburn 6937: // ]]>
1.49 raeburn 6938: </script>
6939:
6940: ENDSCRIPT
6941: return $output;
6942: }
6943:
1.48 raeburn 6944: sub initialize_categories {
6945: my ($itemcount) = @_;
1.120 raeburn 6946: my ($datatable,$css_class,$chgstr);
6947: my %default_names = (
6948: instcode => 'Official courses (with institutional codes)',
6949: communities => 'Communities',
1.272 raeburn 6950: placement => 'Placement Tests',
1.120 raeburn 6951: );
6952: my $select0 = ' selected="selected"';
6953: my $select1 = '';
1.272 raeburn 6954: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6955: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6956: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 6957: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 6958: $select1 = $select0;
6959: $select0 = '';
6960: }
6961: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6962: .'<select name="'.$default.'_pos">'
6963: .'<option value="0"'.$select0.'>1</option>'
6964: .'<option value="1"'.$select1.'>2</option>'
6965: .'<option value="2">3</option></select> '
6966: .$default_names{$default}
6967: .'</span></td><td><span class="LC_nobreak">'
6968: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6969: .&mt('Display').'</label> <label>'
6970: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6971: .'</label></span></td></tr>';
1.120 raeburn 6972: $itemcount ++;
6973: }
1.48 raeburn 6974: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6975: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6976: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6977: .'<select name="addcategory_pos"'.$chgstr.'>'
6978: .'<option value="0">1</option>'
6979: .'<option value="1">2</option>'
6980: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 6981: .&mt('Add category').'</td><td>'.&mt('Name:')
6982: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
6983: return $datatable;
6984: }
6985:
6986: sub build_category_rows {
1.49 raeburn 6987: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6988: my ($text,$name,$item,$chgstr);
1.48 raeburn 6989: if (ref($cats) eq 'ARRAY') {
6990: my $maxdepth = scalar(@{$cats});
6991: if (ref($cats->[$depth]) eq 'HASH') {
6992: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6993: my $numchildren = @{$cats->[$depth]{$parent}};
6994: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 6995: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6996: my ($idxnum,$parent_name,$parent_item);
6997: my $higher = $depth - 1;
6998: if ($higher == 0) {
6999: $parent_name = &escape($parent).'::'.$higher;
7000: } else {
7001: if (ref($path) eq 'ARRAY') {
7002: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7003: }
7004: }
7005: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 7006: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 7007: if ($j < $numchildren) {
1.48 raeburn 7008: $name = $cats->[$depth]{$parent}[$j];
7009: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 7010: $idxnum = $idx->{$item};
7011: } else {
7012: $name = $parent_name;
7013: $item = $parent_item;
1.48 raeburn 7014: }
1.49 raeburn 7015: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
7016: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 7017: for (my $i=0; $i<=$numchildren; $i++) {
7018: my $vpos = $i+1;
7019: my $selstr;
7020: if ($j == $i) {
7021: $selstr = ' selected="selected" ';
7022: }
7023: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
7024: }
7025: $text .= '</select> ';
7026: if ($j < $numchildren) {
7027: my $deeper = $depth+1;
7028: $text .= $name.' '
7029: .'<label><input type="checkbox" name="deletecategory" value="'
7030: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
7031: if(ref($path) eq 'ARRAY') {
7032: push(@{$path},$name);
1.49 raeburn 7033: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 7034: pop(@{$path});
7035: }
7036: } else {
1.59 bisitz 7037: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 7038: if ($j == $numchildren) {
7039: $text .= $name;
7040: } else {
7041: $text .= $item;
7042: }
7043: $text .= '" value="" />';
7044: }
7045: $text .= '</td></tr>';
7046: }
7047: $text .= '</table></td>';
7048: } else {
7049: my $higher = $depth-1;
7050: if ($higher == 0) {
7051: $name = &escape($parent).'::'.$higher;
7052: } else {
7053: if (ref($path) eq 'ARRAY') {
7054: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7055: }
7056: }
7057: my $colspan;
7058: if ($parent ne 'instcode') {
7059: $colspan = $maxdepth - $depth - 1;
7060: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
7061: }
7062: }
7063: }
7064: }
7065: return $text;
7066: }
7067:
1.33 raeburn 7068: sub modifiable_userdata_row {
1.228 raeburn 7069: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
7070: my ($role,$rolename,$statustype);
7071: $role = $item;
1.224 raeburn 7072: if ($context eq 'cancreate') {
1.228 raeburn 7073: if ($item =~ /^emailusername_(.+)$/) {
7074: $statustype = $1;
7075: $role = 'emailusername';
7076: if (ref($usertypes) eq 'HASH') {
7077: if ($usertypes->{$statustype}) {
7078: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7079: } else {
7080: $rolename = &mt('Data provided by user');
7081: }
7082: }
1.224 raeburn 7083: }
7084: } elsif ($context eq 'selfcreate') {
1.63 raeburn 7085: if (ref($usertypes) eq 'HASH') {
7086: $rolename = $usertypes->{$role};
7087: } else {
7088: $rolename = $role;
7089: }
1.33 raeburn 7090: } else {
1.63 raeburn 7091: if ($role eq 'cr') {
7092: $rolename = &mt('Custom role');
7093: } else {
7094: $rolename = &Apache::lonnet::plaintext($role);
7095: }
1.33 raeburn 7096: }
1.224 raeburn 7097: my (@fields,%fieldtitles);
7098: if (ref($fieldsref) eq 'ARRAY') {
7099: @fields = @{$fieldsref};
7100: } else {
7101: @fields = ('lastname','firstname','middlename','generation',
7102: 'permanentemail','id');
7103: }
7104: if ((ref($titlesref) eq 'HASH')) {
7105: %fieldtitles = %{$titlesref};
7106: } else {
7107: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7108: }
1.33 raeburn 7109: my $output;
7110: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7111: $output = '<tr '.$css_class.'>'.
7112: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7113: '<td class="LC_left_item" colspan="2"><table>';
7114: my $rem;
7115: my %checks;
7116: if (ref($settings) eq 'HASH') {
7117: if (ref($settings->{$context}) eq 'HASH') {
7118: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 7119: my $hashref = $settings->{$context}->{$role};
7120: if ($role eq 'emailusername') {
7121: if ($statustype) {
7122: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7123: $hashref = $settings->{$context}->{$role}->{$statustype};
7124: if (ref($hashref) eq 'HASH') {
7125: foreach my $field (@fields) {
7126: if ($hashref->{$field}) {
7127: $checks{$field} = $hashref->{$field};
7128: }
7129: }
7130: }
7131: }
7132: }
7133: } else {
7134: if (ref($hashref) eq 'HASH') {
7135: foreach my $field (@fields) {
7136: if ($hashref->{$field}) {
7137: $checks{$field} = ' checked="checked" ';
7138: }
7139: }
1.33 raeburn 7140: }
7141: }
7142: }
7143: }
7144: }
1.228 raeburn 7145:
1.33 raeburn 7146: for (my $i=0; $i<@fields; $i++) {
7147: my $rem = $i%($numinrow);
7148: if ($rem == 0) {
7149: if ($i > 0) {
7150: $output .= '</tr>';
7151: }
7152: $output .= '<tr>';
7153: }
7154: my $check = ' ';
1.228 raeburn 7155: unless ($role eq 'emailusername') {
7156: if (exists($checks{$fields[$i]})) {
7157: $check = $checks{$fields[$i]}
7158: } else {
7159: if ($role eq 'st') {
7160: if (ref($settings) ne 'HASH') {
7161: $check = ' checked="checked" ';
7162: }
1.33 raeburn 7163: }
7164: }
7165: }
7166: $output .= '<td class="LC_left_item">'.
1.228 raeburn 7167: '<span class="LC_nobreak">';
7168: if ($role eq 'emailusername') {
7169: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7170: $checks{$fields[$i]} = 'omit';
7171: }
7172: foreach my $option ('required','optional','omit') {
7173: my $checked='';
7174: if ($checks{$fields[$i]} eq $option) {
7175: $checked='checked="checked" ';
7176: }
7177: $output .= '<label>'.
7178: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7179: &mt($option).'</label>'.(' ' x2);
7180: }
7181: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7182: } else {
7183: $output .= '<label>'.
7184: '<input type="checkbox" name="canmodify_'.$role.'" '.
7185: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7186: '</label>';
7187: }
7188: $output .= '</span></td>';
1.33 raeburn 7189: $rem = @fields%($numinrow);
7190: }
7191: my $colsleft = $numinrow - $rem;
7192: if ($colsleft > 1 ) {
7193: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7194: ' </td>';
7195: } elsif ($colsleft == 1) {
7196: $output .= '<td class="LC_left_item"> </td>';
7197: }
7198: $output .= '</tr></table></td></tr>';
7199: return $output;
7200: }
1.28 raeburn 7201:
1.93 raeburn 7202: sub insttypes_row {
1.224 raeburn 7203: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 7204: my %lt = &Apache::lonlocal::texthash (
7205: cansearch => 'Users allowed to search',
7206: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 7207: lockablenames => 'User preference to lock name',
1.93 raeburn 7208: );
7209: my $showdom;
7210: if ($context eq 'cansearch') {
7211: $showdom = ' ('.$dom.')';
7212: }
1.165 raeburn 7213: my $class = 'LC_left_item';
7214: if ($context eq 'statustocreate') {
7215: $class = 'LC_right_item';
7216: }
1.224 raeburn 7217: my $css_class = ' class="LC_odd_row"';
7218: if ($rownum ne '') {
7219: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
7220: }
7221: my $output = '<tr'.$css_class.'>'.
7222: '<td>'.$lt{$context}.$showdom.
7223: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7224: my $rem;
7225: if (ref($types) eq 'ARRAY') {
7226: for (my $i=0; $i<@{$types}; $i++) {
7227: if (defined($usertypes->{$types->[$i]})) {
7228: my $rem = $i%($numinrow);
7229: if ($rem == 0) {
7230: if ($i > 0) {
7231: $output .= '</tr>';
7232: }
7233: $output .= '<tr>';
1.23 raeburn 7234: }
1.26 raeburn 7235: my $check = ' ';
1.99 raeburn 7236: if (ref($settings) eq 'HASH') {
7237: if (ref($settings->{$context}) eq 'ARRAY') {
7238: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7239: $check = ' checked="checked" ';
7240: }
7241: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7242: $check = ' checked="checked" ';
7243: }
1.23 raeburn 7244: }
1.26 raeburn 7245: $output .= '<td class="LC_left_item">'.
7246: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7247: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 7248: 'value="'.$types->[$i].'"'.$check.'/>'.
7249: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7250: }
7251: }
1.26 raeburn 7252: $rem = @{$types}%($numinrow);
1.23 raeburn 7253: }
7254: my $colsleft = $numinrow - $rem;
1.131 raeburn 7255: if (($rem == 0) && (@{$types} > 0)) {
7256: $output .= '<tr>';
7257: }
1.23 raeburn 7258: if ($colsleft > 1) {
1.25 raeburn 7259: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 7260: } else {
1.25 raeburn 7261: $output .= '<td class="LC_left_item">';
1.23 raeburn 7262: }
7263: my $defcheck = ' ';
1.99 raeburn 7264: if (ref($settings) eq 'HASH') {
7265: if (ref($settings->{$context}) eq 'ARRAY') {
7266: if (grep(/^default$/,@{$settings->{$context}})) {
7267: $defcheck = ' checked="checked" ';
7268: }
7269: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7270: $defcheck = ' checked="checked" ';
7271: }
1.23 raeburn 7272: }
1.25 raeburn 7273: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 7274: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 7275: 'value="default"'.$defcheck.'/>'.
7276: $othertitle.'</label></span></td>'.
7277: '</tr></table></td></tr>';
7278: return $output;
1.23 raeburn 7279: }
7280:
7281: sub sorted_searchtitles {
7282: my %searchtitles = &Apache::lonlocal::texthash(
7283: 'uname' => 'username',
7284: 'lastname' => 'last name',
7285: 'lastfirst' => 'last name, first name',
7286: );
7287: my @titleorder = ('uname','lastname','lastfirst');
7288: return (\%searchtitles,\@titleorder);
7289: }
7290:
1.25 raeburn 7291: sub sorted_searchtypes {
7292: my %srchtypes_desc = (
7293: exact => 'is exact match',
7294: contains => 'contains ..',
7295: begins => 'begins with ..',
7296: );
7297: my @srchtypeorder = ('exact','begins','contains');
7298: return (\%srchtypes_desc,\@srchtypeorder);
7299: }
7300:
1.3 raeburn 7301: sub usertype_update_row {
7302: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7303: my $datatable;
7304: my $numinrow = 4;
7305: foreach my $type (@{$types}) {
7306: if (defined($usertypes->{$type})) {
7307: $$rownums ++;
7308: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7309: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7310: '</td><td class="LC_left_item"><table>';
7311: for (my $i=0; $i<@{$fields}; $i++) {
7312: my $rem = $i%($numinrow);
7313: if ($rem == 0) {
7314: if ($i > 0) {
7315: $datatable .= '</tr>';
7316: }
7317: $datatable .= '<tr>';
7318: }
7319: my $check = ' ';
1.39 raeburn 7320: if (ref($settings) eq 'HASH') {
7321: if (ref($settings->{'fields'}) eq 'HASH') {
7322: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7323: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7324: $check = ' checked="checked" ';
7325: }
1.3 raeburn 7326: }
7327: }
7328: }
7329:
7330: if ($i == @{$fields}-1) {
7331: my $colsleft = $numinrow - $rem;
7332: if ($colsleft > 1) {
7333: $datatable .= '<td colspan="'.$colsleft.'">';
7334: } else {
7335: $datatable .= '<td>';
7336: }
7337: } else {
7338: $datatable .= '<td>';
7339: }
1.8 raeburn 7340: $datatable .= '<span class="LC_nobreak"><label>'.
7341: '<input type="checkbox" name="updateable_'.$type.
7342: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7343: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 7344: }
7345: $datatable .= '</tr></table></td></tr>';
7346: }
7347: }
7348: return $datatable;
1.1 raeburn 7349: }
7350:
7351: sub modify_login {
1.205 raeburn 7352: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 7353: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7354: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7355: %title = ( coursecatalog => 'Display course catalog',
7356: adminmail => 'Display administrator E-mail address',
1.188 raeburn 7357: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 7358: newuser => 'Link for visitors to create a user account',
7359: loginheader => 'Log-in box header');
7360: @offon = ('off','on');
1.112 raeburn 7361: if (ref($domconfig{login}) eq 'HASH') {
7362: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7363: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7364: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7365: }
7366: }
7367: }
1.9 raeburn 7368: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7369: \%domconfig,\%loginhash);
1.188 raeburn 7370: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7371: foreach my $item (@toggles) {
7372: $loginhash{login}{$item} = $env{'form.'.$item};
7373: }
1.41 raeburn 7374: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 7375: if (ref($colchanges{'login'}) eq 'HASH') {
7376: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7377: \%loginhash);
7378: }
1.110 raeburn 7379:
1.149 raeburn 7380: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 7381: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 7382: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 7383: if (keys(%servers) > 1) {
7384: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 7385: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7386: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7387: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7388: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7389: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7390: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7391: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7392: $changes{'loginvia'}{$lonhost} = 1;
7393: } else {
7394: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7395: $changes{'loginvia'}{$lonhost} = 1;
7396: }
7397: } else {
7398: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7399: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7400: $changes{'loginvia'}{$lonhost} = 1;
7401: }
7402: }
7403: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7404: foreach my $item (@loginvia_attribs) {
7405: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7406: }
7407: } else {
7408: foreach my $item (@loginvia_attribs) {
7409: my $new = $env{'form.'.$lonhost.'_'.$item};
7410: if (($item eq 'serverpath') && ($new eq 'custom')) {
7411: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7412: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7413: $new = '/';
7414: }
7415: }
7416: if (($item eq 'custompath') &&
7417: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7418: $new = '';
7419: }
7420: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7421: $changes{'loginvia'}{$lonhost} = 1;
7422: }
7423: if ($item eq 'exempt') {
1.256 raeburn 7424: $new = &check_exempt_addresses($new);
1.128 raeburn 7425: }
7426: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7427: }
7428: }
1.112 raeburn 7429: } else {
1.128 raeburn 7430: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7431: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 7432: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 7433: foreach my $item (@loginvia_attribs) {
7434: my $new = $env{'form.'.$lonhost.'_'.$item};
7435: if (($item eq 'serverpath') && ($new eq 'custom')) {
7436: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7437: $new = '/';
7438: }
7439: }
7440: if (($item eq 'custompath') &&
7441: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7442: $new = '';
7443: }
7444: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7445: }
1.110 raeburn 7446: }
7447: }
7448: }
7449: }
1.119 raeburn 7450:
1.168 raeburn 7451: my $servadm = $r->dir_config('lonAdmEMail');
7452: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
7453: if (ref($domconfig{'login'}) eq 'HASH') {
7454: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
7455: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
7456: if ($lang eq 'nolang') {
7457: push(@currlangs,$lang);
7458: } elsif (defined($langchoices{$lang})) {
7459: push(@currlangs,$lang);
7460: } else {
7461: next;
7462: }
7463: }
7464: }
7465: }
7466: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
7467: if (@currlangs > 0) {
7468: foreach my $lang (@currlangs) {
7469: if (grep(/^\Q$lang\E$/,@delurls)) {
7470: $changes{'helpurl'}{$lang} = 1;
7471: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
7472: $changes{'helpurl'}{$lang} = 1;
7473: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
7474: push(@newlangs,$lang);
7475: } else {
7476: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7477: }
7478: }
7479: }
7480: unless (grep(/^nolang$/,@currlangs)) {
7481: if ($env{'form.loginhelpurl_nolang.filename'}) {
7482: $changes{'helpurl'}{'nolang'} = 1;
7483: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
7484: push(@newlangs,'nolang');
7485: }
7486: }
7487: if ($env{'form.loginhelpurl_add_lang'}) {
7488: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
7489: ($env{'form.loginhelpurl_add_file.filename'})) {
7490: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
7491: $addedfile = $env{'form.loginhelpurl_add_lang'};
7492: }
7493: }
7494: if ((@newlangs > 0) || ($addedfile)) {
7495: my $error;
7496: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7497: if ($configuserok eq 'ok') {
7498: if ($switchserver) {
7499: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7500: } elsif ($author_ok eq 'ok') {
7501: my @allnew = @newlangs;
7502: if ($addedfile ne '') {
7503: push(@allnew,$addedfile);
7504: }
7505: foreach my $lang (@allnew) {
7506: my $formelem = 'loginhelpurl_'.$lang;
7507: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
7508: $formelem = 'loginhelpurl_add_file';
7509: }
7510: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7511: "help/$lang",'','',$newfile{$lang});
7512: if ($result eq 'ok') {
7513: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
7514: $changes{'helpurl'}{$lang} = 1;
7515: } else {
7516: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
7517: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 7518: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 7519: (!grep(/^\Q$lang\E$/,@delurls))) {
7520: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7521: }
7522: }
7523: }
7524: } else {
7525: $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);
7526: }
7527: } else {
7528: $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);
7529: }
7530: if ($error) {
7531: &Apache::lonnet::logthis($error);
7532: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7533: }
7534: }
1.256 raeburn 7535:
7536: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
7537: if (ref($domconfig{'login'}) eq 'HASH') {
7538: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
7539: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
7540: if ($domservers{$lonhost}) {
7541: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7542: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 7543: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 7544: }
7545: }
7546: }
7547: }
7548: }
7549: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
7550: foreach my $lonhost (sort(keys(%domservers))) {
7551: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7552: $changes{'headtag'}{$lonhost} = 1;
7553: } else {
7554: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
7555: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
7556: }
7557: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
7558: push(@newhosts,$lonhost);
7559: } elsif ($currheadtagurls{$lonhost}) {
7560: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
7561: if ($currexempt{$lonhost}) {
1.289 raeburn 7562: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 7563: $changes{'headtag'}{$lonhost} = 1;
7564: }
7565: } elsif ($possexempt{$lonhost}) {
7566: $changes{'headtag'}{$lonhost} = 1;
7567: }
7568: if ($possexempt{$lonhost}) {
7569: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7570: }
7571: }
7572: }
7573: }
7574: if (@newhosts) {
7575: my $error;
7576: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7577: if ($configuserok eq 'ok') {
7578: if ($switchserver) {
7579: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
7580: } elsif ($author_ok eq 'ok') {
7581: foreach my $lonhost (@newhosts) {
7582: my $formelem = 'loginheadtag_'.$lonhost;
7583: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7584: "login/headtag/$lonhost",'','',
7585: $env{'form.loginheadtag_'.$lonhost.'.filename'});
7586: if ($result eq 'ok') {
7587: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
7588: $changes{'headtag'}{$lonhost} = 1;
7589: if ($possexempt{$lonhost}) {
7590: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7591: }
7592: } else {
7593: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7594: $newheadtagurls{$lonhost},$result);
7595: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7596: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7597: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7598: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7599: }
7600: }
7601: }
7602: } else {
7603: $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);
7604: }
7605: } else {
7606: $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);
7607: }
7608: if ($error) {
7609: &Apache::lonnet::logthis($error);
7610: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7611: }
7612: }
1.169 raeburn 7613: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 7614:
7615: my $defaulthelpfile = '/adm/loginproblems.html';
7616: my $defaulttext = &mt('Default in use');
7617:
1.1 raeburn 7618: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7619: $dom);
7620: if ($putresult eq 'ok') {
1.188 raeburn 7621: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7622: my %defaultchecked = (
7623: 'coursecatalog' => 'on',
1.188 raeburn 7624: 'helpdesk' => 'on',
1.42 raeburn 7625: 'adminmail' => 'off',
1.43 raeburn 7626: 'newuser' => 'off',
1.42 raeburn 7627: );
1.55 raeburn 7628: if (ref($domconfig{'login'}) eq 'HASH') {
7629: foreach my $item (@toggles) {
7630: if ($defaultchecked{$item} eq 'on') {
7631: if (($domconfig{'login'}{$item} eq '0') &&
7632: ($env{'form.'.$item} eq '1')) {
7633: $changes{$item} = 1;
7634: } elsif (($domconfig{'login'}{$item} eq '' ||
7635: $domconfig{'login'}{$item} eq '1') &&
7636: ($env{'form.'.$item} eq '0')) {
7637: $changes{$item} = 1;
7638: }
7639: } elsif ($defaultchecked{$item} eq 'off') {
7640: if (($domconfig{'login'}{$item} eq '1') &&
7641: ($env{'form.'.$item} eq '0')) {
7642: $changes{$item} = 1;
7643: } elsif (($domconfig{'login'}{$item} eq '' ||
7644: $domconfig{'login'}{$item} eq '0') &&
7645: ($env{'form.'.$item} eq '1')) {
7646: $changes{$item} = 1;
7647: }
1.42 raeburn 7648: }
7649: }
1.41 raeburn 7650: }
1.6 raeburn 7651: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7652: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7653: if (ref($lastactref) eq 'HASH') {
7654: $lastactref->{'domainconfig'} = 1;
7655: }
1.1 raeburn 7656: $resulttext = &mt('Changes made:').'<ul>';
7657: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7658: if ($item eq 'loginvia') {
1.112 raeburn 7659: if (ref($changes{$item}) eq 'HASH') {
7660: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7661: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7662: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7663: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7664: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7665: $protocol = 'http' if ($protocol ne 'https');
7666: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7667:
7668: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7669: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7670: } else {
7671: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7672: }
7673: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7674: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7675: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7676: }
7677: $resulttext .= '</li>';
7678: } else {
7679: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7680: }
1.112 raeburn 7681: } else {
1.128 raeburn 7682: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7683: }
7684: }
1.128 raeburn 7685: $resulttext .= '</ul></li>';
1.112 raeburn 7686: }
1.168 raeburn 7687: } elsif ($item eq 'helpurl') {
7688: if (ref($changes{$item}) eq 'HASH') {
7689: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7690: if (grep(/^\Q$lang\E$/,@delurls)) {
7691: my ($chg,$link);
7692: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7693: if ($lang eq 'nolang') {
7694: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7695: } else {
7696: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7697: }
7698: $resulttext .= '<li>'.$chg.'</li>';
7699: } else {
7700: my $chg;
7701: if ($lang eq 'nolang') {
7702: $chg = &mt('custom log-in help file for no preferred language');
7703: } else {
7704: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7705: }
7706: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7707: $loginhash{'login'}{'helpurl'}{$lang}.
7708: '?inhibitmenu=yes',$chg,600,500).
7709: '</li>';
7710: }
7711: }
7712: }
1.256 raeburn 7713: } elsif ($item eq 'headtag') {
7714: if (ref($changes{$item}) eq 'HASH') {
7715: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7716: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7717: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7718: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7719: $resulttext .= '<li><a href="'.
7720: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7721: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7722: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7723: if ($possexempt{$lonhost}) {
7724: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7725: } else {
7726: $resulttext .= &mt('included for any client IP');
7727: }
7728: $resulttext .= '</li>';
7729: }
7730: }
7731: }
1.169 raeburn 7732: } elsif ($item eq 'captcha') {
7733: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 7734: my $chgtxt;
1.169 raeburn 7735: if ($loginhash{'login'}{$item} eq 'notused') {
7736: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7737: } else {
7738: my %captchas = &captcha_phrases();
7739: if ($captchas{$loginhash{'login'}{$item}}) {
7740: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7741: } else {
7742: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7743: }
7744: }
7745: $resulttext .= '<li>'.$chgtxt.'</li>';
7746: }
7747: } elsif ($item eq 'recaptchakeys') {
7748: if (ref($loginhash{'login'}) eq 'HASH') {
7749: my ($privkey,$pubkey);
7750: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7751: $pubkey = $loginhash{'login'}{$item}{'public'};
7752: $privkey = $loginhash{'login'}{$item}{'private'};
7753: }
7754: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7755: if (!$pubkey) {
7756: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7757: } else {
7758: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7759: }
7760: if (!$privkey) {
7761: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7762: } else {
1.251 raeburn 7763: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 7764: }
7765: $chgtxt .= '</ul>';
7766: $resulttext .= '<li>'.$chgtxt.'</li>';
7767: }
1.269 raeburn 7768: } elsif ($item eq 'recaptchaversion') {
7769: if (ref($loginhash{'login'}) eq 'HASH') {
7770: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 7771: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 7772: '</li>';
7773: }
7774: }
1.41 raeburn 7775: } else {
7776: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7777: }
1.1 raeburn 7778: }
1.6 raeburn 7779: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7780: } else {
7781: $resulttext = &mt('No changes made to log-in page settings');
7782: }
7783: } else {
1.11 albertel 7784: $resulttext = '<span class="LC_error">'.
7785: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7786: }
1.6 raeburn 7787: if ($errors) {
1.9 raeburn 7788: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7789: $errors.'</ul>';
7790: }
7791: return $resulttext;
7792: }
7793:
1.256 raeburn 7794: sub check_exempt_addresses {
7795: my ($iplist) = @_;
7796: $iplist =~ s/^\s+//;
7797: $iplist =~ s/\s+$//;
7798: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7799: my (@okips,$new);
7800: foreach my $ip (@poss_ips) {
7801: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7802: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7803: push(@okips,$ip);
7804: }
7805: }
7806: }
7807: if (@okips > 0) {
7808: $new = join(',',@okips);
7809: } else {
7810: $new = '';
7811: }
7812: return $new;
7813: }
7814:
1.6 raeburn 7815: sub color_font_choices {
7816: my %choices =
7817: &Apache::lonlocal::texthash (
7818: img => "Header",
7819: bgs => "Background colors",
7820: links => "Link colors",
1.55 raeburn 7821: images => "Images",
1.6 raeburn 7822: font => "Font color",
1.201 raeburn 7823: fontmenu => "Font menu",
1.76 raeburn 7824: pgbg => "Page",
1.6 raeburn 7825: tabbg => "Header",
7826: sidebg => "Border",
7827: link => "Link",
7828: alink => "Active link",
7829: vlink => "Visited link",
7830: );
7831: return %choices;
7832: }
7833:
7834: sub modify_rolecolors {
1.205 raeburn 7835: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7836: my ($resulttext,%rolehash);
7837: $rolehash{'rolecolors'} = {};
1.55 raeburn 7838: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7839: if ($domconfig{'rolecolors'} eq '') {
7840: $domconfig{'rolecolors'} = {};
7841: }
7842: }
1.9 raeburn 7843: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7844: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7845: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7846: $dom);
7847: if ($putresult eq 'ok') {
7848: if (keys(%changes) > 0) {
1.41 raeburn 7849: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7850: if (ref($lastactref) eq 'HASH') {
7851: $lastactref->{'domainconfig'} = 1;
7852: }
1.6 raeburn 7853: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7854: $rolehash{'rolecolors'});
7855: } else {
7856: $resulttext = &mt('No changes made to default color schemes');
7857: }
7858: } else {
1.11 albertel 7859: $resulttext = '<span class="LC_error">'.
7860: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7861: }
7862: if ($errors) {
7863: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7864: $errors.'</ul>';
7865: }
7866: return $resulttext;
7867: }
7868:
7869: sub modify_colors {
1.9 raeburn 7870: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7871: my (%changes,%choices);
1.51 raeburn 7872: my @bgs;
1.6 raeburn 7873: my @links = ('link','alink','vlink');
1.41 raeburn 7874: my @logintext;
1.6 raeburn 7875: my @images;
7876: my $servadm = $r->dir_config('lonAdmEMail');
7877: my $errors;
1.200 raeburn 7878: my %defaults;
1.6 raeburn 7879: foreach my $role (@{$roles}) {
7880: if ($role eq 'login') {
1.12 raeburn 7881: %choices = &login_choices();
1.41 raeburn 7882: @logintext = ('textcol','bgcol');
1.12 raeburn 7883: } else {
7884: %choices = &color_font_choices();
7885: }
7886: if ($role eq 'login') {
1.41 raeburn 7887: @images = ('img','logo','domlogo','login');
1.51 raeburn 7888: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7889: } else {
7890: @images = ('img');
1.200 raeburn 7891: @bgs = ('pgbg','tabbg','sidebg');
7892: }
7893: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7894: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7895: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7896: }
7897: if ($role eq 'login') {
7898: foreach my $item (@logintext) {
1.234 raeburn 7899: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7900: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7901: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7902: }
7903: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 7904: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7905: }
7906: }
7907: } else {
1.234 raeburn 7908: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7909: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7910: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7911: }
7912: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 7913: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7914: }
1.6 raeburn 7915: }
1.200 raeburn 7916: foreach my $item (@bgs) {
1.234 raeburn 7917: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7918: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7919: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7920: }
7921: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 7922: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7923: }
7924: }
7925: foreach my $item (@links) {
1.234 raeburn 7926: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7927: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7928: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7929: }
7930: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 7931: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7932: }
1.6 raeburn 7933: }
1.46 raeburn 7934: my ($configuserok,$author_ok,$switchserver) =
7935: &config_check($dom,$confname,$servadm);
1.9 raeburn 7936: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7937: if (ref($domconfig->{$role}) ne 'HASH') {
7938: $domconfig->{$role} = {};
7939: }
1.8 raeburn 7940: foreach my $img (@images) {
1.70 raeburn 7941: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7942: if (defined($env{'form.login_showlogo_'.$img})) {
7943: $confhash->{$role}{'showlogo'}{$img} = 1;
7944: } else {
7945: $confhash->{$role}{'showlogo'}{$img} = 0;
7946: }
7947: }
1.18 albertel 7948: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7949: && !defined($domconfig->{$role}{$img})
7950: && !$env{'form.'.$role.'_del_'.$img}
7951: && $env{'form.'.$role.'_import_'.$img}) {
7952: # import the old configured image from the .tab setting
7953: # if they haven't provided a new one
7954: $domconfig->{$role}{$img} =
7955: $env{'form.'.$role.'_import_'.$img};
7956: }
1.6 raeburn 7957: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7958: my $error;
1.6 raeburn 7959: if ($configuserok eq 'ok') {
1.9 raeburn 7960: if ($switchserver) {
1.12 raeburn 7961: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7962: } else {
7963: if ($author_ok eq 'ok') {
7964: my ($result,$logourl) =
7965: &publishlogo($r,'upload',$role.'_'.$img,
7966: $dom,$confname,$img,$width,$height);
7967: if ($result eq 'ok') {
7968: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7969: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7970: } else {
1.12 raeburn 7971: $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 7972: }
7973: } else {
1.46 raeburn 7974: $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 7975: }
7976: }
7977: } else {
1.46 raeburn 7978: $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 7979: }
7980: if ($error) {
1.8 raeburn 7981: &Apache::lonnet::logthis($error);
1.11 albertel 7982: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7983: }
7984: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7985: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7986: my $error;
7987: if ($configuserok eq 'ok') {
7988: # is confname an author?
7989: if ($switchserver eq '') {
7990: if ($author_ok eq 'ok') {
7991: my ($result,$logourl) =
7992: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7993: $dom,$confname,$img,$width,$height);
7994: if ($result eq 'ok') {
7995: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7996: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7997: }
7998: }
7999: }
8000: }
1.6 raeburn 8001: }
8002: }
8003: }
8004: if (ref($domconfig) eq 'HASH') {
8005: if (ref($domconfig->{$role}) eq 'HASH') {
8006: foreach my $img (@images) {
8007: if ($domconfig->{$role}{$img} ne '') {
8008: if ($env{'form.'.$role.'_del_'.$img}) {
8009: $confhash->{$role}{$img} = '';
1.12 raeburn 8010: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8011: } else {
1.9 raeburn 8012: if ($confhash->{$role}{$img} eq '') {
8013: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8014: }
1.6 raeburn 8015: }
8016: } else {
8017: if ($env{'form.'.$role.'_del_'.$img}) {
8018: $confhash->{$role}{$img} = '';
1.12 raeburn 8019: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8020: }
8021: }
1.70 raeburn 8022: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8023: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8024: if ($confhash->{$role}{'showlogo'}{$img} ne
8025: $domconfig->{$role}{'showlogo'}{$img}) {
8026: $changes{$role}{'showlogo'}{$img} = 1;
8027: }
8028: } else {
8029: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8030: $changes{$role}{'showlogo'}{$img} = 1;
8031: }
8032: }
8033: }
8034: }
1.6 raeburn 8035: if ($domconfig->{$role}{'font'} ne '') {
8036: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8037: $changes{$role}{'font'} = 1;
8038: }
8039: } else {
8040: if ($confhash->{$role}{'font'}) {
8041: $changes{$role}{'font'} = 1;
8042: }
8043: }
1.107 raeburn 8044: if ($role ne 'login') {
8045: if ($domconfig->{$role}{'fontmenu'} ne '') {
8046: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8047: $changes{$role}{'fontmenu'} = 1;
8048: }
8049: } else {
8050: if ($confhash->{$role}{'fontmenu'}) {
8051: $changes{$role}{'fontmenu'} = 1;
8052: }
1.97 tempelho 8053: }
8054: }
1.6 raeburn 8055: foreach my $item (@bgs) {
8056: if ($domconfig->{$role}{$item} ne '') {
8057: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8058: $changes{$role}{'bgs'}{$item} = 1;
8059: }
8060: } else {
8061: if ($confhash->{$role}{$item}) {
8062: $changes{$role}{'bgs'}{$item} = 1;
8063: }
8064: }
8065: }
8066: foreach my $item (@links) {
8067: if ($domconfig->{$role}{$item} ne '') {
8068: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8069: $changes{$role}{'links'}{$item} = 1;
8070: }
8071: } else {
8072: if ($confhash->{$role}{$item}) {
8073: $changes{$role}{'links'}{$item} = 1;
8074: }
8075: }
8076: }
1.41 raeburn 8077: foreach my $item (@logintext) {
8078: if ($domconfig->{$role}{$item} ne '') {
8079: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8080: $changes{$role}{'logintext'}{$item} = 1;
8081: }
8082: } else {
8083: if ($confhash->{$role}{$item}) {
8084: $changes{$role}{'logintext'}{$item} = 1;
8085: }
8086: }
8087: }
1.6 raeburn 8088: } else {
8089: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8090: \@logintext,$confhash,\%changes);
1.6 raeburn 8091: }
8092: } else {
8093: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8094: \@logintext,$confhash,\%changes);
1.6 raeburn 8095: }
8096: }
8097: return ($errors,%changes);
8098: }
8099:
1.46 raeburn 8100: sub config_check {
8101: my ($dom,$confname,$servadm) = @_;
8102: my ($configuserok,$author_ok,$switchserver,%currroles);
8103: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8104: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8105: $confname,$servadm);
8106: if ($configuserok eq 'ok') {
8107: $switchserver = &check_switchserver($dom,$confname);
8108: if ($switchserver eq '') {
8109: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8110: }
8111: }
8112: return ($configuserok,$author_ok,$switchserver);
8113: }
8114:
1.6 raeburn 8115: sub default_change_checker {
1.41 raeburn 8116: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8117: foreach my $item (@{$links}) {
8118: if ($confhash->{$role}{$item}) {
8119: $changes->{$role}{'links'}{$item} = 1;
8120: }
8121: }
8122: foreach my $item (@{$bgs}) {
8123: if ($confhash->{$role}{$item}) {
8124: $changes->{$role}{'bgs'}{$item} = 1;
8125: }
8126: }
1.41 raeburn 8127: foreach my $item (@{$logintext}) {
8128: if ($confhash->{$role}{$item}) {
8129: $changes->{$role}{'logintext'}{$item} = 1;
8130: }
8131: }
1.6 raeburn 8132: foreach my $img (@{$images}) {
8133: if ($env{'form.'.$role.'_del_'.$img}) {
8134: $confhash->{$role}{$img} = '';
1.12 raeburn 8135: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8136: }
1.70 raeburn 8137: if ($role eq 'login') {
8138: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8139: $changes->{$role}{'showlogo'}{$img} = 1;
8140: }
8141: }
1.6 raeburn 8142: }
8143: if ($confhash->{$role}{'font'}) {
8144: $changes->{$role}{'font'} = 1;
8145: }
1.48 raeburn 8146: }
1.6 raeburn 8147:
8148: sub display_colorchgs {
8149: my ($dom,$changes,$roles,$confhash) = @_;
8150: my (%choices,$resulttext);
8151: if (!grep(/^login$/,@{$roles})) {
8152: $resulttext = &mt('Changes made:').'<br />';
8153: }
8154: foreach my $role (@{$roles}) {
8155: if ($role eq 'login') {
8156: %choices = &login_choices();
8157: } else {
8158: %choices = &color_font_choices();
8159: }
8160: if (ref($changes->{$role}) eq 'HASH') {
8161: if ($role ne 'login') {
8162: $resulttext .= '<h4>'.&mt($role).'</h4>';
8163: }
8164: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8165: if ($role ne 'login') {
8166: $resulttext .= '<ul>';
8167: }
8168: if (ref($changes->{$role}{$key}) eq 'HASH') {
8169: if ($role ne 'login') {
8170: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8171: }
8172: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8173: if (($role eq 'login') && ($key eq 'showlogo')) {
8174: if ($confhash->{$role}{$key}{$item}) {
8175: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8176: } else {
8177: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8178: }
8179: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8180: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8181: } else {
1.12 raeburn 8182: my $newitem = $confhash->{$role}{$item};
8183: if ($key eq 'images') {
8184: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
8185: }
8186: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8187: }
8188: }
8189: if ($role ne 'login') {
8190: $resulttext .= '</ul></li>';
8191: }
8192: } else {
8193: if ($confhash->{$role}{$key} eq '') {
8194: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8195: } else {
8196: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8197: }
8198: }
8199: if ($role ne 'login') {
8200: $resulttext .= '</ul>';
8201: }
8202: }
8203: }
8204: }
1.3 raeburn 8205: return $resulttext;
1.1 raeburn 8206: }
8207:
1.9 raeburn 8208: sub thumb_dimensions {
8209: return ('200','50');
8210: }
8211:
1.16 raeburn 8212: sub check_dimensions {
8213: my ($inputfile) = @_;
8214: my ($fullwidth,$fullheight);
8215: if ($inputfile =~ m|^[/\w.\-]+$|) {
8216: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8217: my $imageinfo = <PIPE>;
8218: if (!close(PIPE)) {
8219: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8220: }
8221: chomp($imageinfo);
8222: my ($fullsize) =
1.21 raeburn 8223: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8224: if ($fullsize) {
8225: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8226: }
8227: }
8228: }
8229: return ($fullwidth,$fullheight);
8230: }
8231:
1.9 raeburn 8232: sub check_configuser {
8233: my ($uhome,$dom,$confname,$servadm) = @_;
8234: my ($configuserok,%currroles);
8235: if ($uhome eq 'no_host') {
8236: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
8237: my $configpass = &LONCAPA::Enrollment::create_password();
8238: $configuserok =
8239: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8240: $configpass,'','','','','',undef,$servadm);
8241: } else {
8242: $configuserok = 'ok';
8243: %currroles =
8244: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8245: }
8246: return ($configuserok,%currroles);
8247: }
8248:
8249: sub check_authorstatus {
8250: my ($dom,$confname,%currroles) = @_;
8251: my $author_ok;
1.40 raeburn 8252: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8253: my $start = time;
8254: my $end = 0;
8255: $author_ok =
8256: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8257: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8258: } else {
8259: $author_ok = 'ok';
8260: }
8261: return $author_ok;
8262: }
8263:
8264: sub publishlogo {
1.46 raeburn 8265: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 8266: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 8267: if ($action eq 'upload') {
8268: $fname=$env{'form.'.$formname.'.filename'};
8269: chop($env{'form.'.$formname});
8270: } else {
8271: ($fname) = ($formname =~ /([^\/]+)$/);
8272: }
1.46 raeburn 8273: if ($savefileas ne '') {
8274: $fname = $savefileas;
8275: }
1.9 raeburn 8276: $fname=&Apache::lonnet::clean_filename($fname);
8277: # See if there is anything left
8278: unless ($fname) { return ('error: no uploaded file'); }
8279: $fname="$subdir/$fname";
1.210 raeburn 8280: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 8281: my $filepath="$docroot/priv";
8282: my $relpath = "$dom/$confname";
1.9 raeburn 8283: my ($fnamepath,$file,$fetchthumb);
8284: $file=$fname;
8285: if ($fname=~m|/|) {
8286: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8287: }
1.164 raeburn 8288: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8289: my $count;
1.164 raeburn 8290: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8291: $filepath.="/$parts[$count]";
8292: if ((-e $filepath)!=1) {
8293: mkdir($filepath,02770);
8294: }
8295: }
8296: # Check for bad extension and disallow upload
8297: if ($file=~/\.(\w+)$/ &&
8298: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8299: $output =
1.207 bisitz 8300: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8301: } elsif ($file=~/\.(\w+)$/ &&
8302: !defined(&Apache::loncommon::fileembstyle($1))) {
8303: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8304: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 8305: $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 8306: } elsif (-d "$filepath/$file") {
1.195 bisitz 8307: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8308: } else {
8309: my $source = $filepath.'/'.$file;
8310: my $logfile;
8311: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 8312: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8313: }
8314: print $logfile
8315: "\n================= Publish ".localtime()." ================\n".
8316: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8317: # Save the file
8318: if (!open(FH,'>'.$source)) {
8319: &Apache::lonnet::logthis('Failed to create '.$source);
8320: return (&mt('Failed to create file'));
8321: }
8322: if ($action eq 'upload') {
8323: if (!print FH ($env{'form.'.$formname})) {
8324: &Apache::lonnet::logthis('Failed to write to '.$source);
8325: return (&mt('Failed to write file'));
8326: }
8327: } else {
8328: my $original = &Apache::lonnet::filelocation('',$formname);
8329: if(!copy($original,$source)) {
8330: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8331: return (&mt('Failed to write file'));
8332: }
8333: }
8334: close(FH);
8335: chmod(0660, $source); # Permissions to rw-rw---.
8336:
8337: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8338: my $copyfile=$targetdir.'/'.$file;
8339:
8340: my @parts=split(/\//,$targetdir);
8341: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8342: for (my $count=5;$count<=$#parts;$count++) {
8343: $path.="/$parts[$count]";
8344: if (!-e $path) {
8345: print $logfile "\nCreating directory ".$path;
8346: mkdir($path,02770);
8347: }
8348: }
8349: my $versionresult;
8350: if (-e $copyfile) {
8351: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8352: } else {
8353: $versionresult = 'ok';
8354: }
8355: if ($versionresult eq 'ok') {
8356: if (copy($source,$copyfile)) {
8357: print $logfile "\nCopied original source to ".$copyfile."\n";
8358: $output = 'ok';
8359: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8360: push(@{$modified_urls},[$copyfile,$source]);
8361: my $metaoutput =
8362: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8363: unless ($registered_cleanup) {
8364: my $handlers = $r->get_handlers('PerlCleanupHandler');
8365: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8366: $registered_cleanup=1;
8367: }
1.9 raeburn 8368: } else {
8369: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8370: $output = &mt('Failed to copy file to RES space').", $!";
8371: }
8372: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8373: my $inputfile = $filepath.'/'.$file;
8374: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8375: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8376: if ($fullwidth ne '' && $fullheight ne '') {
8377: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8378: my $thumbsize = $thumbwidth.'x'.$thumbheight;
8379: system("convert -sample $thumbsize $inputfile $outfile");
8380: chmod(0660, $filepath.'/tn-'.$file);
8381: if (-e $outfile) {
8382: my $copyfile=$targetdir.'/tn-'.$file;
8383: if (copy($outfile,$copyfile)) {
8384: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8385: my $thumb_metaoutput =
8386: &write_metadata($dom,$confname,$formname,
8387: $targetdir,'tn-'.$file,$logfile);
8388: push(@{$modified_urls},[$copyfile,$outfile]);
8389: unless ($registered_cleanup) {
8390: my $handlers = $r->get_handlers('PerlCleanupHandler');
8391: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8392: $registered_cleanup=1;
8393: }
1.267 raeburn 8394: $madethumb = 1;
1.16 raeburn 8395: } else {
8396: print $logfile "\nUnable to write ".$copyfile.
8397: ':'.$!."\n";
8398: }
8399: }
1.9 raeburn 8400: }
8401: }
8402: }
8403: } else {
8404: $output = $versionresult;
8405: }
8406: }
1.267 raeburn 8407: return ($output,$logourl,$madethumb);
1.9 raeburn 8408: }
8409:
8410: sub logo_versioning {
8411: my ($targetdir,$file,$logfile) = @_;
8412: my $target = $targetdir.'/'.$file;
8413: my ($maxversion,$fn,$extn,$output);
8414: $maxversion = 0;
8415: if ($file =~ /^(.+)\.(\w+)$/) {
8416: $fn=$1;
8417: $extn=$2;
8418: }
8419: opendir(DIR,$targetdir);
8420: while (my $filename=readdir(DIR)) {
8421: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8422: $maxversion=($1>$maxversion)?$1:$maxversion;
8423: }
8424: }
8425: $maxversion++;
8426: print $logfile "\nCreating old version ".$maxversion."\n";
8427: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8428: if (copy($target,$copyfile)) {
8429: print $logfile "Copied old target to ".$copyfile."\n";
8430: $copyfile=$copyfile.'.meta';
8431: if (copy($target.'.meta',$copyfile)) {
8432: print $logfile "Copied old target metadata to ".$copyfile."\n";
8433: $output = 'ok';
8434: } else {
8435: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8436: $output = &mt('Failed to copy old meta').", $!, ";
8437: }
8438: } else {
8439: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8440: $output = &mt('Failed to copy old target').", $!, ";
8441: }
8442: return $output;
8443: }
8444:
8445: sub write_metadata {
8446: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
8447: my (%metadatafields,%metadatakeys,$output);
8448: $metadatafields{'title'}=$formname;
8449: $metadatafields{'creationdate'}=time;
8450: $metadatafields{'lastrevisiondate'}=time;
8451: $metadatafields{'copyright'}='public';
8452: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
8453: $env{'user.domain'};
8454: $metadatafields{'authorspace'}=$confname.':'.$dom;
8455: $metadatafields{'domain'}=$dom;
8456: {
8457: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
8458: my $mfh;
1.155 raeburn 8459: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 8460: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 8461: unless ($_=~/\./) {
8462: my $unikey=$_;
8463: $unikey=~/^([A-Za-z]+)/;
8464: my $tag=$1;
8465: $tag=~tr/A-Z/a-z/;
8466: print $mfh "\n\<$tag";
8467: foreach (split(/\,/,$metadatakeys{$unikey})) {
8468: my $value=$metadatafields{$unikey.'.'.$_};
8469: $value=~s/\"/\'\'/g;
8470: print $mfh ' '.$_.'="'.$value.'"';
8471: }
8472: print $mfh '>'.
8473: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
8474: .'</'.$tag.'>';
8475: }
8476: }
8477: $output = 'ok';
8478: print $logfile "\nWrote metadata";
8479: close($mfh);
8480: } else {
8481: print $logfile "\nFailed to open metadata file";
1.9 raeburn 8482: $output = &mt('Could not write metadata');
8483: }
8484: }
1.155 raeburn 8485: return $output;
8486: }
8487:
8488: sub notifysubscribed {
8489: foreach my $targetsource (@{$modified_urls}){
8490: next unless (ref($targetsource) eq 'ARRAY');
8491: my ($target,$source)=@{$targetsource};
8492: if ($source ne '') {
8493: if (open(my $logfh,'>>'.$source.'.log')) {
8494: print $logfh "\nCleanup phase: Notifications\n";
8495: my @subscribed=&subscribed_hosts($target);
8496: foreach my $subhost (@subscribed) {
8497: print $logfh "\nNotifying host ".$subhost.':';
8498: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
8499: print $logfh $reply;
8500: }
8501: my @subscribedmeta=&subscribed_hosts("$target.meta");
8502: foreach my $subhost (@subscribedmeta) {
8503: print $logfh "\nNotifying host for metadata only ".$subhost.':';
8504: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
8505: $subhost);
8506: print $logfh $reply;
8507: }
8508: print $logfh "\n============ Done ============\n";
1.160 raeburn 8509: close($logfh);
1.155 raeburn 8510: }
8511: }
8512: }
8513: return OK;
8514: }
8515:
8516: sub subscribed_hosts {
8517: my ($target) = @_;
8518: my @subscribed;
8519: if (open(my $fh,"<$target.subscription")) {
8520: while (my $subline=<$fh>) {
8521: if ($subline =~ /^($match_lonid):/) {
8522: my $host = $1;
8523: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
8524: unless (grep(/^\Q$host\E$/,@subscribed)) {
8525: push(@subscribed,$host);
8526: }
8527: }
8528: }
8529: }
8530: }
8531: return @subscribed;
1.9 raeburn 8532: }
8533:
8534: sub check_switchserver {
8535: my ($dom,$confname) = @_;
8536: my ($allowed,$switchserver);
8537: my $home = &Apache::lonnet::homeserver($confname,$dom);
8538: if ($home eq 'no_host') {
8539: $home = &Apache::lonnet::domain($dom,'primary');
8540: }
8541: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 8542: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
8543: if (!$allowed) {
1.180 raeburn 8544: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 8545: }
8546: return $switchserver;
8547: }
8548:
1.1 raeburn 8549: sub modify_quotas {
1.216 raeburn 8550: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 8551: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 8552: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 8553: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8554: $validationfieldsref);
1.86 raeburn 8555: if ($action eq 'quotas') {
8556: $context = 'tools';
1.163 raeburn 8557: } else {
1.86 raeburn 8558: $context = $action;
8559: }
8560: if ($context eq 'requestcourses') {
1.271 raeburn 8561: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 8562: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 8563: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8564: %titles = &courserequest_titles();
8565: $toolregexp = join('|',@usertools);
8566: %conditions = &courserequest_conditions();
1.216 raeburn 8567: $confname = $dom.'-domainconfig';
8568: my $servadm = $r->dir_config('lonAdmEMail');
8569: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 8570: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8571: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 8572: } elsif ($context eq 'requestauthor') {
8573: @usertools = ('author');
8574: %titles = &authorrequest_titles();
1.86 raeburn 8575: } else {
1.162 raeburn 8576: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 8577: %titles = &tool_titles();
1.86 raeburn 8578: }
1.212 raeburn 8579: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 8580: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8581: foreach my $key (keys(%env)) {
1.101 raeburn 8582: if ($context eq 'requestcourses') {
8583: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8584: my $item = $1;
8585: my $type = $2;
8586: if ($type =~ /^limit_(.+)/) {
8587: $limithash{$item}{$1} = $env{$key};
8588: } else {
8589: $confhash{$item}{$type} = $env{$key};
8590: }
8591: }
1.163 raeburn 8592: } elsif ($context eq 'requestauthor') {
8593: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8594: $confhash{$1} = $env{$key};
8595: }
1.101 raeburn 8596: } else {
1.86 raeburn 8597: if ($key =~ /^form\.quota_(.+)$/) {
8598: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 8599: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8600: $confhash{'authorquota'}{$1} = $env{$key};
8601: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8602: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8603: }
1.72 raeburn 8604: }
8605: }
1.163 raeburn 8606: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 8607: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8608: @approvalnotify = sort(@approvalnotify);
8609: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 8610: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 8611: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8612: foreach my $type (@hasuniquecode) {
8613: if (grep(/^\Q$type\E$/,@crstypes)) {
8614: $confhash{'uniquecode'}{$type} = 1;
8615: }
1.216 raeburn 8616: }
1.242 raeburn 8617: my (%newbook,%allpos);
1.216 raeburn 8618: if ($context eq 'requestcourses') {
1.242 raeburn 8619: foreach my $type ('textbooks','templates') {
8620: @{$allpos{$type}} = ();
8621: my $invalid;
8622: if ($type eq 'textbooks') {
8623: $invalid = &mt('Invalid LON-CAPA course for textbook');
8624: } else {
8625: $invalid = &mt('Invalid LON-CAPA course for template');
8626: }
8627: if ($env{'form.'.$type.'_addbook'}) {
8628: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8629: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8630: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8631: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8632: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8633: } else {
8634: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8635: my $position = $env{'form.'.$type.'_addbook_pos'};
8636: $position =~ s/\D+//g;
8637: if ($position ne '') {
8638: $allpos{$type}[$position] = $newbook{$type};
8639: }
1.216 raeburn 8640: }
1.242 raeburn 8641: } else {
8642: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 8643: }
8644: }
1.242 raeburn 8645: }
1.216 raeburn 8646: }
1.102 raeburn 8647: if (ref($domconfig{$action}) eq 'HASH') {
8648: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8649: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8650: $changes{'notify'}{'approval'} = 1;
8651: }
8652: } else {
1.144 raeburn 8653: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8654: $changes{'notify'}{'approval'} = 1;
8655: }
8656: }
1.218 raeburn 8657: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8658: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8659: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8660: unless ($confhash{'uniquecode'}{$crstype}) {
8661: $changes{'uniquecode'} = 1;
8662: }
8663: }
8664: unless ($changes{'uniquecode'}) {
8665: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8666: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8667: $changes{'uniquecode'} = 1;
8668: }
8669: }
8670: }
8671: } else {
8672: $changes{'uniquecode'} = 1;
8673: }
8674: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8675: $changes{'uniquecode'} = 1;
1.216 raeburn 8676: }
8677: if ($context eq 'requestcourses') {
1.242 raeburn 8678: foreach my $type ('textbooks','templates') {
8679: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8680: my %deletions;
8681: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8682: if (@todelete) {
8683: map { $deletions{$_} = 1; } @todelete;
8684: }
8685: my %imgdeletions;
8686: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8687: if (@todeleteimages) {
8688: map { $imgdeletions{$_} = 1; } @todeleteimages;
8689: }
8690: my $maxnum = $env{'form.'.$type.'_maxnum'};
8691: for (my $i=0; $i<=$maxnum; $i++) {
8692: my $itemid = $env{'form.'.$type.'_id_'.$i};
8693: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8694: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8695: if ($deletions{$key}) {
8696: if ($domconfig{$action}{$type}{$key}{'image'}) {
8697: #FIXME need to obsolete item in RES space
8698: }
8699: next;
8700: } else {
8701: my $newpos = $env{'form.'.$itemid};
8702: $newpos =~ s/\D+//g;
1.243 raeburn 8703: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 8704: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 8705: ($type eq 'templates'));
1.242 raeburn 8706: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8707: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8708: $changes{$type}{$key} = 1;
8709: }
8710: }
8711: $allpos{$type}[$newpos] = $key;
8712: }
8713: if ($imgdeletions{$key}) {
8714: $changes{$type}{$key} = 1;
1.216 raeburn 8715: #FIXME need to obsolete item in RES space
1.242 raeburn 8716: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8717: my ($cdom,$cnum) = split(/_/,$key);
8718: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8719: $cdom,$cnum,$type,$configuserok,
8720: $switchserver,$author_ok);
8721: if ($imgurl) {
8722: $confhash{$type}{$key}{'image'} = $imgurl;
8723: $changes{$type}{$key} = 1;
1.216 raeburn 8724: }
1.242 raeburn 8725: if ($error) {
8726: &Apache::lonnet::logthis($error);
8727: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8728: }
8729: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8730: $confhash{$type}{$key}{'image'} =
8731: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 8732: }
8733: }
8734: }
8735: }
8736: }
8737: }
1.102 raeburn 8738: } else {
1.144 raeburn 8739: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8740: $changes{'notify'}{'approval'} = 1;
8741: }
1.218 raeburn 8742: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 8743: $changes{'uniquecode'} = 1;
8744: }
8745: }
8746: if ($context eq 'requestcourses') {
1.242 raeburn 8747: foreach my $type ('textbooks','templates') {
8748: if ($newbook{$type}) {
8749: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 8750: foreach my $item ('subject','title','publisher','author') {
8751: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8752: ($type eq 'template'));
1.242 raeburn 8753: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8754: if ($env{'form.'.$type.'_addbook_'.$item}) {
8755: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8756: }
8757: }
8758: if ($type eq 'textbooks') {
8759: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8760: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8761: my ($imageurl,$error) =
8762: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8763: $configuserok,$switchserver,$author_ok);
8764: if ($imageurl) {
8765: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8766: }
8767: if ($error) {
8768: &Apache::lonnet::logthis($error);
8769: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8770: }
8771: }
1.216 raeburn 8772: }
8773: }
1.242 raeburn 8774: if (@{$allpos{$type}} > 0) {
8775: my $idx = 0;
8776: foreach my $item (@{$allpos{$type}}) {
8777: if ($item ne '') {
8778: $confhash{$type}{$item}{'order'} = $idx;
8779: if (ref($domconfig{$action}) eq 'HASH') {
8780: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8781: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8782: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8783: $changes{$type}{$item} = 1;
8784: }
1.216 raeburn 8785: }
8786: }
8787: }
1.242 raeburn 8788: $idx ++;
1.216 raeburn 8789: }
8790: }
8791: }
8792: }
1.235 raeburn 8793: if (ref($validationitemsref) eq 'ARRAY') {
8794: foreach my $item (@{$validationitemsref}) {
8795: if ($item eq 'fields') {
8796: my @changed;
8797: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8798: if (@{$confhash{'validation'}{$item}} > 0) {
8799: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8800: }
1.266 raeburn 8801: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8802: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8803: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8804: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8805: $domconfig{'requestcourses'}{'validation'}{$item});
8806: } else {
8807: @changed = @{$confhash{'validation'}{$item}};
8808: }
1.235 raeburn 8809: } else {
8810: @changed = @{$confhash{'validation'}{$item}};
8811: }
8812: } else {
8813: @changed = @{$confhash{'validation'}{$item}};
8814: }
8815: if (@changed) {
8816: if ($confhash{'validation'}{$item}) {
8817: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8818: } else {
8819: $changes{'validation'}{$item} = &mt('None');
8820: }
8821: }
8822: } else {
8823: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8824: if ($item eq 'markup') {
8825: if ($env{'form.requestcourses_validation_'.$item}) {
8826: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8827: }
8828: }
1.266 raeburn 8829: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8830: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8831: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8832: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8833: }
8834: } else {
8835: if ($confhash{'validation'}{$item} ne '') {
8836: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8837: }
1.235 raeburn 8838: }
8839: } else {
8840: if ($confhash{'validation'}{$item} ne '') {
8841: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8842: }
8843: }
8844: }
8845: }
8846: }
8847: if ($env{'form.validationdc'}) {
8848: my $newval = $env{'form.validationdc'};
1.285 raeburn 8849: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 8850: if (exists($domcoords{$newval})) {
8851: $confhash{'validation'}{'dc'} = $newval;
8852: }
8853: }
8854: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 8855: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8856: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8857: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8858: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8859: if ($confhash{'validation'}{'dc'} eq '') {
8860: $changes{'validation'}{'dc'} = &mt('None');
8861: } else {
8862: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8863: }
1.235 raeburn 8864: }
1.266 raeburn 8865: } elsif ($confhash{'validation'}{'dc'} ne '') {
8866: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 8867: }
8868: } elsif ($confhash{'validation'}{'dc'} ne '') {
8869: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8870: }
8871: } elsif ($confhash{'validation'}{'dc'} ne '') {
8872: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 8873: }
1.266 raeburn 8874: } else {
8875: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8876: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8877: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8878: $changes{'validation'}{'dc'} = &mt('None');
8879: }
8880: }
1.235 raeburn 8881: }
8882: }
1.102 raeburn 8883: }
8884: } else {
1.86 raeburn 8885: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 8886: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8887: }
1.72 raeburn 8888: foreach my $item (@usertools) {
8889: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8890: my $unset;
1.101 raeburn 8891: if ($context eq 'requestcourses') {
1.104 raeburn 8892: $unset = '0';
8893: if ($type eq '_LC_adv') {
8894: $unset = '';
8895: }
1.101 raeburn 8896: if ($confhash{$item}{$type} eq 'autolimit') {
8897: $confhash{$item}{$type} .= '=';
8898: unless ($limithash{$item}{$type} =~ /\D/) {
8899: $confhash{$item}{$type} .= $limithash{$item}{$type};
8900: }
8901: }
1.163 raeburn 8902: } elsif ($context eq 'requestauthor') {
8903: $unset = '0';
8904: if ($type eq '_LC_adv') {
8905: $unset = '';
8906: }
1.72 raeburn 8907: } else {
1.101 raeburn 8908: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8909: $confhash{$item}{$type} = 1;
8910: } else {
8911: $confhash{$item}{$type} = 0;
8912: }
1.72 raeburn 8913: }
1.86 raeburn 8914: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 8915: if ($action eq 'requestauthor') {
8916: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8917: $changes{$type} = 1;
8918: }
8919: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8920: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8921: $changes{$item}{$type} = 1;
8922: }
8923: } else {
8924: if ($context eq 'requestcourses') {
1.104 raeburn 8925: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8926: $changes{$item}{$type} = 1;
8927: }
8928: } else {
8929: if (!$confhash{$item}{$type}) {
8930: $changes{$item}{$type} = 1;
8931: }
8932: }
8933: }
8934: } else {
8935: if ($context eq 'requestcourses') {
1.104 raeburn 8936: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8937: $changes{$item}{$type} = 1;
8938: }
1.163 raeburn 8939: } elsif ($context eq 'requestauthor') {
8940: if ($confhash{$type} ne $unset) {
8941: $changes{$type} = 1;
8942: }
1.72 raeburn 8943: } else {
8944: if (!$confhash{$item}{$type}) {
8945: $changes{$item}{$type} = 1;
8946: }
8947: }
8948: }
1.1 raeburn 8949: }
8950: }
1.163 raeburn 8951: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8952: if (ref($domconfig{'quotas'}) eq 'HASH') {
8953: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8954: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8955: if (exists($confhash{'defaultquota'}{$key})) {
8956: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8957: $changes{'defaultquota'}{$key} = 1;
8958: }
8959: } else {
8960: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8961: }
8962: }
1.86 raeburn 8963: } else {
8964: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8965: if (exists($confhash{'defaultquota'}{$key})) {
8966: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8967: $changes{'defaultquota'}{$key} = 1;
8968: }
8969: } else {
8970: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8971: }
1.1 raeburn 8972: }
8973: }
1.197 raeburn 8974: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8975: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8976: if (exists($confhash{'authorquota'}{$key})) {
8977: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8978: $changes{'authorquota'}{$key} = 1;
8979: }
8980: } else {
8981: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8982: }
8983: }
8984: }
1.1 raeburn 8985: }
1.86 raeburn 8986: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8987: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8988: if (ref($domconfig{'quotas'}) eq 'HASH') {
8989: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8990: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8991: $changes{'defaultquota'}{$key} = 1;
8992: }
8993: } else {
8994: if (!exists($domconfig{'quotas'}{$key})) {
8995: $changes{'defaultquota'}{$key} = 1;
8996: }
1.72 raeburn 8997: }
8998: } else {
1.86 raeburn 8999: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 9000: }
1.1 raeburn 9001: }
9002: }
1.197 raeburn 9003: if (ref($confhash{'authorquota'}) eq 'HASH') {
9004: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9005: if (ref($domconfig{'quotas'}) eq 'HASH') {
9006: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9007: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9008: $changes{'authorquota'}{$key} = 1;
9009: }
9010: } else {
9011: $changes{'authorquota'}{$key} = 1;
9012: }
9013: } else {
9014: $changes{'authorquota'}{$key} = 1;
9015: }
9016: }
9017: }
1.1 raeburn 9018: }
1.72 raeburn 9019:
1.163 raeburn 9020: if ($context eq 'requestauthor') {
9021: $domdefaults{'requestauthor'} = \%confhash;
9022: } else {
9023: foreach my $key (keys(%confhash)) {
1.242 raeburn 9024: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 9025: $domdefaults{$key} = $confhash{$key};
9026: }
1.163 raeburn 9027: }
1.72 raeburn 9028: }
1.163 raeburn 9029:
1.1 raeburn 9030: my %quotahash = (
1.86 raeburn 9031: $action => { %confhash }
1.1 raeburn 9032: );
9033: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9034: $dom);
9035: if ($putresult eq 'ok') {
9036: if (keys(%changes) > 0) {
1.72 raeburn 9037: my $cachetime = 24*60*60;
9038: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9039: if (ref($lastactref) eq 'HASH') {
9040: $lastactref->{'domdefaults'} = 1;
9041: }
1.1 raeburn 9042: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 9043: unless (($context eq 'requestcourses') ||
1.163 raeburn 9044: ($context eq 'requestauthor')) {
1.86 raeburn 9045: if (ref($changes{'defaultquota'}) eq 'HASH') {
9046: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9047: foreach my $type (@{$types},'default') {
9048: if (defined($changes{'defaultquota'}{$type})) {
9049: my $typetitle = $usertypes->{$type};
9050: if ($type eq 'default') {
9051: $typetitle = $othertitle;
9052: }
1.213 raeburn 9053: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9054: }
9055: }
1.86 raeburn 9056: $resulttext .= '</ul></li>';
1.72 raeburn 9057: }
1.197 raeburn 9058: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 9059: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 9060: foreach my $type (@{$types},'default') {
9061: if (defined($changes{'authorquota'}{$type})) {
9062: my $typetitle = $usertypes->{$type};
9063: if ($type eq 'default') {
9064: $typetitle = $othertitle;
9065: }
1.213 raeburn 9066: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 9067: }
9068: }
9069: $resulttext .= '</ul></li>';
9070: }
1.72 raeburn 9071: }
1.80 raeburn 9072: my %newenv;
1.72 raeburn 9073: foreach my $item (@usertools) {
1.163 raeburn 9074: my (%haschgs,%inconf);
9075: if ($context eq 'requestauthor') {
9076: %haschgs = %changes;
1.210 raeburn 9077: %inconf = %confhash;
1.163 raeburn 9078: } else {
9079: if (ref($changes{$item}) eq 'HASH') {
9080: %haschgs = %{$changes{$item}};
9081: }
9082: if (ref($confhash{$item}) eq 'HASH') {
9083: %inconf = %{$confhash{$item}};
9084: }
9085: }
9086: if (keys(%haschgs) > 0) {
1.80 raeburn 9087: my $newacc =
9088: &Apache::lonnet::usertools_access($env{'user.name'},
9089: $env{'user.domain'},
1.86 raeburn 9090: $item,'reload',$context);
1.210 raeburn 9091: if (($context eq 'requestcourses') ||
1.163 raeburn 9092: ($context eq 'requestauthor')) {
1.108 raeburn 9093: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9094: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9095: }
9096: } else {
9097: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9098: $newenv{'environment.availabletools.'.$item} = $newacc;
9099: }
1.80 raeburn 9100: }
1.163 raeburn 9101: unless ($context eq 'requestauthor') {
9102: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9103: }
1.72 raeburn 9104: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 9105: if ($haschgs{$type}) {
1.72 raeburn 9106: my $typetitle = $usertypes->{$type};
9107: if ($type eq 'default') {
9108: $typetitle = $othertitle;
9109: } elsif ($type eq '_LC_adv') {
9110: $typetitle = 'LON-CAPA Advanced Users';
9111: }
1.163 raeburn 9112: if ($inconf{$type}) {
1.101 raeburn 9113: if ($context eq 'requestcourses') {
9114: my $cond;
1.163 raeburn 9115: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9116: if ($1 eq '') {
9117: $cond = &mt('(Automatic processing of any request).');
9118: } else {
9119: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9120: }
9121: } else {
1.163 raeburn 9122: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9123: }
9124: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 9125: } elsif ($context eq 'requestauthor') {
9126: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9127: $titles{$inconf{$type}},$typetitle);
9128:
1.101 raeburn 9129: } else {
9130: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9131: }
1.72 raeburn 9132: } else {
1.104 raeburn 9133: if ($type eq '_LC_adv') {
1.163 raeburn 9134: if ($inconf{$type} eq '0') {
1.104 raeburn 9135: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9136: } else {
9137: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9138: }
9139: } else {
9140: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9141: }
1.72 raeburn 9142: }
9143: }
1.26 raeburn 9144: }
1.163 raeburn 9145: unless ($context eq 'requestauthor') {
9146: $resulttext .= '</ul></li>';
9147: }
1.26 raeburn 9148: }
1.1 raeburn 9149: }
1.163 raeburn 9150: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9151: if (ref($changes{'notify'}) eq 'HASH') {
9152: if ($changes{'notify'}{'approval'}) {
9153: if (ref($confhash{'notify'}) eq 'HASH') {
9154: if ($confhash{'notify'}{'approval'}) {
9155: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9156: } else {
1.163 raeburn 9157: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9158: }
9159: }
9160: }
9161: }
9162: }
1.216 raeburn 9163: if ($action eq 'requestcourses') {
9164: my @offon = ('off','on');
9165: if ($changes{'uniquecode'}) {
1.218 raeburn 9166: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9167: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9168: $resulttext .= '<li>'.
9169: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9170: '</li>';
9171: } else {
9172: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9173: '</li>';
9174: }
1.216 raeburn 9175: }
1.242 raeburn 9176: foreach my $type ('textbooks','templates') {
9177: if (ref($changes{$type}) eq 'HASH') {
9178: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9179: foreach my $key (sort(keys(%{$changes{$type}}))) {
9180: my %coursehash = &Apache::lonnet::coursedescription($key);
9181: my $coursetitle = $coursehash{'description'};
9182: my $position = $confhash{$type}{$key}{'order'} + 1;
9183: $resulttext .= '<li>';
1.243 raeburn 9184: foreach my $item ('subject','title','publisher','author') {
9185: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9186: ($type eq 'templates'));
1.242 raeburn 9187: my $name = $item.':';
9188: $name =~ s/^(\w)/\U$1/;
9189: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9190: }
9191: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9192: if ($type eq 'textbooks') {
9193: if ($confhash{$type}{$key}{'image'}) {
9194: $resulttext .= ' '.&mt('Image: [_1]',
9195: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9196: ' alt="Textbook cover" />').'<br />';
9197: }
9198: }
9199: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 9200: }
1.242 raeburn 9201: $resulttext .= '</ul></li>';
1.216 raeburn 9202: }
9203: }
1.235 raeburn 9204: if (ref($changes{'validation'}) eq 'HASH') {
9205: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9206: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9207: foreach my $item (@{$validationitemsref}) {
9208: if (exists($changes{'validation'}{$item})) {
9209: if ($item eq 'markup') {
9210: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9211: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9212: } else {
9213: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9214: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9215: }
9216: }
9217: }
9218: if (exists($changes{'validation'}{'dc'})) {
9219: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9220: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9221: }
9222: }
9223: }
1.216 raeburn 9224: }
1.1 raeburn 9225: $resulttext .= '</ul>';
1.80 raeburn 9226: if (keys(%newenv)) {
9227: &Apache::lonnet::appenv(\%newenv);
9228: }
1.1 raeburn 9229: } else {
1.86 raeburn 9230: if ($context eq 'requestcourses') {
9231: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 9232: } elsif ($context eq 'requestauthor') {
9233: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9234: } else {
1.90 weissno 9235: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9236: }
1.1 raeburn 9237: }
9238: } else {
1.11 albertel 9239: $resulttext = '<span class="LC_error">'.
9240: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9241: }
1.216 raeburn 9242: if ($errors) {
9243: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9244: '<ul>'.$errors.'</ul></p>';
9245: }
1.3 raeburn 9246: return $resulttext;
1.1 raeburn 9247: }
9248:
1.216 raeburn 9249: sub process_textbook_image {
1.242 raeburn 9250: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 9251: my $filename = $env{'form.'.$caller.'.filename'};
9252: my ($error,$url);
9253: my ($width,$height) = (50,50);
9254: if ($configuserok eq 'ok') {
9255: if ($switchserver) {
9256: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9257: $switchserver);
9258: } elsif ($author_ok eq 'ok') {
9259: my ($result,$imageurl) =
9260: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 9261: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 9262: if ($result eq 'ok') {
9263: $url = $imageurl;
9264: } else {
9265: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9266: }
9267: } else {
9268: $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);
9269: }
9270: } else {
9271: $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);
9272: }
9273: return ($url,$error);
9274: }
9275:
1.267 raeburn 9276: sub modify_ltitools {
9277: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
9278: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9279: my ($newid,@allpos,%changes,%confhash,$errors,$resulttext);
9280: my $confname = $dom.'-domainconfig';
9281: my $servadm = $r->dir_config('lonAdmEMail');
9282: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9283: my (%posslti,%possfield);
9284: my @courseroles = ('cc','in','ta','ep','st');
9285: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
9286: map { $posslti{$_} = 1; } @ltiroles;
9287: my @allfields = ('fullname','firstname','lastname','email','user','roles');
9288: map { $possfield{$_} = 1; } @allfields;
9289: my %lt = <itools_names();
9290: if ($env{'form.ltitools_add'}) {
9291: my $title = $env{'form.ltitools_add_title'};
9292: $title =~ s/(`)/'/g;
9293: ($newid,my $error) = &get_ltitools_id($dom,$title);
9294: if ($newid) {
9295: my $position = $env{'form.ltitools_add_pos'};
9296: $position =~ s/\D+//g;
9297: if ($position ne '') {
9298: $allpos[$position] = $newid;
9299: }
9300: $changes{$newid} = 1;
9301: foreach my $item ('title','url','key','secret') {
9302: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
9303: if ($env{'form.ltitools_add_'.$item}) {
9304: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9305: }
9306: }
9307: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
9308: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
9309: }
9310: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
9311: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
9312: }
9313: foreach my $item ('width','height') {
9314: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
9315: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
9316: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
9317: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9318: }
9319: }
9320: if ($env{'form.ltitools_add_target'} eq 'window') {
9321: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
9322: } else {
9323: $confhash{$newid}{'display'}{'target'} = 'iframe';
9324: }
9325: foreach my $item ('passback','roster') {
9326: if ($env{'form.ltitools_add_'.$item}) {
9327: $confhash{$newid}{$item} = 1;
9328: }
9329: }
9330: if ($env{'form.ltitools_add_image.filename'} ne '') {
9331: my ($imageurl,$error) =
9332: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
9333: $configuserok,$switchserver,$author_ok);
9334: if ($imageurl) {
9335: $confhash{$newid}{'image'} = $imageurl;
9336: }
9337: if ($error) {
9338: &Apache::lonnet::logthis($error);
9339: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9340: }
9341: }
9342: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
9343: foreach my $field (@fields) {
9344: if ($possfield{$field}) {
9345: if ($field eq 'roles') {
9346: foreach my $role (@courseroles) {
9347: my $choice = $env{'form.ltitools_add_roles_'.$role};
9348: if (($choice ne '') && ($posslti{$choice})) {
9349: $confhash{$newid}{'roles'}{$role} = $choice;
9350: if ($role eq 'cc') {
9351: $confhash{$newid}{'roles'}{'co'} = $choice;
9352: }
9353: }
9354: }
9355: } else {
9356: $confhash{$newid}{'fields'}{$field} = 1;
9357: }
9358: }
9359: }
1.273 raeburn 9360: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
9361: foreach my $item (@courseconfig) {
9362: $confhash{$newid}{'crsconf'}{$item} = 1;
9363: }
1.267 raeburn 9364: if ($env{'form.ltitools_add_custom'}) {
9365: my $name = $env{'form.ltitools_add_custom_name'};
9366: my $value = $env{'form.ltitools_add_custom_value'};
9367: $value =~ s/(`)/'/g;
9368: $name =~ s/(`)/'/g;
9369: $confhash{$newid}{'custom'}{$name} = $value;
9370: }
9371: } else {
9372: my $error = &mt('Failed to acquire unique ID for new external tool');
9373: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9374: }
9375: }
9376: if (ref($domconfig{$action}) eq 'HASH') {
9377: my %deletions;
9378: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
9379: if (@todelete) {
9380: map { $deletions{$_} = 1; } @todelete;
9381: }
9382: my %customadds;
9383: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
9384: if (@newcustom) {
9385: map { $customadds{$_} = 1; } @newcustom;
9386: }
9387: my %imgdeletions;
9388: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
9389: if (@todeleteimages) {
9390: map { $imgdeletions{$_} = 1; } @todeleteimages;
9391: }
9392: my $maxnum = $env{'form.ltitools_maxnum'};
9393: for (my $i=0; $i<=$maxnum; $i++) {
9394: my $itemid = $env{'form.ltitools_id_'.$i};
9395: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9396: if ($deletions{$itemid}) {
9397: if ($domconfig{$action}{$itemid}{'image'}) {
9398: #FIXME need to obsolete item in RES space
9399: }
9400: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
9401: next;
9402: } else {
9403: my $newpos = $env{'form.ltitools_'.$itemid};
9404: $newpos =~ s/\D+//g;
9405: foreach my $item ('title','url','key','secret') {
9406: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9407: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
9408: $changes{$itemid} = 1;
9409: }
9410: }
9411: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
9412: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
9413: }
9414: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
9415: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
9416: }
9417: foreach my $size ('width','height') {
9418: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
9419: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
9420: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
9421: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
9422: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9423: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
9424: $changes{$itemid} = 1;
9425: }
9426: } else {
9427: $changes{$itemid} = 1;
9428: }
9429: }
9430: }
9431: if ($env{'form.ltitools_target_'.$i} eq 'window') {
9432: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
9433: } else {
9434: $confhash{$itemid}{'display'}{'target'} = 'iframe';
9435: }
9436: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9437: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
9438: $changes{$itemid} = 1;
9439: }
9440: } else {
9441: $changes{$itemid} = 1;
9442: }
9443: foreach my $extra ('passback','roster') {
9444: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
9445: $confhash{$itemid}{$extra} = 1;
9446: }
9447: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
9448: $changes{$itemid} = 1;
9449: }
9450: }
1.273 raeburn 9451: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
9452: foreach my $item ('label','title','target') {
9453: if (grep(/^\Q$item\E$/,@courseconfig)) {
9454: $confhash{$itemid}{'crsconf'}{$item} = 1;
9455: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
9456: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
9457: $changes{$itemid} = 1;
9458: }
9459: } else {
9460: $changes{$itemid} = 1;
9461: }
9462: }
9463: }
1.267 raeburn 9464: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
9465: foreach my $field (@fields) {
9466: if ($possfield{$field}) {
9467: if ($field eq 'roles') {
9468: foreach my $role (@courseroles) {
9469: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
9470: if (($choice ne '') && ($posslti{$choice})) {
9471: $confhash{$itemid}{'roles'}{$role} = $choice;
9472: if ($role eq 'cc') {
9473: $confhash{$itemid}{'roles'}{'co'} = $choice;
9474: }
9475: }
9476: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
9477: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
9478: $changes{$itemid} = 1;
9479: }
9480: } elsif ($confhash{$itemid}{'roles'}{$role}) {
9481: $changes{$itemid} = 1;
9482: }
9483: }
9484: } else {
9485: $confhash{$itemid}{'fields'}{$field} = 1;
9486: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
9487: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
9488: $changes{$itemid} = 1;
9489: }
9490: } else {
9491: $changes{$itemid} = 1;
9492: }
9493: }
9494: }
9495: }
9496: $allpos[$newpos] = $itemid;
9497: }
9498: if ($imgdeletions{$itemid}) {
9499: $changes{$itemid} = 1;
9500: #FIXME need to obsolete item in RES space
9501: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
9502: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
9503: $itemid,$configuserok,$switchserver,
9504: $author_ok);
9505: if ($imgurl) {
9506: $confhash{$itemid}{'image'} = $imgurl;
9507: $changes{$itemid} = 1;
9508: }
9509: if ($error) {
9510: &Apache::lonnet::logthis($error);
9511: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9512: }
9513: } elsif ($domconfig{$action}{$itemid}{'image'}) {
9514: $confhash{$itemid}{'image'} =
9515: $domconfig{$action}{$itemid}{'image'};
9516: }
9517: if ($customadds{$i}) {
9518: my $name = $env{'form.ltitools_custom_name_'.$i};
9519: $name =~ s/(`)/'/g;
9520: $name =~ s/^\s+//;
9521: $name =~ s/\s+$//;
9522: my $value = $env{'form.ltitools_custom_value_'.$i};
9523: $value =~ s/(`)/'/g;
9524: $value =~ s/^\s+//;
9525: $value =~ s/\s+$//;
9526: if ($name ne '') {
9527: $confhash{$itemid}{'custom'}{$name} = $value;
9528: $changes{$itemid} = 1;
9529: }
9530: }
9531: my %customdels;
9532: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
9533: if (@customdeletions) {
9534: $changes{$itemid} = 1;
9535: }
9536: map { $customdels{$_} = 1; } @customdeletions;
9537: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
9538: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
9539: unless ($customdels{$key}) {
9540: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
9541: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
9542: }
9543: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
9544: $changes{$itemid} = 1;
9545: }
9546: }
9547: }
9548: }
9549: unless ($changes{$itemid}) {
9550: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
9551: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
9552: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
9553: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
9554: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
9555: $changes{$itemid} = 1;
9556: last;
9557: }
9558: }
9559: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
9560: $changes{$itemid} = 1;
9561: }
9562: }
9563: last if ($changes{$itemid});
9564: }
9565: }
9566: }
9567: }
9568: }
9569: if (@allpos > 0) {
9570: my $idx = 0;
9571: foreach my $itemid (@allpos) {
9572: if ($itemid ne '') {
9573: $confhash{$itemid}{'order'} = $idx;
9574: if (ref($domconfig{$action}) eq 'HASH') {
9575: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9576: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
9577: $changes{$itemid} = 1;
9578: }
9579: }
9580: }
9581: $idx ++;
9582: }
9583: }
9584: }
9585: my %ltitoolshash = (
9586: $action => { %confhash }
9587: );
9588: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
9589: $dom);
9590: if ($putresult eq 'ok') {
9591: if (keys(%changes) > 0) {
9592: my $cachetime = 24*60*60;
9593: &Apache::lonnet::do_cache_new('ltitools',$dom,\%confhash,$cachetime);
9594: if (ref($lastactref) eq 'HASH') {
9595: $lastactref->{'ltitools'} = 1;
9596: }
9597: $resulttext = &mt('Changes made:').'<ul>';
9598: my %bynum;
9599: foreach my $itemid (sort(keys(%changes))) {
9600: my $position = $confhash{$itemid}{'order'};
9601: $bynum{$position} = $itemid;
9602: }
9603: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9604: my $itemid = $bynum{$pos};
9605: if (ref($confhash{$itemid}) ne 'HASH') {
9606: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9607: } else {
9608: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
9609: if ($confhash{$itemid}{'image'}) {
9610: $resulttext .= ' '.
9611: '<img src="'.$confhash{$itemid}{'image'}.'"'.
9612: ' alt="'.&mt('Tool Provider icon').'" />';
9613: }
9614: $resulttext .= '</li><ul>';
9615: my $position = $pos + 1;
9616: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
9617: foreach my $item ('version','msgtype','url','key') {
9618: if ($confhash{$itemid}{$item} ne '') {
9619: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
9620: }
9621: }
9622: if ($confhash{$itemid}{'secret'} ne '') {
9623: $resulttext .= '<li>'.$lt{'secret'}.': ';
9624: my $num = length($confhash{$itemid}{'secret'});
9625: $resulttext .= ('*'x$num).'</li>';
9626: }
1.273 raeburn 9627: $resulttext .= '<li>'.&mt('Configurable in course:');
9628: my @possconfig = ('label','title','target');
9629: my $numconfig = 0;
9630: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
9631: foreach my $item (@possconfig) {
9632: if ($confhash{$itemid}{'crsconf'}{$item}) {
9633: $numconfig ++;
9634: $resulttext .= ' '.$lt{'crs'.$item};
9635: }
9636: }
9637: }
9638: if (!$numconfig) {
9639: $resulttext .= &mt('None');
9640: }
9641: $resulttext .= '</li>';
1.267 raeburn 9642: foreach my $item ('passback','roster') {
9643: $resulttext .= '<li>'.$lt{$item}.' ';
9644: if ($confhash{$itemid}{$item}) {
9645: $resulttext .= &mt('Yes');
9646: } else {
9647: $resulttext .= &mt('No');
9648: }
9649: $resulttext .= '</li>';
9650: }
9651: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
9652: my $displaylist;
9653: if ($confhash{$itemid}{'display'}{'target'}) {
9654: $displaylist = &mt('Display target').': '.
9655: $confhash{$itemid}{'display'}{'target'}.',';
9656: }
9657: foreach my $size ('width','height') {
9658: if ($confhash{$itemid}{'display'}{$size}) {
9659: $displaylist .= (' 'x2).$lt{$size}.': '.
9660: $confhash{$itemid}{'display'}{$size}.',';
9661: }
9662: }
9663: if ($displaylist) {
9664: $displaylist =~ s/,$//;
9665: $resulttext .= '<li>'.$displaylist.'</li>';
9666: }
9667: }
9668: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
9669: my $fieldlist;
9670: foreach my $field (@allfields) {
9671: if ($confhash{$itemid}{'fields'}{$field}) {
9672: $fieldlist .= (' 'x2).$lt{$field}.',';
9673: }
9674: }
9675: if ($fieldlist) {
9676: $fieldlist =~ s/,$//;
9677: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
9678: }
9679: }
9680: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
9681: my $rolemaps;
9682: foreach my $role (@courseroles) {
9683: if ($confhash{$itemid}{'roles'}{$role}) {
9684: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
9685: $confhash{$itemid}{'roles'}{$role}.',';
9686: }
9687: }
9688: if ($rolemaps) {
9689: $rolemaps =~ s/,$//;
9690: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
9691: }
9692: }
9693: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
9694: my $customlist;
9695: if (keys(%{$confhash{$itemid}{'custom'}})) {
9696: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
9697: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
9698: }
9699: }
9700: if ($customlist) {
9701: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
9702: }
9703: }
9704: $resulttext .= '</ul></li>';
9705: }
9706: }
9707: $resulttext .= '</ul>';
9708: } else {
9709: $resulttext = &mt('No changes made.');
9710: }
9711: } else {
9712: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9713: }
9714: if ($errors) {
9715: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9716: $errors.'</ul>';
9717: }
9718: return $resulttext;
9719: }
9720:
9721: sub process_ltitools_image {
9722: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
9723: my $filename = $env{'form.'.$caller.'.filename'};
9724: my ($error,$url);
9725: my ($width,$height) = (21,21);
9726: if ($configuserok eq 'ok') {
9727: if ($switchserver) {
9728: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
9729: $switchserver);
9730: } elsif ($author_ok eq 'ok') {
9731: my ($result,$imageurl,$madethumb) =
9732: &publishlogo($r,'upload',$caller,$dom,$confname,
9733: "ltitools/$itemid/icon",$width,$height);
9734: if ($result eq 'ok') {
9735: if ($madethumb) {
9736: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
9737: my $imagethumb = "$path/tn-".$imagefile;
9738: $url = $imagethumb;
9739: } else {
9740: $url = $imageurl;
9741: }
9742: } else {
9743: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9744: }
9745: } else {
9746: $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);
9747: }
9748: } else {
9749: $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);
9750: }
9751: return ($url,$error);
9752: }
9753:
9754: sub get_ltitools_id {
9755: my ($cdom,$title) = @_;
9756: # get lock on ltitools db
9757: my $lockhash = {
9758: lock => $env{'user.name'}.
9759: ':'.$env{'user.domain'},
9760: };
9761: my $tries = 0;
9762: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9763: my ($id,$error);
9764:
9765: while (($gotlock ne 'ok') && ($tries<10)) {
9766: $tries ++;
9767: sleep (0.1);
9768: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9769: }
9770: if ($gotlock eq 'ok') {
9771: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
9772: if ($currids{'lock'}) {
9773: delete($currids{'lock'});
9774: if (keys(%currids)) {
9775: my @curr = sort { $a <=> $b } keys(%currids);
9776: if ($curr[-1] =~ /^\d+$/) {
9777: $id = 1 + $curr[-1];
9778: }
9779: } else {
9780: $id = 1;
9781: }
9782: if ($id) {
9783: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
9784: $error = 'nostore';
9785: }
9786: } else {
9787: $error = 'nonumber';
9788: }
9789: }
9790: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
9791: } else {
9792: $error = 'nolock';
9793: }
9794: return ($id,$error);
9795: }
9796:
1.3 raeburn 9797: sub modify_autoenroll {
1.205 raeburn 9798: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 9799: my ($resulttext,%changes);
9800: my %currautoenroll;
9801: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9802: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9803: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9804: }
9805: }
9806: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9807: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 9808: sender => 'Sender for notification messages',
1.274 raeburn 9809: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9810: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 9811: my @offon = ('off','on');
1.17 raeburn 9812: my $sender_uname = $env{'form.sender_uname'};
9813: my $sender_domain = $env{'form.sender_domain'};
9814: if ($sender_domain eq '') {
9815: $sender_uname = '';
9816: } elsif ($sender_uname eq '') {
9817: $sender_domain = '';
9818: }
1.129 raeburn 9819: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 9820: my $failsafe = $env{'form.autoenroll_failsafe'};
9821: $failsafe =~ s{^\s+|\s+$}{}g;
9822: if ($failsafe =~ /\D/) {
9823: undef($failsafe);
9824: }
1.1 raeburn 9825: my %autoenrollhash = (
1.129 raeburn 9826: autoenroll => { 'run' => $env{'form.autoenroll_run'},
9827: 'sender_uname' => $sender_uname,
9828: 'sender_domain' => $sender_domain,
9829: 'co-owners' => $coowners,
1.274 raeburn 9830: 'autofailsafe' => $failsafe,
1.1 raeburn 9831: }
9832: );
1.4 raeburn 9833: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
9834: $dom);
1.1 raeburn 9835: if ($putresult eq 'ok') {
9836: if (exists($currautoenroll{'run'})) {
9837: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
9838: $changes{'run'} = 1;
9839: }
9840: } elsif ($autorun) {
9841: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 9842: $changes{'run'} = 1;
1.1 raeburn 9843: }
9844: }
1.17 raeburn 9845: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 9846: $changes{'sender'} = 1;
9847: }
1.17 raeburn 9848: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 9849: $changes{'sender'} = 1;
9850: }
1.129 raeburn 9851: if ($currautoenroll{'co-owners'} ne '') {
9852: if ($currautoenroll{'co-owners'} ne $coowners) {
9853: $changes{'coowners'} = 1;
9854: }
9855: } elsif ($coowners) {
9856: $changes{'coowners'} = 1;
1.274 raeburn 9857: }
9858: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
9859: $changes{'autofailsafe'} = 1;
9860: }
1.1 raeburn 9861: if (keys(%changes) > 0) {
9862: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 9863: if ($changes{'run'}) {
1.1 raeburn 9864: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
9865: }
9866: if ($changes{'sender'}) {
1.17 raeburn 9867: if ($sender_uname eq '' || $sender_domain eq '') {
9868: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
9869: } else {
9870: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
9871: }
1.1 raeburn 9872: }
1.129 raeburn 9873: if ($changes{'coowners'}) {
9874: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
9875: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9876: if (ref($lastactref) eq 'HASH') {
9877: $lastactref->{'domainconfig'} = 1;
9878: }
1.129 raeburn 9879: }
1.274 raeburn 9880: if ($changes{'autofailsafe'}) {
9881: if ($failsafe ne '') {
9882: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
9883: } else {
9884: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
9885: }
9886: &Apache::lonnet::get_domain_defaults($dom,1);
9887: if (ref($lastactref) eq 'HASH') {
9888: $lastactref->{'domdefaults'} = 1;
9889: }
9890: }
1.1 raeburn 9891: $resulttext .= '</ul>';
9892: } else {
9893: $resulttext = &mt('No changes made to auto-enrollment settings');
9894: }
9895: } else {
1.11 albertel 9896: $resulttext = '<span class="LC_error">'.
9897: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9898: }
1.3 raeburn 9899: return $resulttext;
1.1 raeburn 9900: }
9901:
9902: sub modify_autoupdate {
1.3 raeburn 9903: my ($dom,%domconfig) = @_;
1.1 raeburn 9904: my ($resulttext,%currautoupdate,%fields,%changes);
9905: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
9906: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
9907: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
9908: }
9909: }
9910: my @offon = ('off','on');
9911: my %title = &Apache::lonlocal::texthash (
9912: run => 'Auto-update:',
9913: classlists => 'Updates to user information in classlists?'
9914: );
1.44 raeburn 9915: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9916: my %fieldtitles = &Apache::lonlocal::texthash (
9917: id => 'Student/Employee ID',
1.20 raeburn 9918: permanentemail => 'E-mail address',
1.1 raeburn 9919: lastname => 'Last Name',
9920: firstname => 'First Name',
9921: middlename => 'Middle Name',
1.132 raeburn 9922: generation => 'Generation',
1.1 raeburn 9923: );
1.142 raeburn 9924: $othertitle = &mt('All users');
1.1 raeburn 9925: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 9926: $othertitle = &mt('Other users');
1.1 raeburn 9927: }
9928: foreach my $key (keys(%env)) {
9929: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 9930: my ($usertype,$item) = ($1,$2);
9931: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
9932: if ($usertype eq 'default') {
9933: push(@{$fields{$1}},$2);
9934: } elsif (ref($types) eq 'ARRAY') {
9935: if (grep(/^\Q$usertype\E$/,@{$types})) {
9936: push(@{$fields{$1}},$2);
9937: }
9938: }
9939: }
1.1 raeburn 9940: }
9941: }
1.131 raeburn 9942: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
9943: @lockablenames = sort(@lockablenames);
9944: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
9945: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9946: if (@changed) {
9947: $changes{'lockablenames'} = 1;
9948: }
9949: } else {
9950: if (@lockablenames) {
9951: $changes{'lockablenames'} = 1;
9952: }
9953: }
1.1 raeburn 9954: my %updatehash = (
9955: autoupdate => { run => $env{'form.autoupdate_run'},
9956: classlists => $env{'form.classlists'},
9957: fields => {%fields},
1.131 raeburn 9958: lockablenames => \@lockablenames,
1.1 raeburn 9959: }
9960: );
9961: foreach my $key (keys(%currautoupdate)) {
9962: if (($key eq 'run') || ($key eq 'classlists')) {
9963: if (exists($updatehash{autoupdate}{$key})) {
9964: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
9965: $changes{$key} = 1;
9966: }
9967: }
9968: } elsif ($key eq 'fields') {
9969: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 9970: foreach my $item (@{$types},'default') {
1.1 raeburn 9971: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
9972: my $change = 0;
9973: foreach my $type (@{$currautoupdate{$key}{$item}}) {
9974: if (!exists($fields{$item})) {
9975: $change = 1;
1.132 raeburn 9976: last;
1.1 raeburn 9977: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 9978: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 9979: $change = 1;
1.132 raeburn 9980: last;
1.1 raeburn 9981: }
9982: }
9983: }
9984: if ($change) {
9985: push(@{$changes{$key}},$item);
9986: }
1.26 raeburn 9987: }
1.1 raeburn 9988: }
9989: }
1.131 raeburn 9990: } elsif ($key eq 'lockablenames') {
9991: if (ref($currautoupdate{$key}) eq 'ARRAY') {
9992: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9993: if (@changed) {
9994: $changes{'lockablenames'} = 1;
9995: }
9996: } else {
9997: if (@lockablenames) {
9998: $changes{'lockablenames'} = 1;
9999: }
10000: }
10001: }
10002: }
10003: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10004: if (@lockablenames) {
10005: $changes{'lockablenames'} = 1;
1.1 raeburn 10006: }
10007: }
1.26 raeburn 10008: foreach my $item (@{$types},'default') {
10009: if (defined($fields{$item})) {
10010: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 10011: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10012: my $change = 0;
10013: if (ref($fields{$item}) eq 'ARRAY') {
10014: foreach my $type (@{$fields{$item}}) {
10015: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10016: $change = 1;
10017: last;
10018: }
10019: }
10020: }
10021: if ($change) {
10022: push(@{$changes{'fields'}},$item);
10023: }
10024: } else {
1.26 raeburn 10025: push(@{$changes{'fields'}},$item);
10026: }
10027: } else {
10028: push(@{$changes{'fields'}},$item);
1.1 raeburn 10029: }
10030: }
10031: }
10032: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10033: $dom);
10034: if ($putresult eq 'ok') {
10035: if (keys(%changes) > 0) {
10036: $resulttext = &mt('Changes made:').'<ul>';
10037: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 10038: if ($key eq 'lockablenames') {
10039: $resulttext .= '<li>';
10040: if (@lockablenames) {
10041: $usertypes->{'default'} = $othertitle;
10042: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10043: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10044: } else {
10045: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10046: }
10047: $resulttext .= '</li>';
10048: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 10049: foreach my $item (@{$changes{$key}}) {
10050: my @newvalues;
10051: foreach my $type (@{$fields{$item}}) {
10052: push(@newvalues,$fieldtitles{$type});
10053: }
1.3 raeburn 10054: my $newvaluestr;
10055: if (@newvalues > 0) {
10056: $newvaluestr = join(', ',@newvalues);
10057: } else {
10058: $newvaluestr = &mt('none');
1.6 raeburn 10059: }
1.1 raeburn 10060: if ($item eq 'default') {
1.26 raeburn 10061: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 10062: } else {
1.26 raeburn 10063: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 10064: }
10065: }
10066: } else {
10067: my $newvalue;
10068: if ($key eq 'run') {
10069: $newvalue = $offon[$env{'form.autoupdate_run'}];
10070: } else {
10071: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 10072: }
1.1 raeburn 10073: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
10074: }
10075: }
10076: $resulttext .= '</ul>';
10077: } else {
1.3 raeburn 10078: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 10079: }
10080: } else {
1.11 albertel 10081: $resulttext = '<span class="LC_error">'.
10082: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10083: }
1.3 raeburn 10084: return $resulttext;
1.1 raeburn 10085: }
10086:
1.125 raeburn 10087: sub modify_autocreate {
10088: my ($dom,%domconfig) = @_;
10089: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10090: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10091: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10092: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10093: }
10094: }
10095: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10096: req => 'Auto-creation of validated requests for official courses',
10097: xmldc => 'Identity of course creator of courses from XML files',
10098: );
10099: my @types = ('xml','req');
10100: foreach my $item (@types) {
10101: $newvals{$item} = $env{'form.autocreate_'.$item};
10102: $newvals{$item} =~ s/\D//g;
10103: $newvals{$item} = 0 if ($newvals{$item} eq '');
10104: }
10105: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 10106: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 10107: unless (exists($domcoords{$newvals{'xmldc'}})) {
10108: $newvals{'xmldc'} = '';
10109: }
10110: %autocreatehash = (
10111: autocreate => { xml => $newvals{'xml'},
10112: req => $newvals{'req'},
10113: }
10114: );
10115: if ($newvals{'xmldc'} ne '') {
10116: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10117: }
10118: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10119: $dom);
10120: if ($putresult eq 'ok') {
10121: my @items = @types;
10122: if ($newvals{'xml'}) {
10123: push(@items,'xmldc');
10124: }
10125: foreach my $item (@items) {
10126: if (exists($currautocreate{$item})) {
10127: if ($currautocreate{$item} ne $newvals{$item}) {
10128: $changes{$item} = 1;
10129: }
10130: } elsif ($newvals{$item}) {
10131: $changes{$item} = 1;
10132: }
10133: }
10134: if (keys(%changes) > 0) {
10135: my @offon = ('off','on');
10136: $resulttext = &mt('Changes made:').'<ul>';
10137: foreach my $item (@types) {
10138: if ($changes{$item}) {
10139: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 10140: $resulttext .= '<li>'.
10141: &mt("$title{$item} set to [_1]$newtxt [_2]",
10142: '<b>','</b>').
10143: '</li>';
1.125 raeburn 10144: }
10145: }
10146: if ($changes{'xmldc'}) {
10147: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10148: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 10149: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 10150: }
10151: $resulttext .= '</ul>';
10152: } else {
10153: $resulttext = &mt('No changes made to auto-creation settings');
10154: }
10155: } else {
10156: $resulttext = '<span class="LC_error">'.
10157: &mt('An error occurred: [_1]',$putresult).'</span>';
10158: }
10159: return $resulttext;
10160: }
10161:
1.23 raeburn 10162: sub modify_directorysrch {
10163: my ($dom,%domconfig) = @_;
10164: my ($resulttext,%changes);
10165: my %currdirsrch;
10166: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10167: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10168: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10169: }
10170: }
1.277 raeburn 10171: my %title = ( available => 'Institutional directory search available',
10172: localonly => 'Other domains can search institution',
10173: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 10174: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 10175: searchby => 'Search types',
10176: searchtypes => 'Search latitude');
10177: my @offon = ('off','on');
1.24 raeburn 10178: my @otherdoms = ('Yes','No');
1.23 raeburn 10179:
1.25 raeburn 10180: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 10181: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10182: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10183:
1.44 raeburn 10184: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 10185: if (keys(%{$usertypes}) == 0) {
10186: @cansearch = ('default');
10187: } else {
10188: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10189: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10190: if (!grep(/^\Q$type\E$/,@cansearch)) {
10191: push(@{$changes{'cansearch'}},$type);
10192: }
1.23 raeburn 10193: }
1.26 raeburn 10194: foreach my $type (@cansearch) {
10195: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10196: push(@{$changes{'cansearch'}},$type);
10197: }
1.23 raeburn 10198: }
1.26 raeburn 10199: } else {
10200: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 10201: }
10202: }
10203:
10204: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10205: foreach my $by (@{$currdirsrch{'searchby'}}) {
10206: if (!grep(/^\Q$by\E$/,@searchby)) {
10207: push(@{$changes{'searchby'}},$by);
10208: }
10209: }
10210: foreach my $by (@searchby) {
10211: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10212: push(@{$changes{'searchby'}},$by);
10213: }
10214: }
10215: } else {
10216: push(@{$changes{'searchby'}},@searchby);
10217: }
1.25 raeburn 10218:
10219: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10220: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10221: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10222: push(@{$changes{'searchtypes'}},$type);
10223: }
10224: }
10225: foreach my $type (@searchtypes) {
10226: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10227: push(@{$changes{'searchtypes'}},$type);
10228: }
10229: }
10230: } else {
10231: if (exists($currdirsrch{'searchtypes'})) {
10232: foreach my $type (@searchtypes) {
10233: if ($type ne $currdirsrch{'searchtypes'}) {
10234: push(@{$changes{'searchtypes'}},$type);
10235: }
10236: }
10237: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10238: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10239: }
10240: } else {
10241: push(@{$changes{'searchtypes'}},@searchtypes);
10242: }
10243: }
10244:
1.23 raeburn 10245: my %dirsrch_hash = (
10246: directorysrch => { available => $env{'form.dirsrch_available'},
10247: cansearch => \@cansearch,
1.277 raeburn 10248: localonly => $env{'form.dirsrch_instlocalonly'},
10249: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10250: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 10251: searchby => \@searchby,
1.25 raeburn 10252: searchtypes => \@searchtypes,
1.23 raeburn 10253: }
10254: );
10255: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10256: $dom);
10257: if ($putresult eq 'ok') {
10258: if (exists($currdirsrch{'available'})) {
10259: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10260: $changes{'available'} = 1;
10261: }
10262: } else {
10263: if ($env{'form.dirsrch_available'} eq '1') {
10264: $changes{'available'} = 1;
10265: }
10266: }
1.277 raeburn 10267: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 10268: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
10269: $changes{'lcavailable'} = 1;
10270: }
1.277 raeburn 10271: } else {
10272: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10273: $changes{'lcavailable'} = 1;
10274: }
10275: }
1.24 raeburn 10276: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 10277: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
10278: $changes{'localonly'} = 1;
10279: }
1.24 raeburn 10280: } else {
1.277 raeburn 10281: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 10282: $changes{'localonly'} = 1;
10283: }
10284: }
1.277 raeburn 10285: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 10286: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
10287: $changes{'lclocalonly'} = 1;
10288: }
1.277 raeburn 10289: } else {
10290: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10291: $changes{'lclocalonly'} = 1;
10292: }
10293: }
1.23 raeburn 10294: if (keys(%changes) > 0) {
10295: $resulttext = &mt('Changes made:').'<ul>';
10296: if ($changes{'available'}) {
10297: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10298: }
1.277 raeburn 10299: if ($changes{'lcavailable'}) {
10300: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10301: }
1.24 raeburn 10302: if ($changes{'localonly'}) {
1.277 raeburn 10303: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 10304: }
1.277 raeburn 10305: if ($changes{'lclocalonly'}) {
10306: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 10307: }
1.23 raeburn 10308: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10309: my $chgtext;
1.26 raeburn 10310: if (ref($usertypes) eq 'HASH') {
10311: if (keys(%{$usertypes}) > 0) {
10312: foreach my $type (@{$types}) {
10313: if (grep(/^\Q$type\E$/,@cansearch)) {
10314: $chgtext .= $usertypes->{$type}.'; ';
10315: }
10316: }
10317: if (grep(/^default$/,@cansearch)) {
10318: $chgtext .= $othertitle;
10319: } else {
10320: $chgtext =~ s/\; $//;
10321: }
1.210 raeburn 10322: $resulttext .=
1.178 raeburn 10323: '<li>'.
10324: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10325: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10326: '</li>';
1.23 raeburn 10327: }
10328: }
10329: }
10330: if (ref($changes{'searchby'}) eq 'ARRAY') {
10331: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10332: my $chgtext;
10333: foreach my $type (@{$titleorder}) {
10334: if (grep(/^\Q$type\E$/,@searchby)) {
10335: if (defined($searchtitles->{$type})) {
10336: $chgtext .= $searchtitles->{$type}.'; ';
10337: }
10338: }
10339: }
10340: $chgtext =~ s/\; $//;
10341: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10342: }
1.25 raeburn 10343: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10344: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10345: my $chgtext;
10346: foreach my $type (@{$srchtypeorder}) {
10347: if (grep(/^\Q$type\E$/,@searchtypes)) {
10348: if (defined($srchtypes_desc->{$type})) {
10349: $chgtext .= $srchtypes_desc->{$type}.'; ';
10350: }
10351: }
10352: }
10353: $chgtext =~ s/\; $//;
1.178 raeburn 10354: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 10355: }
10356: $resulttext .= '</ul>';
10357: } else {
1.277 raeburn 10358: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 10359: }
10360: } else {
10361: $resulttext = '<span class="LC_error">'.
1.27 raeburn 10362: &mt('An error occurred: [_1]',$putresult).'</span>';
10363: }
10364: return $resulttext;
10365: }
10366:
1.28 raeburn 10367: sub modify_contacts {
1.205 raeburn 10368: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 10369: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10370: if (ref($domconfig{'contacts'}) eq 'HASH') {
10371: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10372: $currsetting{$key} = $domconfig{'contacts'}{$key};
10373: }
10374: }
1.286 raeburn 10375: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 10376: my @contacts = ('supportemail','adminemail');
1.286 raeburn 10377: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
10378: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 10379: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 10380: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 10381: foreach my $type (@mailings) {
10382: @{$newsetting{$type}} =
10383: &Apache::loncommon::get_env_multiple('form.'.$type);
10384: foreach my $item (@contacts) {
10385: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
10386: $contacts_hash{contacts}{$type}{$item} = 1;
10387: } else {
10388: $contacts_hash{contacts}{$type}{$item} = 0;
10389: }
1.289 raeburn 10390: }
1.28 raeburn 10391: $others{$type} = $env{'form.'.$type.'_others'};
10392: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 10393: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10394: $bcc{$type} = $env{'form.'.$type.'_bcc'};
10395: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 10396: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
10397: $includestr{$type} = $env{'form.'.$type.'_includestr'};
10398: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
10399: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10400: }
1.134 raeburn 10401: }
1.28 raeburn 10402: }
10403: foreach my $item (@contacts) {
10404: $to{$item} = $env{'form.'.$item};
10405: $contacts_hash{'contacts'}{$item} = $to{$item};
10406: }
1.203 raeburn 10407: foreach my $item (@toggles) {
10408: if ($env{'form.'.$item} =~ /^(0|1)$/) {
10409: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
10410: }
10411: }
1.286 raeburn 10412: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
10413: foreach my $field (@{$fields}) {
10414: if (ref($possoptions->{$field}) eq 'ARRAY') {
10415: my $value = $env{'form.helpform_'.$field};
10416: $value =~ s/^\s+|\s+$//g;
10417: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
10418: $contacts_hash{contacts}{'helpform'}{$field} = $value;
10419: if ($field eq 'screenshot') {
10420: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
10421: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
10422: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
10423: }
10424: }
10425: }
10426: }
10427: }
10428: }
1.28 raeburn 10429: if (keys(%currsetting) > 0) {
10430: foreach my $item (@contacts) {
10431: if ($to{$item} ne $currsetting{$item}) {
10432: $changes{$item} = 1;
10433: }
10434: }
10435: foreach my $type (@mailings) {
10436: foreach my $item (@contacts) {
10437: if (ref($currsetting{$type}) eq 'HASH') {
10438: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
10439: push(@{$changes{$type}},$item);
10440: }
10441: } else {
10442: push(@{$changes{$type}},@{$newsetting{$type}});
10443: }
10444: }
10445: if ($others{$type} ne $currsetting{$type}{'others'}) {
10446: push(@{$changes{$type}},'others');
10447: }
1.289 raeburn 10448: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10449: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
10450: push(@{$changes{$type}},'bcc');
10451: }
1.286 raeburn 10452: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
10453: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
10454: push(@{$changes{$type}},'include');
10455: }
10456: }
10457: }
10458: if (ref($fields) eq 'ARRAY') {
10459: if (ref($currsetting{'helpform'}) eq 'HASH') {
10460: foreach my $field (@{$fields}) {
10461: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
10462: push(@{$changes{'helpform'}},$field);
10463: }
10464: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10465: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
10466: push(@{$changes{'helpform'}},'maxsize');
10467: }
10468: }
10469: }
10470: } else {
10471: foreach my $field (@{$fields}) {
10472: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10473: push(@{$changes{'helpform'}},$field);
10474: }
10475: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10476: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10477: push(@{$changes{'helpform'}},'maxsize');
10478: }
10479: }
10480: }
1.134 raeburn 10481: }
1.28 raeburn 10482: }
10483: } else {
10484: my %default;
10485: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
10486: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
10487: $default{'errormail'} = 'adminemail';
10488: $default{'packagesmail'} = 'adminemail';
10489: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 10490: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 10491: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 10492: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 10493: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 10494: foreach my $item (@contacts) {
10495: if ($to{$item} ne $default{$item}) {
1.286 raeburn 10496: $changes{$item} = 1;
1.203 raeburn 10497: }
1.28 raeburn 10498: }
10499: foreach my $type (@mailings) {
10500: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
10501: push(@{$changes{$type}},@{$newsetting{$type}});
10502: }
10503: if ($others{$type} ne '') {
10504: push(@{$changes{$type}},'others');
1.134 raeburn 10505: }
1.286 raeburn 10506: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10507: if ($bcc{$type} ne '') {
10508: push(@{$changes{$type}},'bcc');
10509: }
1.286 raeburn 10510: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
10511: push(@{$changes{$type}},'include');
10512: }
1.134 raeburn 10513: }
1.28 raeburn 10514: }
1.286 raeburn 10515: if (ref($fields) eq 'ARRAY') {
10516: foreach my $field (@{$fields}) {
10517: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10518: push(@{$changes{'helpform'}},$field);
10519: }
10520: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10521: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10522: push(@{$changes{'helpform'}},'maxsize');
10523: }
10524: }
10525: }
1.289 raeburn 10526: }
1.28 raeburn 10527: }
1.203 raeburn 10528: foreach my $item (@toggles) {
10529: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
10530: $changes{$item} = 1;
10531: } elsif ((!$env{'form.'.$item}) &&
10532: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
10533: $changes{$item} = 1;
10534: }
10535: }
1.28 raeburn 10536: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
10537: $dom);
10538: if ($putresult eq 'ok') {
10539: if (keys(%changes) > 0) {
1.205 raeburn 10540: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10541: if (ref($lastactref) eq 'HASH') {
10542: $lastactref->{'domainconfig'} = 1;
10543: }
1.28 raeburn 10544: my ($titles,$short_titles) = &contact_titles();
10545: $resulttext = &mt('Changes made:').'<ul>';
10546: foreach my $item (@contacts) {
10547: if ($changes{$item}) {
10548: $resulttext .= '<li>'.$titles->{$item}.
10549: &mt(' set to: ').
10550: '<span class="LC_cusr_emph">'.
10551: $to{$item}.'</span></li>';
10552: }
10553: }
10554: foreach my $type (@mailings) {
10555: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 10556: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 10557: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 10558: } else {
10559: $resulttext .= '<li>'.$titles->{$type}.': ';
10560: }
1.28 raeburn 10561: my @text;
10562: foreach my $item (@{$newsetting{$type}}) {
10563: push(@text,$short_titles->{$item});
10564: }
10565: if ($others{$type} ne '') {
10566: push(@text,$others{$type});
10567: }
1.286 raeburn 10568: if (@text) {
10569: $resulttext .= '<span class="LC_cusr_emph">'.
10570: join(', ',@text).'</span>';
10571: }
10572: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10573: if ($bcc{$type} ne '') {
1.286 raeburn 10574: my $bcctext;
10575: if (@text) {
1.289 raeburn 10576: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 10577: } else {
10578: $bcctext = '(Bcc)';
10579: }
10580: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10581: } elsif (!@text) {
10582: $resulttext .= &mt('No one');
10583: }
1.289 raeburn 10584: if ($includestr{$type} ne '') {
1.286 raeburn 10585: if ($includeloc{$type} eq 'b') {
10586: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
10587: } elsif ($includeloc{$type} eq 's') {
10588: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
10589: }
1.134 raeburn 10590: }
1.286 raeburn 10591: } elsif (!@text) {
10592: $resulttext .= &mt('No recipients');
1.134 raeburn 10593: }
10594: $resulttext .= '</li>';
1.28 raeburn 10595: }
10596: }
1.203 raeburn 10597: my @offon = ('off','on');
10598: if ($changes{'reporterrors'}) {
10599: $resulttext .= '<li>'.
10600: &mt('E-mail error reports to [_1] set to "'.
10601: $offon[$env{'form.reporterrors'}].'".',
10602: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10603: &mt('LON-CAPA core group - MSU'),600,500)).
10604: '</li>';
10605: }
10606: if ($changes{'reportupdates'}) {
10607: $resulttext .= '<li>'.
10608: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
10609: $offon[$env{'form.reportupdates'}].'".',
10610: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10611: &mt('LON-CAPA core group - MSU'),600,500)).
10612: '</li>';
10613: }
1.286 raeburn 10614: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
10615: my (@optional,@required,@unused,$maxsizechg);
10616: foreach my $field (@{$changes{'helpform'}}) {
10617: if ($field eq 'maxsize') {
10618: $maxsizechg = 1;
10619: next;
10620: }
10621: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 10622: push(@optional,$field);
1.286 raeburn 10623: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
10624: push(@unused,$field);
10625: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 10626: push(@required,$field);
1.286 raeburn 10627: }
10628: }
10629: if (@optional) {
10630: $resulttext .= '<li>'.
10631: &mt('Help form fields changed to "Optional": [_1].',
10632: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
10633: '</li>';
10634: }
10635: if (@required) {
10636: $resulttext .= '<li>'.
10637: &mt('Help form fields changed to "Required": [_1].',
10638: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
10639: '</li>';
10640: }
10641: if (@unused) {
10642: $resulttext .= '<li>'.
10643: &mt('Help form fields changed to "Not shown": [_1].',
10644: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
10645: '</li>';
10646: }
10647: if ($maxsizechg) {
10648: $resulttext .= '<li>'.
10649: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
10650: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
10651: '</li>';
10652:
10653: }
10654: }
1.28 raeburn 10655: $resulttext .= '</ul>';
10656: } else {
1.288 raeburn 10657: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 10658: }
10659: } else {
10660: $resulttext = '<span class="LC_error">'.
10661: &mt('An error occurred: [_1].',$putresult).'</span>';
10662: }
10663: return $resulttext;
10664: }
10665:
10666: sub modify_usercreation {
1.27 raeburn 10667: my ($dom,%domconfig) = @_;
1.224 raeburn 10668: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 10669: my $warningmsg;
1.27 raeburn 10670: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10671: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 10672: if ($key eq 'cancreate') {
10673: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10674: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10675: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269 raeburn 10676: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
10677: ($item eq 'recaptchaversion')) {
1.224 raeburn 10678: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10679: } else {
10680: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10681: }
10682: }
10683: }
10684: } elsif ($key eq 'email_rule') {
10685: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10686: } else {
10687: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10688: }
1.27 raeburn 10689: }
10690: }
10691: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 10692: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 10693: my @contexts = ('author','course','requestcrs');
1.34 raeburn 10694: foreach my $item(@contexts) {
1.224 raeburn 10695: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 10696: }
1.34 raeburn 10697: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10698: foreach my $item (@contexts) {
1.224 raeburn 10699: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
10700: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 10701: }
1.27 raeburn 10702: }
1.34 raeburn 10703: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
10704: foreach my $item (@contexts) {
1.43 raeburn 10705: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 10706: if ($cancreate{$item} ne 'any') {
10707: push(@{$changes{'cancreate'}},$item);
10708: }
10709: } else {
10710: if ($cancreate{$item} ne 'none') {
10711: push(@{$changes{'cancreate'}},$item);
10712: }
1.27 raeburn 10713: }
10714: }
10715: } else {
1.43 raeburn 10716: foreach my $item (@contexts) {
1.34 raeburn 10717: push(@{$changes{'cancreate'}},$item);
10718: }
1.27 raeburn 10719: }
1.34 raeburn 10720:
1.27 raeburn 10721: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
10722: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
10723: if (!grep(/^\Q$type\E$/,@username_rule)) {
10724: push(@{$changes{'username_rule'}},$type);
10725: }
10726: }
10727: foreach my $type (@username_rule) {
10728: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
10729: push(@{$changes{'username_rule'}},$type);
10730: }
10731: }
10732: } else {
10733: push(@{$changes{'username_rule'}},@username_rule);
10734: }
10735:
1.32 raeburn 10736: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
10737: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
10738: if (!grep(/^\Q$type\E$/,@id_rule)) {
10739: push(@{$changes{'id_rule'}},$type);
10740: }
10741: }
10742: foreach my $type (@id_rule) {
10743: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
10744: push(@{$changes{'id_rule'}},$type);
10745: }
10746: }
10747: } else {
10748: push(@{$changes{'id_rule'}},@id_rule);
10749: }
10750:
1.43 raeburn 10751: my @authen_contexts = ('author','course','domain');
1.28 raeburn 10752: my @authtypes = ('int','krb4','krb5','loc');
10753: my %authhash;
1.43 raeburn 10754: foreach my $item (@authen_contexts) {
1.28 raeburn 10755: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
10756: foreach my $auth (@authtypes) {
10757: if (grep(/^\Q$auth\E$/,@authallowed)) {
10758: $authhash{$item}{$auth} = 1;
10759: } else {
10760: $authhash{$item}{$auth} = 0;
10761: }
10762: }
10763: }
10764: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 10765: foreach my $item (@authen_contexts) {
1.28 raeburn 10766: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
10767: foreach my $auth (@authtypes) {
10768: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
10769: push(@{$changes{'authtypes'}},$item);
10770: last;
10771: }
10772: }
10773: }
10774: }
10775: } else {
1.43 raeburn 10776: foreach my $item (@authen_contexts) {
1.28 raeburn 10777: push(@{$changes{'authtypes'}},$item);
10778: }
10779: }
10780:
1.224 raeburn 10781: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
10782: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
10783: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
10784: $save_usercreate{'id_rule'} = \@id_rule;
10785: $save_usercreate{'username_rule'} = \@username_rule,
10786: $save_usercreate{'authtypes'} = \%authhash;
10787:
1.27 raeburn 10788: my %usercreation_hash = (
1.224 raeburn 10789: usercreation => \%save_usercreate,
10790: );
1.27 raeburn 10791:
10792: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
10793: $dom);
1.50 raeburn 10794:
1.224 raeburn 10795: if ($putresult eq 'ok') {
10796: if (keys(%changes) > 0) {
10797: $resulttext = &mt('Changes made:').'<ul>';
10798: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10799: my %lt = &usercreation_types();
10800: foreach my $type (@{$changes{'cancreate'}}) {
10801: my $chgtext = $lt{$type}.', ';
10802: if ($cancreate{$type} eq 'none') {
10803: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
10804: } elsif ($cancreate{$type} eq 'any') {
10805: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
10806: } elsif ($cancreate{$type} eq 'official') {
10807: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
10808: } elsif ($cancreate{$type} eq 'unofficial') {
10809: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
10810: }
10811: $resulttext .= '<li>'.$chgtext.'</li>';
10812: }
10813: }
10814: if (ref($changes{'username_rule'}) eq 'ARRAY') {
10815: my ($rules,$ruleorder) =
10816: &Apache::lonnet::inst_userrules($dom,'username');
10817: my $chgtext = '<ul>';
10818: foreach my $type (@username_rule) {
10819: if (ref($rules->{$type}) eq 'HASH') {
10820: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
10821: }
10822: }
10823: $chgtext .= '</ul>';
10824: if (@username_rule > 0) {
10825: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10826: } else {
10827: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
10828: }
10829: }
10830: if (ref($changes{'id_rule'}) eq 'ARRAY') {
10831: my ($idrules,$idruleorder) =
10832: &Apache::lonnet::inst_userrules($dom,'id');
10833: my $chgtext = '<ul>';
10834: foreach my $type (@id_rule) {
10835: if (ref($idrules->{$type}) eq 'HASH') {
10836: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
10837: }
10838: }
10839: $chgtext .= '</ul>';
10840: if (@id_rule > 0) {
10841: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10842: } else {
10843: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
10844: }
10845: }
10846: my %authname = &authtype_names();
10847: my %context_title = &context_names();
10848: if (ref($changes{'authtypes'}) eq 'ARRAY') {
10849: my $chgtext = '<ul>';
10850: foreach my $type (@{$changes{'authtypes'}}) {
10851: my @allowed;
10852: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
10853: foreach my $auth (@authtypes) {
10854: if ($authhash{$type}{$auth}) {
10855: push(@allowed,$authname{$auth});
10856: }
10857: }
10858: if (@allowed > 0) {
10859: $chgtext .= join(', ',@allowed).'</li>';
10860: } else {
10861: $chgtext .= &mt('none').'</li>';
10862: }
10863: }
10864: $chgtext .= '</ul>';
10865: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
10866: $resulttext .= '</li>';
10867: }
10868: $resulttext .= '</ul>';
10869: } else {
10870: $resulttext = &mt('No changes made to user creation settings');
10871: }
10872: } else {
10873: $resulttext = '<span class="LC_error">'.
10874: &mt('An error occurred: [_1]',$putresult).'</span>';
10875: }
10876: if ($warningmsg ne '') {
10877: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10878: }
10879: return $resulttext;
10880: }
10881:
10882: sub modify_selfcreation {
10883: my ($dom,%domconfig) = @_;
10884: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
10885: my (%save_usercreate,%save_usermodify);
1.228 raeburn 10886: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10887: if (ref($types) eq 'ARRAY') {
10888: $usertypes->{'default'} = $othertitle;
10889: push(@{$types},'default');
10890: }
1.224 raeburn 10891: #
10892: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
10893: #
10894: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10895: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
10896: if ($key eq 'cancreate') {
10897: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10898: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10899: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
10900: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.269 raeburn 10901: ($item eq 'recaptchaversion') ||
1.236 raeburn 10902: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 10903: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 10904: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10905: } else {
10906: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10907: }
10908: }
10909: }
10910: } elsif ($key eq 'email_rule') {
10911: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10912: } else {
10913: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10914: }
10915: }
10916: }
10917: #
10918: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
10919: #
10920: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10921: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
10922: if ($key eq 'selfcreate') {
10923: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
10924: } else {
10925: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
10926: }
10927: }
10928: }
10929:
10930: my @contexts = ('selfcreate');
10931: @{$cancreate{'selfcreate'}} = ();
10932: %{$cancreate{'emailusername'}} = ();
10933: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 10934: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 10935: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 10936: my %selfcreatetypes = (
10937: sso => 'users authenticated by institutional single sign on',
10938: login => 'users authenticated by institutional log-in',
1.236 raeburn 10939: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 10940: );
1.224 raeburn 10941: #
10942: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
10943: # is permitted.
10944: #
1.236 raeburn 10945:
10946: my @statuses;
10947: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10948: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
10949: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
10950: }
10951: }
10952: push(@statuses,'default');
10953:
1.228 raeburn 10954: foreach my $item ('login','sso','email') {
1.224 raeburn 10955: if ($item eq 'email') {
1.236 raeburn 10956: if ($env{'form.cancreate_email'}) {
1.224 raeburn 10957: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 10958: push(@contexts,'selfcreateprocessing');
10959: foreach my $type (@statuses) {
10960: if ($type eq 'default') {
10961: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
10962: } else {
10963: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
10964: }
10965: }
1.224 raeburn 10966: }
10967: } else {
10968: if ($env{'form.cancreate_'.$item}) {
10969: push(@{$cancreate{'selfcreate'}},$item);
10970: }
10971: }
10972: }
10973: my (@email_rule,%userinfo,%savecaptcha);
10974: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
10975: #
1.228 raeburn 10976: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
10977: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 10978: #
1.236 raeburn 10979:
1.244 raeburn 10980: if ($env{'form.cancreate_email'}) {
1.228 raeburn 10981: push(@contexts,'emailusername');
10982: if (ref($types) eq 'ARRAY') {
10983: foreach my $type (@{$types}) {
10984: if (ref($infofields) eq 'ARRAY') {
10985: foreach my $field (@{$infofields}) {
10986: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
10987: $cancreate{'emailusername'}{$type}{$field} = $1;
10988: }
10989: }
1.224 raeburn 10990: }
10991: }
10992: }
10993: #
10994: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
10995: # queued requests for self-creation of account using e-mail address as username
10996: #
10997:
10998: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
10999: @approvalnotify = sort(@approvalnotify);
11000: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
11001: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11002: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11003: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11004: push(@{$changes{'cancreate'}},'notify');
11005: }
11006: } else {
11007: if ($cancreate{'notify'}{'approval'}) {
11008: push(@{$changes{'cancreate'}},'notify');
11009: }
11010: }
11011: } elsif ($cancreate{'notify'}{'approval'}) {
11012: push(@{$changes{'cancreate'}},'notify');
11013: }
11014:
11015: #
11016: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
11017: #
11018: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
11019: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11020: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11021: if (@{$curr_usercreation{'email_rule'}} > 0) {
11022: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
11023: if (!grep(/^\Q$type\E$/,@email_rule)) {
11024: push(@{$changes{'email_rule'}},$type);
11025: }
11026: }
11027: }
11028: if (@email_rule > 0) {
11029: foreach my $type (@email_rule) {
11030: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
11031: push(@{$changes{'email_rule'}},$type);
11032: }
11033: }
11034: }
11035: } elsif (@email_rule > 0) {
11036: push(@{$changes{'email_rule'}},@email_rule);
11037: }
11038: }
11039: #
1.236 raeburn 11040: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 11041: # institutional log-in.
11042: #
11043: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11044: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11045: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11046: ($domdefaults{'auth_def'} eq 'localauth'))) {
11047: $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.').' '.
11048: &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.');
11049: }
11050: }
11051: my @fields = ('lastname','firstname','middlename','generation',
11052: 'permanentemail','id');
1.240 raeburn 11053: my @shibfields = (@fields,'inststatus');
1.224 raeburn 11054: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11055: #
11056: # Where usernames may created for institutional log-in and/or institutional single sign on:
11057: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11058: # may self-create accounts
11059: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11060: # which the user may supply, if institutional data is unavailable.
11061: #
11062: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
11063: if (ref($types) eq 'ARRAY') {
1.228 raeburn 11064: if (@{$types} > 1) {
1.224 raeburn 11065: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11066: push(@contexts,'statustocreate');
11067: } else {
11068: undef($cancreate{'statustocreate'});
11069: }
11070: foreach my $type (@{$types}) {
11071: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11072: foreach my $field (@fields) {
11073: if (grep(/^\Q$field\E$/,@modifiable)) {
11074: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11075: } else {
11076: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11077: }
11078: }
11079: }
11080: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
11081: foreach my $type (@{$types}) {
11082: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11083: foreach my $field (@fields) {
11084: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11085: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11086: push(@{$changes{'selfcreate'}},$type);
11087: last;
11088: }
11089: }
11090: }
11091: }
11092: } else {
11093: foreach my $type (@{$types}) {
11094: push(@{$changes{'selfcreate'}},$type);
11095: }
11096: }
11097: }
1.240 raeburn 11098: foreach my $field (@shibfields) {
11099: if ($env{'form.shibenv_'.$field} ne '') {
11100: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11101: }
11102: }
11103: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11104: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11105: foreach my $field (@shibfields) {
11106: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11107: push(@{$changes{'cancreate'}},'shibenv');
11108: }
11109: }
11110: } else {
11111: foreach my $field (@shibfields) {
11112: if ($env{'form.shibenv_'.$field}) {
11113: push(@{$changes{'cancreate'}},'shibenv');
11114: last;
11115: }
11116: }
11117: }
11118: }
1.224 raeburn 11119: }
11120: foreach my $item (@contexts) {
11121: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11122: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11123: if (ref($cancreate{$item}) eq 'ARRAY') {
11124: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11125: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11126: push(@{$changes{'cancreate'}},$item);
11127: }
11128: }
11129: }
11130: }
11131: if (ref($cancreate{$item}) eq 'ARRAY') {
11132: foreach my $type (@{$cancreate{$item}}) {
11133: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11134: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11135: push(@{$changes{'cancreate'}},$item);
11136: }
11137: }
11138: }
11139: }
11140: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11141: if (ref($cancreate{$item}) eq 'HASH') {
11142: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 11143: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
11144: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
11145: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
11146: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11147: push(@{$changes{'cancreate'}},$item);
11148: }
11149: }
11150: }
1.236 raeburn 11151: } elsif ($item eq 'selfcreateprocessing') {
11152: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
11153: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11154: push(@{$changes{'cancreate'}},$item);
11155: }
11156: }
1.228 raeburn 11157: } else {
11158: if (!$cancreate{$item}{$curr}) {
11159: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11160: push(@{$changes{'cancreate'}},$item);
11161: }
1.224 raeburn 11162: }
11163: }
11164: }
11165: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 11166: if (ref($cancreate{$item}{$field}) eq 'HASH') {
11167: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
11168: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
11169: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
11170: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11171: push(@{$changes{'cancreate'}},$item);
11172: }
11173: }
11174: } else {
11175: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11176: push(@{$changes{'cancreate'}},$item);
11177: }
11178: }
11179: }
1.236 raeburn 11180: } elsif ($item eq 'selfcreateprocessing') {
11181: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
11182: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11183: push(@{$changes{'cancreate'}},$item);
11184: }
11185: }
1.228 raeburn 11186: } else {
11187: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
11188: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11189: push(@{$changes{'cancreate'}},$item);
11190: }
1.224 raeburn 11191: }
11192: }
11193: }
11194: }
11195: } elsif ($curr_usercreation{'cancreate'}{$item}) {
11196: if (ref($cancreate{$item}) eq 'ARRAY') {
11197: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
11198: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11199: push(@{$changes{'cancreate'}},$item);
11200: }
11201: }
11202: } elsif (ref($cancreate{$item}) eq 'HASH') {
11203: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
11204: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11205: push(@{$changes{'cancreate'}},$item);
11206: }
11207: }
11208: }
11209: } elsif ($item eq 'emailusername') {
1.228 raeburn 11210: if (ref($cancreate{$item}) eq 'HASH') {
11211: foreach my $type (keys(%{$cancreate{$item}})) {
11212: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11213: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11214: if ($cancreate{$item}{$type}{$field}) {
11215: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11216: push(@{$changes{'cancreate'}},$item);
11217: }
11218: last;
11219: }
11220: }
11221: }
11222: }
1.224 raeburn 11223: }
11224: }
11225: }
11226: #
11227: # Populate %save_usercreate hash with updates to self-creation configuration.
11228: #
11229: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
11230: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 11231: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 11232: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
11233: if (ref($cancreate{'notify'}) eq 'HASH') {
11234: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
11235: }
1.236 raeburn 11236: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
11237: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
11238: }
1.224 raeburn 11239: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11240: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
11241: }
1.240 raeburn 11242: if (ref($cancreate{'shibenv'}) eq 'HASH') {
11243: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
11244: }
1.224 raeburn 11245: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
11246: $save_usercreate{'emailrule'} = \@email_rule;
11247:
11248: my %userconfig_hash = (
11249: usercreation => \%save_usercreate,
11250: usermodification => \%save_usermodify,
11251: );
11252: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
11253: $dom);
11254: #
11255: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
11256: #
1.27 raeburn 11257: if ($putresult eq 'ok') {
11258: if (keys(%changes) > 0) {
11259: $resulttext = &mt('Changes made:').'<ul>';
11260: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 11261: my %lt = &selfcreation_types();
1.34 raeburn 11262: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 11263: my $chgtext;
1.45 raeburn 11264: if ($type eq 'selfcreate') {
1.50 raeburn 11265: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 11266: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 11267: } else {
1.224 raeburn 11268: $chgtext .= &mt('Self-creation of a new account is permitted for:').
11269: '<ul>';
1.50 raeburn 11270: foreach my $case (@{$cancreate{$type}}) {
11271: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
11272: }
11273: $chgtext .= '</ul>';
1.100 raeburn 11274: if (ref($cancreate{$type}) eq 'ARRAY') {
11275: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
11276: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11277: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 11278: $chgtext .= '<br />'.
11279: '<span class="LC_warning">'.
11280: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11281: '</span>';
1.100 raeburn 11282: }
11283: }
11284: }
11285: }
1.43 raeburn 11286: }
1.240 raeburn 11287: } elsif ($type eq 'shibenv') {
11288: if (keys(%{$cancreate{$type}}) == 0) {
11289: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
11290: } else {
11291: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
11292: '<ul>';
11293: foreach my $field (@shibfields) {
11294: next if ($cancreate{$type}{$field} eq '');
11295: if ($field eq 'inststatus') {
11296: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
11297: } else {
11298: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
11299: }
11300: }
11301: $chgtext .= '</ul>';
11302: }
1.93 raeburn 11303: } elsif ($type eq 'statustocreate') {
1.96 raeburn 11304: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
11305: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
11306: if (@{$cancreate{'selfcreate'}} > 0) {
11307: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 11308: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 11309: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 11310: $chgtext .= '<br />'.
11311: '<span class="LC_warning">'.
11312: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11313: '</span>';
11314: }
1.96 raeburn 11315: } elsif (ref($usertypes) eq 'HASH') {
11316: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 11317: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
11318: } else {
11319: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
11320: }
11321: $chgtext .= '<ul>';
11322: foreach my $case (@{$cancreate{$type}}) {
11323: if ($case eq 'default') {
11324: $chgtext .= '<li>'.$othertitle.'</li>';
11325: } else {
11326: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 11327: }
11328: }
1.100 raeburn 11329: $chgtext .= '</ul>';
11330: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 11331: $chgtext .= '<br /><span class="LC_warning">'.
11332: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
11333: '</span>';
1.100 raeburn 11334: }
11335: }
11336: } else {
11337: if (@{$cancreate{$type}} == 0) {
11338: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
11339: } else {
11340: $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 11341: }
11342: }
11343: }
1.236 raeburn 11344: } elsif ($type eq 'selfcreateprocessing') {
11345: my %choices = &Apache::lonlocal::texthash (
11346: automatic => 'Automatic approval',
11347: approval => 'Queued for approval',
11348: );
11349: if (@statuses > 1) {
11350: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
11351: '<ul>';
11352: foreach my $type (@statuses) {
11353: if ($type eq 'default') {
11354: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11355: } else {
11356: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11357: }
11358: }
11359: $chgtext .= '</ul>';
11360: } else {
11361: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
11362: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
11363: }
1.165 raeburn 11364: } elsif ($type eq 'captcha') {
1.224 raeburn 11365: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 11366: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
11367: } else {
11368: my %captchas = &captcha_phrases();
1.224 raeburn 11369: if ($captchas{$savecaptcha{$type}}) {
11370: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 11371: } else {
1.210 raeburn 11372: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 11373: }
11374: }
11375: } elsif ($type eq 'recaptchakeys') {
11376: my ($privkey,$pubkey);
1.224 raeburn 11377: if (ref($savecaptcha{$type}) eq 'HASH') {
11378: $pubkey = $savecaptcha{$type}{'public'};
11379: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 11380: }
11381: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
11382: if (!$pubkey) {
11383: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
11384: } else {
11385: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11386: }
11387: if (!$privkey) {
11388: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
11389: } else {
11390: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
11391: }
11392: $chgtext .= '</ul>';
1.269 raeburn 11393: } elsif ($type eq 'recaptchaversion') {
11394: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 11395: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 11396: }
1.224 raeburn 11397: } elsif ($type eq 'emailusername') {
11398: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 11399: if (ref($types) eq 'ARRAY') {
11400: foreach my $type (@{$types}) {
11401: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
11402: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 11403: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 11404: '<ul>';
11405: foreach my $field (@{$infofields}) {
11406: if ($cancreate{'emailusername'}{$type}{$field}) {
11407: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
11408: }
11409: }
1.245 raeburn 11410: $chgtext .= '</ul>';
11411: } else {
11412: $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 11413: }
11414: } else {
1.245 raeburn 11415: $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 11416: }
11417: }
11418: }
11419: }
11420: } elsif ($type eq 'notify') {
11421: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
11422: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11423: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
11424: if ($cancreate{'notify'}{'approval'}) {
11425: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
11426: }
11427: }
1.43 raeburn 11428: }
1.34 raeburn 11429: }
1.224 raeburn 11430: if ($chgtext) {
11431: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 11432: }
11433: }
11434: }
1.43 raeburn 11435: if (ref($changes{'email_rule'}) eq 'ARRAY') {
11436: my ($emailrules,$emailruleorder) =
11437: &Apache::lonnet::inst_userrules($dom,'email');
11438: my $chgtext = '<ul>';
11439: foreach my $type (@email_rule) {
11440: if (ref($emailrules->{$type}) eq 'HASH') {
11441: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
11442: }
11443: }
11444: $chgtext .= '</ul>';
11445: if (@email_rule > 0) {
1.224 raeburn 11446: $resulttext .= '<li>'.
11447: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
11448: $chgtext.
11449: '</li>';
1.43 raeburn 11450: } else {
1.224 raeburn 11451: $resulttext .= '<li>'.
11452: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
11453: '</li>';
1.43 raeburn 11454: }
11455: }
1.224 raeburn 11456: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
11457: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
11458: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11459: foreach my $type (@{$changes{'selfcreate'}}) {
11460: my $typename = $type;
11461: if (ref($usertypes) eq 'HASH') {
11462: if ($usertypes->{$type} ne '') {
11463: $typename = $usertypes->{$type};
11464: }
11465: }
11466: my @modifiable;
11467: $resulttext .= '<li>'.
11468: &mt('Self-creation of account by users with status: [_1]',
11469: '<span class="LC_cusr_emph">'.$typename.'</span>').
11470: ' - '.&mt('modifiable fields (if institutional data blank): ');
11471: foreach my $field (@fields) {
11472: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
11473: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 11474: }
11475: }
1.224 raeburn 11476: if (@modifiable > 0) {
11477: $resulttext .= join(', ',@modifiable);
1.43 raeburn 11478: } else {
1.224 raeburn 11479: $resulttext .= &mt('none');
1.43 raeburn 11480: }
1.224 raeburn 11481: $resulttext .= '</li>';
1.28 raeburn 11482: }
1.224 raeburn 11483: $resulttext .= '</ul></li>';
1.28 raeburn 11484: }
1.27 raeburn 11485: $resulttext .= '</ul>';
11486: } else {
1.224 raeburn 11487: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 11488: }
11489: } else {
11490: $resulttext = '<span class="LC_error">'.
1.23 raeburn 11491: &mt('An error occurred: [_1]',$putresult).'</span>';
11492: }
1.43 raeburn 11493: if ($warningmsg ne '') {
11494: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11495: }
1.23 raeburn 11496: return $resulttext;
11497: }
11498:
1.165 raeburn 11499: sub process_captcha {
11500: my ($container,$changes,$newsettings,$current) = @_;
11501: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
11502: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
11503: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
11504: $newsettings->{'captcha'} = 'original';
11505: }
11506: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 11507: if ($container eq 'cancreate') {
1.169 raeburn 11508: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11509: push(@{$changes->{'cancreate'}},'captcha');
11510: } elsif (!defined($changes->{'cancreate'})) {
11511: $changes->{'cancreate'} = ['captcha'];
11512: }
11513: } else {
11514: $changes->{'captcha'} = 1;
1.165 raeburn 11515: }
11516: }
1.269 raeburn 11517: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 11518: if ($newsettings->{'captcha'} eq 'recaptcha') {
11519: $newpub = $env{'form.'.$container.'_recaptchapub'};
11520: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 11521: $newpub =~ s/[^\w\-]//g;
11522: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 11523: $newsettings->{'recaptchakeys'} = {
11524: public => $newpub,
11525: private => $newpriv,
11526: };
1.269 raeburn 11527: $newversion = $env{'form.'.$container.'_recaptchaversion'};
11528: $newversion =~ s/\D//g;
11529: if ($newversion ne '2') {
11530: $newversion = 1;
11531: }
11532: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 11533: }
11534: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
11535: $currpub = $current->{'recaptchakeys'}{'public'};
11536: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 11537: unless ($newsettings->{'captcha'} eq 'recaptcha') {
11538: $newsettings->{'recaptchakeys'} = {
11539: public => '',
11540: private => '',
11541: }
11542: }
1.165 raeburn 11543: }
1.269 raeburn 11544: if ($current->{'captcha'} eq 'recaptcha') {
11545: $currversion = $current->{'recaptchaversion'};
11546: if ($currversion ne '2') {
11547: $currversion = 1;
11548: }
11549: }
11550: if ($currversion ne $newversion) {
11551: if ($container eq 'cancreate') {
11552: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11553: push(@{$changes->{'cancreate'}},'recaptchaversion');
11554: } elsif (!defined($changes->{'cancreate'})) {
11555: $changes->{'cancreate'} = ['recaptchaversion'];
11556: }
11557: } else {
11558: $changes->{'recaptchaversion'} = 1;
11559: }
11560: }
1.165 raeburn 11561: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 11562: if ($container eq 'cancreate') {
11563: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11564: push(@{$changes->{'cancreate'}},'recaptchakeys');
11565: } elsif (!defined($changes->{'cancreate'})) {
11566: $changes->{'cancreate'} = ['recaptchakeys'];
11567: }
11568: } else {
1.210 raeburn 11569: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 11570: }
11571: }
11572: return;
11573: }
11574:
1.33 raeburn 11575: sub modify_usermodification {
11576: my ($dom,%domconfig) = @_;
1.224 raeburn 11577: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 11578: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11579: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 11580: if ($key eq 'selfcreate') {
11581: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
11582: } else {
11583: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
11584: }
1.33 raeburn 11585: }
11586: }
1.224 raeburn 11587: my @contexts = ('author','course');
1.33 raeburn 11588: my %context_title = (
11589: author => 'In author context',
11590: course => 'In course context',
11591: );
11592: my @fields = ('lastname','firstname','middlename','generation',
11593: 'permanentemail','id');
11594: my %roles = (
11595: author => ['ca','aa'],
11596: course => ['st','ep','ta','in','cr'],
11597: );
11598: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11599: foreach my $context (@contexts) {
11600: foreach my $role (@{$roles{$context}}) {
11601: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
11602: foreach my $item (@fields) {
11603: if (grep(/^\Q$item\E$/,@modifiable)) {
11604: $modifyhash{$context}{$role}{$item} = 1;
11605: } else {
11606: $modifyhash{$context}{$role}{$item} = 0;
11607: }
11608: }
11609: }
11610: if (ref($curr_usermodification{$context}) eq 'HASH') {
11611: foreach my $role (@{$roles{$context}}) {
11612: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
11613: foreach my $field (@fields) {
11614: if ($modifyhash{$context}{$role}{$field} ne
11615: $curr_usermodification{$context}{$role}{$field}) {
11616: push(@{$changes{$context}},$role);
11617: last;
11618: }
11619: }
11620: }
11621: }
11622: } else {
11623: foreach my $context (@contexts) {
11624: foreach my $role (@{$roles{$context}}) {
11625: push(@{$changes{$context}},$role);
11626: }
11627: }
11628: }
11629: }
11630: my %usermodification_hash = (
11631: usermodification => \%modifyhash,
11632: );
11633: my $putresult = &Apache::lonnet::put_dom('configuration',
11634: \%usermodification_hash,$dom);
11635: if ($putresult eq 'ok') {
11636: if (keys(%changes) > 0) {
11637: $resulttext = &mt('Changes made: ').'<ul>';
11638: foreach my $context (@contexts) {
11639: if (ref($changes{$context}) eq 'ARRAY') {
11640: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
11641: if (ref($changes{$context}) eq 'ARRAY') {
11642: foreach my $role (@{$changes{$context}}) {
11643: my $rolename;
1.224 raeburn 11644: if ($role eq 'cr') {
11645: $rolename = &mt('Custom');
1.33 raeburn 11646: } else {
1.224 raeburn 11647: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 11648: }
11649: my @modifiable;
1.224 raeburn 11650: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 11651: foreach my $field (@fields) {
11652: if ($modifyhash{$context}{$role}{$field}) {
11653: push(@modifiable,$fieldtitles{$field});
11654: }
11655: }
11656: if (@modifiable > 0) {
11657: $resulttext .= join(', ',@modifiable);
11658: } else {
11659: $resulttext .= &mt('none');
11660: }
11661: $resulttext .= '</li>';
11662: }
11663: $resulttext .= '</ul></li>';
11664: }
11665: }
11666: }
11667: $resulttext .= '</ul>';
11668: } else {
11669: $resulttext = &mt('No changes made to user modification settings');
11670: }
11671: } else {
11672: $resulttext = '<span class="LC_error">'.
11673: &mt('An error occurred: [_1]',$putresult).'</span>';
11674: }
11675: return $resulttext;
11676: }
11677:
1.43 raeburn 11678: sub modify_defaults {
1.212 raeburn 11679: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 11680: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 11681: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 11682: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 11683: my @authtypes = ('internal','krb4','krb5','localauth');
11684: foreach my $item (@items) {
11685: $newvalues{$item} = $env{'form.'.$item};
11686: if ($item eq 'auth_def') {
11687: if ($newvalues{$item} ne '') {
11688: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
11689: push(@errors,$item);
11690: }
11691: }
11692: } elsif ($item eq 'lang_def') {
11693: if ($newvalues{$item} ne '') {
11694: if ($newvalues{$item} =~ /^(\w+)/) {
11695: my $langcode = $1;
1.103 raeburn 11696: if ($langcode ne 'x_chef') {
11697: if (code2language($langcode) eq '') {
11698: push(@errors,$item);
11699: }
1.43 raeburn 11700: }
11701: } else {
11702: push(@errors,$item);
11703: }
11704: }
1.54 raeburn 11705: } elsif ($item eq 'timezone_def') {
11706: if ($newvalues{$item} ne '') {
1.62 raeburn 11707: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 11708: push(@errors,$item);
11709: }
11710: }
1.68 raeburn 11711: } elsif ($item eq 'datelocale_def') {
11712: if ($newvalues{$item} ne '') {
11713: my @datelocale_ids = DateTime::Locale->ids();
11714: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
11715: push(@errors,$item);
11716: }
11717: }
1.141 raeburn 11718: } elsif ($item eq 'portal_def') {
11719: if ($newvalues{$item} ne '') {
11720: 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])\/?$/) {
11721: push(@errors,$item);
11722: }
11723: }
1.43 raeburn 11724: }
11725: if (grep(/^\Q$item\E$/,@errors)) {
11726: $newvalues{$item} = $domdefaults{$item};
11727: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
11728: $changes{$item} = 1;
11729: }
1.72 raeburn 11730: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 11731: }
11732: my %defaults_hash = (
1.72 raeburn 11733: defaults => \%newvalues,
11734: );
1.43 raeburn 11735: my $title = &defaults_titles();
1.236 raeburn 11736:
11737: my $currinststatus;
11738: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11739: $currinststatus = $domconfig{'inststatus'};
11740: } else {
11741: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11742: $currinststatus = {
11743: inststatustypes => $usertypes,
11744: inststatusorder => $types,
11745: inststatusguest => [],
11746: };
11747: }
11748: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
11749: my @allpos;
11750: my %guests;
11751: my %alltypes;
11752: my ($currtitles,$currguests,$currorder);
11753: if (ref($currinststatus) eq 'HASH') {
11754: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
11755: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
11756: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
11757: if ($currinststatus->{inststatustypes}->{$type} ne '') {
11758: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
11759: }
11760: }
11761: unless (grep(/^\Q$type\E$/,@todelete)) {
11762: my $position = $env{'form.inststatus_pos_'.$type};
11763: $position =~ s/\D+//g;
11764: $allpos[$position] = $type;
11765: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
11766: $alltypes{$type} =~ s/`//g;
11767: if ($env{'form.inststatus_guest_'.$type}) {
11768: $guests{$type} = 1;
11769: }
11770: }
11771: }
11772: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
11773: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
11774: }
11775: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
11776: $currtitles =~ s/,$//;
11777: }
11778: }
11779: if ($env{'form.addinststatus'}) {
11780: my $newtype = $env{'form.addinststatus'};
11781: $newtype =~ s/\W//g;
11782: unless (exists($alltypes{$newtype})) {
11783: if ($env{'form.addinststatus_guest'}) {
11784: $guests{$newtype} = 1;
11785: }
11786: $alltypes{$newtype} = $env{'form.addinststatus_title'};
11787: $alltypes{$newtype} =~ s/`//g;
11788: my $position = $env{'form.addinststatus_pos'};
11789: $position =~ s/\D+//g;
11790: if ($position ne '') {
11791: $allpos[$position] = $newtype;
11792: }
11793: }
11794: }
11795: my (@orderedstatus,@orderedguests);
11796: foreach my $type (@allpos) {
11797: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
11798: push(@orderedstatus,$type);
11799: if ($guests{$type}) {
11800: push(@orderedguests,$type);
11801: }
11802: }
11803: }
11804: foreach my $type (keys(%alltypes)) {
11805: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
11806: delete($alltypes{$type});
11807: }
11808: }
11809: $defaults_hash{'inststatus'} = {
11810: inststatustypes => \%alltypes,
11811: inststatusorder => \@orderedstatus,
11812: inststatusguest => \@orderedguests,
11813: };
11814: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
11815: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
11816: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
11817: }
11818: }
11819: if ($currorder ne join(',',@orderedstatus)) {
11820: $changes{'inststatus'}{'inststatusorder'} = 1;
11821: }
11822: if ($currguests ne join(',',@orderedguests)) {
11823: $changes{'inststatus'}{'inststatusguest'} = 1;
11824: }
11825: my $newtitles;
11826: foreach my $item (@orderedstatus) {
11827: $newtitles .= $alltypes{$item}.',';
11828: }
11829: $newtitles =~ s/,$//;
11830: if ($currtitles ne $newtitles) {
11831: $changes{'inststatus'}{'inststatustypes'} = 1;
11832: }
1.43 raeburn 11833: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
11834: $dom);
11835: if ($putresult eq 'ok') {
11836: if (keys(%changes) > 0) {
11837: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 11838: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 11839: 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";
11840: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 11841: if ($item eq 'inststatus') {
11842: if (ref($changes{'inststatus'}) eq 'HASH') {
11843: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
11844: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
11845: foreach my $type (@orderedstatus) {
11846: $resulttext .= $alltypes{$type}.', ';
11847: }
11848: $resulttext =~ s/, $//;
11849: $resulttext .= '</li>';
11850: }
11851: if ($changes{'inststatus'}{'inststatusguest'}) {
11852: $resulttext .= '<li>';
11853: if (@orderedguests) {
11854: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
11855: foreach my $type (@orderedguests) {
11856: $resulttext .= $alltypes{$type}.', ';
11857: }
11858: $resulttext =~ s/, $//;
11859: } else {
11860: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
11861: }
11862: $resulttext .= '</li>';
11863: }
11864: }
11865: } else {
11866: my $value = $env{'form.'.$item};
11867: if ($value eq '') {
11868: $value = &mt('none');
11869: } elsif ($item eq 'auth_def') {
11870: my %authnames = &authtype_names();
11871: my %shortauth = (
11872: internal => 'int',
11873: krb4 => 'krb4',
11874: krb5 => 'krb5',
11875: localauth => 'loc',
11876: );
11877: $value = $authnames{$shortauth{$value}};
11878: }
11879: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
11880: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 11881: }
11882: }
11883: $resulttext .= '</ul>';
11884: $mailmsgtext .= "\n";
11885: my $cachetime = 24*60*60;
1.72 raeburn 11886: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11887: if (ref($lastactref) eq 'HASH') {
11888: $lastactref->{'domdefaults'} = 1;
11889: }
1.68 raeburn 11890: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 11891: my $notify = 1;
11892: if (ref($domconfig{'contacts'}) eq 'HASH') {
11893: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
11894: $notify = 0;
11895: }
11896: }
11897: if ($notify) {
11898: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
11899: "LON-CAPA Domain Settings Change - $dom",
11900: $mailmsgtext);
11901: }
1.54 raeburn 11902: }
1.43 raeburn 11903: } else {
1.54 raeburn 11904: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 11905: }
11906: } else {
11907: $resulttext = '<span class="LC_error">'.
11908: &mt('An error occurred: [_1]',$putresult).'</span>';
11909: }
11910: if (@errors > 0) {
11911: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
11912: foreach my $item (@errors) {
11913: $resulttext .= ' "'.$title->{$item}.'",';
11914: }
11915: $resulttext =~ s/,$//;
11916: }
11917: return $resulttext;
11918: }
11919:
1.46 raeburn 11920: sub modify_scantron {
1.205 raeburn 11921: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 11922: my ($resulttext,%confhash,%changes,$errors);
11923: my $custom = 'custom.tab';
11924: my $default = 'default.tab';
11925: my $servadm = $r->dir_config('lonAdmEMail');
11926: my ($configuserok,$author_ok,$switchserver) =
11927: &config_check($dom,$confname,$servadm);
11928: if ($env{'form.scantronformat.filename'} ne '') {
11929: my $error;
11930: if ($configuserok eq 'ok') {
11931: if ($switchserver) {
1.130 raeburn 11932: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 11933: } else {
11934: if ($author_ok eq 'ok') {
11935: my ($result,$scantronurl) =
11936: &publishlogo($r,'upload','scantronformat',$dom,
11937: $confname,'scantron','','',$custom);
11938: if ($result eq 'ok') {
11939: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 11940: $changes{'scantronformat'} = 1;
1.46 raeburn 11941: } else {
11942: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
11943: }
11944: } else {
11945: $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);
11946: }
11947: }
11948: } else {
11949: $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);
11950: }
11951: if ($error) {
11952: &Apache::lonnet::logthis($error);
11953: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11954: }
11955: }
1.48 raeburn 11956: if (ref($domconfig{'scantron'}) eq 'HASH') {
11957: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
11958: if ($env{'form.scantronformat_del'}) {
11959: $confhash{'scantron'}{'scantronformat'} = '';
11960: $changes{'scantronformat'} = 1;
1.46 raeburn 11961: }
11962: }
11963: }
11964: if (keys(%confhash) > 0) {
11965: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
11966: $dom);
11967: if ($putresult eq 'ok') {
11968: if (keys(%changes) > 0) {
1.48 raeburn 11969: if (ref($confhash{'scantron'}) eq 'HASH') {
11970: $resulttext = &mt('Changes made:').'<ul>';
11971: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 11972: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 11973: } else {
1.130 raeburn 11974: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 11975: }
1.48 raeburn 11976: $resulttext .= '</ul>';
11977: } else {
1.130 raeburn 11978: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 11979: }
11980: $resulttext .= '</ul>';
11981: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11982: if (ref($lastactref) eq 'HASH') {
11983: $lastactref->{'domainconfig'} = 1;
11984: }
1.46 raeburn 11985: } else {
1.130 raeburn 11986: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11987: }
11988: } else {
11989: $resulttext = '<span class="LC_error">'.
11990: &mt('An error occurred: [_1]',$putresult).'</span>';
11991: }
11992: } else {
1.130 raeburn 11993: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11994: }
11995: if ($errors) {
11996: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11997: $errors.'</ul>';
11998: }
11999: return $resulttext;
12000: }
12001:
1.48 raeburn 12002: sub modify_coursecategories {
1.239 raeburn 12003: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 12004: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
12005: $cathash);
1.48 raeburn 12006: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 12007: my @catitems = ('unauth','auth');
12008: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 12009: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 12010: $cathash = $domconfig{'coursecategories'}{'cats'};
12011: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
12012: $changes{'togglecats'} = 1;
12013: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
12014: }
12015: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
12016: $changes{'categorize'} = 1;
12017: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
12018: }
1.120 raeburn 12019: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
12020: $changes{'togglecatscomm'} = 1;
12021: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
12022: }
12023: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
12024: $changes{'categorizecomm'} = 1;
12025: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 12026:
12027: }
12028: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
12029: $changes{'togglecatsplace'} = 1;
12030: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
12031: }
12032: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
12033: $changes{'categorizeplace'} = 1;
12034: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 12035: }
1.238 raeburn 12036: foreach my $item (@catitems) {
12037: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12038: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
12039: $changes{$item} = 1;
12040: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12041: }
12042: }
12043: }
1.57 raeburn 12044: } else {
12045: $changes{'togglecats'} = 1;
12046: $changes{'categorize'} = 1;
1.124 raeburn 12047: $changes{'togglecatscomm'} = 1;
12048: $changes{'categorizecomm'} = 1;
1.272 raeburn 12049: $changes{'togglecatsplace'} = 1;
12050: $changes{'categorizeplace'} = 1;
1.87 raeburn 12051: $domconfig{'coursecategories'} = {
12052: togglecats => $env{'form.togglecats'},
12053: categorize => $env{'form.categorize'},
1.124 raeburn 12054: togglecatscomm => $env{'form.togglecatscomm'},
12055: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 12056: togglecatsplace => $env{'form.togglecatsplace'},
12057: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 12058: };
1.238 raeburn 12059: foreach my $item (@catitems) {
12060: if ($env{'form.coursecat_'.$item} ne 'std') {
12061: $changes{$item} = 1;
12062: }
12063: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12064: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12065: }
12066: }
1.57 raeburn 12067: }
12068: if (ref($cathash) eq 'HASH') {
12069: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 12070: push (@deletecategory,'instcode::0');
12071: }
1.120 raeburn 12072: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
12073: push(@deletecategory,'communities::0');
12074: }
1.272 raeburn 12075: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
12076: push(@deletecategory,'placement::0');
12077: }
1.48 raeburn 12078: }
1.57 raeburn 12079: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
12080: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12081: if (@deletecategory > 0) {
12082: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 12083: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 12084: foreach my $item (@deletecategory) {
1.57 raeburn 12085: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
12086: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 12087: $deletions{$item} = 1;
1.57 raeburn 12088: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 12089: }
12090: }
12091: }
1.57 raeburn 12092: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 12093: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 12094: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 12095: $reorderings{$item} = 1;
1.57 raeburn 12096: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 12097: }
12098: if ($env{'form.addcategory_name_'.$item} ne '') {
12099: my $newcat = $env{'form.addcategory_name_'.$item};
12100: my $newdepth = $depth+1;
12101: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12102: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 12103: $adds{$newitem} = 1;
12104: }
12105: if ($env{'form.subcat_'.$item} ne '') {
12106: my $newcat = $env{'form.subcat_'.$item};
12107: my $newdepth = $depth+1;
12108: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12109: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 12110: $adds{$newitem} = 1;
12111: }
12112: }
12113: }
12114: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 12115: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12116: my $newitem = 'instcode::0';
1.57 raeburn 12117: if ($cathash->{$newitem} eq '') {
12118: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12119: $adds{$newitem} = 1;
12120: }
12121: } else {
12122: my $newitem = 'instcode::0';
1.57 raeburn 12123: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12124: $adds{$newitem} = 1;
12125: }
12126: }
1.120 raeburn 12127: if ($env{'form.communities'} eq '1') {
12128: if (ref($cathash) eq 'HASH') {
12129: my $newitem = 'communities::0';
12130: if ($cathash->{$newitem} eq '') {
12131: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12132: $adds{$newitem} = 1;
12133: }
12134: } else {
12135: my $newitem = 'communities::0';
12136: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12137: $adds{$newitem} = 1;
12138: }
12139: }
1.272 raeburn 12140: if ($env{'form.placement'} eq '1') {
12141: if (ref($cathash) eq 'HASH') {
12142: my $newitem = 'placement::0';
12143: if ($cathash->{$newitem} eq '') {
12144: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12145: $adds{$newitem} = 1;
12146: }
12147: } else {
12148: my $newitem = 'placement::0';
12149: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12150: $adds{$newitem} = 1;
12151: }
12152: }
1.48 raeburn 12153: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 12154: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 12155: ($env{'form.addcategory_name'} ne 'communities') &&
12156: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 12157: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
12158: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
12159: $adds{$newitem} = 1;
12160: }
1.48 raeburn 12161: }
1.57 raeburn 12162: my $putresult;
1.48 raeburn 12163: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12164: if (keys(%deletions) > 0) {
12165: foreach my $key (keys(%deletions)) {
12166: if ($predelallitems{$key} ne '') {
12167: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
12168: }
12169: }
12170: }
12171: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 12172: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 12173: if (ref($chkcats[0]) eq 'ARRAY') {
12174: my $depth = 0;
12175: my $chg = 0;
12176: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
12177: my $name = $chkcats[0][$i];
12178: my $item;
12179: if ($name eq '') {
12180: $chg ++;
12181: } else {
12182: $item = &escape($name).'::0';
12183: if ($chg) {
1.57 raeburn 12184: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 12185: }
12186: $depth ++;
1.57 raeburn 12187: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 12188: $depth --;
12189: }
12190: }
12191: }
1.57 raeburn 12192: }
12193: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12194: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 12195: if ($putresult eq 'ok') {
1.57 raeburn 12196: my %title = (
1.120 raeburn 12197: togglecats => 'Show/Hide a course in catalog',
12198: categorize => 'Assign a category to a course',
12199: togglecatscomm => 'Show/Hide a community in catalog',
12200: categorizecomm => 'Assign a category to a community',
1.57 raeburn 12201: );
12202: my %level = (
1.120 raeburn 12203: dom => 'set in Domain ("Modify Course/Community")',
12204: crs => 'set in Course ("Course Configuration")',
12205: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 12206: none => 'No catalog',
12207: std => 'Standard catalog',
12208: domonly => 'Domain-only catalog',
12209: codesrch => 'Code search form',
1.57 raeburn 12210: );
1.48 raeburn 12211: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 12212: if ($changes{'togglecats'}) {
12213: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
12214: }
12215: if ($changes{'categorize'}) {
12216: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 12217: }
1.120 raeburn 12218: if ($changes{'togglecatscomm'}) {
12219: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
12220: }
12221: if ($changes{'categorizecomm'}) {
12222: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
12223: }
1.238 raeburn 12224: if ($changes{'unauth'}) {
12225: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
12226: }
12227: if ($changes{'auth'}) {
12228: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
12229: }
1.57 raeburn 12230: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12231: my $cathash;
12232: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
12233: $cathash = $domconfig{'coursecategories'}{'cats'};
12234: } else {
12235: $cathash = {};
12236: }
12237: my (@cats,@trails,%allitems);
12238: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
12239: if (keys(%deletions) > 0) {
12240: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
12241: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
12242: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
12243: }
12244: $resulttext .= '</ul></li>';
12245: }
12246: if (keys(%reorderings) > 0) {
12247: my %sort_by_trail;
12248: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
12249: foreach my $key (keys(%reorderings)) {
12250: if ($allitems{$key} ne '') {
12251: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12252: }
1.48 raeburn 12253: }
1.57 raeburn 12254: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12255: $resulttext .= '<li>'.$trails[$trail].'</li>';
12256: }
12257: $resulttext .= '</ul></li>';
1.48 raeburn 12258: }
1.57 raeburn 12259: if (keys(%adds) > 0) {
12260: my %sort_by_trail;
12261: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
12262: foreach my $key (keys(%adds)) {
12263: if ($allitems{$key} ne '') {
12264: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12265: }
12266: }
12267: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12268: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 12269: }
1.57 raeburn 12270: $resulttext .= '</ul></li>';
1.48 raeburn 12271: }
12272: }
12273: $resulttext .= '</ul>';
1.239 raeburn 12274: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 12275: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12276: if ($changes{'auth'}) {
12277: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
12278: }
12279: if ($changes{'unauth'}) {
12280: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
12281: }
12282: my $cachetime = 24*60*60;
12283: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 12284: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 12285: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 12286: }
12287: }
1.48 raeburn 12288: } else {
12289: $resulttext = '<span class="LC_error">'.
1.57 raeburn 12290: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 12291: }
12292: } else {
1.120 raeburn 12293: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 12294: }
12295: return $resulttext;
12296: }
12297:
1.69 raeburn 12298: sub modify_serverstatuses {
12299: my ($dom,%domconfig) = @_;
12300: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
12301: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
12302: %currserverstatus = %{$domconfig{'serverstatuses'}};
12303: }
12304: my @pages = &serverstatus_pages();
12305: foreach my $type (@pages) {
12306: $newserverstatus{$type}{'namedusers'} = '';
12307: $newserverstatus{$type}{'machines'} = '';
12308: if (defined($env{'form.'.$type.'_namedusers'})) {
12309: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
12310: my @okusers;
12311: foreach my $user (@users) {
12312: my ($uname,$udom) = split(/:/,$user);
12313: if (($udom =~ /^$match_domain$/) &&
12314: (&Apache::lonnet::domain($udom)) &&
12315: ($uname =~ /^$match_username$/)) {
12316: if (!grep(/^\Q$user\E/,@okusers)) {
12317: push(@okusers,$user);
12318: }
12319: }
12320: }
12321: if (@okusers > 0) {
12322: @okusers = sort(@okusers);
12323: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
12324: }
12325: }
12326: if (defined($env{'form.'.$type.'_machines'})) {
12327: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
12328: my @okmachines;
12329: foreach my $ip (@machines) {
12330: my @parts = split(/\./,$ip);
12331: next if (@parts < 4);
12332: my $badip = 0;
12333: for (my $i=0; $i<4; $i++) {
12334: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
12335: $badip = 1;
12336: last;
12337: }
12338: }
12339: if (!$badip) {
12340: push(@okmachines,$ip);
12341: }
12342: }
12343: @okmachines = sort(@okmachines);
12344: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
12345: }
12346: }
12347: my %serverstatushash = (
12348: serverstatuses => \%newserverstatus,
12349: );
12350: foreach my $type (@pages) {
1.83 raeburn 12351: foreach my $setting ('namedusers','machines') {
1.84 raeburn 12352: my (@current,@new);
1.83 raeburn 12353: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 12354: if ($currserverstatus{$type}{$setting} ne '') {
12355: @current = split(/,/,$currserverstatus{$type}{$setting});
12356: }
12357: }
12358: if ($newserverstatus{$type}{$setting} ne '') {
12359: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 12360: }
12361: if (@current > 0) {
12362: if (@new > 0) {
12363: foreach my $item (@current) {
12364: if (!grep(/^\Q$item\E$/,@new)) {
12365: $changes{$type}{$setting} = 1;
1.82 raeburn 12366: last;
12367: }
12368: }
1.84 raeburn 12369: foreach my $item (@new) {
12370: if (!grep(/^\Q$item\E$/,@current)) {
12371: $changes{$type}{$setting} = 1;
12372: last;
1.82 raeburn 12373: }
12374: }
12375: } else {
1.83 raeburn 12376: $changes{$type}{$setting} = 1;
1.69 raeburn 12377: }
1.83 raeburn 12378: } elsif (@new > 0) {
12379: $changes{$type}{$setting} = 1;
1.69 raeburn 12380: }
12381: }
12382: }
12383: if (keys(%changes) > 0) {
1.81 raeburn 12384: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 12385: my $putresult = &Apache::lonnet::put_dom('configuration',
12386: \%serverstatushash,$dom);
12387: if ($putresult eq 'ok') {
12388: $resulttext .= &mt('Changes made:').'<ul>';
12389: foreach my $type (@pages) {
1.84 raeburn 12390: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 12391: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 12392: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 12393: if ($newserverstatus{$type}{'namedusers'} eq '') {
12394: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
12395: } else {
12396: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
12397: }
1.84 raeburn 12398: }
12399: if ($changes{$type}{'machines'}) {
1.69 raeburn 12400: if ($newserverstatus{$type}{'machines'} eq '') {
12401: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
12402: } else {
12403: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
12404: }
12405:
12406: }
12407: $resulttext .= '</ul></li>';
12408: }
12409: }
12410: $resulttext .= '</ul>';
12411: } else {
12412: $resulttext = '<span class="LC_error">'.
12413: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
12414:
12415: }
12416: } else {
12417: $resulttext = &mt('No changes made to access to server status pages');
12418: }
12419: return $resulttext;
12420: }
12421:
1.118 jms 12422: sub modify_helpsettings {
1.285 raeburn 12423: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 12424: my ($resulttext,$errors,%changes,%helphash);
12425: my %defaultchecked = ('submitbugs' => 'on');
12426: my @offon = ('off','on');
1.118 jms 12427: my @toggles = ('submitbugs');
1.285 raeburn 12428: my %current = ('submitbugs' => '',
12429: 'adhoc' => {},
12430: );
1.118 jms 12431: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 12432: %current = %{$domconfig{'helpsettings'}};
12433: }
1.285 raeburn 12434: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 12435: foreach my $item (@toggles) {
12436: if ($defaultchecked{$item} eq 'on') {
12437: if ($current{$item} eq '') {
12438: if ($env{'form.'.$item} eq '0') {
12439: $changes{$item} = 1;
12440: }
12441: } elsif ($current{$item} ne $env{'form.'.$item}) {
12442: $changes{$item} = 1;
12443: }
12444: } elsif ($defaultchecked{$item} eq 'off') {
12445: if ($current{$item} eq '') {
12446: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 12447: $changes{$item} = 1;
12448: }
1.282 raeburn 12449: } elsif ($current{$item} ne $env{'form.'.$item}) {
12450: $changes{$item} = 1;
12451: }
12452: }
12453: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
12454: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
12455: }
12456: }
1.285 raeburn 12457: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 12458: my $confname = $dom.'-domainconfig';
12459: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 12460: my (@allpos,%newsettings,%changedprivs,$newrole);
12461: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.291 ! raeburn 12462: my @accesstypes = ('all','anydh','anyda','none','status','inc','exc');
1.290 raeburn 12463: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 12464: my %lt = &Apache::lonlocal::texthash(
12465: s => 'system',
12466: d => 'domain',
12467: order => 'Display order',
12468: access => 'Role usage',
1.291 ! raeburn 12469: all => 'All with domain helpdesk or helpdesk assistant role',
! 12470: anydh => 'All with domain helpdesk role',
! 12471: anyda => 'All with domain helpdesk assistant role',
1.285 raeburn 12472: none => 'None',
12473: status => 'Determined based on institutional status',
12474: inc => 'Include all, but exclude specific personnel',
12475: exc => 'Exclude all, but include specific personnel',
12476: );
12477: for (my $num=0; $num<=$maxnum; $num++) {
12478: my ($prefix,$identifier,$rolename,%curr);
12479: if ($num == $maxnum) {
12480: next unless ($env{'form.newcusthelp'} == $maxnum);
12481: $identifier = 'custhelp'.$num;
12482: $prefix = 'helproles_'.$num;
12483: $rolename = $env{'form.custhelpname'.$num};
12484: $rolename=~s/[^A-Za-z0-9]//gs;
12485: next if ($rolename eq '');
12486: next if (exists($existing{'rolesdef_'.$rolename}));
12487: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12488: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12489: $newprivs{'c'},$confname,$dom);
12490: if ($result ne 'ok') {
12491: $errors .= '<li><span class="LC_error">'.
12492: &mt('An error occurred storing the new custom role: [_1]',
12493: $result).'</span></li>';
12494: next;
12495: } else {
12496: $changedprivs{$rolename} = \%newprivs;
12497: $newrole = $rolename;
12498: }
12499: } else {
12500: $prefix = 'helproles_'.$num;
12501: $rolename = $env{'form.'.$prefix};
12502: next if ($rolename eq '');
12503: next unless (exists($existing{'rolesdef_'.$rolename}));
12504: $identifier = 'custhelp'.$num;
12505: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12506: my %currprivs;
1.289 raeburn 12507: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 12508: split(/\_/,$existing{'rolesdef_'.$rolename});
12509: foreach my $level ('c','d','s') {
12510: if ($newprivs{$level} ne $currprivs{$level}) {
12511: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12512: $newprivs{'c'},$confname,$dom);
12513: if ($result ne 'ok') {
12514: $errors .= '<li><span class="LC_error">'.
12515: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
12516: $rolename,$result).'</span></li>';
12517: } else {
12518: $changedprivs{$rolename} = \%newprivs;
12519: }
12520: last;
12521: }
12522: }
12523: if (ref($current{'adhoc'}) eq 'HASH') {
12524: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12525: %curr = %{$current{'adhoc'}{$rolename}};
12526: }
12527: }
12528: }
12529: my $newpos = $env{'form.'.$prefix.'_pos'};
12530: $newpos =~ s/\D+//g;
12531: $allpos[$newpos] = $rolename;
12532: my $newdesc = $env{'form.'.$prefix.'_desc'};
12533: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
12534: if ($curr{'desc'}) {
12535: if ($curr{'desc'} ne $newdesc) {
12536: $changes{'customrole'}{$rolename}{'desc'} = 1;
12537: $newsettings{$rolename}{'desc'} = $newdesc;
12538: }
12539: } elsif ($newdesc ne '') {
12540: $changes{'customrole'}{$rolename}{'desc'} = 1;
12541: $newsettings{$rolename}{'desc'} = $newdesc;
12542: }
12543: my $access = $env{'form.'.$prefix.'_access'};
12544: if (grep(/^\Q$access\E$/,@accesstypes)) {
12545: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
12546: if ($access eq 'status') {
12547: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
12548: if (scalar(@statuses) == 0) {
1.289 raeburn 12549: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 12550: } else {
12551: my (@shownstatus,$numtypes);
12552: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12553: if (ref($types) eq 'ARRAY') {
12554: $numtypes = scalar(@{$types});
12555: foreach my $type (sort(@statuses)) {
12556: if ($type eq 'default') {
12557: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12558: } elsif (grep(/^\Q$type\E$/,@{$types})) {
12559: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12560: push(@shownstatus,$usertypes->{$type});
12561: }
12562: }
12563: }
12564: if (grep(/^default$/,@statuses)) {
12565: push(@shownstatus,$othertitle);
12566: }
12567: if (scalar(@shownstatus) == 1+$numtypes) {
12568: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
12569: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
12570: } else {
12571: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
12572: if (ref($curr{'status'}) eq 'ARRAY') {
12573: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12574: if (@diffs) {
12575: $changes{'customrole'}{$rolename}{$access} = 1;
12576: }
12577: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12578: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 12579: }
1.166 raeburn 12580: }
12581: }
1.285 raeburn 12582: } elsif (($access eq 'inc') || ($access eq 'exc')) {
12583: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
12584: my @newspecstaff;
12585: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12586: foreach my $person (sort(@personnel)) {
12587: if ($domhelpdesk{$person}) {
12588: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
12589: }
12590: }
12591: if (ref($curr{$access}) eq 'ARRAY') {
12592: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12593: if (@diffs) {
12594: $changes{'customrole'}{$rolename}{$access} = 1;
12595: }
12596: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12597: $changes{'customrole'}{$rolename}{$access} = 1;
12598: }
12599: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12600: my ($uname,$udom) = split(/:/,$person);
12601: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
12602: }
12603: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 12604: }
1.285 raeburn 12605: } else {
12606: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
12607: }
12608: unless ($curr{'access'} eq $access) {
12609: $changes{'customrole'}{$rolename}{'access'} = 1;
12610: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 12611: }
12612: }
1.285 raeburn 12613: if (@allpos > 0) {
12614: my $idx = 0;
12615: foreach my $rolename (@allpos) {
12616: if ($rolename ne '') {
12617: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
12618: if (ref($current{'adhoc'}) eq 'HASH') {
12619: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12620: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
12621: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 12622: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 12623: }
12624: }
1.282 raeburn 12625: }
1.285 raeburn 12626: $idx ++;
1.166 raeburn 12627: }
12628: }
1.118 jms 12629: }
1.123 jms 12630: my $putresult;
12631: if (keys(%changes) > 0) {
1.166 raeburn 12632: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 12633: if ($putresult eq 'ok') {
1.285 raeburn 12634: if (ref($helphash{'helpsettings'}) eq 'HASH') {
12635: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
12636: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
12637: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
12638: }
12639: }
12640: my $cachetime = 24*60*60;
12641: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12642: if (ref($lastactref) eq 'HASH') {
12643: $lastactref->{'domdefaults'} = 1;
12644: }
12645: } else {
12646: $errors .= '<li><span class="LC_error">'.
12647: &mt('An error occurred storing the settings: [_1]',
12648: $putresult).'</span></li>';
12649: }
12650: }
12651: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
12652: $resulttext = &mt('Changes made:').'<ul>';
12653: my (%shownprivs,@levelorder);
12654: @levelorder = ('c','d','s');
12655: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 12656: foreach my $item (sort(keys(%changes))) {
12657: if ($item eq 'submitbugs') {
12658: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
12659: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
12660: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 12661: } elsif ($item eq 'customrole') {
12662: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 12663: my @keyorder = ('order','desc','access','status','exc','inc');
12664: my %keytext = &Apache::lonlocal::texthash(
12665: order => 'Order',
12666: desc => 'Role description',
12667: access => 'Role usage',
12668: status => 'Allowed instituional types',
12669: exc => 'Allowed personnel',
12670: inc => 'Disallowed personnel',
12671: );
1.282 raeburn 12672: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 12673: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
12674: if ($role eq $newrole) {
12675: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
12676: $role).'<ul>';
12677: } else {
12678: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12679: $role).'<ul>';
12680: }
12681: foreach my $key (@keyorder) {
12682: if ($changes{'customrole'}{$role}{$key}) {
12683: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
12684: $keytext{$key},$newsettings{$role}{$key}).
12685: '</li>';
12686: }
12687: }
12688: if (ref($changedprivs{$role}) eq 'HASH') {
12689: $shownprivs{$role} = 1;
12690: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
12691: foreach my $level (@levelorder) {
12692: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12693: next if ($item eq '');
12694: my ($priv) = split(/\&/,$item,2);
12695: if (&Apache::lonnet::plaintext($priv)) {
12696: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12697: unless ($level eq 'c') {
12698: $resulttext .= ' ('.$lt{$level}.')';
12699: }
12700: $resulttext .= '</li>';
12701: }
12702: }
12703: }
12704: $resulttext .= '</ul>';
12705: }
12706: $resulttext .= '</ul></li>';
12707: }
12708: }
12709: }
12710: }
12711: }
12712: }
12713: if (keys(%changedprivs)) {
12714: foreach my $role (sort(keys(%changedprivs))) {
12715: unless ($shownprivs{$role}) {
12716: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12717: $role).'<ul>'.
12718: '<li>'.&mt('Privileges set to :').'<ul>';
12719: foreach my $level (@levelorder) {
12720: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12721: next if ($item eq '');
12722: my ($priv) = split(/\&/,$item,2);
12723: if (&Apache::lonnet::plaintext($priv)) {
12724: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12725: unless ($level eq 'c') {
12726: $resulttext .= ' ('.$lt{$level}.')';
12727: }
12728: $resulttext .= '</li>';
12729: }
1.282 raeburn 12730: }
12731: }
1.285 raeburn 12732: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 12733: }
12734: }
12735: }
1.285 raeburn 12736: $resulttext .= '</ul>';
12737: } else {
12738: $resulttext = &mt('No changes made to help settings');
1.118 jms 12739: }
12740: if ($errors) {
1.168 raeburn 12741: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 12742: $errors.'</ul>';
1.118 jms 12743: }
12744: return $resulttext;
12745: }
12746:
1.121 raeburn 12747: sub modify_coursedefaults {
1.212 raeburn 12748: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 12749: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 12750: my %defaultchecked = (
12751: 'canuse_pdfforms' => 'off',
12752: 'uselcmath' => 'on',
12753: 'usejsme' => 'on'
12754: );
12755: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 12756: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 12757: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
12758: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
12759: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 12760: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 12761: my %staticdefaults = (
12762: anonsurvey_threshold => 10,
12763: uploadquota => 500,
1.257 raeburn 12764: postsubmit => 60,
1.276 raeburn 12765: mysqltables => 172800,
1.198 raeburn 12766: );
1.121 raeburn 12767:
12768: $defaultshash{'coursedefaults'} = {};
12769:
12770: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
12771: if ($domconfig{'coursedefaults'} eq '') {
12772: $domconfig{'coursedefaults'} = {};
12773: }
12774: }
12775:
12776: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
12777: foreach my $item (@toggles) {
12778: if ($defaultchecked{$item} eq 'on') {
12779: if (($domconfig{'coursedefaults'}{$item} eq '') &&
12780: ($env{'form.'.$item} eq '0')) {
12781: $changes{$item} = 1;
1.192 raeburn 12782: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 12783: $changes{$item} = 1;
12784: }
12785: } elsif ($defaultchecked{$item} eq 'off') {
12786: if (($domconfig{'coursedefaults'}{$item} eq '') &&
12787: ($env{'form.'.$item} eq '1')) {
12788: $changes{$item} = 1;
12789: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
12790: $changes{$item} = 1;
12791: }
12792: }
12793: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
12794: }
1.198 raeburn 12795: foreach my $item (@numbers) {
12796: my ($currdef,$newdef);
1.208 raeburn 12797: $newdef = $env{'form.'.$item};
1.198 raeburn 12798: if ($item eq 'anonsurvey_threshold') {
12799: $currdef = $domconfig{'coursedefaults'}{$item};
12800: $newdef =~ s/\D//g;
12801: if ($newdef eq '' || $newdef < 1) {
12802: $newdef = 1;
12803: }
12804: $defaultshash{'coursedefaults'}{$item} = $newdef;
12805: } else {
1.276 raeburn 12806: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
12807: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
12808: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 12809: }
12810: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 12811: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 12812: }
12813: if ($currdef ne $newdef) {
12814: my $staticdef;
12815: if ($item eq 'anonsurvey_threshold') {
12816: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
12817: $changes{$item} = 1;
12818: }
1.276 raeburn 12819: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 12820: my $setting = $1;
1.276 raeburn 12821: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
12822: $changes{$setting} = 1;
1.198 raeburn 12823: }
12824: }
1.139 raeburn 12825: }
12826: }
1.264 raeburn 12827: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
12828: my @currclonecode;
12829: if (ref($currclone) eq 'HASH') {
12830: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
12831: @currclonecode = @{$currclone->{'instcode'}};
12832: }
12833: }
12834: my $newclone;
1.289 raeburn 12835: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 12836: $newclone = $env{'form.canclone'};
12837: }
12838: if ($newclone eq 'instcode') {
12839: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
12840: my (%codedefaults,@code_order,@clonecode);
12841: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
12842: \@code_order);
12843: foreach my $item (@code_order) {
12844: if (grep(/^\Q$item\E$/,@newcodes)) {
12845: push(@clonecode,$item);
12846: }
12847: }
12848: if (@clonecode) {
12849: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
12850: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
12851: if (@diffs) {
12852: $changes{'canclone'} = 1;
12853: }
12854: } else {
12855: $newclone eq '';
12856: }
12857: } elsif ($newclone ne '') {
1.289 raeburn 12858: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
12859: }
1.264 raeburn 12860: if ($newclone ne $currclone) {
12861: $changes{'canclone'} = 1;
12862: }
1.257 raeburn 12863: my %credits;
12864: foreach my $type (@types) {
12865: unless ($type eq 'community') {
12866: $credits{$type} = $env{'form.'.$type.'_credits'};
12867: $credits{$type} =~ s/[^\d.]+//g;
12868: }
12869: }
12870: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
12871: ($env{'form.coursecredits'} eq '1')) {
12872: $changes{'coursecredits'} = 1;
12873: foreach my $type (keys(%credits)) {
12874: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
12875: }
12876: } else {
1.289 raeburn 12877: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 12878: foreach my $type (@types) {
12879: unless ($type eq 'community') {
1.289 raeburn 12880: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 12881: $changes{'coursecredits'} = 1;
12882: }
12883: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
12884: }
12885: }
12886: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
12887: foreach my $type (@types) {
12888: unless ($type eq 'community') {
12889: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
12890: $changes{'coursecredits'} = 1;
12891: last;
12892: }
12893: }
12894: }
12895: }
12896: }
12897: if ($env{'form.postsubmit'} eq '1') {
12898: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
12899: my %currtimeout;
12900: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12901: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
12902: $changes{'postsubmit'} = 1;
12903: }
12904: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12905: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
12906: }
12907: } else {
12908: $changes{'postsubmit'} = 1;
12909: }
12910: foreach my $type (@types) {
12911: my $timeout = $env{'form.'.$type.'_timeout'};
12912: $timeout =~ s/\D//g;
12913: if ($timeout == $staticdefaults{'postsubmit'}) {
12914: $timeout = '';
12915: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
12916: $timeout = '0';
12917: }
12918: unless ($timeout eq '') {
12919: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
12920: }
12921: if (exists($currtimeout{$type})) {
12922: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 12923: $changes{'postsubmit'} = 1;
1.257 raeburn 12924: }
12925: } elsif ($timeout ne '') {
12926: $changes{'postsubmit'} = 1;
12927: }
12928: }
12929: } else {
12930: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
12931: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12932: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
12933: $changes{'postsubmit'} = 1;
12934: }
12935: } else {
12936: $changes{'postsubmit'} = 1;
12937: }
1.192 raeburn 12938: }
1.121 raeburn 12939: }
12940: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12941: $dom);
12942: if ($putresult eq 'ok') {
12943: if (keys(%changes) > 0) {
1.213 raeburn 12944: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 12945: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 12946: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.276 raeburn 12947: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.257 raeburn 12948: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
12949: if ($changes{$item}) {
12950: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
12951: }
1.289 raeburn 12952: }
1.192 raeburn 12953: if ($changes{'coursecredits'}) {
12954: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 12955: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
12956: $domdefaults{$type.'credits'} =
12957: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
12958: }
12959: }
12960: }
12961: if ($changes{'postsubmit'}) {
12962: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12963: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
12964: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12965: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
12966: $domdefaults{$type.'postsubtimeout'} =
12967: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
12968: }
12969: }
1.192 raeburn 12970: }
12971: }
1.198 raeburn 12972: if ($changes{'uploadquota'}) {
12973: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
12974: foreach my $type (@types) {
12975: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
12976: }
12977: }
12978: }
1.264 raeburn 12979: if ($changes{'canclone'}) {
12980: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
12981: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
12982: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
12983: if (@clonecodes) {
12984: $domdefaults{'canclone'} = join('+',@clonecodes);
12985: }
12986: }
12987: } else {
12988: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
12989: }
12990: }
1.121 raeburn 12991: my $cachetime = 24*60*60;
12992: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12993: if (ref($lastactref) eq 'HASH') {
12994: $lastactref->{'domdefaults'} = 1;
12995: }
1.121 raeburn 12996: }
12997: $resulttext = &mt('Changes made:').'<ul>';
12998: foreach my $item (sort(keys(%changes))) {
12999: if ($item eq 'canuse_pdfforms') {
13000: if ($env{'form.'.$item} eq '1') {
13001: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
13002: } else {
13003: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
13004: }
1.257 raeburn 13005: } elsif ($item eq 'uselcmath') {
13006: if ($env{'form.'.$item} eq '1') {
13007: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
13008: } else {
13009: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
13010: }
13011: } elsif ($item eq 'usejsme') {
13012: if ($env{'form.'.$item} eq '1') {
13013: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
13014: } else {
1.289 raeburn 13015: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 13016: }
1.139 raeburn 13017: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 13018: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 13019: } elsif ($item eq 'uploadquota') {
13020: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13021: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
13022: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
13023: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 13024: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 13025: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 13026: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
13027: '</ul>'.
13028: '</li>';
13029: } else {
13030: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
13031: }
1.276 raeburn 13032: } elsif ($item eq 'mysqltables') {
13033: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
13034: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
13035: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
13036: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
13037: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
13038: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
13039: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
13040: '</ul>'.
13041: '</li>';
13042: } else {
13043: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
13044: }
1.257 raeburn 13045: } elsif ($item eq 'postsubmit') {
13046: if ($domdefaults{'postsubmit'} eq 'off') {
13047: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
13048: } else {
13049: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 13050: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 13051: $resulttext .= &mt('durations:').'<ul>';
13052: foreach my $type (@types) {
13053: $resulttext .= '<li>';
13054: my $timeout;
13055: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13056: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13057: }
13058: my $display;
13059: if ($timeout eq '0') {
13060: $display = &mt('unlimited');
13061: } elsif ($timeout eq '') {
13062: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
13063: } else {
13064: $display = &mt('[quant,_1,second]',$timeout);
13065: }
13066: if ($type eq 'community') {
13067: $resulttext .= &mt('Communities');
13068: } elsif ($type eq 'official') {
13069: $resulttext .= &mt('Official courses');
13070: } elsif ($type eq 'unofficial') {
13071: $resulttext .= &mt('Unofficial courses');
13072: } elsif ($type eq 'textbook') {
13073: $resulttext .= &mt('Textbook courses');
1.271 raeburn 13074: } elsif ($type eq 'placement') {
13075: $resulttext .= &mt('Placement tests');
1.257 raeburn 13076: }
13077: $resulttext .= ' -- '.$display.'</li>';
13078: }
13079: $resulttext .= '</ul>';
13080: }
1.289 raeburn 13081: $resulttext .= '</li>';
1.257 raeburn 13082: }
1.192 raeburn 13083: } elsif ($item eq 'coursecredits') {
13084: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13085: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 13086: ($domdefaults{'unofficialcredits'} eq '') &&
13087: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 13088: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13089: } else {
13090: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
13091: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
13092: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 13093: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 13094: '</ul>'.
13095: '</li>';
13096: }
13097: } else {
13098: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13099: }
1.264 raeburn 13100: } elsif ($item eq 'canclone') {
13101: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13102: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13103: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
13104: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
13105: }
13106: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
13107: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
13108: } else {
1.289 raeburn 13109: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 13110: }
1.140 raeburn 13111: }
1.121 raeburn 13112: }
13113: $resulttext .= '</ul>';
13114: } else {
13115: $resulttext = &mt('No changes made to course defaults');
13116: }
13117: } else {
13118: $resulttext = '<span class="LC_error">'.
13119: &mt('An error occurred: [_1]',$putresult).'</span>';
13120: }
13121: return $resulttext;
13122: }
13123:
1.231 raeburn 13124: sub modify_selfenrollment {
13125: my ($dom,$lastactref,%domconfig) = @_;
13126: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 13127: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 13128: my %titles = &tool_titles();
1.232 raeburn 13129: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
13130: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 13131: $ordered{'default'} = ['types','registered','approval','limit'];
13132:
13133: my (%roles,%shown,%toplevel);
13134: $roles{'0'} = &Apache::lonnet::plaintext('dc');
13135:
13136: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
13137: if ($domconfig{'selfenrollment'} eq '') {
13138: $domconfig{'selfenrollment'} = {};
13139: }
13140: }
13141: %toplevel = (
13142: admin => 'Configuration Rights',
13143: default => 'Default settings',
13144: validation => 'Validation of self-enrollment requests',
13145: );
1.233 raeburn 13146: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 13147:
13148: if (ref($ordered{'admin'}) eq 'ARRAY') {
13149: foreach my $item (@{$ordered{'admin'}}) {
13150: foreach my $type (@types) {
13151: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
13152: $selfenrollhash{'admin'}{$type}{$item} = 1;
13153: } else {
13154: $selfenrollhash{'admin'}{$type}{$item} = 0;
13155: }
13156: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
13157: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
13158: if ($selfenrollhash{'admin'}{$type}{$item} ne
13159: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
13160: push(@{$changes{'admin'}{$type}},$item);
13161: }
13162: } else {
13163: if (!$selfenrollhash{'admin'}{$type}{$item}) {
13164: push(@{$changes{'admin'}{$type}},$item);
13165: }
13166: }
13167: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
13168: push(@{$changes{'admin'}{$type}},$item);
13169: }
13170: }
13171: }
13172: }
13173:
13174: foreach my $item (@{$ordered{'default'}}) {
13175: foreach my $type (@types) {
13176: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
13177: if ($item eq 'types') {
13178: unless (($value eq 'all') || ($value eq 'dom')) {
13179: $value = '';
13180: }
13181: } elsif ($item eq 'registered') {
13182: unless ($value eq '1') {
13183: $value = 0;
13184: }
13185: } elsif ($item eq 'approval') {
13186: unless ($value =~ /^[012]$/) {
13187: $value = 0;
13188: }
13189: } else {
13190: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13191: $value = 'none';
13192: }
13193: }
13194: $selfenrollhash{'default'}{$type}{$item} = $value;
13195: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
13196: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13197: if ($selfenrollhash{'default'}{$type}{$item} ne
13198: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
13199: push(@{$changes{'default'}{$type}},$item);
13200: }
13201: } else {
13202: push(@{$changes{'default'}{$type}},$item);
13203: }
13204: } else {
13205: push(@{$changes{'default'}{$type}},$item);
13206: }
13207: if ($item eq 'limit') {
13208: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13209: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
13210: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
13211: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
13212: }
13213: } else {
13214: $selfenrollhash{'default'}{$type}{'cap'} = '';
13215: }
13216: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13217: if ($selfenrollhash{'default'}{$type}{'cap'} ne
13218: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
13219: push(@{$changes{'default'}{$type}},'cap');
13220: }
13221: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
13222: push(@{$changes{'default'}{$type}},'cap');
13223: }
13224: }
13225: }
13226: }
13227:
13228: foreach my $item (@{$itemsref}) {
13229: if ($item eq 'fields') {
13230: my @changed;
13231: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
13232: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
13233: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
13234: }
13235: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13236: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
13237: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
13238: $domconfig{'selfenrollment'}{'validation'}{$item});
13239: } else {
13240: @changed = @{$selfenrollhash{'validation'}{$item}};
13241: }
13242: } else {
13243: @changed = @{$selfenrollhash{'validation'}{$item}};
13244: }
13245: if (@changed) {
13246: if ($selfenrollhash{'validation'}{$item}) {
13247: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
13248: } else {
13249: $changes{'validation'}{$item} = &mt('None');
13250: }
13251: }
13252: } else {
13253: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
13254: if ($item eq 'markup') {
13255: if ($env{'form.selfenroll_validation_'.$item}) {
13256: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13257: }
13258: }
13259: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13260: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
13261: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
13262: }
13263: }
13264: }
13265: }
13266:
13267: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
13268: $dom);
13269: if ($putresult eq 'ok') {
13270: if (keys(%changes) > 0) {
13271: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13272: $resulttext = &mt('Changes made:').'<ul>';
13273: foreach my $key ('admin','default','validation') {
13274: if (ref($changes{$key}) eq 'HASH') {
13275: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
13276: if ($key eq 'validation') {
13277: foreach my $item (@{$itemsref}) {
13278: if (exists($changes{$key}{$item})) {
13279: if ($item eq 'markup') {
13280: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13281: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
13282: } else {
13283: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13284: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
13285: }
13286: }
13287: }
13288: } else {
13289: foreach my $type (@types) {
13290: if ($type eq 'community') {
13291: $roles{'1'} = &mt('Community personnel');
13292: } else {
13293: $roles{'1'} = &mt('Course personnel');
13294: }
13295: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 13296: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13297: if ($key eq 'admin') {
13298: my @mgrdc = ();
13299: if (ref($ordered{$key}) eq 'ARRAY') {
13300: foreach my $item (@{$ordered{'admin'}}) {
13301: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13302: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
13303: push(@mgrdc,$item);
13304: }
13305: }
13306: }
13307: if (@mgrdc) {
13308: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
13309: } else {
13310: delete($domdefaults{$type.'selfenrolladmdc'});
13311: }
13312: }
13313: } else {
13314: if (ref($ordered{$key}) eq 'ARRAY') {
13315: foreach my $item (@{$ordered{$key}}) {
13316: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13317: $domdefaults{$type.'selfenroll'.$item} =
13318: $selfenrollhash{$key}{$type}{$item};
13319: }
13320: }
13321: }
13322: }
13323: }
1.231 raeburn 13324: $resulttext .= '<li>'.$titles{$type}.'<ul>';
13325: foreach my $item (@{$ordered{$key}}) {
13326: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13327: $resulttext .= '<li>';
13328: if ($key eq 'admin') {
13329: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
13330: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
13331: } else {
13332: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
13333: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
13334: }
13335: $resulttext .= '</li>';
13336: }
13337: }
13338: $resulttext .= '</ul></li>';
13339: }
13340: }
13341: $resulttext .= '</ul></li>';
13342: }
13343: }
1.232 raeburn 13344: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
13345: my $cachetime = 24*60*60;
13346: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13347: if (ref($lastactref) eq 'HASH') {
13348: $lastactref->{'domdefaults'} = 1;
13349: }
13350: }
1.231 raeburn 13351: }
13352: $resulttext .= '</ul>';
13353: } else {
13354: $resulttext = &mt('No changes made to self-enrollment settings');
13355: }
13356: } else {
13357: $resulttext = '<span class="LC_error">'.
13358: &mt('An error occurred: [_1]',$putresult).'</span>';
13359: }
13360: return $resulttext;
13361: }
13362:
1.137 raeburn 13363: sub modify_usersessions {
1.212 raeburn 13364: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 13365: my @hostingtypes = ('version','excludedomain','includedomain');
13366: my @offloadtypes = ('primary','default');
13367: my %types = (
13368: remote => \@hostingtypes,
13369: hosted => \@hostingtypes,
13370: spares => \@offloadtypes,
13371: );
13372: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 13373: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 13374: my (%by_ip,%by_location,@intdoms,@instdoms);
13375: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 13376: my @locations = sort(keys(%by_location));
1.137 raeburn 13377: my (%defaultshash,%changes);
13378: foreach my $prefix (@prefixes) {
13379: $defaultshash{'usersessions'}{$prefix} = {};
13380: }
1.212 raeburn 13381: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 13382: my $resulttext;
1.138 raeburn 13383: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 13384: foreach my $prefix (@prefixes) {
1.145 raeburn 13385: next if ($prefix eq 'spares');
13386: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 13387: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13388: if ($type eq 'version') {
13389: my $value = $env{'form.'.$prefix.'_'.$type};
13390: my $okvalue;
13391: if ($value ne '') {
13392: if (grep(/^\Q$value\E$/,@lcversions)) {
13393: $okvalue = $value;
13394: }
13395: }
13396: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13397: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13398: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
13399: if ($inuse == 0) {
13400: $changes{$prefix}{$type} = 1;
13401: } else {
13402: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
13403: $changes{$prefix}{$type} = 1;
13404: }
13405: if ($okvalue ne '') {
13406: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13407: }
13408: }
13409: } else {
13410: if (($inuse == 1) && ($okvalue ne '')) {
13411: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13412: $changes{$prefix}{$type} = 1;
13413: }
13414: }
13415: } else {
13416: if (($inuse == 1) && ($okvalue ne '')) {
13417: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13418: $changes{$prefix}{$type} = 1;
13419: }
13420: }
13421: } else {
13422: if (($inuse == 1) && ($okvalue ne '')) {
13423: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13424: $changes{$prefix}{$type} = 1;
13425: }
13426: }
13427: } else {
13428: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13429: my @okvals;
13430: foreach my $val (@vals) {
1.138 raeburn 13431: if ($val =~ /:/) {
13432: my @items = split(/:/,$val);
13433: foreach my $item (@items) {
13434: if (ref($by_location{$item}) eq 'ARRAY') {
13435: push(@okvals,$item);
13436: }
13437: }
13438: } else {
13439: if (ref($by_location{$val}) eq 'ARRAY') {
13440: push(@okvals,$val);
13441: }
1.137 raeburn 13442: }
13443: }
13444: @okvals = sort(@okvals);
13445: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13446: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13447: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13448: if ($inuse == 0) {
13449: $changes{$prefix}{$type} = 1;
13450: } else {
13451: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13452: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
13453: if (@changed > 0) {
13454: $changes{$prefix}{$type} = 1;
13455: }
13456: }
13457: } else {
13458: if ($inuse == 1) {
13459: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13460: $changes{$prefix}{$type} = 1;
13461: }
13462: }
13463: } else {
13464: if ($inuse == 1) {
13465: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13466: $changes{$prefix}{$type} = 1;
13467: }
13468: }
13469: } else {
13470: if ($inuse == 1) {
13471: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13472: $changes{$prefix}{$type} = 1;
13473: }
13474: }
13475: }
13476: }
13477: }
1.145 raeburn 13478:
13479: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 13480: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 13481: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
13482: my $savespares;
13483:
13484: foreach my $lonhost (sort(keys(%servers))) {
13485: my $serverhomeID =
13486: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 13487: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 13488: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
13489: my %spareschg;
13490: foreach my $type (@{$types{'spares'}}) {
13491: my @okspares;
13492: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
13493: foreach my $server (@checked) {
1.152 raeburn 13494: if (&Apache::lonnet::hostname($server) ne '') {
13495: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
13496: unless (grep(/^\Q$server\E$/,@okspares)) {
13497: push(@okspares,$server);
13498: }
1.145 raeburn 13499: }
13500: }
13501: }
13502: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
13503: my $newspare;
1.152 raeburn 13504: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
13505: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 13506: $newspare = $new;
13507: }
13508: }
1.152 raeburn 13509: my @spares;
13510: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
13511: @spares = sort(@okspares,$newspare);
13512: } else {
13513: @spares = sort(@okspares);
13514: }
13515: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 13516: if (ref($spareid{$lonhost}) eq 'HASH') {
13517: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 13518: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 13519: if (@diffs > 0) {
13520: $spareschg{$type} = 1;
13521: }
13522: }
13523: }
13524: }
13525: if (keys(%spareschg) > 0) {
13526: $changes{'spares'}{$lonhost} = \%spareschg;
13527: }
13528: }
1.261 raeburn 13529: $defaultshash{'usersessions'}{'offloadnow'} = {};
13530: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
13531: my @okoffload;
13532: if (@offloadnow) {
13533: foreach my $server (@offloadnow) {
13534: if (&Apache::lonnet::hostname($server) ne '') {
13535: unless (grep(/^\Q$server\E$/,@okoffload)) {
13536: push(@okoffload,$server);
13537: }
13538: }
13539: }
13540: if (@okoffload) {
13541: foreach my $lonhost (@okoffload) {
13542: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
13543: }
13544: }
13545: }
1.145 raeburn 13546: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13547: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
13548: if (ref($changes{'spares'}) eq 'HASH') {
13549: if (keys(%{$changes{'spares'}}) > 0) {
13550: $savespares = 1;
13551: }
13552: }
13553: } else {
13554: $savespares = 1;
13555: }
1.261 raeburn 13556: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
13557: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
13558: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
13559: $changes{'offloadnow'} = 1;
13560: last;
13561: }
13562: }
13563: unless ($changes{'offloadnow'}) {
1.289 raeburn 13564: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 13565: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
13566: $changes{'offloadnow'} = 1;
13567: last;
13568: }
13569: }
13570: }
13571: } elsif (@okoffload) {
13572: $changes{'offloadnow'} = 1;
13573: }
13574: } elsif (@okoffload) {
13575: $changes{'offloadnow'} = 1;
1.145 raeburn 13576: }
1.147 raeburn 13577: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
13578: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 13579: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13580: $dom);
13581: if ($putresult eq 'ok') {
13582: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13583: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
13584: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
13585: }
13586: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
13587: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
13588: }
1.261 raeburn 13589: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13590: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
13591: }
1.137 raeburn 13592: }
13593: my $cachetime = 24*60*60;
13594: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13595: if (ref($lastactref) eq 'HASH') {
13596: $lastactref->{'domdefaults'} = 1;
13597: }
1.147 raeburn 13598: if (keys(%changes) > 0) {
13599: my %lt = &usersession_titles();
13600: $resulttext = &mt('Changes made:').'<ul>';
13601: foreach my $prefix (@prefixes) {
13602: if (ref($changes{$prefix}) eq 'HASH') {
13603: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
13604: if ($prefix eq 'spares') {
13605: if (ref($changes{$prefix}) eq 'HASH') {
13606: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
13607: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 13608: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 13609: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
13610: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 13611: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
13612: foreach my $type (@{$types{$prefix}}) {
13613: if ($changes{$prefix}{$lonhost}{$type}) {
13614: my $offloadto = &mt('None');
13615: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
13616: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
13617: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
13618: }
1.145 raeburn 13619: }
1.147 raeburn 13620: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 13621: }
1.137 raeburn 13622: }
13623: }
1.147 raeburn 13624: $resulttext .= '</li>';
1.137 raeburn 13625: }
13626: }
1.147 raeburn 13627: } else {
13628: foreach my $type (@{$types{$prefix}}) {
13629: if (defined($changes{$prefix}{$type})) {
13630: my $newvalue;
13631: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13632: if (ref($defaultshash{'usersessions'}{$prefix})) {
13633: if ($type eq 'version') {
13634: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
13635: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13636: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
13637: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
13638: }
1.145 raeburn 13639: }
13640: }
13641: }
1.147 raeburn 13642: if ($newvalue eq '') {
13643: if ($type eq 'version') {
13644: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
13645: } else {
13646: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
13647: }
1.145 raeburn 13648: } else {
1.147 raeburn 13649: if ($type eq 'version') {
13650: $newvalue .= ' '.&mt('(or later)');
13651: }
13652: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 13653: }
1.137 raeburn 13654: }
13655: }
13656: }
1.147 raeburn 13657: $resulttext .= '</ul>';
1.137 raeburn 13658: }
13659: }
1.261 raeburn 13660: if ($changes{'offloadnow'}) {
13661: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13662: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
13663: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
13664: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
13665: $resulttext .= '<li>'.$lonhost.'</li>';
13666: }
13667: $resulttext .= '</ul>';
13668: } else {
13669: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
13670: }
13671: } else {
13672: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
13673: }
13674: }
1.147 raeburn 13675: $resulttext .= '</ul>';
13676: } else {
13677: $resulttext = $nochgmsg;
1.137 raeburn 13678: }
13679: } else {
13680: $resulttext = '<span class="LC_error">'.
13681: &mt('An error occurred: [_1]',$putresult).'</span>';
13682: }
13683: } else {
1.147 raeburn 13684: $resulttext = $nochgmsg;
1.137 raeburn 13685: }
13686: return $resulttext;
13687: }
13688:
1.275 raeburn 13689: sub modify_ssl {
13690: my ($dom,$lastactref,%domconfig) = @_;
13691: my (%by_ip,%by_location,@intdoms,@instdoms);
13692: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
13693: my @locations = sort(keys(%by_location));
13694: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13695: my (%defaultshash,%changes);
13696: my $action = 'ssl';
13697: my @prefixes = ('connect','replication');
13698: foreach my $prefix (@prefixes) {
13699: $defaultshash{$action}{$prefix} = {};
13700: }
13701: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13702: my $resulttext;
13703: my %iphost = &Apache::lonnet::get_iphost();
13704: my @reptypes = ('certreq','nocertreq');
13705: my @connecttypes = ('dom','intdom','other');
13706: my %types = (
13707: connect => \@connecttypes,
13708: replication => \@reptypes,
13709: );
13710: foreach my $prefix (sort(keys(%types))) {
13711: foreach my $type (@{$types{$prefix}}) {
13712: if ($prefix eq 'connect') {
13713: my $value = 'yes';
13714: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
13715: $value = $env{'form.'.$prefix.'_'.$type};
13716: }
13717: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
13718: if ($domconfig{$action}{$prefix}{$type} ne '') {
13719: if ($value ne $domconfig{$action}{$prefix}{$type}) {
13720: $changes{$prefix}{$type} = 1;
13721: }
13722: $defaultshash{$action}{$prefix}{$type} = $value;
13723: } else {
13724: $defaultshash{$action}{$prefix}{$type} = $value;
13725: $changes{$prefix}{$type} = 1;
13726: }
13727: } else {
13728: $defaultshash{$action}{$prefix}{$type} = $value;
13729: $changes{$prefix}{$type} = 1;
13730: }
13731: if (($type eq 'dom') && (keys(%servers) == 1)) {
13732: delete($changes{$prefix}{$type});
13733: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
13734: delete($changes{$prefix}{$type});
13735: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
13736: delete($changes{$prefix}{$type});
13737: }
13738: } elsif ($prefix eq 'replication') {
13739: if (@locations > 0) {
13740: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13741: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13742: my @okvals;
13743: foreach my $val (@vals) {
13744: if ($val =~ /:/) {
13745: my @items = split(/:/,$val);
13746: foreach my $item (@items) {
13747: if (ref($by_location{$item}) eq 'ARRAY') {
13748: push(@okvals,$item);
13749: }
13750: }
13751: } else {
13752: if (ref($by_location{$val}) eq 'ARRAY') {
13753: push(@okvals,$val);
13754: }
13755: }
13756: }
13757: @okvals = sort(@okvals);
13758: if (ref($domconfig{$action}) eq 'HASH') {
13759: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
13760: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
13761: if ($inuse == 0) {
13762: $changes{$prefix}{$type} = 1;
13763: } else {
13764: $defaultshash{$action}{$prefix}{$type} = \@okvals;
13765: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
13766: if (@changed > 0) {
13767: $changes{$prefix}{$type} = 1;
13768: }
13769: }
13770: } else {
13771: if ($inuse == 1) {
13772: $defaultshash{$action}{$prefix}{$type} = \@okvals;
13773: $changes{$prefix}{$type} = 1;
13774: }
13775: }
13776: } else {
13777: if ($inuse == 1) {
13778: $defaultshash{$action}{$prefix}{$type} = \@okvals;
13779: $changes{$prefix}{$type} = 1;
13780: }
13781: }
13782: } else {
13783: if ($inuse == 1) {
13784: $defaultshash{$action}{$prefix}{$type} = \@okvals;
13785: $changes{$prefix}{$type} = 1;
13786: }
13787: }
13788: }
13789: }
13790: }
13791: }
13792: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
13793: if (keys(%changes) > 0) {
13794: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13795: $dom);
13796: if ($putresult eq 'ok') {
13797: if (ref($defaultshash{$action}) eq 'HASH') {
13798: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
13799: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
13800: }
13801: if (ref($defaultshash{$action}{'connect'}) eq 'HASH') {
13802: $domdefaults{'connect'} = $domconfig{$action}{'connect'};
13803: }
13804: }
13805: my $cachetime = 24*60*60;
13806: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13807: if (ref($lastactref) eq 'HASH') {
13808: $lastactref->{'domdefaults'} = 1;
13809: }
13810: if (keys(%changes) > 0) {
13811: my %titles = &ssl_titles();
13812: $resulttext = &mt('Changes made:').'<ul>';
13813: foreach my $prefix (@prefixes) {
13814: if (ref($changes{$prefix}) eq 'HASH') {
13815: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
13816: foreach my $type (@{$types{$prefix}}) {
13817: if (defined($changes{$prefix}{$type})) {
13818: my $newvalue;
13819: if (ref($defaultshash{$action}) eq 'HASH') {
13820: if (ref($defaultshash{$action}{$prefix})) {
13821: if ($prefix eq 'connect') {
13822: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
13823: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
13824: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
13825: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
13826: }
13827: }
13828: }
13829: if ($newvalue eq '') {
13830: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
13831: } else {
13832: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
13833: }
13834: }
13835: }
13836: }
13837: $resulttext .= '</ul>';
13838: }
13839: }
13840: } else {
13841: $resulttext = $nochgmsg;
13842: }
13843: } else {
13844: $resulttext = '<span class="LC_error">'.
13845: &mt('An error occurred: [_1]',$putresult).'</span>';
13846: }
13847: } else {
13848: $resulttext = $nochgmsg;
13849: }
13850: return $resulttext;
13851: }
13852:
1.279 raeburn 13853: sub modify_trust {
13854: my ($dom,$lastactref,%domconfig) = @_;
13855: my (%by_ip,%by_location,@intdoms,@instdoms);
13856: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
13857: my @locations = sort(keys(%by_location));
13858: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
13859: my @types = ('exc','inc');
13860: my (%defaultshash,%changes);
13861: foreach my $prefix (@prefixes) {
13862: $defaultshash{'trust'}{$prefix} = {};
13863: }
13864: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13865: my $resulttext;
13866: foreach my $prefix (@prefixes) {
13867: foreach my $type (@types) {
13868: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13869: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13870: my @okvals;
13871: foreach my $val (@vals) {
13872: if ($val =~ /:/) {
13873: my @items = split(/:/,$val);
13874: foreach my $item (@items) {
13875: if (ref($by_location{$item}) eq 'ARRAY') {
13876: push(@okvals,$item);
13877: }
13878: }
13879: } else {
13880: if (ref($by_location{$val}) eq 'ARRAY') {
13881: push(@okvals,$val);
13882: }
13883: }
13884: }
13885: @okvals = sort(@okvals);
13886: if (ref($domconfig{'trust'}) eq 'HASH') {
13887: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
13888: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
13889: if ($inuse == 0) {
13890: $changes{$prefix}{$type} = 1;
13891: } else {
13892: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
13893: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
13894: if (@changed > 0) {
13895: $changes{$prefix}{$type} = 1;
13896: }
13897: }
13898: } else {
13899: if ($inuse == 1) {
13900: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
13901: $changes{$prefix}{$type} = 1;
13902: }
13903: }
13904: } else {
13905: if ($inuse == 1) {
13906: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
13907: $changes{$prefix}{$type} = 1;
13908: }
13909: }
13910: } else {
13911: if ($inuse == 1) {
13912: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
13913: $changes{$prefix}{$type} = 1;
13914: }
13915: }
13916: }
13917: }
13918: my $nochgmsg = &mt('No changes made to trust settings.');
13919: if (keys(%changes) > 0) {
13920: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13921: $dom);
13922: if ($putresult eq 'ok') {
13923: if (ref($defaultshash{'trust'}) eq 'HASH') {
13924: foreach my $prefix (@prefixes) {
13925: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
13926: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
13927: }
13928: }
13929: }
13930: my $cachetime = 24*60*60;
13931: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13932: if (ref($lastactref) eq 'HASH') {
13933: $lastactref->{'domdefaults'} = 1;
13934: }
13935: if (keys(%changes) > 0) {
13936: my %lt = &trust_titles();
13937: $resulttext = &mt('Changes made:').'<ul>';
13938: foreach my $prefix (@prefixes) {
13939: if (ref($changes{$prefix}) eq 'HASH') {
13940: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
13941: foreach my $type (@types) {
13942: if (defined($changes{$prefix}{$type})) {
13943: my $newvalue;
13944: if (ref($defaultshash{'trust'}) eq 'HASH') {
13945: if (ref($defaultshash{'trust'}{$prefix})) {
13946: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
13947: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
13948: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
13949: }
13950: }
13951: }
13952: }
13953: if ($newvalue eq '') {
13954: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
13955: } else {
13956: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
13957: }
13958: }
13959: }
13960: $resulttext .= '</ul>';
13961: }
13962: }
13963: $resulttext .= '</ul>';
13964: } else {
13965: $resulttext = $nochgmsg;
13966: }
13967: } else {
13968: $resulttext = '<span class="LC_error">'.
13969: &mt('An error occurred: [_1]',$putresult).'</span>';
13970: }
13971: } else {
13972: $resulttext = $nochgmsg;
13973: }
13974: return $resulttext;
13975: }
13976:
1.150 raeburn 13977: sub modify_loadbalancing {
13978: my ($dom,%domconfig) = @_;
13979: my $primary_id = &Apache::lonnet::domain($dom,'primary');
13980: my $intdom = &Apache::lonnet::internet_dom($primary_id);
13981: my ($othertitle,$usertypes,$types) =
13982: &Apache::loncommon::sorted_inst_types($dom);
13983: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 13984: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 13985: my @sparestypes = ('primary','default');
13986: my %typetitles = &sparestype_titles();
13987: my $resulttext;
1.171 raeburn 13988: my (%currbalancer,%currtargets,%currrules,%existing);
13989: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13990: %existing = %{$domconfig{'loadbalancing'}};
13991: }
13992: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
13993: \%currtargets,\%currrules);
13994: my ($saveloadbalancing,%defaultshash,%changes);
13995: my ($alltypes,$othertypes,$titles) =
13996: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
13997: my %ruletitles = &offloadtype_text();
13998: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
13999: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
14000: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
14001: if ($balancer eq '') {
14002: next;
14003: }
1.210 raeburn 14004: if (!exists($servers{$balancer})) {
1.171 raeburn 14005: if (exists($currbalancer{$balancer})) {
14006: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 14007: }
1.171 raeburn 14008: next;
14009: }
14010: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
14011: push(@{$changes{'delete'}},$balancer);
14012: next;
14013: }
14014: if (!exists($currbalancer{$balancer})) {
14015: push(@{$changes{'add'}},$balancer);
14016: }
14017: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
14018: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
14019: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
14020: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14021: $saveloadbalancing = 1;
14022: }
14023: foreach my $sparetype (@sparestypes) {
14024: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
14025: my @offloadto;
14026: foreach my $target (@targets) {
14027: if (($servers{$target}) && ($target ne $balancer)) {
14028: if ($sparetype eq 'default') {
14029: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
14030: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 14031: }
14032: }
1.171 raeburn 14033: unless(grep(/^\Q$target\E$/,@offloadto)) {
14034: push(@offloadto,$target);
14035: }
1.150 raeburn 14036: }
14037: }
1.284 raeburn 14038: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
14039: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
14040: push(@offloadto,$balancer);
14041: }
14042: }
14043: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 14044: }
1.171 raeburn 14045: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 14046: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14047: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
14048: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 14049: if (@targetdiffs > 0) {
1.171 raeburn 14050: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14051: }
1.171 raeburn 14052: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14053: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14054: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14055: }
14056: }
14057: }
14058: } else {
1.171 raeburn 14059: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 14060: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14061: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14062: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14063: $changes{'curr'}{$balancer}{'targets'} = 1;
14064: }
1.150 raeburn 14065: }
14066: }
1.210 raeburn 14067: }
1.150 raeburn 14068: }
14069: my $ishomedom;
1.171 raeburn 14070: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
14071: $ishomedom = 1;
1.150 raeburn 14072: }
14073: if (ref($alltypes) eq 'ARRAY') {
14074: foreach my $type (@{$alltypes}) {
14075: my $rule;
1.210 raeburn 14076: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 14077: (!$ishomedom)) {
1.171 raeburn 14078: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
14079: }
14080: if ($rule eq 'specific') {
1.255 raeburn 14081: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 14082: if (exists($servers{$specifiedhost})) {
1.255 raeburn 14083: $rule = $specifiedhost;
14084: }
1.150 raeburn 14085: }
1.171 raeburn 14086: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
14087: if (ref($currrules{$balancer}) eq 'HASH') {
14088: if ($rule ne $currrules{$balancer}{$type}) {
14089: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14090: }
14091: } elsif ($rule ne '') {
1.171 raeburn 14092: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14093: }
14094: }
14095: }
1.171 raeburn 14096: }
14097: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
14098: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
14099: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
14100: $defaultshash{'loadbalancing'} = {};
14101: }
14102: my $putresult = &Apache::lonnet::put_dom('configuration',
14103: \%defaultshash,$dom);
14104: if ($putresult eq 'ok') {
14105: if (keys(%changes) > 0) {
1.252 raeburn 14106: my %toupdate;
1.171 raeburn 14107: if (ref($changes{'delete'}) eq 'ARRAY') {
14108: foreach my $balancer (sort(@{$changes{'delete'}})) {
14109: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 14110: $toupdate{$balancer} = 1;
1.150 raeburn 14111: }
1.171 raeburn 14112: }
14113: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 14114: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 14115: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 14116: $toupdate{$balancer} = 1;
1.171 raeburn 14117: }
14118: }
14119: if (ref($changes{'curr'}) eq 'HASH') {
14120: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 14121: $toupdate{$balancer} = 1;
1.171 raeburn 14122: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
14123: if ($changes{'curr'}{$balancer}{'targets'}) {
14124: my %offloadstr;
14125: foreach my $sparetype (@sparestypes) {
14126: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14127: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14128: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14129: }
14130: }
1.150 raeburn 14131: }
1.171 raeburn 14132: if (keys(%offloadstr) == 0) {
14133: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 14134: } else {
1.171 raeburn 14135: my $showoffload;
14136: foreach my $sparetype (@sparestypes) {
14137: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
14138: if (defined($offloadstr{$sparetype})) {
14139: $showoffload .= $offloadstr{$sparetype};
14140: } else {
14141: $showoffload .= &mt('None');
14142: }
14143: $showoffload .= (' 'x3);
14144: }
14145: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 14146: }
14147: }
14148: }
1.171 raeburn 14149: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
14150: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
14151: foreach my $type (@{$alltypes}) {
14152: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
14153: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14154: my $balancetext;
14155: if ($rule eq '') {
14156: $balancetext = $ruletitles{'default'};
1.209 raeburn 14157: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 14158: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 14159: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 14160: foreach my $sparetype (@sparestypes) {
14161: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14162: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14163: }
14164: }
1.253 raeburn 14165: foreach my $item (@{$alltypes}) {
14166: next if ($item =~ /^_LC_ipchange/);
14167: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
14168: if ($hasrule eq 'homeserver') {
14169: map { $toupdate{$_} = 1; } (keys(%libraryservers));
14170: } else {
14171: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
14172: if ($servers{$hasrule}) {
14173: $toupdate{$hasrule} = 1;
14174: }
14175: }
14176: }
14177: }
1.254 raeburn 14178: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
14179: $balancetext = $ruletitles{$rule};
14180: } else {
14181: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14182: $balancetext = $ruletitles{'particular'}.' '.$receiver;
14183: if ($receiver) {
14184: $toupdate{$receiver};
14185: }
14186: }
14187: } else {
14188: $balancetext = $ruletitles{$rule};
1.252 raeburn 14189: }
1.171 raeburn 14190: } else {
14191: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
14192: }
1.210 raeburn 14193: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 14194: }
14195: }
14196: }
14197: }
1.252 raeburn 14198: if (keys(%toupdate)) {
14199: my %thismachine;
14200: my $updatedhere;
14201: my $cachetime = 60*60*24;
14202: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
14203: foreach my $lonhost (keys(%toupdate)) {
14204: if ($thismachine{$lonhost}) {
14205: unless ($updatedhere) {
14206: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
14207: $defaultshash{'loadbalancing'},
14208: $cachetime);
14209: $updatedhere = 1;
14210: }
14211: } else {
14212: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
14213: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
14214: }
14215: }
14216: }
1.150 raeburn 14217: }
1.171 raeburn 14218: }
14219: if ($resulttext ne '') {
14220: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 14221: } else {
14222: $resulttext = $nochgmsg;
14223: }
14224: } else {
1.171 raeburn 14225: $resulttext = $nochgmsg;
1.150 raeburn 14226: }
14227: } else {
1.171 raeburn 14228: $resulttext = '<span class="LC_error">'.
14229: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 14230: }
14231: } else {
1.171 raeburn 14232: $resulttext = $nochgmsg;
1.150 raeburn 14233: }
14234: return $resulttext;
14235: }
14236:
1.48 raeburn 14237: sub recurse_check {
14238: my ($chkcats,$categories,$depth,$name) = @_;
14239: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
14240: my $chg = 0;
14241: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
14242: my $category = $chkcats->[$depth]{$name}[$j];
14243: my $item;
14244: if ($category eq '') {
14245: $chg ++;
14246: } else {
14247: my $deeper = $depth + 1;
14248: $item = &escape($category).':'.&escape($name).':'.$depth;
14249: if ($chg) {
14250: $categories->{$item} -= $chg;
14251: }
14252: &recurse_check($chkcats,$categories,$deeper,$category);
14253: $deeper --;
14254: }
14255: }
14256: }
14257: return;
14258: }
14259:
14260: sub recurse_cat_deletes {
14261: my ($item,$coursecategories,$deletions) = @_;
14262: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14263: my $subdepth = $depth + 1;
14264: if (ref($coursecategories) eq 'HASH') {
14265: foreach my $subitem (keys(%{$coursecategories})) {
14266: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
14267: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
14268: delete($coursecategories->{$subitem});
14269: $deletions->{$subitem} = 1;
14270: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 14271: }
1.48 raeburn 14272: }
14273: }
14274: return;
14275: }
14276:
1.125 raeburn 14277: sub active_dc_picker {
1.191 raeburn 14278: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 14279: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 14280: my @domcoord = keys(%domcoords);
14281: if (keys(%currhash)) {
14282: foreach my $dc (keys(%currhash)) {
14283: unless (exists($domcoords{$dc})) {
14284: push(@domcoord,$dc);
14285: }
14286: }
14287: }
14288: @domcoord = sort(@domcoord);
1.210 raeburn 14289: my $numdcs = scalar(@domcoord);
1.191 raeburn 14290: my $rows = 0;
14291: my $table;
1.125 raeburn 14292: if ($numdcs > 1) {
1.191 raeburn 14293: $table = '<table>';
14294: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 14295: my $rem = $i%($numinrow);
14296: if ($rem == 0) {
14297: if ($i > 0) {
1.191 raeburn 14298: $table .= '</tr>';
1.125 raeburn 14299: }
1.191 raeburn 14300: $table .= '<tr>';
14301: $rows ++;
1.125 raeburn 14302: }
1.191 raeburn 14303: my $check = '';
14304: if ($inputtype eq 'radio') {
14305: if (keys(%currhash) == 0) {
14306: if (!$i) {
14307: $check = ' checked="checked"';
14308: }
14309: } elsif (exists($currhash{$domcoord[$i]})) {
14310: $check = ' checked="checked"';
14311: }
14312: } else {
14313: if (exists($currhash{$domcoord[$i]})) {
14314: $check = ' checked="checked"';
1.125 raeburn 14315: }
14316: }
1.191 raeburn 14317: if ($i == @domcoord - 1) {
1.125 raeburn 14318: my $colsleft = $numinrow - $rem;
14319: if ($colsleft > 1) {
1.191 raeburn 14320: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 14321: } else {
1.191 raeburn 14322: $table .= '<td class="LC_left_item">';
1.125 raeburn 14323: }
14324: } else {
1.191 raeburn 14325: $table .= '<td class="LC_left_item">';
14326: }
14327: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
14328: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
14329: $table .= '<span class="LC_nobreak"><label>'.
14330: '<input type="'.$inputtype.'" name="'.$name.'"'.
14331: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
14332: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 14333: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 14334: }
1.219 raeburn 14335: $table .= '</label></span></td>';
1.191 raeburn 14336: }
14337: $table .= '</tr></table>';
14338: } elsif ($numdcs == 1) {
1.219 raeburn 14339: my ($dcname,$dcdom) = split(':',$domcoord[0]);
14340: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 14341: if ($inputtype eq 'radio') {
1.247 raeburn 14342: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 14343: if ($user ne $dcname.':'.$dcdom) {
14344: $table .= ' ('.$dcname.':'.$dcdom.')';
14345: }
1.191 raeburn 14346: } else {
14347: my $check;
14348: if (exists($currhash{$domcoord[0]})) {
14349: $check = ' checked="checked"';
1.125 raeburn 14350: }
1.247 raeburn 14351: $table = '<span class="LC_nobreak"><label>'.
14352: '<input type="checkbox" name="'.$name.'" '.
14353: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 14354: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 14355: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 14356: }
1.220 raeburn 14357: $table .= '</label></span>';
1.191 raeburn 14358: $rows ++;
1.125 raeburn 14359: }
14360: }
1.191 raeburn 14361: return ($numdcs,$table,$rows);
1.125 raeburn 14362: }
14363:
1.137 raeburn 14364: sub usersession_titles {
14365: return &Apache::lonlocal::texthash(
14366: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
14367: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 14368: spares => 'Servers offloaded to, when busy',
1.137 raeburn 14369: version => 'LON-CAPA version requirement',
1.138 raeburn 14370: excludedomain => 'Allow all, but exclude specific domains',
14371: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 14372: primary => 'Primary (checked first)',
1.154 raeburn 14373: default => 'Default',
1.137 raeburn 14374: );
14375: }
14376:
1.152 raeburn 14377: sub id_for_thisdom {
14378: my (%servers) = @_;
14379: my %altids;
14380: foreach my $server (keys(%servers)) {
14381: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
14382: if ($serverhome ne $server) {
14383: $altids{$serverhome} = $server;
14384: }
14385: }
14386: return %altids;
14387: }
14388:
1.150 raeburn 14389: sub count_servers {
14390: my ($currbalancer,%servers) = @_;
14391: my (@spares,$numspares);
14392: foreach my $lonhost (sort(keys(%servers))) {
14393: next if ($currbalancer eq $lonhost);
14394: push(@spares,$lonhost);
14395: }
14396: if ($currbalancer) {
14397: $numspares = scalar(@spares);
14398: } else {
14399: $numspares = scalar(@spares) - 1;
14400: }
14401: return ($numspares,@spares);
14402: }
14403:
14404: sub lonbalance_targets_js {
1.171 raeburn 14405: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 14406: my $select = &mt('Select');
14407: my ($alltargets,$allishome,$allinsttypes,@alltypes);
14408: if (ref($servers) eq 'HASH') {
14409: $alltargets = join("','",sort(keys(%{$servers})));
14410: my @homedoms;
14411: foreach my $server (sort(keys(%{$servers}))) {
14412: if (&Apache::lonnet::host_domain($server) eq $dom) {
14413: push(@homedoms,'1');
14414: } else {
14415: push(@homedoms,'0');
14416: }
14417: }
14418: $allishome = join("','",@homedoms);
14419: }
14420: if (ref($types) eq 'ARRAY') {
14421: if (@{$types} > 0) {
14422: @alltypes = @{$types};
14423: }
14424: }
14425: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
14426: $allinsttypes = join("','",@alltypes);
1.171 raeburn 14427: my (%currbalancer,%currtargets,%currrules,%existing);
14428: if (ref($settings) eq 'HASH') {
14429: %existing = %{$settings};
14430: }
14431: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
14432: \%currtargets,\%currrules);
1.210 raeburn 14433: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 14434: return <<"END";
14435:
14436: <script type="text/javascript">
14437: // <![CDATA[
14438:
1.171 raeburn 14439: currBalancers = new Array('$balancers');
14440:
14441: function toggleTargets(balnum) {
14442: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14443: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
14444: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
14445: var prevbalancer = prevhostitem.value;
14446: var baltotal = document.getElementById('loadbalancing_total').value;
14447: prevhostitem.value = balancer;
14448: if (prevbalancer != '') {
14449: var prevIdx = currBalancers.indexOf(prevbalancer);
14450: if (prevIdx != -1) {
14451: currBalancers.splice(prevIdx,1);
14452: }
14453: }
1.150 raeburn 14454: if (balancer == '') {
1.171 raeburn 14455: hideSpares(balnum);
1.150 raeburn 14456: } else {
1.171 raeburn 14457: var currIdx = currBalancers.indexOf(balancer);
14458: if (currIdx == -1) {
14459: currBalancers.push(balancer);
14460: }
1.150 raeburn 14461: var homedoms = new Array('$allishome');
1.171 raeburn 14462: var ishomedom = homedoms[lonhostitem.selectedIndex];
14463: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 14464: }
1.171 raeburn 14465: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 14466: return;
14467: }
14468:
1.171 raeburn 14469: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 14470: var alltargets = new Array('$alltargets');
14471: var insttypes = new Array('$allinsttypes');
1.151 raeburn 14472: var offloadtypes = new Array('primary','default');
14473:
1.171 raeburn 14474: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
14475: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 14476:
1.151 raeburn 14477: for (var i=0; i<offloadtypes.length; i++) {
14478: var count = 0;
14479: for (var j=0; j<alltargets.length; j++) {
14480: if (alltargets[j] != balancer) {
1.171 raeburn 14481: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
14482: item.value = alltargets[j];
14483: item.style.textAlign='left';
14484: item.style.textFace='normal';
14485: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
14486: if (currBalancers.indexOf(alltargets[j]) == -1) {
14487: item.disabled = '';
14488: } else {
14489: item.disabled = 'disabled';
14490: item.checked = false;
14491: }
1.151 raeburn 14492: count ++;
14493: }
1.150 raeburn 14494: }
14495: }
1.151 raeburn 14496: for (var k=0; k<insttypes.length; k++) {
14497: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 14498: if (ishomedom == 1) {
1.171 raeburn 14499: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14500: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14501: } else {
1.171 raeburn 14502: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14503: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 14504: }
14505: } else {
1.171 raeburn 14506: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14507: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14508: }
1.151 raeburn 14509: if ((insttypes[k] != '_LC_external') &&
14510: ((insttypes[k] != '_LC_internetdom') ||
14511: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 14512: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
14513: item.options.length = 0;
14514: item.options[0] = new Option("","",true,true);
1.210 raeburn 14515: var idx = 0;
1.151 raeburn 14516: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 14517: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
14518: idx ++;
14519: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 14520: }
14521: }
14522: }
14523: }
14524: return;
14525: }
14526:
1.171 raeburn 14527: function hideSpares(balnum) {
1.150 raeburn 14528: var alltargets = new Array('$alltargets');
14529: var insttypes = new Array('$allinsttypes');
14530: var offloadtypes = new Array('primary','default');
14531:
1.171 raeburn 14532: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
14533: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 14534:
14535: var total = alltargets.length - 1;
14536: for (var i=0; i<offloadtypes; i++) {
14537: for (var j=0; j<total; j++) {
1.171 raeburn 14538: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
14539: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
14540: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 14541: }
1.150 raeburn 14542: }
14543: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 14544: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14545: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 14546: if (insttypes[k] != '_LC_external') {
1.171 raeburn 14547: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
14548: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 14549: }
14550: }
14551: return;
14552: }
14553:
1.171 raeburn 14554: function checkOffloads(item,balnum,type) {
1.150 raeburn 14555: var alltargets = new Array('$alltargets');
14556: var offloadtypes = new Array('primary','default');
14557: if (item.checked) {
14558: var total = alltargets.length - 1;
14559: var other;
14560: if (type == offloadtypes[0]) {
1.151 raeburn 14561: other = offloadtypes[1];
1.150 raeburn 14562: } else {
1.151 raeburn 14563: other = offloadtypes[0];
1.150 raeburn 14564: }
14565: for (var i=0; i<total; i++) {
1.171 raeburn 14566: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 14567: if (server == item.value) {
1.171 raeburn 14568: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
14569: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 14570: }
14571: }
14572: }
14573: }
14574: return;
14575: }
14576:
1.171 raeburn 14577: function singleServerToggle(balnum,type) {
14578: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 14579: if (offloadtoSelIdx == 0) {
1.171 raeburn 14580: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
14581: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14582:
14583: } else {
1.171 raeburn 14584: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
14585: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 14586: }
14587: return;
14588: }
14589:
1.171 raeburn 14590: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 14591: if (type == '_LC_external') {
1.171 raeburn 14592: return;
1.150 raeburn 14593: }
1.171 raeburn 14594: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 14595: for (var i=0; i<typesRules.length; i++) {
14596: if (formname.elements[typesRules[i]].checked) {
14597: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 14598: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
14599: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14600: } else {
1.171 raeburn 14601: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
14602: }
14603: }
14604: }
14605: return;
14606: }
14607:
14608: function balancerDeleteChange(balnum) {
14609: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14610: var baltotal = document.getElementById('loadbalancing_total').value;
14611: var addtarget;
14612: var removetarget;
14613: var action = 'delete';
14614: if (document.getElementById('loadbalancing_delete_'+balnum)) {
14615: var lonhost = hostitem.value;
14616: var currIdx = currBalancers.indexOf(lonhost);
14617: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
14618: if (currIdx != -1) {
14619: currBalancers.splice(currIdx,1);
14620: }
14621: addtarget = lonhost;
14622: } else {
14623: if (currIdx == -1) {
14624: currBalancers.push(lonhost);
14625: }
14626: removetarget = lonhost;
14627: action = 'undelete';
14628: }
14629: balancerChange(balnum,baltotal,action,addtarget,removetarget);
14630: }
14631: return;
14632: }
14633:
14634: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
14635: if (baltotal > 1) {
14636: var offloadtypes = new Array('primary','default');
14637: var alltargets = new Array('$alltargets');
14638: var insttypes = new Array('$allinsttypes');
14639: for (var i=0; i<baltotal; i++) {
14640: if (i != balnum) {
14641: for (var j=0; j<offloadtypes.length; j++) {
14642: var total = alltargets.length - 1;
14643: for (var k=0; k<total; k++) {
14644: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
14645: var server = serveritem.value;
14646: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14647: if (server == addtarget) {
14648: serveritem.disabled = '';
14649: }
14650: }
14651: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14652: if (server == removetarget) {
14653: serveritem.disabled = 'disabled';
14654: serveritem.checked = false;
14655: }
14656: }
14657: }
14658: }
14659: for (var j=0; j<insttypes.length; j++) {
14660: if (insttypes[j] != '_LC_external') {
14661: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
14662: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
14663: var currSel = singleserver.selectedIndex;
14664: var currVal = singleserver.options[currSel].value;
14665: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14666: var numoptions = singleserver.options.length;
14667: var needsnew = 1;
14668: for (var k=0; k<numoptions; k++) {
14669: if (singleserver.options[k] == addtarget) {
14670: needsnew = 0;
14671: break;
14672: }
14673: }
14674: if (needsnew == 1) {
14675: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
14676: }
14677: }
14678: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14679: singleserver.options.length = 0;
14680: if ((currVal) && (currVal != removetarget)) {
14681: singleserver.options[0] = new Option("","",false,false);
14682: } else {
14683: singleserver.options[0] = new Option("","",true,true);
14684: }
14685: var idx = 0;
14686: for (var m=0; m<alltargets.length; m++) {
14687: if (currBalancers.indexOf(alltargets[m]) == -1) {
14688: idx ++;
14689: if (currVal == alltargets[m]) {
14690: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
14691: } else {
14692: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
14693: }
14694: }
14695: }
14696: }
14697: }
14698: }
14699: }
1.150 raeburn 14700: }
14701: }
14702: }
14703: return;
14704: }
14705:
1.152 raeburn 14706: // ]]>
14707: </script>
14708:
14709: END
14710: }
14711:
14712: sub new_spares_js {
14713: my @sparestypes = ('primary','default');
14714: my $types = join("','",@sparestypes);
14715: my $select = &mt('Select');
14716: return <<"END";
14717:
14718: <script type="text/javascript">
14719: // <![CDATA[
14720:
14721: function updateNewSpares(formname,lonhost) {
14722: var types = new Array('$types');
14723: var include = new Array();
14724: var exclude = new Array();
14725: for (var i=0; i<types.length; i++) {
14726: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
14727: for (var j=0; j<spareboxes.length; j++) {
14728: if (formname.elements[spareboxes[j]].checked) {
14729: exclude.push(formname.elements[spareboxes[j]].value);
14730: } else {
14731: include.push(formname.elements[spareboxes[j]].value);
14732: }
14733: }
14734: }
14735: for (var i=0; i<types.length; i++) {
14736: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
14737: var selIdx = newSpare.selectedIndex;
14738: var currnew = newSpare.options[selIdx].value;
14739: var okSpares = new Array();
14740: for (var j=0; j<newSpare.options.length; j++) {
14741: var possible = newSpare.options[j].value;
14742: if (possible != '') {
14743: if (exclude.indexOf(possible) == -1) {
14744: okSpares.push(possible);
14745: } else {
14746: if (currnew == possible) {
14747: selIdx = 0;
14748: }
14749: }
14750: }
14751: }
14752: for (var k=0; k<include.length; k++) {
14753: if (okSpares.indexOf(include[k]) == -1) {
14754: okSpares.push(include[k]);
14755: }
14756: }
14757: okSpares.sort();
14758: newSpare.options.length = 0;
14759: if (selIdx == 0) {
14760: newSpare.options[0] = new Option("$select","",true,true);
14761: } else {
14762: newSpare.options[0] = new Option("$select","",false,false);
14763: }
14764: for (var m=0; m<okSpares.length; m++) {
14765: var idx = m+1;
14766: var selThis = 0;
14767: if (selIdx != 0) {
14768: if (okSpares[m] == currnew) {
14769: selThis = 1;
14770: }
14771: }
14772: if (selThis == 1) {
14773: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
14774: } else {
14775: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
14776: }
14777: }
14778: }
14779: return;
14780: }
14781:
14782: function checkNewSpares(lonhost,type) {
14783: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
14784: var chosen = newSpare.options[newSpare.selectedIndex].value;
14785: if (chosen != '') {
14786: var othertype;
14787: var othernewSpare;
14788: if (type == 'primary') {
14789: othernewSpare = document.getElementById('newspare_default_'+lonhost);
14790: }
14791: if (type == 'default') {
14792: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
14793: }
14794: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
14795: othernewSpare.selectedIndex = 0;
14796: }
14797: }
14798: return;
14799: }
14800:
14801: // ]]>
14802: </script>
14803:
14804: END
14805:
14806: }
14807:
14808: sub common_domprefs_js {
14809: return <<"END";
14810:
14811: <script type="text/javascript">
14812: // <![CDATA[
14813:
1.150 raeburn 14814: function getIndicesByName(formname,item) {
1.152 raeburn 14815: var group = new Array();
1.150 raeburn 14816: for (var i=0;i<formname.elements.length;i++) {
14817: if (formname.elements[i].name == item) {
1.152 raeburn 14818: group.push(formname.elements[i].id);
1.150 raeburn 14819: }
14820: }
1.152 raeburn 14821: return group;
1.150 raeburn 14822: }
14823:
14824: // ]]>
14825: </script>
14826:
14827: END
1.152 raeburn 14828:
1.150 raeburn 14829: }
14830:
1.165 raeburn 14831: sub recaptcha_js {
14832: my %lt = &captcha_phrases();
14833: return <<"END";
14834:
14835: <script type="text/javascript">
14836: // <![CDATA[
14837:
14838: function updateCaptcha(caller,context) {
14839: var privitem;
14840: var pubitem;
14841: var privtext;
14842: var pubtext;
1.269 raeburn 14843: var versionitem;
14844: var versiontext;
1.165 raeburn 14845: if (document.getElementById(context+'_recaptchapub')) {
14846: pubitem = document.getElementById(context+'_recaptchapub');
14847: } else {
14848: return;
14849: }
14850: if (document.getElementById(context+'_recaptchapriv')) {
14851: privitem = document.getElementById(context+'_recaptchapriv');
14852: } else {
14853: return;
14854: }
14855: if (document.getElementById(context+'_recaptchapubtxt')) {
14856: pubtext = document.getElementById(context+'_recaptchapubtxt');
14857: } else {
14858: return;
14859: }
14860: if (document.getElementById(context+'_recaptchaprivtxt')) {
14861: privtext = document.getElementById(context+'_recaptchaprivtxt');
14862: } else {
14863: return;
14864: }
1.269 raeburn 14865: if (document.getElementById(context+'_recaptchaversion')) {
14866: versionitem = document.getElementById(context+'_recaptchaversion');
14867: } else {
14868: return;
14869: }
14870: if (document.getElementById(context+'_recaptchavertxt')) {
14871: versiontext = document.getElementById(context+'_recaptchavertxt');
14872: } else {
14873: return;
14874: }
1.165 raeburn 14875: if (caller.checked) {
14876: if (caller.value == 'recaptcha') {
14877: pubitem.type = 'text';
14878: privitem.type = 'text';
14879: pubitem.size = '40';
14880: privitem.size = '40';
14881: pubtext.innerHTML = "$lt{'pub'}";
14882: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 14883: versionitem.type = 'text';
14884: versionitem.size = '3';
1.289 raeburn 14885: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 14886: } else {
14887: pubitem.type = 'hidden';
14888: privitem.type = 'hidden';
1.269 raeburn 14889: versionitem.type = 'hidden';
1.165 raeburn 14890: pubtext.innerHTML = '';
14891: privtext.innerHTML = '';
1.269 raeburn 14892: versiontext.innerHTML = '';
1.165 raeburn 14893: }
14894: }
14895: return;
14896: }
14897:
14898: // ]]>
14899: </script>
14900:
14901: END
14902:
14903: }
14904:
1.236 raeburn 14905: sub toggle_display_js {
1.192 raeburn 14906: return <<"END";
14907:
14908: <script type="text/javascript">
14909: // <![CDATA[
14910:
1.236 raeburn 14911: function toggleDisplay(domForm,caller) {
14912: if (document.getElementById(caller)) {
14913: var divitem = document.getElementById(caller);
14914: var optionsElement = domForm.coursecredits;
1.264 raeburn 14915: var checkval = 1;
14916: var dispval = 'block';
1.236 raeburn 14917: if (caller == 'emailoptions') {
14918: optionsElement = domForm.cancreate_email;
14919: }
1.257 raeburn 14920: if (caller == 'studentsubmission') {
14921: optionsElement = domForm.postsubmit;
14922: }
1.264 raeburn 14923: if (caller == 'cloneinstcode') {
14924: optionsElement = domForm.canclone;
14925: checkval = 'instcode';
14926: }
1.236 raeburn 14927: if (optionsElement.length) {
1.192 raeburn 14928: var currval;
1.236 raeburn 14929: for (var i=0; i<optionsElement.length; i++) {
14930: if (optionsElement[i].checked) {
14931: currval = optionsElement[i].value;
1.192 raeburn 14932: }
14933: }
1.264 raeburn 14934: if (currval == checkval) {
14935: divitem.style.display = dispval;
1.192 raeburn 14936: } else {
1.236 raeburn 14937: divitem.style.display = 'none';
1.192 raeburn 14938: }
14939: }
14940: }
14941: return;
14942: }
14943:
14944: // ]]>
14945: </script>
14946:
14947: END
14948:
14949: }
14950:
1.165 raeburn 14951: sub captcha_phrases {
14952: return &Apache::lonlocal::texthash (
14953: priv => 'Private key',
14954: pub => 'Public key',
14955: original => 'original (CAPTCHA)',
14956: recaptcha => 'successor (ReCAPTCHA)',
14957: notused => 'unused',
1.289 raeburn 14958: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 14959: );
14960: }
14961:
1.205 raeburn 14962: sub devalidate_remote_domconfs {
1.212 raeburn 14963: my ($dom,$cachekeys) = @_;
14964: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 14965: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14966: my %thismachine;
14967: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.267 raeburn 14968: my @posscached = ('domainconfig','domdefaults','ltitools');
1.260 raeburn 14969: if (keys(%servers)) {
1.205 raeburn 14970: foreach my $server (keys(%servers)) {
14971: next if ($thismachine{$server});
1.212 raeburn 14972: my @cached;
14973: foreach my $name (@posscached) {
14974: if ($cachekeys->{$name}) {
14975: push(@cached,&escape($name).':'.&escape($dom));
14976: }
14977: }
14978: if (@cached) {
14979: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
14980: }
1.205 raeburn 14981: }
14982: }
14983: return;
14984: }
14985:
1.3 raeburn 14986: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>