Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.57
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.57! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.56 2015/03/11 15:56:36 raeburn Exp $
1.160.6.40 raeburn 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
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
1.160.6.13 raeburn 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
1.160.6.27 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 raeburn 90: requestcourses or requestauthor).
1.101 raeburn 91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20 raeburn 97: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 98: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 99:
1.101 raeburn 100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.160.6.30 raeburn 106: (official, unofficial, community, and textbook). In each case the radio buttons
107: allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.160.6.37 raeburn 167: use Apache::lonuserutils();
1.160.6.39 raeburn 168: use Apache::loncoursequeueadmin();
1.69 raeburn 169: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 170: use LONCAPA::Enrollment;
1.81 raeburn 171: use LONCAPA::lonauthcgi();
1.9 raeburn 172: use File::Copy;
1.43 raeburn 173: use Locale::Language;
1.62 raeburn 174: use DateTime::TimeZone;
1.68 raeburn 175: use DateTime::Locale;
1.1 raeburn 176:
1.155 raeburn 177: my $registered_cleanup;
178: my $modified_urls;
179:
1.1 raeburn 180: sub handler {
181: my $r=shift;
182: if ($r->header_only) {
183: &Apache::loncommon::content_type($r,'text/html');
184: $r->send_http_header;
185: return OK;
186: }
187:
1.91 raeburn 188: my $context = 'domain';
1.1 raeburn 189: my $dom = $env{'request.role.domain'};
1.5 albertel 190: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 191: if (&Apache::lonnet::allowed('mau',$dom)) {
192: &Apache::loncommon::content_type($r,'text/html');
193: $r->send_http_header;
194: } else {
195: $env{'user.error.msg'}=
196: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
197: return HTTP_NOT_ACCEPTABLE;
198: }
1.155 raeburn 199:
200: $registered_cleanup=0;
201: @{$modified_urls}=();
202:
1.1 raeburn 203: &Apache::lonhtmlcommon::clear_breadcrumbs();
204: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 205: ['phase','actions']);
1.30 raeburn 206: my $phase = 'pickactions';
1.3 raeburn 207: if ( exists($env{'form.phase'}) ) {
208: $phase = $env{'form.phase'};
209: }
1.150 raeburn 210: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 211: my %domconfig =
1.6 raeburn 212: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 213: 'quotas','autoenroll','autoupdate','autocreate',
214: 'directorysrch','usercreation','usermodification',
215: 'contacts','defaults','scantron','coursecategories',
1.160.6.16 raeburn 216: 'serverstatuses','requestcourses','coursedefaults',
1.160.6.38 raeburn 217: 'usersessions','loadbalancing','requestauthor',
1.160.6.40 raeburn 218: 'selfenrollment','inststatus'],$dom);
1.43 raeburn 219: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 220: 'autoupdate','autocreate','directorysrch','contacts',
1.160.6.34 raeburn 221: 'usercreation','selfcreation','usermodification','scantron',
1.160.6.5 raeburn 222: 'requestcourses','requestauthor','coursecategories',
1.160.6.41 raeburn 223: 'serverstatuses','coursedefaults','selfenrollment',
1.160.6.37 raeburn 224: 'usersessions');
1.160.6.7 raeburn 225: my %existing;
226: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
227: %existing = %{$domconfig{'loadbalancing'}};
228: }
229: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 230: push(@prefs_order,'loadbalancing');
231: }
1.30 raeburn 232: my %prefs = (
233: 'rolecolors' =>
234: { text => 'Default color schemes',
1.67 raeburn 235: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 236: header => [{col1 => 'Student Settings',
237: col2 => '',},
238: {col1 => 'Coordinator Settings',
239: col2 => '',},
240: {col1 => 'Author Settings',
241: col2 => '',},
242: {col1 => 'Administrator Settings',
243: col2 => '',}],
1.160.6.37 raeburn 244: print => \&print_rolecolors,
245: modify => \&modify_rolecolors,
1.30 raeburn 246: },
1.110 raeburn 247: 'login' =>
1.30 raeburn 248: { text => 'Log-in page options',
1.67 raeburn 249: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 250: header => [{col1 => 'Log-in Page Items',
251: col2 => '',},
252: {col1 => 'Log-in Help',
1.160.6.56 raeburn 253: col2 => 'Value'},
254: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 255: col2 => 'Value'}],
1.160.6.37 raeburn 256: print => \&print_login,
257: modify => \&modify_login,
1.30 raeburn 258: },
1.43 raeburn 259: 'defaults' =>
1.160.6.40 raeburn 260: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 261: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 262: header => [{col1 => 'Setting',
1.160.6.40 raeburn 263: col2 => 'Value'},
264: {col1 => 'Institutional user types',
265: col2 => 'Assignable to e-mail usernames'}],
1.160.6.37 raeburn 266: print => \&print_defaults,
267: modify => \&modify_defaults,
1.43 raeburn 268: },
1.30 raeburn 269: 'quotas' =>
1.160.6.20 raeburn 270: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 271: help => 'Domain_Configuration_Quotas',
1.77 raeburn 272: header => [{col1 => 'User affiliation',
1.72 raeburn 273: col2 => 'Available tools',
1.160.6.28 raeburn 274: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 275: print => \&print_quotas,
276: modify => \&modify_quotas,
1.30 raeburn 277: },
278: 'autoenroll' =>
279: { text => 'Auto-enrollment settings',
1.67 raeburn 280: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 281: header => [{col1 => 'Configuration setting',
282: col2 => 'Value(s)'}],
1.160.6.37 raeburn 283: print => \&print_autoenroll,
284: modify => \&modify_autoenroll,
1.30 raeburn 285: },
286: 'autoupdate' =>
287: { text => 'Auto-update settings',
1.67 raeburn 288: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 289: header => [{col1 => 'Setting',
290: col2 => 'Value',},
1.131 raeburn 291: {col1 => 'Setting',
292: col2 => 'Affiliation'},
1.43 raeburn 293: {col1 => 'User population',
1.160.6.35 raeburn 294: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 295: print => \&print_autoupdate,
296: modify => \&modify_autoupdate,
1.30 raeburn 297: },
1.125 raeburn 298: 'autocreate' =>
299: { text => 'Auto-course creation settings',
300: help => 'Domain_Configuration_Auto_Creation',
301: header => [{col1 => 'Configuration Setting',
302: col2 => 'Value',}],
1.160.6.37 raeburn 303: print => \&print_autocreate,
304: modify => \&modify_autocreate,
1.125 raeburn 305: },
1.30 raeburn 306: 'directorysrch' =>
307: { text => 'Institutional directory searches',
1.67 raeburn 308: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 309: header => [{col1 => 'Setting',
310: col2 => 'Value',}],
1.160.6.37 raeburn 311: print => \&print_directorysrch,
312: modify => \&modify_directorysrch,
1.30 raeburn 313: },
314: 'contacts' =>
315: { text => 'Contact Information',
1.67 raeburn 316: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 317: header => [{col1 => 'Setting',
318: col2 => 'Value',}],
1.160.6.37 raeburn 319: print => \&print_contacts,
320: modify => \&modify_contacts,
1.30 raeburn 321: },
322: 'usercreation' =>
323: { text => 'User creation',
1.67 raeburn 324: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 325: header => [{col1 => 'Format rule type',
326: col2 => 'Format rules in force'},
1.34 raeburn 327: {col1 => 'User account creation',
328: col2 => 'Usernames which may be created',},
1.30 raeburn 329: {col1 => 'Context',
1.43 raeburn 330: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 331: print => \&print_usercreation,
332: modify => \&modify_usercreation,
1.30 raeburn 333: },
1.160.6.34 raeburn 334: 'selfcreation' =>
335: { text => 'Users self-creating accounts',
336: help => 'Domain_Configuration_Self_Creation',
337: header => [{col1 => 'Self-creation with institutional username',
338: col2 => 'Enabled?'},
339: {col1 => 'Institutional user type (login/SSO self-creation)',
340: col2 => 'Information user can enter'},
341: {col1 => 'Self-creation with e-mail as username',
342: col2 => 'Settings'}],
1.160.6.37 raeburn 343: print => \&print_selfcreation,
344: modify => \&modify_selfcreation,
1.160.6.34 raeburn 345: },
1.69 raeburn 346: 'usermodification' =>
1.33 raeburn 347: { text => 'User modification',
1.67 raeburn 348: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 349: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 350: col2 => 'User information updatable in author context'},
1.33 raeburn 351: {col1 => 'Target user has role',
1.160.6.35 raeburn 352: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 353: print => \&print_usermodification,
354: modify => \&modify_usermodification,
1.33 raeburn 355: },
1.69 raeburn 356: 'scantron' =>
1.95 www 357: { text => 'Bubblesheet format file',
1.67 raeburn 358: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 359: header => [ {col1 => 'Item',
360: col2 => '',
361: }],
1.160.6.37 raeburn 362: print => \&print_scantron,
363: modify => \&modify_scantron,
1.46 raeburn 364: },
1.86 raeburn 365: 'requestcourses' =>
366: {text => 'Request creation of courses',
367: help => 'Domain_Configuration_Request_Courses',
368: header => [{col1 => 'User affiliation',
1.102 raeburn 369: col2 => 'Availability/Processing of requests',},
370: {col1 => 'Setting',
1.160.6.30 raeburn 371: col2 => 'Value'},
372: {col1 => 'Available textbooks',
1.160.6.39 raeburn 373: col2 => ''},
1.160.6.46 raeburn 374: {col1 => 'Available templates',
375: col2 => ''},
1.160.6.39 raeburn 376: {col1 => 'Validation (not official courses)',
377: col2 => 'Value'},],
1.160.6.37 raeburn 378: print => \&print_quotas,
379: modify => \&modify_quotas,
1.86 raeburn 380: },
1.160.6.5 raeburn 381: 'requestauthor' =>
1.160.6.34 raeburn 382: {text => 'Request Authoring Space',
1.160.6.5 raeburn 383: help => 'Domain_Configuration_Request_Author',
384: header => [{col1 => 'User affiliation',
385: col2 => 'Availability/Processing of requests',},
386: {col1 => 'Setting',
387: col2 => 'Value'}],
1.160.6.37 raeburn 388: print => \&print_quotas,
389: modify => \&modify_quotas,
1.160.6.5 raeburn 390: },
1.69 raeburn 391: 'coursecategories' =>
1.120 raeburn 392: { text => 'Cataloging of courses/communities',
1.67 raeburn 393: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 394: header => [{col1 => 'Catalog type/availability',
395: col2 => '',},
396: {col1 => 'Category settings for standard catalog',
1.57 raeburn 397: col2 => '',},
398: {col1 => 'Categories',
399: col2 => '',
400: }],
1.160.6.37 raeburn 401: print => \&print_coursecategories,
402: modify => \&modify_coursecategories,
1.69 raeburn 403: },
404: 'serverstatuses' =>
1.77 raeburn 405: {text => 'Access to server status pages',
1.69 raeburn 406: help => 'Domain_Configuration_Server_Status',
407: header => [{col1 => 'Status Page',
408: col2 => 'Other named users',
409: col3 => 'Specific IPs',
410: }],
1.160.6.37 raeburn 411: print => \&print_serverstatuses,
412: modify => \&modify_serverstatuses,
1.69 raeburn 413: },
1.160.6.39 raeburn 414: 'coursedefaults' =>
1.160.6.16 raeburn 415: {text => 'Course/Community defaults',
416: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57! raeburn 417: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
! 418: col2 => 'Value',},
! 419: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 420: col2 => 'Value',},],
1.160.6.37 raeburn 421: print => \&print_coursedefaults,
422: modify => \&modify_coursedefaults,
423: },
1.160.6.39 raeburn 424: 'selfenrollment' =>
1.160.6.37 raeburn 425: {text => 'Self-enrollment in Course/Community',
426: help => 'Domain_Configuration_Selfenrollment',
427: header => [{col1 => 'Configuration Rights',
428: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
429: {col1 => 'Defaults',
430: col2 => 'Value'},
431: {col1 => 'Self-enrollment validation (optional)',
432: col2 => 'Value'},],
433: print => \&print_selfenrollment,
434: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 435: },
1.141 raeburn 436: 'usersessions' =>
1.145 raeburn 437: {text => 'User session hosting/offloading',
1.137 raeburn 438: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 439: header => [{col1 => 'Domain server',
440: col2 => 'Servers to offload sessions to when busy'},
441: {col1 => 'Hosting of users from other domains',
1.137 raeburn 442: col2 => 'Rules'},
443: {col1 => "Hosting domain's own users elsewhere",
444: col2 => 'Rules'}],
1.160.6.37 raeburn 445: print => \&print_usersessions,
446: modify => \&modify_usersessions,
1.137 raeburn 447: },
1.150 raeburn 448: 'loadbalancing' =>
1.160.6.7 raeburn 449: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 450: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 451: header => [{col1 => 'Balancers',
1.150 raeburn 452: col2 => 'Default destinations',
1.160.6.13 raeburn 453: col3 => 'User affiliation',
1.150 raeburn 454: col4 => 'Overrides'},
455: ],
1.160.6.37 raeburn 456: print => \&print_loadbalancing,
457: modify => \&modify_loadbalancing,
1.150 raeburn 458: },
1.3 raeburn 459: );
1.110 raeburn 460: if (keys(%servers) > 1) {
461: $prefs{'login'} = { text => 'Log-in page options',
462: help => 'Domain_Configuration_Login_Page',
463: header => [{col1 => 'Log-in Service',
464: col2 => 'Server Setting',},
465: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 466: col2 => ''},
467: {col1 => 'Log-in Help',
1.160.6.56 raeburn 468: col2 => 'Value'},
469: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 470: col2 => 'Value'}],
1.160.6.37 raeburn 471: print => \&print_login,
472: modify => \&modify_login,
1.110 raeburn 473: };
474: }
1.160.6.13 raeburn 475:
1.6 raeburn 476: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 477: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 478: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 479: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 480: text=>"Settings to display/modify"});
1.9 raeburn 481: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 482:
1.3 raeburn 483: if ($phase eq 'process') {
1.160.6.27 raeburn 484: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
485: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 486: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 487: $r->rflush();
1.160.6.27 raeburn 488: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 489: }
1.30 raeburn 490: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 491: my $js = &recaptcha_js().
1.160.6.40 raeburn 492: &toggle_display_js();
1.160.6.7 raeburn 493: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 494: my ($othertitle,$usertypes,$types) =
495: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 496: $js .= &lonbalance_targets_js($dom,$types,\%servers,
497: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 498: &new_spares_js().
499: &common_domprefs_js().
500: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 501: }
1.160.6.30 raeburn 502: if (grep(/^requestcourses$/,@actions)) {
503: my $javascript_validations;
504: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
505: $js .= <<END;
506: <script type="text/javascript">
507: $javascript_validations
508: </script>
509: $coursebrowserjs
510: END
511: }
1.150 raeburn 512: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 513: } else {
1.160.6.11 raeburn 514: # check if domconfig user exists for the domain.
515: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 516: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 517: &config_check($dom,$confname,$servadm);
518: unless ($configuserok eq 'ok') {
519: &Apache::lonconfigsettings::print_header($r,$phase,$context);
520: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
521: $confname).
522: '<br />'
523: );
524: if ($switchserver) {
525: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
526: '<br />'.
527: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
528: '<br />'.
529: &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).
530: '<br />'.
531: &mt('To do that now, use the following link: [_1]',$switchserver)
532: );
533: } else {
534: $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.').
535: '<br />'.
536: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
537: );
538: }
539: $r->print(&Apache::loncommon::end_page());
540: return OK;
541: }
1.21 raeburn 542: if (keys(%domconfig) == 0) {
543: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 544: my @ids=&Apache::lonnet::current_machine_ids();
545: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 546: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 547: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 548: my $custom_img_count = 0;
549: foreach my $img (@loginimages) {
550: if ($designhash{$dom.'.login.'.$img} ne '') {
551: $custom_img_count ++;
552: }
553: }
554: foreach my $role (@roles) {
555: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
556: $custom_img_count ++;
557: }
558: }
559: if ($custom_img_count > 0) {
1.94 raeburn 560: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 561: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 562: $r->print(
563: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
564: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
565: &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 />'.
566: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
567: if ($switch_server) {
1.30 raeburn 568: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 569: }
1.91 raeburn 570: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 571: return OK;
572: }
573: }
574: }
1.91 raeburn 575: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 576: }
577: return OK;
578: }
579:
580: sub process_changes {
1.160.6.24 raeburn 581: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 582: my %domconfig;
583: if (ref($values) eq 'HASH') {
584: %domconfig = %{$values};
585: }
1.3 raeburn 586: my $output;
587: if ($action eq 'login') {
1.160.6.24 raeburn 588: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 589: } elsif ($action eq 'rolecolors') {
1.9 raeburn 590: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 591: $lastactref,%domconfig);
1.3 raeburn 592: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 593: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 594: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 595: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 596: } elsif ($action eq 'autoupdate') {
597: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 598: } elsif ($action eq 'autocreate') {
599: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 600: } elsif ($action eq 'directorysrch') {
601: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 602: } elsif ($action eq 'usercreation') {
1.28 raeburn 603: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 604: } elsif ($action eq 'selfcreation') {
605: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 606: } elsif ($action eq 'usermodification') {
607: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 608: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 609: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 610: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 611: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 612: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 613: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 614: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 615: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 616: } elsif ($action eq 'serverstatuses') {
617: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 618: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 619: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 620: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 621: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.16 raeburn 622: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 623: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 624: } elsif ($action eq 'selfenrollment') {
625: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 626: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 627: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 628: } elsif ($action eq 'loadbalancing') {
629: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 630: }
631: return $output;
632: }
633:
634: sub print_config_box {
1.9 raeburn 635: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 636: my $rowtotal = 0;
1.49 raeburn 637: my $output;
638: if ($action eq 'coursecategories') {
639: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 640: } elsif ($action eq 'defaults') {
641: $output = &defaults_javascript($settings);
1.91 raeburn 642: }
1.160.6.40 raeburn 643: $output .=
1.30 raeburn 644: '<table class="LC_nested_outer">
1.3 raeburn 645: <tr>
1.66 raeburn 646: <th align="left" valign="middle"><span class="LC_nobreak">'.
647: &mt($item->{text}).' '.
648: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
649: '</tr>';
1.30 raeburn 650: $rowtotal ++;
1.110 raeburn 651: my $numheaders = 1;
652: if (ref($item->{'header'}) eq 'ARRAY') {
653: $numheaders = scalar(@{$item->{'header'}});
654: }
655: if ($numheaders > 1) {
1.64 raeburn 656: my $colspan = '';
1.145 raeburn 657: my $rightcolspan = '';
1.160.6.42 raeburn 658: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.56 raeburn 659: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 660: $colspan = ' colspan="2"';
661: }
1.145 raeburn 662: if ($action eq 'usersessions') {
663: $rightcolspan = ' colspan="3"';
664: }
1.30 raeburn 665: $output .= '
1.3 raeburn 666: <tr>
667: <td>
668: <table class="LC_nested">
669: <tr class="LC_info_row">
1.59 bisitz 670: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 671: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 672: </tr>';
1.69 raeburn 673: $rowtotal ++;
1.160.6.37 raeburn 674: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57! raeburn 675: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.40 raeburn 676: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
1.160.6.37 raeburn 677: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 678: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 679: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 680: } elsif ($action eq 'login') {
1.160.6.56 raeburn 681: if ($numheaders == 4) {
1.160.6.5 raeburn 682: $colspan = ' colspan="2"';
683: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
684: } else {
685: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
686: }
1.160.6.37 raeburn 687: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 688: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 689: } elsif ($action eq 'rolecolors') {
1.30 raeburn 690: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 691: }
1.30 raeburn 692: $output .= '
1.6 raeburn 693: </table>
694: </td>
695: </tr>
696: <tr>
697: <td>
698: <table class="LC_nested">
699: <tr class="LC_info_row">
1.160.6.37 raeburn 700: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 701: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 702: </tr>';
703: $rowtotal ++;
1.160.6.37 raeburn 704: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
705: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.42 raeburn 706: ($action eq 'usersessions') || ($action eq 'coursecategories')) {
707: if ($action eq 'coursecategories') {
708: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
709: $colspan = ' colspan="2"';
710: } else {
711: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
712: }
713: $output .= '
1.63 raeburn 714: </table>
715: </td>
716: </tr>
717: <tr>
718: <td>
719: <table class="LC_nested">
720: <tr class="LC_info_row">
721: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 722: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 723: </tr>'."\n";
724: if ($action eq 'coursecategories') {
725: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
726: } else {
727: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
728: }
1.63 raeburn 729: $rowtotal ++;
1.160.6.57! raeburn 730: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
! 731: ($action eq 'defaults')) {
1.160.6.37 raeburn 732: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 733: } elsif ($action eq 'login') {
1.160.6.56 raeburn 734: if ($numheaders == 4) {
1.160.6.5 raeburn 735: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
736: </table>
737: </td>
738: </tr>
739: <tr>
740: <td>
741: <table class="LC_nested">
742: <tr class="LC_info_row">
743: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 744: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 745: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
746: $rowtotal ++;
747: } else {
748: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
749: }
1.160.6.56 raeburn 750: $output .= '
751: </table>
752: </td>
753: </tr>
754: <tr>
755: <td>
756: <table class="LC_nested">
757: <tr class="LC_info_row">';
758: if ($numheaders == 4) {
759: $output .= '
760: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
761: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
762: </tr>';
763: } else {
764: $output .= '
765: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
766: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
767: </tr>';
768: }
769: $rowtotal ++;
770: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 771: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 772: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
773: $rowtotal ++;
774: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 775: </table>
776: </td>
777: </tr>
778: <tr>
779: <td>
780: <table class="LC_nested">
781: <tr class="LC_info_row">
782: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
783: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 784: &textbookcourses_javascript($settings).
785: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
786: </table>
787: </td>
788: </tr>
789: <tr>
790: <td>
791: <table class="LC_nested">
792: <tr class="LC_info_row">
793: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
794: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
795: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 796: </table>
797: </td>
798: </tr>
799: <tr>
800: <td>
801: <table class="LC_nested">
802: <tr class="LC_info_row">
1.160.6.46 raeburn 803: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
804: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 805: </tr>'.
806: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 807: } elsif ($action eq 'requestauthor') {
808: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 809: $rowtotal ++;
1.122 jms 810: } elsif ($action eq 'rolecolors') {
1.30 raeburn 811: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 812: </table>
813: </td>
814: </tr>
815: <tr>
816: <td>
817: <table class="LC_nested">
818: <tr class="LC_info_row">
1.69 raeburn 819: <td class="LC_left_item"'.$colspan.' valign="top">'.
820: &mt($item->{'header'}->[2]->{'col1'}).'</td>
821: <td class="LC_right_item" valign="top">'.
822: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 823: </tr>'.
1.30 raeburn 824: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 825: </table>
826: </td>
827: </tr>
828: <tr>
829: <td>
830: <table class="LC_nested">
831: <tr class="LC_info_row">
1.59 bisitz 832: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
833: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 834: </tr>'.
1.30 raeburn 835: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
836: $rowtotal += 2;
1.6 raeburn 837: }
1.3 raeburn 838: } else {
1.30 raeburn 839: $output .= '
1.3 raeburn 840: <tr>
841: <td>
842: <table class="LC_nested">
1.30 raeburn 843: <tr class="LC_info_row">';
1.24 raeburn 844: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 845: $output .= '
1.59 bisitz 846: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 847: } elsif ($action eq 'serverstatuses') {
848: $output .= '
849: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
850: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
851:
1.6 raeburn 852: } else {
1.30 raeburn 853: $output .= '
1.69 raeburn 854: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
855: }
1.72 raeburn 856: if (defined($item->{'header'}->[0]->{'col3'})) {
857: $output .= '<td class="LC_left_item" valign="top">'.
858: &mt($item->{'header'}->[0]->{'col2'});
859: if ($action eq 'serverstatuses') {
860: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
861: }
1.69 raeburn 862: } else {
863: $output .= '<td class="LC_right_item" valign="top">'.
864: &mt($item->{'header'}->[0]->{'col2'});
865: }
866: $output .= '</td>';
867: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 868: if (defined($item->{'header'}->[0]->{'col4'})) {
869: $output .= '<td class="LC_left_item" valign="top">'.
870: &mt($item->{'header'}->[0]->{'col3'});
871: } else {
872: $output .= '<td class="LC_right_item" valign="top">'.
873: &mt($item->{'header'}->[0]->{'col3'});
874: }
1.69 raeburn 875: if ($action eq 'serverstatuses') {
876: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
877: }
878: $output .= '</td>';
1.6 raeburn 879: }
1.150 raeburn 880: if ($item->{'header'}->[0]->{'col4'}) {
881: $output .= '<td class="LC_right_item" valign="top">'.
882: &mt($item->{'header'}->[0]->{'col4'});
883: }
1.69 raeburn 884: $output .= '</tr>';
1.48 raeburn 885: $rowtotal ++;
1.160.6.5 raeburn 886: if ($action eq 'quotas') {
1.86 raeburn 887: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.37 raeburn 888: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
1.160.6.40 raeburn 889: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.160.6.37 raeburn 890: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 891: } elsif ($action eq 'scantron') {
892: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 893: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 894: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.160.6.49 raeburn 895: } elsif ($action eq 'coursedefaults') {
896: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.121 raeburn 897: }
1.3 raeburn 898: }
1.30 raeburn 899: $output .= '
1.3 raeburn 900: </table>
901: </td>
902: </tr>
1.30 raeburn 903: </table><br />';
904: return ($output,$rowtotal);
1.1 raeburn 905: }
906:
1.3 raeburn 907: sub print_login {
1.160.6.5 raeburn 908: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 909: my ($css_class,$datatable);
1.6 raeburn 910: my %choices = &login_choices();
1.110 raeburn 911:
1.160.6.5 raeburn 912: if ($caller eq 'service') {
1.149 raeburn 913: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 914: my $choice = $choices{'disallowlogin'};
915: $css_class = ' class="LC_odd_row"';
1.128 raeburn 916: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 917: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 918: '<th>'.$choices{'server'}.'</th>'.
919: '<th>'.$choices{'serverpath'}.'</th>'.
920: '<th>'.$choices{'custompath'}.'</th>'.
921: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 922: my %disallowed;
923: if (ref($settings) eq 'HASH') {
924: if (ref($settings->{'loginvia'}) eq 'HASH') {
925: %disallowed = %{$settings->{'loginvia'}};
926: }
927: }
928: foreach my $lonhost (sort(keys(%servers))) {
929: my $direct = 'selected="selected"';
1.128 raeburn 930: if (ref($disallowed{$lonhost}) eq 'HASH') {
931: if ($disallowed{$lonhost}{'server'} ne '') {
932: $direct = '';
933: }
1.110 raeburn 934: }
1.115 raeburn 935: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 936: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 937: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
938: '</option>';
1.160.6.13 raeburn 939: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 940: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 941: my $selected = '';
1.128 raeburn 942: if (ref($disallowed{$lonhost}) eq 'HASH') {
943: if ($hostid eq $disallowed{$lonhost}{'server'}) {
944: $selected = 'selected="selected"';
945: }
1.110 raeburn 946: }
947: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
948: $servers{$hostid}.'</option>';
949: }
1.128 raeburn 950: $datatable .= '</select></td>'.
951: '<td><select name="'.$lonhost.'_serverpath">';
952: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
953: my $pathname = $path;
954: if ($path eq 'custom') {
955: $pathname = &mt('Custom Path').' ->';
956: }
957: my $selected = '';
958: if (ref($disallowed{$lonhost}) eq 'HASH') {
959: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
960: $selected = 'selected="selected"';
961: }
962: } elsif ($path eq '') {
963: $selected = 'selected="selected"';
964: }
965: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
966: }
967: $datatable .= '</select></td>';
968: my ($custom,$exempt);
969: if (ref($disallowed{$lonhost}) eq 'HASH') {
970: $custom = $disallowed{$lonhost}{'custompath'};
971: $exempt = $disallowed{$lonhost}{'exempt'};
972: }
973: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
974: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
975: '</tr>';
1.110 raeburn 976: }
977: $datatable .= '</table></td></tr>';
978: return $datatable;
1.160.6.5 raeburn 979: } elsif ($caller eq 'page') {
980: my %defaultchecked = (
981: 'coursecatalog' => 'on',
1.160.6.14 raeburn 982: 'helpdesk' => 'on',
1.160.6.5 raeburn 983: 'adminmail' => 'off',
984: 'newuser' => 'off',
985: );
1.160.6.14 raeburn 986: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 987: my (%checkedon,%checkedoff);
1.42 raeburn 988: foreach my $item (@toggles) {
1.160.6.5 raeburn 989: if ($defaultchecked{$item} eq 'on') {
990: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 991: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 992: } elsif ($defaultchecked{$item} eq 'off') {
993: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 994: $checkedon{$item} = ' ';
995: }
1.1 raeburn 996: }
1.160.6.5 raeburn 997: my @images = ('img','logo','domlogo','login');
998: my @logintext = ('textcol','bgcol');
999: my @bgs = ('pgbg','mainbg','sidebg');
1000: my @links = ('link','alink','vlink');
1001: my %designhash = &Apache::loncommon::get_domainconf($dom);
1002: my %defaultdesign = %Apache::loncommon::defaultdesign;
1003: my (%is_custom,%designs);
1004: my %defaults = (
1005: font => $defaultdesign{'login.font'},
1006: );
1.6 raeburn 1007: foreach my $item (@images) {
1.160.6.5 raeburn 1008: $defaults{$item} = $defaultdesign{'login.'.$item};
1009: $defaults{'showlogo'}{$item} = 1;
1010: }
1011: foreach my $item (@bgs) {
1012: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1013: }
1.41 raeburn 1014: foreach my $item (@logintext) {
1.160.6.5 raeburn 1015: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1016: }
1.160.6.5 raeburn 1017: foreach my $item (@links) {
1018: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1019: }
1.160.6.5 raeburn 1020: if (ref($settings) eq 'HASH') {
1021: foreach my $item (@toggles) {
1022: if ($settings->{$item} eq '1') {
1023: $checkedon{$item} = ' checked="checked" ';
1024: $checkedoff{$item} = ' ';
1025: } elsif ($settings->{$item} eq '0') {
1026: $checkedoff{$item} = ' checked="checked" ';
1027: $checkedon{$item} = ' ';
1028: }
1.6 raeburn 1029: }
1.160.6.5 raeburn 1030: foreach my $item (@images) {
1031: if (defined($settings->{$item})) {
1032: $designs{$item} = $settings->{$item};
1033: $is_custom{$item} = 1;
1034: }
1035: if (defined($settings->{'showlogo'}{$item})) {
1036: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1037: }
1038: }
1039: foreach my $item (@logintext) {
1040: if ($settings->{$item} ne '') {
1041: $designs{'logintext'}{$item} = $settings->{$item};
1042: $is_custom{$item} = 1;
1043: }
1044: }
1045: if ($settings->{'font'} ne '') {
1046: $designs{'font'} = $settings->{'font'};
1047: $is_custom{'font'} = 1;
1048: }
1049: foreach my $item (@bgs) {
1050: if ($settings->{$item} ne '') {
1051: $designs{'bgs'}{$item} = $settings->{$item};
1052: $is_custom{$item} = 1;
1053: }
1054: }
1055: foreach my $item (@links) {
1056: if ($settings->{$item} ne '') {
1057: $designs{'links'}{$item} = $settings->{$item};
1058: $is_custom{$item} = 1;
1059: }
1060: }
1061: } else {
1062: if ($designhash{$dom.'.login.font'} ne '') {
1063: $designs{'font'} = $designhash{$dom.'.login.font'};
1064: $is_custom{'font'} = 1;
1065: }
1066: foreach my $item (@images) {
1067: if ($designhash{$dom.'.login.'.$item} ne '') {
1068: $designs{$item} = $designhash{$dom.'.login.'.$item};
1069: $is_custom{$item} = 1;
1070: }
1071: }
1072: foreach my $item (@bgs) {
1073: if ($designhash{$dom.'.login.'.$item} ne '') {
1074: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1075: $is_custom{$item} = 1;
1076: }
1077: }
1078: foreach my $item (@links) {
1079: if ($designhash{$dom.'.login.'.$item} ne '') {
1080: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1081: $is_custom{$item} = 1;
1082: }
1.6 raeburn 1083: }
1084: }
1.160.6.5 raeburn 1085: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1086: logo => 'Institution Logo',
1087: domlogo => 'Domain Logo',
1088: login => 'Login box');
1089: my $itemcount = 1;
1090: foreach my $item (@toggles) {
1091: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1092: $datatable .=
1093: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1094: '</td><td>'.
1095: '<span class="LC_nobreak"><label><input type="radio" name="'.
1096: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1097: '</label> <label><input type="radio" name="'.$item.'"'.
1098: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1099: '</tr>';
1100: $itemcount ++;
1.6 raeburn 1101: }
1.160.6.5 raeburn 1102: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1103: $datatable .= '</tr></table></td></tr>';
1104: } elsif ($caller eq 'help') {
1105: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1106: my $switchserver = &check_switchserver($dom,$confname);
1107: my $itemcount = 1;
1108: $defaulturl = '/adm/loginproblems.html';
1109: $defaulttype = 'default';
1110: %lt = &Apache::lonlocal::texthash (
1111: del => 'Delete?',
1112: rep => 'Replace:',
1113: upl => 'Upload:',
1114: default => 'Default',
1115: custom => 'Custom',
1116: );
1117: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1118: my @currlangs;
1119: if (ref($settings) eq 'HASH') {
1120: if (ref($settings->{'helpurl'}) eq 'HASH') {
1121: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1122: next if ($settings->{'helpurl'}{$key} eq '');
1123: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1124: $type{$key} = 'custom';
1125: unless ($key eq 'nolang') {
1126: push(@currlangs,$key);
1127: }
1128: }
1129: } elsif ($settings->{'helpurl'} ne '') {
1130: $type{'nolang'} = 'custom';
1131: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1132: }
1133: }
1.160.6.5 raeburn 1134: foreach my $lang ('nolang',sort(@currlangs)) {
1135: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1136: $datatable .= '<tr'.$css_class.'>';
1137: if ($url{$lang} eq '') {
1138: $url{$lang} = $defaulturl;
1139: }
1140: if ($type{$lang} eq '') {
1141: $type{$lang} = $defaulttype;
1142: }
1143: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1144: if ($lang eq 'nolang') {
1145: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1146: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1147: } else {
1148: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1149: $langchoices{$lang},
1150: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1151: }
1152: $datatable .= '</span></td>'."\n".
1153: '<td class="LC_left_item">';
1154: if ($type{$lang} eq 'custom') {
1155: $datatable .= '<span class="LC_nobreak"><label>'.
1156: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1157: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1158: } else {
1159: $datatable .= $lt{'upl'};
1160: }
1161: $datatable .='<br />';
1162: if ($switchserver) {
1163: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1164: } else {
1165: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1166: }
1.160.6.5 raeburn 1167: $datatable .= '</td></tr>';
1168: $itemcount ++;
1.6 raeburn 1169: }
1.160.6.5 raeburn 1170: my @addlangs;
1171: foreach my $lang (sort(keys(%langchoices))) {
1172: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1173: push(@addlangs,$lang);
1174: }
1175: if (@addlangs > 0) {
1176: my %toadd;
1177: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1178: $toadd{''} = &mt('Select');
1179: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1180: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1181: &mt('Add log-in help page for a specific language:').' '.
1182: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1183: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1184: if ($switchserver) {
1185: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1186: } else {
1187: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1188: }
1.160.6.5 raeburn 1189: $datatable .= '</td></tr>';
1190: $itemcount ++;
1.6 raeburn 1191: }
1.160.6.5 raeburn 1192: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1193: } elsif ($caller eq 'headtag') {
1194: my %domservers = &Apache::lonnet::get_servers($dom);
1195: my $choice = $choices{'headtag'};
1196: $css_class = ' class="LC_odd_row"';
1197: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1198: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1199: '<th>'.$choices{'current'}.'</th>'.
1200: '<th>'.$choices{'action'}.'</th>'.
1201: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1202: my (%currurls,%currexempt);
1203: if (ref($settings) eq 'HASH') {
1204: if (ref($settings->{'headtag'}) eq 'HASH') {
1205: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1206: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1207: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1208: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1209: }
1210: }
1211: }
1212: }
1213: my %lt = &Apache::lonlocal::texthash(
1214: del => 'Delete?',
1215: rep => 'Replace:',
1216: upl => 'Upload:',
1217: curr => 'View contents',
1218: none => 'None',
1219: );
1220: my $switchserver = &check_switchserver($dom,$confname);
1221: foreach my $lonhost (sort(keys(%domservers))) {
1222: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1223: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1224: if ($currurls{$lonhost}) {
1225: $datatable .= '<td class="LC_right_item"><a href="'.
1226: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1227: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1228: '">'.$lt{'curr'}.'</a></td>'.
1229: '<td><span class="LC_nobreak"><label>'.
1230: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1231: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1232: } else {
1233: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1234: }
1235: $datatable .='<br />';
1236: if ($switchserver) {
1237: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1238: } else {
1239: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1240: }
1241: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1242: }
1243: $datatable .= '</table></td></tr>';
1.1 raeburn 1244: }
1.6 raeburn 1245: return $datatable;
1246: }
1247:
1248: sub login_choices {
1249: my %choices =
1250: &Apache::lonlocal::texthash (
1.116 bisitz 1251: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1252: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1253: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1254: disallowlogin => "Login page requests redirected",
1255: hostid => "Server",
1.128 raeburn 1256: server => "Redirect to:",
1257: serverpath => "Path",
1258: custompath => "Custom",
1259: exempt => "Exempt IP(s)",
1.110 raeburn 1260: directlogin => "No redirect",
1261: newuser => "Link to create a user account",
1262: img => "Header",
1263: logo => "Main Logo",
1264: domlogo => "Domain Logo",
1265: login => "Log-in Header",
1266: textcol => "Text color",
1267: bgcol => "Box color",
1268: bgs => "Background colors",
1269: links => "Link colors",
1270: font => "Font color",
1271: pgbg => "Header",
1272: mainbg => "Page",
1273: sidebg => "Login box",
1274: link => "Link",
1275: alink => "Active link",
1276: vlink => "Visited link",
1.160.6.56 raeburn 1277: headtag => "Custom markup",
1278: action => "Action",
1279: current => "Current",
1.6 raeburn 1280: );
1281: return %choices;
1282: }
1283:
1284: sub print_rolecolors {
1.30 raeburn 1285: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1286: my %choices = &color_font_choices();
1287: my @bgs = ('pgbg','tabbg','sidebg');
1288: my @links = ('link','alink','vlink');
1289: my @images = ('img');
1290: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1291: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1292: my %defaultdesign = %Apache::loncommon::defaultdesign;
1293: my (%is_custom,%designs);
1.160.6.22 raeburn 1294: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1295: if (ref($settings) eq 'HASH') {
1296: if (ref($settings->{$role}) eq 'HASH') {
1297: if ($settings->{$role}->{'img'} ne '') {
1298: $designs{'img'} = $settings->{$role}->{'img'};
1299: $is_custom{'img'} = 1;
1300: }
1301: if ($settings->{$role}->{'font'} ne '') {
1302: $designs{'font'} = $settings->{$role}->{'font'};
1303: $is_custom{'font'} = 1;
1304: }
1.97 tempelho 1305: if ($settings->{$role}->{'fontmenu'} ne '') {
1306: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1307: $is_custom{'fontmenu'} = 1;
1308: }
1.6 raeburn 1309: foreach my $item (@bgs) {
1310: if ($settings->{$role}->{$item} ne '') {
1311: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1312: $is_custom{$item} = 1;
1313: }
1314: }
1315: foreach my $item (@links) {
1316: if ($settings->{$role}->{$item} ne '') {
1317: $designs{'links'}{$item} = $settings->{$role}->{$item};
1318: $is_custom{$item} = 1;
1319: }
1320: }
1321: }
1322: } else {
1323: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1324: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1325: $is_custom{'img'} = 1;
1326: }
1.97 tempelho 1327: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1328: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1329: $is_custom{'fontmenu'} = 1;
1330: }
1.6 raeburn 1331: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1332: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1333: $is_custom{'font'} = 1;
1334: }
1335: foreach my $item (@bgs) {
1336: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1337: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1338: $is_custom{$item} = 1;
1339:
1340: }
1341: }
1342: foreach my $item (@links) {
1343: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1344: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1345: $is_custom{$item} = 1;
1346: }
1347: }
1348: }
1349: my $itemcount = 1;
1.30 raeburn 1350: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1351: $datatable .= '</tr></table></td></tr>';
1352: return $datatable;
1353: }
1354:
1.160.6.22 raeburn 1355: sub role_defaults {
1356: my ($role,$bgs,$links,$images,$logintext) = @_;
1357: my %defaults;
1358: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1359: return %defaults;
1360: }
1361: my %defaultdesign = %Apache::loncommon::defaultdesign;
1362: if ($role eq 'login') {
1363: %defaults = (
1364: font => $defaultdesign{$role.'.font'},
1365: );
1366: if (ref($logintext) eq 'ARRAY') {
1367: foreach my $item (@{$logintext}) {
1368: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1369: }
1370: }
1371: foreach my $item (@{$images}) {
1372: $defaults{'showlogo'}{$item} = 1;
1373: }
1374: } else {
1375: %defaults = (
1376: img => $defaultdesign{$role.'.img'},
1377: font => $defaultdesign{$role.'.font'},
1378: fontmenu => $defaultdesign{$role.'.fontmenu'},
1379: );
1380: }
1381: foreach my $item (@{$bgs}) {
1382: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1383: }
1384: foreach my $item (@{$links}) {
1385: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1386: }
1387: foreach my $item (@{$images}) {
1388: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1389: }
1390: return %defaults;
1391: }
1392:
1.6 raeburn 1393: sub display_color_options {
1.9 raeburn 1394: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1395: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1396: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1397: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1398: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1399: '<td>'.$choices->{'font'}.'</td>';
1400: if (!$is_custom->{'font'}) {
1.30 raeburn 1401: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1402: } else {
1403: $datatable .= '<td> </td>';
1404: }
1.160.6.9 raeburn 1405: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1406:
1.8 raeburn 1407: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1408: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1409: ' value="'.$current_color.'" /> '.
1410: ' </td></tr>';
1.107 raeburn 1411: unless ($role eq 'login') {
1412: $datatable .= '<tr'.$css_class.'>'.
1413: '<td>'.$choices->{'fontmenu'}.'</td>';
1414: if (!$is_custom->{'fontmenu'}) {
1415: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1416: } else {
1417: $datatable .= '<td> </td>';
1418: }
1.160.6.22 raeburn 1419: $current_color = $designs->{'fontmenu'} ?
1420: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1421: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1422: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1423: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1424: ' value="'.$current_color.'" /> '.
1425: ' </td></tr>';
1.97 tempelho 1426: }
1.9 raeburn 1427: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1428: foreach my $img (@{$images}) {
1.18 albertel 1429: $itemcount ++;
1.6 raeburn 1430: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1431: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1432: '<td>'.$choices->{$img};
1.41 raeburn 1433: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1434: if ($role eq 'login') {
1435: if ($img eq 'login') {
1436: $login_hdr_pick =
1.135 bisitz 1437: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1438: $logincolors =
1439: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1440: $designs,$defaults);
1.70 raeburn 1441: } elsif ($img ne 'domlogo') {
1442: $datatable.= &logo_display_options($img,$defaults,$designs);
1443: }
1444: }
1445: $datatable .= '</td>';
1.6 raeburn 1446: if ($designs->{$img} ne '') {
1447: $imgfile = $designs->{$img};
1.18 albertel 1448: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1449: } else {
1450: $imgfile = $defaults->{$img};
1451: }
1452: if ($imgfile) {
1.9 raeburn 1453: my ($showfile,$fullsize);
1454: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1455: my $urldir = $1;
1456: my $filename = $2;
1457: my @info = &Apache::lonnet::stat_file($designs->{$img});
1458: if (@info) {
1459: my $thumbfile = 'tn-'.$filename;
1460: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1461: if (@thumb) {
1462: $showfile = $urldir.'/'.$thumbfile;
1463: } else {
1464: $showfile = $imgfile;
1465: }
1466: } else {
1467: $showfile = '';
1468: }
1469: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1470: $showfile = $imgfile;
1.6 raeburn 1471: my $imgdir = $1;
1472: my $filename = $2;
1.159 raeburn 1473: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1474: $showfile = "/$imgdir/tn-".$filename;
1475: } else {
1.159 raeburn 1476: my $input = $londocroot.$imgfile;
1477: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1478: if (!-e $output) {
1.9 raeburn 1479: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1480: my ($fullwidth,$fullheight) = &check_dimensions($input);
1481: if ($fullwidth ne '' && $fullheight ne '') {
1482: if ($fullwidth > $width && $fullheight > $height) {
1483: my $size = $width.'x'.$height;
1484: system("convert -sample $size $input $output");
1.159 raeburn 1485: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1486: }
1487: }
1.6 raeburn 1488: }
1489: }
1.16 raeburn 1490: }
1.6 raeburn 1491: if ($showfile) {
1.40 raeburn 1492: if ($showfile =~ m{^/(adm|res)/}) {
1493: if ($showfile =~ m{^/res/}) {
1494: my $local_showfile =
1495: &Apache::lonnet::filelocation('',$showfile);
1496: &Apache::lonnet::repcopy($local_showfile);
1497: }
1498: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1499: }
1500: if ($imgfile) {
1501: if ($imgfile =~ m{^/(adm|res)/}) {
1502: if ($imgfile =~ m{^/res/}) {
1503: my $local_imgfile =
1504: &Apache::lonnet::filelocation('',$imgfile);
1505: &Apache::lonnet::repcopy($local_imgfile);
1506: }
1507: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1508: } else {
1509: $fullsize = $imgfile;
1510: }
1511: }
1.41 raeburn 1512: $datatable .= '<td>';
1513: if ($img eq 'login') {
1.135 bisitz 1514: $datatable .= $login_hdr_pick;
1515: }
1.41 raeburn 1516: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1517: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1518: } else {
1.160.6.22 raeburn 1519: $datatable .= '<td> </td><td class="LC_left_item">'.
1520: &mt('Upload:').'<br />';
1.6 raeburn 1521: }
1522: } else {
1.160.6.22 raeburn 1523: $datatable .= '<td> </td><td class="LC_left_item">'.
1524: &mt('Upload:').'<br />';
1.6 raeburn 1525: }
1.9 raeburn 1526: if ($switchserver) {
1527: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1528: } else {
1.135 bisitz 1529: if ($img ne 'login') { # suppress file selection for Log-in header
1530: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1531: }
1.9 raeburn 1532: }
1533: $datatable .= '</td></tr>';
1.6 raeburn 1534: }
1535: $itemcount ++;
1536: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1537: $datatable .= '<tr'.$css_class.'>'.
1538: '<td>'.$choices->{'bgs'}.'</td>';
1539: my $bgs_def;
1540: foreach my $item (@{$bgs}) {
1541: if (!$is_custom->{$item}) {
1.70 raeburn 1542: $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 1543: }
1544: }
1545: if ($bgs_def) {
1.8 raeburn 1546: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1547: } else {
1548: $datatable .= '<td> </td>';
1549: }
1550: $datatable .= '<td class="LC_right_item">'.
1551: '<table border="0"><tr>';
1.160.6.13 raeburn 1552:
1.6 raeburn 1553: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1554: $datatable .= '<td align="center">'.$choices->{$item};
1555: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1556: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1557: $datatable .= ' ';
1.6 raeburn 1558: }
1.160.6.9 raeburn 1559: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1560: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1561: }
1562: $datatable .= '</tr></table></td></tr>';
1563: $itemcount ++;
1564: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1565: $datatable .= '<tr'.$css_class.'>'.
1566: '<td>'.$choices->{'links'}.'</td>';
1567: my $links_def;
1568: foreach my $item (@{$links}) {
1569: if (!$is_custom->{$item}) {
1.30 raeburn 1570: $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 1571: }
1572: }
1573: if ($links_def) {
1.8 raeburn 1574: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1575: } else {
1576: $datatable .= '<td> </td>';
1577: }
1578: $datatable .= '<td class="LC_right_item">'.
1579: '<table border="0"><tr>';
1580: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1581: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1582: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1583: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1584: $datatable.=' ';
1.6 raeburn 1585: }
1.160.6.9 raeburn 1586: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1587: '" /></td>';
1588: }
1.30 raeburn 1589: $$rowtotal += $itemcount;
1.3 raeburn 1590: return $datatable;
1591: }
1592:
1.70 raeburn 1593: sub logo_display_options {
1594: my ($img,$defaults,$designs) = @_;
1595: my $checkedon;
1596: if (ref($defaults) eq 'HASH') {
1597: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1598: if ($defaults->{'showlogo'}{$img}) {
1599: $checkedon = 'checked="checked" ';
1600: }
1601: }
1602: }
1603: if (ref($designs) eq 'HASH') {
1604: if (ref($designs->{'showlogo'}) eq 'HASH') {
1605: if (defined($designs->{'showlogo'}{$img})) {
1606: if ($designs->{'showlogo'}{$img} == 0) {
1607: $checkedon = '';
1608: } elsif ($designs->{'showlogo'}{$img} == 1) {
1609: $checkedon = 'checked="checked" ';
1610: }
1611: }
1612: }
1613: }
1614: return '<br /><label> <input type="checkbox" name="'.
1615: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1616: &mt('show').'</label>'."\n";
1617: }
1618:
1.41 raeburn 1619: sub login_header_options {
1.135 bisitz 1620: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1621: my $output = '';
1.41 raeburn 1622: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1623: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1624: if (!$is_custom->{'textcol'}) {
1625: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1626: ' ';
1627: }
1628: if (!$is_custom->{'bgcol'}) {
1629: $output .= $choices->{'bgcol'}.': '.
1630: '<span id="css_'.$role.'_font" style="background-color: '.
1631: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1632: }
1633: $output .= '<br />';
1634: }
1635: $output .='<br />';
1636: return $output;
1637: }
1638:
1639: sub login_text_colors {
1.160.6.22 raeburn 1640: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1641: my $color_menu = '<table border="0"><tr>';
1642: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1643: $color_menu .= '<td align="center">'.$choices->{$item};
1644: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1645: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1646: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1647: }
1648: $color_menu .= '</tr></table><br />';
1649: return $color_menu;
1650: }
1651:
1652: sub image_changes {
1653: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1654: my $output;
1.135 bisitz 1655: if ($img eq 'login') {
1656: # suppress image for Log-in header
1657: } elsif (!$is_custom) {
1.70 raeburn 1658: if ($img ne 'domlogo') {
1.41 raeburn 1659: $output .= &mt('Default image:').'<br />';
1660: } else {
1661: $output .= &mt('Default in use:').'<br />';
1662: }
1663: }
1.135 bisitz 1664: if ($img eq 'login') { # suppress image for Log-in header
1665: $output .= '<td>'.$logincolors;
1.41 raeburn 1666: } else {
1.135 bisitz 1667: if ($img_import) {
1668: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1669: }
1670: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1671: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1672: if ($is_custom) {
1673: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1674: '<input type="checkbox" name="'.
1675: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1676: '</label> '.&mt('Replace:').'</span><br />';
1677: } else {
1.160.6.22 raeburn 1678: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1679: }
1.41 raeburn 1680: }
1681: return $output;
1682: }
1683:
1.3 raeburn 1684: sub print_quotas {
1.86 raeburn 1685: my ($dom,$settings,$rowtotal,$action) = @_;
1686: my $context;
1687: if ($action eq 'quotas') {
1688: $context = 'tools';
1689: } else {
1690: $context = $action;
1691: }
1.160.6.20 raeburn 1692: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1693: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1694: my $typecount = 0;
1.101 raeburn 1695: my ($css_class,%titles);
1.86 raeburn 1696: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1697: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1698: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1699: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1700: %titles = &courserequest_titles();
1.160.6.5 raeburn 1701: } elsif ($context eq 'requestauthor') {
1702: @usertools = ('author');
1703: @options = ('norequest','approval','automatic');
1704: %titles = &authorrequest_titles();
1.86 raeburn 1705: } else {
1.160.6.4 raeburn 1706: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1707: %titles = &tool_titles();
1.86 raeburn 1708: }
1.26 raeburn 1709: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1710: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1711: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1712: unless (($context eq 'requestcourses') ||
1713: ($context eq 'requestauthor')) {
1.86 raeburn 1714: if (ref($settings) eq 'HASH') {
1715: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1716: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1717: } else {
1718: $currdefquota = $settings->{$type};
1719: }
1.160.6.20 raeburn 1720: if (ref($settings->{authorquota}) eq 'HASH') {
1721: $currauthorquota = $settings->{authorquota}->{$type};
1722: }
1.78 raeburn 1723: }
1.72 raeburn 1724: }
1.3 raeburn 1725: if (defined($usertypes->{$type})) {
1726: $typecount ++;
1727: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1728: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1729: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1730: '<td class="LC_left_item">';
1.101 raeburn 1731: if ($context eq 'requestcourses') {
1732: $datatable .= '<table><tr>';
1733: }
1734: my %cell;
1.72 raeburn 1735: foreach my $item (@usertools) {
1.101 raeburn 1736: if ($context eq 'requestcourses') {
1737: my ($curroption,$currlimit);
1738: if (ref($settings) eq 'HASH') {
1739: if (ref($settings->{$item}) eq 'HASH') {
1740: $curroption = $settings->{$item}->{$type};
1741: if ($curroption =~ /^autolimit=(\d*)$/) {
1742: $currlimit = $1;
1743: }
1744: }
1745: }
1746: if (!$curroption) {
1747: $curroption = 'norequest';
1748: }
1749: $datatable .= '<th>'.$titles{$item}.'</th>';
1750: foreach my $option (@options) {
1751: my $val = $option;
1752: if ($option eq 'norequest') {
1753: $val = 0;
1754: }
1755: if ($option eq 'validate') {
1756: my $canvalidate = 0;
1757: if (ref($validations{$item}) eq 'HASH') {
1758: if ($validations{$item}{$type}) {
1759: $canvalidate = 1;
1760: }
1761: }
1762: next if (!$canvalidate);
1763: }
1764: my $checked = '';
1765: if ($option eq $curroption) {
1766: $checked = ' checked="checked"';
1767: } elsif ($option eq 'autolimit') {
1768: if ($curroption =~ /^autolimit/) {
1769: $checked = ' checked="checked"';
1770: }
1771: }
1772: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1773: '<input type="radio" name="crsreq_'.$item.
1774: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1775: $titles{$option}.'</label>';
1.101 raeburn 1776: if ($option eq 'autolimit') {
1.127 raeburn 1777: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1778: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1779: 'value="'.$currlimit.'" />';
1.101 raeburn 1780: }
1.127 raeburn 1781: $cell{$item} .= '</span> ';
1.103 raeburn 1782: if ($option eq 'autolimit') {
1.127 raeburn 1783: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1784: }
1.101 raeburn 1785: }
1.160.6.5 raeburn 1786: } elsif ($context eq 'requestauthor') {
1787: my $curroption;
1788: if (ref($settings) eq 'HASH') {
1789: $curroption = $settings->{$type};
1790: }
1791: if (!$curroption) {
1792: $curroption = 'norequest';
1793: }
1794: foreach my $option (@options) {
1795: my $val = $option;
1796: if ($option eq 'norequest') {
1797: $val = 0;
1798: }
1799: my $checked = '';
1800: if ($option eq $curroption) {
1801: $checked = ' checked="checked"';
1802: }
1803: $datatable .= '<span class="LC_nobreak"><label>'.
1804: '<input type="radio" name="authorreq_'.$type.
1805: '" value="'.$val.'"'.$checked.' />'.
1806: $titles{$option}.'</label></span> ';
1807: }
1.101 raeburn 1808: } else {
1809: my $checked = 'checked="checked" ';
1810: if (ref($settings) eq 'HASH') {
1811: if (ref($settings->{$item}) eq 'HASH') {
1812: if ($settings->{$item}->{$type} == 0) {
1813: $checked = '';
1814: } elsif ($settings->{$item}->{$type} == 1) {
1815: $checked = 'checked="checked" ';
1816: }
1.78 raeburn 1817: }
1.72 raeburn 1818: }
1.101 raeburn 1819: $datatable .= '<span class="LC_nobreak"><label>'.
1820: '<input type="checkbox" name="'.$context.'_'.$item.
1821: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1822: '</label></span> ';
1.72 raeburn 1823: }
1.101 raeburn 1824: }
1825: if ($context eq 'requestcourses') {
1826: $datatable .= '</tr><tr>';
1827: foreach my $item (@usertools) {
1.106 raeburn 1828: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1829: }
1830: $datatable .= '</tr></table>';
1.72 raeburn 1831: }
1.86 raeburn 1832: $datatable .= '</td>';
1.160.6.5 raeburn 1833: unless (($context eq 'requestcourses') ||
1834: ($context eq 'requestauthor')) {
1.86 raeburn 1835: $datatable .=
1.160.6.20 raeburn 1836: '<td class="LC_right_item">'.
1837: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1838: '<input type="text" name="quota_'.$type.
1.72 raeburn 1839: '" value="'.$currdefquota.
1.160.6.20 raeburn 1840: '" size="5" /></span>'.(' ' x 2).
1841: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1842: '<input type="text" name="authorquota_'.$type.
1843: '" value="'.$currauthorquota.
1844: '" size="5" /></span></td>';
1.86 raeburn 1845: }
1846: $datatable .= '</tr>';
1.3 raeburn 1847: }
1848: }
1849: }
1.160.6.5 raeburn 1850: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1851: $defaultquota = '20';
1.160.6.20 raeburn 1852: $authorquota = '500';
1.86 raeburn 1853: if (ref($settings) eq 'HASH') {
1854: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1855: $defaultquota = $settings->{'defaultquota'}->{'default'};
1856: } elsif (defined($settings->{'default'})) {
1857: $defaultquota = $settings->{'default'};
1858: }
1.160.6.20 raeburn 1859: if (ref($settings->{'authorquota'}) eq 'HASH') {
1860: $authorquota = $settings->{'authorquota'}->{'default'};
1861: }
1.3 raeburn 1862: }
1863: }
1864: $typecount ++;
1865: $css_class = $typecount%2?' class="LC_odd_row"':'';
1866: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1867: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1868: '<td class="LC_left_item">';
1.101 raeburn 1869: if ($context eq 'requestcourses') {
1870: $datatable .= '<table><tr>';
1871: }
1872: my %defcell;
1.72 raeburn 1873: foreach my $item (@usertools) {
1.101 raeburn 1874: if ($context eq 'requestcourses') {
1875: my ($curroption,$currlimit);
1876: if (ref($settings) eq 'HASH') {
1877: if (ref($settings->{$item}) eq 'HASH') {
1878: $curroption = $settings->{$item}->{'default'};
1879: if ($curroption =~ /^autolimit=(\d*)$/) {
1880: $currlimit = $1;
1881: }
1882: }
1883: }
1884: if (!$curroption) {
1885: $curroption = 'norequest';
1886: }
1887: $datatable .= '<th>'.$titles{$item}.'</th>';
1888: foreach my $option (@options) {
1889: my $val = $option;
1890: if ($option eq 'norequest') {
1891: $val = 0;
1892: }
1893: if ($option eq 'validate') {
1894: my $canvalidate = 0;
1895: if (ref($validations{$item}) eq 'HASH') {
1896: if ($validations{$item}{'default'}) {
1897: $canvalidate = 1;
1898: }
1899: }
1900: next if (!$canvalidate);
1901: }
1902: my $checked = '';
1903: if ($option eq $curroption) {
1904: $checked = ' checked="checked"';
1905: } elsif ($option eq 'autolimit') {
1906: if ($curroption =~ /^autolimit/) {
1907: $checked = ' checked="checked"';
1908: }
1909: }
1910: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1911: '<input type="radio" name="crsreq_'.$item.
1912: '_default" value="'.$val.'"'.$checked.' />'.
1913: $titles{$option}.'</label>';
1914: if ($option eq 'autolimit') {
1.127 raeburn 1915: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1916: $item.'_limit_default" size="1" '.
1917: 'value="'.$currlimit.'" />';
1918: }
1.127 raeburn 1919: $defcell{$item} .= '</span> ';
1.104 raeburn 1920: if ($option eq 'autolimit') {
1.127 raeburn 1921: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1922: }
1.101 raeburn 1923: }
1.160.6.5 raeburn 1924: } elsif ($context eq 'requestauthor') {
1925: my $curroption;
1926: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1927: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1928: }
1929: if (!$curroption) {
1930: $curroption = 'norequest';
1931: }
1932: foreach my $option (@options) {
1933: my $val = $option;
1934: if ($option eq 'norequest') {
1935: $val = 0;
1936: }
1937: my $checked = '';
1938: if ($option eq $curroption) {
1939: $checked = ' checked="checked"';
1940: }
1941: $datatable .= '<span class="LC_nobreak"><label>'.
1942: '<input type="radio" name="authorreq_default"'.
1943: ' value="'.$val.'"'.$checked.' />'.
1944: $titles{$option}.'</label></span> ';
1945: }
1.101 raeburn 1946: } else {
1947: my $checked = 'checked="checked" ';
1948: if (ref($settings) eq 'HASH') {
1949: if (ref($settings->{$item}) eq 'HASH') {
1950: if ($settings->{$item}->{'default'} == 0) {
1951: $checked = '';
1952: } elsif ($settings->{$item}->{'default'} == 1) {
1953: $checked = 'checked="checked" ';
1954: }
1.78 raeburn 1955: }
1.72 raeburn 1956: }
1.101 raeburn 1957: $datatable .= '<span class="LC_nobreak"><label>'.
1958: '<input type="checkbox" name="'.$context.'_'.$item.
1959: '" value="default" '.$checked.'/>'.$titles{$item}.
1960: '</label></span> ';
1961: }
1962: }
1963: if ($context eq 'requestcourses') {
1964: $datatable .= '</tr><tr>';
1965: foreach my $item (@usertools) {
1.106 raeburn 1966: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1967: }
1.101 raeburn 1968: $datatable .= '</tr></table>';
1.72 raeburn 1969: }
1.86 raeburn 1970: $datatable .= '</td>';
1.160.6.5 raeburn 1971: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 1972: $datatable .= '<td class="LC_right_item">'.
1973: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1974: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 1975: $defaultquota.'" size="5" /></span>'.(' ' x2).
1976: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1977: '<input type="text" name="authorquota" value="'.
1978: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1979: }
1980: $datatable .= '</tr>';
1.72 raeburn 1981: $typecount ++;
1982: $css_class = $typecount%2?' class="LC_odd_row"':'';
1983: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 1984: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1985: if ($context eq 'requestcourses') {
1.109 raeburn 1986: $datatable .= &mt('(overrides affiliation, if set)').
1987: '</td>'.
1988: '<td class="LC_left_item">'.
1989: '<table><tr>';
1.101 raeburn 1990: } else {
1.109 raeburn 1991: $datatable .= &mt('(overrides affiliation, if checked)').
1992: '</td>'.
1993: '<td class="LC_left_item" colspan="2">'.
1994: '<br />';
1.101 raeburn 1995: }
1996: my %advcell;
1.72 raeburn 1997: foreach my $item (@usertools) {
1.101 raeburn 1998: if ($context eq 'requestcourses') {
1999: my ($curroption,$currlimit);
2000: if (ref($settings) eq 'HASH') {
2001: if (ref($settings->{$item}) eq 'HASH') {
2002: $curroption = $settings->{$item}->{'_LC_adv'};
2003: if ($curroption =~ /^autolimit=(\d*)$/) {
2004: $currlimit = $1;
2005: }
2006: }
2007: }
2008: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2009: my $checked = '';
2010: if ($curroption eq '') {
2011: $checked = ' checked="checked"';
2012: }
2013: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2014: '<input type="radio" name="crsreq_'.$item.
2015: '__LC_adv" value=""'.$checked.' />'.
2016: &mt('No override set').'</label></span> ';
1.101 raeburn 2017: foreach my $option (@options) {
2018: my $val = $option;
2019: if ($option eq 'norequest') {
2020: $val = 0;
2021: }
2022: if ($option eq 'validate') {
2023: my $canvalidate = 0;
2024: if (ref($validations{$item}) eq 'HASH') {
2025: if ($validations{$item}{'_LC_adv'}) {
2026: $canvalidate = 1;
2027: }
2028: }
2029: next if (!$canvalidate);
2030: }
2031: my $checked = '';
1.104 raeburn 2032: if ($val eq $curroption) {
1.101 raeburn 2033: $checked = ' checked="checked"';
2034: } elsif ($option eq 'autolimit') {
2035: if ($curroption =~ /^autolimit/) {
2036: $checked = ' checked="checked"';
2037: }
2038: }
2039: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2040: '<input type="radio" name="crsreq_'.$item.
2041: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2042: $titles{$option}.'</label>';
2043: if ($option eq 'autolimit') {
1.127 raeburn 2044: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2045: $item.'_limit__LC_adv" size="1" '.
2046: 'value="'.$currlimit.'" />';
2047: }
1.127 raeburn 2048: $advcell{$item} .= '</span> ';
1.104 raeburn 2049: if ($option eq 'autolimit') {
1.127 raeburn 2050: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2051: }
1.101 raeburn 2052: }
1.160.6.5 raeburn 2053: } elsif ($context eq 'requestauthor') {
2054: my $curroption;
2055: if (ref($settings) eq 'HASH') {
2056: $curroption = $settings->{'_LC_adv'};
2057: }
2058: my $checked = '';
2059: if ($curroption eq '') {
2060: $checked = ' checked="checked"';
2061: }
2062: $datatable .= '<span class="LC_nobreak"><label>'.
2063: '<input type="radio" name="authorreq__LC_adv"'.
2064: ' value=""'.$checked.' />'.
2065: &mt('No override set').'</label></span> ';
2066: foreach my $option (@options) {
2067: my $val = $option;
2068: if ($option eq 'norequest') {
2069: $val = 0;
2070: }
2071: my $checked = '';
2072: if ($val eq $curroption) {
2073: $checked = ' checked="checked"';
2074: }
2075: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2076: '<input type="radio" name="authorreq__LC_adv"'.
2077: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2078: $titles{$option}.'</label></span> ';
2079: }
1.101 raeburn 2080: } else {
2081: my $checked = 'checked="checked" ';
2082: if (ref($settings) eq 'HASH') {
2083: if (ref($settings->{$item}) eq 'HASH') {
2084: if ($settings->{$item}->{'_LC_adv'} == 0) {
2085: $checked = '';
2086: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2087: $checked = 'checked="checked" ';
2088: }
1.79 raeburn 2089: }
1.72 raeburn 2090: }
1.101 raeburn 2091: $datatable .= '<span class="LC_nobreak"><label>'.
2092: '<input type="checkbox" name="'.$context.'_'.$item.
2093: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2094: '</label></span> ';
2095: }
2096: }
2097: if ($context eq 'requestcourses') {
2098: $datatable .= '</tr><tr>';
2099: foreach my $item (@usertools) {
1.106 raeburn 2100: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2101: }
1.101 raeburn 2102: $datatable .= '</tr></table>';
1.72 raeburn 2103: }
1.98 raeburn 2104: $datatable .= '</td></tr>';
1.30 raeburn 2105: $$rowtotal += $typecount;
1.3 raeburn 2106: return $datatable;
2107: }
2108:
1.160.6.5 raeburn 2109: sub print_requestmail {
2110: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2111: my ($now,$datatable,%currapp);
1.102 raeburn 2112: $now = time;
2113: if (ref($settings) eq 'HASH') {
2114: if (ref($settings->{'notify'}) eq 'HASH') {
2115: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2116: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2117: }
2118: }
2119: }
1.160.6.16 raeburn 2120: my $numinrow = 2;
1.160.6.34 raeburn 2121: my $css_class;
2122: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2123: my $text;
2124: if ($action eq 'requestcourses') {
2125: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2126: } elsif ($action eq 'requestauthor') {
2127: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2128: } else {
1.160.6.34 raeburn 2129: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2130: }
1.160.6.34 raeburn 2131: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2132: ' <td>'.$text.'</td>'.
1.102 raeburn 2133: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2134: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2135: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2136: if ($numdc > 0) {
2137: $datatable .= $table;
1.102 raeburn 2138: } else {
2139: $datatable .= &mt('There are no active Domain Coordinators');
2140: }
2141: $datatable .='</td></tr>';
2142: return $datatable;
2143: }
2144:
1.160.6.30 raeburn 2145: sub print_studentcode {
2146: my ($settings,$rowtotal) = @_;
2147: my $rownum = 0;
2148: my ($output,%current);
2149: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2150: if (ref($settings) eq 'HASH') {
2151: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2152: foreach my $type (@crstypes) {
2153: $current{$type} = $settings->{'uniquecode'}{$type};
2154: }
1.160.6.30 raeburn 2155: }
2156: }
2157: $output .= '<tr>'.
2158: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2159: '<td class="LC_left_item">';
2160: foreach my $type (@crstypes) {
2161: my $check = ' ';
2162: if ($current{$type}) {
2163: $check = ' checked="checked" ';
2164: }
2165: $output .= '<span class="LC_nobreak"><label>'.
2166: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2167: &mt($type).'</label></span>'.(' 'x2).' ';
2168: }
2169: $output .= '</td></tr>';
2170: $$rowtotal ++;
2171: return $output;
2172: }
2173:
2174: sub print_textbookcourses {
1.160.6.46 raeburn 2175: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2176: my $rownum = 0;
2177: my $css_class;
2178: my $itemcount = 1;
2179: my $maxnum = 0;
2180: my $bookshash;
2181: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2182: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2183: }
2184: my %ordered;
2185: if (ref($bookshash) eq 'HASH') {
2186: foreach my $item (keys(%{$bookshash})) {
2187: if (ref($bookshash->{$item}) eq 'HASH') {
2188: my $num = $bookshash->{$item}{'order'};
2189: $ordered{$num} = $item;
2190: }
2191: }
2192: }
2193: my $confname = $dom.'-domainconfig';
2194: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2195: my $maxnum = scalar(keys(%ordered));
2196: my $datatable;
1.160.6.30 raeburn 2197: if (keys(%ordered)) {
2198: my @items = sort { $a <=> $b } keys(%ordered);
2199: for (my $i=0; $i<@items; $i++) {
2200: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2201: my $key = $ordered{$items[$i]};
2202: my %coursehash=&Apache::lonnet::coursedescription($key);
2203: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2204: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2205: if (ref($bookshash->{$key}) eq 'HASH') {
2206: $subject = $bookshash->{$key}->{'subject'};
2207: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2208: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2209: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2210: $author = $bookshash->{$key}->{'author'};
2211: $image = $bookshash->{$key}->{'image'};
2212: if ($image ne '') {
2213: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2214: my $imagethumb = "$path/tn-".$imagefile;
2215: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2216: }
1.160.6.30 raeburn 2217: }
2218: }
1.160.6.46 raeburn 2219: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2220: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2221: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2222: for (my $k=0; $k<=$maxnum; $k++) {
2223: my $vpos = $k+1;
2224: my $selstr;
2225: if ($k == $i) {
2226: $selstr = ' selected="selected" ';
2227: }
2228: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2229: }
2230: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2231: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2232: &mt('Delete?').'</label></span></td>'.
2233: '<td colspan="2">'.
1.160.6.46 raeburn 2234: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2235: (' 'x2).
1.160.6.46 raeburn 2236: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2237: if ($type eq 'textbooks') {
2238: $datatable .= (' 'x2).
1.160.6.47 raeburn 2239: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2240: (' 'x2).
1.160.6.46 raeburn 2241: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2242: (' 'x2).
2243: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2244: if ($image) {
2245: $datatable .= '<span class="LC_nobreak">'.
2246: $imgsrc.
2247: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2248: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2249: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2250: }
2251: if ($switchserver) {
2252: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2253: } else {
2254: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2255: }
1.160.6.30 raeburn 2256: }
1.160.6.46 raeburn 2257: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2258: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2259: $coursetitle.'</span></td></tr>'."\n";
2260: $itemcount ++;
2261: }
2262: }
2263: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2264: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2265: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2266: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2267: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2268: for (my $k=0; $k<$maxnum+1; $k++) {
2269: my $vpos = $k+1;
2270: my $selstr;
2271: if ($k == $maxnum) {
2272: $selstr = ' selected="selected" ';
2273: }
2274: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2275: }
2276: $datatable .= '</select> '."\n".
1.160.6.46 raeburn 2277: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.160.6.30 raeburn 2278: '<td colspan="2">'.
1.160.6.46 raeburn 2279: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2280: (' 'x2).
1.160.6.46 raeburn 2281: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2282: (' 'x2);
2283: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2284: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2285: (' 'x2).
2286: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2287: (' 'x2).
2288: '<span class="LC_nobreak">'.&mt('Image:').' ';
2289: if ($switchserver) {
2290: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2291: } else {
2292: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2293: }
1.160.6.30 raeburn 2294: }
2295: $datatable .= '</span>'."\n".
2296: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2297: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2298: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2299: &Apache::loncommon::selectcourse_link
1.160.6.46 raeburn 2300: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.160.6.30 raeburn 2301: '</span></td>'."\n".
2302: '</tr>'."\n";
2303: $itemcount ++;
2304: return $datatable;
2305: }
2306:
2307: sub textbookcourses_javascript {
1.160.6.46 raeburn 2308: my ($settings) = @_;
2309: return unless(ref($settings) eq 'HASH');
2310: my (%ordered,%total,%jstext);
2311: foreach my $type ('textbooks','templates') {
2312: $total{$type} = 0;
2313: if (ref($settings->{$type}) eq 'HASH') {
2314: foreach my $item (keys(%{$settings->{$type}})) {
2315: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2316: my $num = $settings->{$type}->{$item}{'order'};
2317: $ordered{$type}{$num} = $item;
2318: }
2319: }
2320: $total{$type} = scalar(keys(%{$settings->{$type}}));
2321: }
2322: my @jsarray = ();
2323: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2324: push(@jsarray,$ordered{$type}{$item});
2325: }
2326: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2327: }
2328: return <<"ENDSCRIPT";
2329: <script type="text/javascript">
2330: // <![CDATA[
1.160.6.46 raeburn 2331: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2332: var changedVal;
1.160.6.46 raeburn 2333: $jstext{'textbooks'};
2334: $jstext{'templates'};
2335: var newpos;
2336: var maxh;
2337: if (caller == 'textbooks') {
2338: newpos = 'textbooks_addbook_pos';
2339: maxh = 1 + $total{'textbooks'};
2340: } else {
2341: newpos = 'templates_addbook_pos';
2342: maxh = 1 + $total{'templates'};
2343: }
1.160.6.30 raeburn 2344: var current = new Array;
2345: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2346: if (item == newpos) {
2347: changedVal = newitemVal;
2348: } else {
2349: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2350: current[newitemVal] = newpos;
2351: }
1.160.6.46 raeburn 2352: if (caller == 'textbooks') {
2353: for (var i=0; i<textbooks.length; i++) {
2354: var elementName = 'textbooks_'+textbooks[i];
2355: if (elementName != item) {
2356: if (form.elements[elementName]) {
2357: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2358: current[currVal] = elementName;
2359: }
2360: }
2361: }
2362: }
2363: if (caller == 'templates') {
2364: for (var i=0; i<templates.length; i++) {
2365: var elementName = 'templates_'+templates[i];
2366: if (elementName != item) {
2367: if (form.elements[elementName]) {
2368: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2369: current[currVal] = elementName;
2370: }
1.160.6.30 raeburn 2371: }
2372: }
2373: }
2374: var oldVal;
2375: for (var j=0; j<maxh; j++) {
2376: if (current[j] == undefined) {
2377: oldVal = j;
2378: }
2379: }
2380: if (oldVal < changedVal) {
2381: for (var k=oldVal+1; k<=changedVal ; k++) {
2382: var elementName = current[k];
2383: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2384: }
2385: } else {
2386: for (var k=changedVal; k<oldVal; k++) {
2387: var elementName = current[k];
2388: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2389: }
2390: }
2391: return;
2392: }
2393:
2394: // ]]>
2395: </script>
2396:
2397: ENDSCRIPT
2398: }
2399:
1.3 raeburn 2400: sub print_autoenroll {
1.30 raeburn 2401: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2402: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2403: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2404: if (ref($settings) eq 'HASH') {
2405: if (exists($settings->{'run'})) {
2406: if ($settings->{'run'} eq '0') {
2407: $runoff = ' checked="checked" ';
2408: $runon = ' ';
2409: } else {
2410: $runon = ' checked="checked" ';
2411: $runoff = ' ';
2412: }
2413: } else {
2414: if ($autorun) {
2415: $runon = ' checked="checked" ';
2416: $runoff = ' ';
2417: } else {
2418: $runoff = ' checked="checked" ';
2419: $runon = ' ';
2420: }
2421: }
1.129 raeburn 2422: if (exists($settings->{'co-owners'})) {
2423: if ($settings->{'co-owners'} eq '0') {
2424: $coownersoff = ' checked="checked" ';
2425: $coownerson = ' ';
2426: } else {
2427: $coownerson = ' checked="checked" ';
2428: $coownersoff = ' ';
2429: }
2430: } else {
2431: $coownersoff = ' checked="checked" ';
2432: $coownerson = ' ';
2433: }
1.3 raeburn 2434: if (exists($settings->{'sender_domain'})) {
2435: $defdom = $settings->{'sender_domain'};
2436: }
1.14 raeburn 2437: } else {
2438: if ($autorun) {
2439: $runon = ' checked="checked" ';
2440: $runoff = ' ';
2441: } else {
2442: $runoff = ' checked="checked" ';
2443: $runon = ' ';
2444: }
1.3 raeburn 2445: }
2446: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2447: my $notif_sender;
2448: if (ref($settings) eq 'HASH') {
2449: $notif_sender = $settings->{'sender_uname'};
2450: }
1.3 raeburn 2451: my $datatable='<tr class="LC_odd_row">'.
2452: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2453: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2454: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2455: $runon.' value="1" />'.&mt('Yes').'</label> '.
2456: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2457: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2458: '</tr><tr>'.
2459: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2460: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2461: &mt('username').': '.
2462: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2463: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2464: ': '.$domform.'</span></td></tr>'.
2465: '<tr class="LC_odd_row">'.
2466: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2467: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2468: '<input type="radio" name="autoassign_coowners"'.
2469: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2470: '<label><input type="radio" name="autoassign_coowners"'.
2471: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2472: '</tr>';
2473: $$rowtotal += 3;
1.3 raeburn 2474: return $datatable;
2475: }
2476:
2477: sub print_autoupdate {
1.30 raeburn 2478: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2479: my $datatable;
2480: if ($position eq 'top') {
2481: my $updateon = ' ';
2482: my $updateoff = ' checked="checked" ';
2483: my $classlistson = ' ';
2484: my $classlistsoff = ' checked="checked" ';
2485: if (ref($settings) eq 'HASH') {
2486: if ($settings->{'run'} eq '1') {
2487: $updateon = $updateoff;
2488: $updateoff = ' ';
2489: }
2490: if ($settings->{'classlists'} eq '1') {
2491: $classlistson = $classlistsoff;
2492: $classlistsoff = ' ';
2493: }
2494: }
2495: my %title = (
2496: run => 'Auto-update active?',
2497: classlists => 'Update information in classlists?',
2498: );
2499: $datatable = '<tr class="LC_odd_row">'.
2500: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2501: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2502: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2503: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2504: '<label><input type="radio" name="autoupdate_run"'.
2505: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2506: '</tr><tr>'.
2507: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2508: '<td class="LC_right_item"><span class="LC_nobreak">'.
2509: '<label><input type="radio" name="classlists"'.
2510: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2511: '<label><input type="radio" name="classlists"'.
2512: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2513: '</tr>';
1.30 raeburn 2514: $$rowtotal += 2;
1.131 raeburn 2515: } elsif ($position eq 'middle') {
2516: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2517: my $numinrow = 3;
2518: my $locknamesettings;
2519: $datatable .= &insttypes_row($settings,$types,$usertypes,
2520: $dom,$numinrow,$othertitle,
2521: 'lockablenames');
2522: $$rowtotal ++;
1.3 raeburn 2523: } else {
1.44 raeburn 2524: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2525: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2526: 'permanentemail','id');
1.33 raeburn 2527: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2528: my $numrows = 0;
1.26 raeburn 2529: if (ref($types) eq 'ARRAY') {
2530: if (@{$types} > 0) {
2531: $datatable =
2532: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2533: \@fields,$types,\$numrows);
1.30 raeburn 2534: $$rowtotal += @{$types};
1.26 raeburn 2535: }
1.3 raeburn 2536: }
2537: $datatable .=
2538: &usertype_update_row($settings,{'default' => $othertitle},
2539: \%fieldtitles,\@fields,['default'],
2540: \$numrows);
1.30 raeburn 2541: $$rowtotal ++;
1.3 raeburn 2542: }
2543: return $datatable;
2544: }
2545:
1.125 raeburn 2546: sub print_autocreate {
2547: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2548: my (%createon,%createoff,%currhash);
1.125 raeburn 2549: my @types = ('xml','req');
2550: if (ref($settings) eq 'HASH') {
2551: foreach my $item (@types) {
2552: $createoff{$item} = ' checked="checked" ';
2553: $createon{$item} = ' ';
2554: if (exists($settings->{$item})) {
2555: if ($settings->{$item}) {
2556: $createon{$item} = ' checked="checked" ';
2557: $createoff{$item} = ' ';
2558: }
2559: }
2560: }
1.160.6.16 raeburn 2561: if ($settings->{'xmldc'} ne '') {
2562: $currhash{$settings->{'xmldc'}} = 1;
2563: }
1.125 raeburn 2564: } else {
2565: foreach my $item (@types) {
2566: $createoff{$item} = ' checked="checked" ';
2567: $createon{$item} = ' ';
2568: }
2569: }
2570: $$rowtotal += 2;
1.160.6.16 raeburn 2571: my $numinrow = 2;
1.125 raeburn 2572: my $datatable='<tr class="LC_odd_row">'.
2573: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2574: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2575: '<input type="radio" name="autocreate_xml"'.
2576: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2577: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2578: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2579: '</td></tr><tr>'.
2580: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2581: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2582: '<input type="radio" name="autocreate_req"'.
2583: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2584: '<label><input type="radio" name="autocreate_req"'.
2585: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2586: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2587: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2588: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2589: if ($numdc > 1) {
1.160.6.50 raeburn 2590: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2591: '</td><td class="LC_left_item">';
1.125 raeburn 2592: } else {
1.160.6.50 raeburn 2593: $datatable .= &mt('Course creation processed as:').
2594: '</td><td class="LC_right_item">';
1.125 raeburn 2595: }
1.160.6.50 raeburn 2596: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2597: $$rowtotal += $rows;
1.125 raeburn 2598: return $datatable;
2599: }
2600:
1.23 raeburn 2601: sub print_directorysrch {
1.30 raeburn 2602: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2603: my $srchon = ' ';
2604: my $srchoff = ' checked="checked" ';
1.25 raeburn 2605: my ($exacton,$containson,$beginson);
1.24 raeburn 2606: my $localon = ' ';
2607: my $localoff = ' checked="checked" ';
1.23 raeburn 2608: if (ref($settings) eq 'HASH') {
2609: if ($settings->{'available'} eq '1') {
2610: $srchon = $srchoff;
2611: $srchoff = ' ';
2612: }
1.24 raeburn 2613: if ($settings->{'localonly'} eq '1') {
2614: $localon = $localoff;
2615: $localoff = ' ';
2616: }
1.25 raeburn 2617: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2618: foreach my $type (@{$settings->{'searchtypes'}}) {
2619: if ($type eq 'exact') {
2620: $exacton = ' checked="checked" ';
2621: } elsif ($type eq 'contains') {
2622: $containson = ' checked="checked" ';
2623: } elsif ($type eq 'begins') {
2624: $beginson = ' checked="checked" ';
2625: }
2626: }
2627: } else {
2628: if ($settings->{'searchtypes'} eq 'exact') {
2629: $exacton = ' checked="checked" ';
2630: } elsif ($settings->{'searchtypes'} eq 'contains') {
2631: $containson = ' checked="checked" ';
2632: } elsif ($settings->{'searchtypes'} eq 'specify') {
2633: $exacton = ' checked="checked" ';
2634: $containson = ' checked="checked" ';
2635: }
1.23 raeburn 2636: }
2637: }
2638: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2639: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2640:
2641: my $numinrow = 4;
1.26 raeburn 2642: my $cansrchrow = 0;
1.23 raeburn 2643: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2644: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2645: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2646: '<input type="radio" name="dirsrch_available"'.
2647: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2648: '<label><input type="radio" name="dirsrch_available"'.
2649: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2650: '</tr><tr>'.
1.30 raeburn 2651: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2652: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2653: '<input type="radio" name="dirsrch_localonly"'.
2654: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2655: '<label><input type="radio" name="dirsrch_localonly"'.
2656: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2657: '</tr>';
1.30 raeburn 2658: $$rowtotal += 2;
1.26 raeburn 2659: if (ref($usertypes) eq 'HASH') {
2660: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2661: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2662: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2663: $cansrchrow = 1;
2664: }
2665: }
2666: if ($cansrchrow) {
1.30 raeburn 2667: $$rowtotal ++;
1.26 raeburn 2668: $datatable .= '<tr>';
2669: } else {
2670: $datatable .= '<tr class="LC_odd_row">';
2671: }
1.30 raeburn 2672: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2673: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2674: foreach my $title (@{$titleorder}) {
2675: if (defined($searchtitles->{$title})) {
2676: my $check = ' ';
1.93 raeburn 2677: if (ref($settings) eq 'HASH') {
1.39 raeburn 2678: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2679: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2680: $check = ' checked="checked" ';
2681: }
1.25 raeburn 2682: }
2683: }
2684: $datatable .= '<td class="LC_left_item">'.
2685: '<span class="LC_nobreak"><label>'.
2686: '<input type="checkbox" name="searchby" '.
2687: 'value="'.$title.'"'.$check.'/>'.
2688: $searchtitles->{$title}.'</label></span></td>';
2689: }
2690: }
1.26 raeburn 2691: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2692: $$rowtotal ++;
1.26 raeburn 2693: if ($cansrchrow) {
2694: $datatable .= '<tr class="LC_odd_row">';
2695: } else {
2696: $datatable .= '<tr>';
2697: }
1.30 raeburn 2698: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2699: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2700: '<span class="LC_nobreak"><label>'.
2701: '<input type="checkbox" name="searchtypes" '.
2702: $exacton.' value="exact" />'.&mt('Exact match').
2703: '</label> '.
2704: '<label><input type="checkbox" name="searchtypes" '.
2705: $beginson.' value="begins" />'.&mt('Begins with').
2706: '</label> '.
2707: '<label><input type="checkbox" name="searchtypes" '.
2708: $containson.' value="contains" />'.&mt('Contains').
2709: '</label></span></td></tr>';
1.30 raeburn 2710: $$rowtotal ++;
1.25 raeburn 2711: return $datatable;
2712: }
2713:
1.28 raeburn 2714: sub print_contacts {
1.30 raeburn 2715: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2716: my $datatable;
2717: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2718: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2719: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.23 raeburn 2720: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2721: foreach my $type (@mailings) {
2722: $otheremails{$type} = '';
2723: }
1.134 raeburn 2724: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2725: if (ref($settings) eq 'HASH') {
2726: foreach my $item (@contacts) {
2727: if (exists($settings->{$item})) {
2728: $to{$item} = $settings->{$item};
2729: }
2730: }
2731: foreach my $type (@mailings) {
2732: if (exists($settings->{$type})) {
2733: if (ref($settings->{$type}) eq 'HASH') {
2734: foreach my $item (@contacts) {
2735: if ($settings->{$type}{$item}) {
2736: $checked{$type}{$item} = ' checked="checked" ';
2737: }
2738: }
2739: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2740: if ($type eq 'helpdeskmail') {
2741: $bccemails{$type} = $settings->{$type}{'bcc'};
2742: }
1.28 raeburn 2743: }
1.89 raeburn 2744: } elsif ($type eq 'lonstatusmail') {
2745: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2746: }
2747: }
2748: } else {
2749: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2750: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2751: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2752: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2753: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2754: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2755: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.23 raeburn 2756: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2757: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2758: }
2759: my ($titles,$short_titles) = &contact_titles();
2760: my $rownum = 0;
2761: my $css_class;
2762: foreach my $item (@contacts) {
1.69 raeburn 2763: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2764: $datatable .= '<tr'.$css_class.'>'.
2765: '<td><span class="LC_nobreak">'.$titles->{$item}.
2766: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2767: '<input type="text" name="'.$item.'" value="'.
2768: $to{$item}.'" /></td></tr>';
1.160.6.23 raeburn 2769: $rownum ++;
1.28 raeburn 2770: }
2771: foreach my $type (@mailings) {
1.69 raeburn 2772: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2773: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2774: '<td><span class="LC_nobreak">'.
2775: $titles->{$type}.': </span></td>'.
1.28 raeburn 2776: '<td class="LC_left_item">'.
2777: '<span class="LC_nobreak">';
2778: foreach my $item (@contacts) {
2779: $datatable .= '<label>'.
2780: '<input type="checkbox" name="'.$type.'"'.
2781: $checked{$type}{$item}.
2782: ' value="'.$item.'" />'.$short_titles->{$item}.
2783: '</label> ';
2784: }
2785: $datatable .= '</span><br />'.&mt('Others').': '.
2786: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2787: 'value="'.$otheremails{$type}.'" />';
2788: if ($type eq 'helpdeskmail') {
1.136 raeburn 2789: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2790: '<input type="text" name="'.$type.'_bcc" '.
2791: 'value="'.$bccemails{$type}.'" />';
2792: }
2793: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 2794: $rownum ++;
1.28 raeburn 2795: }
1.160.6.23 raeburn 2796: my %choices;
2797: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2798: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2799: &mt('LON-CAPA core group - MSU'),600,500));
2800: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2801: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2802: &mt('LON-CAPA core group - MSU'),600,500));
2803: my @toggles = ('reporterrors','reportupdates');
2804: my %defaultchecked = ('reporterrors' => 'on',
2805: 'reportupdates' => 'on');
2806: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2807: \%choices,$rownum);
2808: $datatable .= $reports;
1.30 raeburn 2809: $$rowtotal += $rownum;
1.28 raeburn 2810: return $datatable;
2811: }
2812:
1.118 jms 2813: sub print_helpsettings {
1.160.6.5 raeburn 2814: my ($dom,$confname,$settings,$rowtotal) = @_;
2815: my ($datatable,$itemcount);
2816: $itemcount = 1;
2817: my (%choices,%defaultchecked,@toggles);
2818: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2819: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2820: &mt('LON-CAPA bug tracker'),600,500));
2821: %defaultchecked = ('submitbugs' => 'on');
2822: @toggles = ('submitbugs',);
1.122 jms 2823:
1.160.6.5 raeburn 2824: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2825: \%choices,$itemcount);
2826: return $datatable;
1.121 raeburn 2827: }
2828:
2829: sub radiobutton_prefs {
1.160.6.16 raeburn 2830: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57! raeburn 2831: $additional,$align) = @_;
1.121 raeburn 2832: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2833: (ref($choices) eq 'HASH'));
2834:
2835: my (%checkedon,%checkedoff,$datatable,$css_class);
2836:
2837: foreach my $item (@{$toggles}) {
2838: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2839: $checkedon{$item} = ' checked="checked" ';
2840: $checkedoff{$item} = ' ';
1.121 raeburn 2841: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2842: $checkedoff{$item} = ' checked="checked" ';
2843: $checkedon{$item} = ' ';
2844: }
2845: }
2846: if (ref($settings) eq 'HASH') {
1.121 raeburn 2847: foreach my $item (@{$toggles}) {
1.118 jms 2848: if ($settings->{$item} eq '1') {
2849: $checkedon{$item} = ' checked="checked" ';
2850: $checkedoff{$item} = ' ';
2851: } elsif ($settings->{$item} eq '0') {
2852: $checkedoff{$item} = ' checked="checked" ';
2853: $checkedon{$item} = ' ';
2854: }
2855: }
1.121 raeburn 2856: }
1.160.6.16 raeburn 2857: if ($onclick) {
2858: $onclick = ' onclick="'.$onclick.'"';
2859: }
1.121 raeburn 2860: foreach my $item (@{$toggles}) {
1.118 jms 2861: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2862: $datatable .=
1.160.6.16 raeburn 2863: '<tr'.$css_class.'><td valign="top">'.
2864: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57! raeburn 2865: '</span></td>';
! 2866: if ($align eq 'left') {
! 2867: $datatable .= '<td class="LC_left_item">';
! 2868: } else {
! 2869: $datatable .= '<td class="LC_right_item">';
! 2870: }
! 2871: $datatable .=
! 2872: '<span class="LC_nobreak">'.
1.118 jms 2873: '<label><input type="radio" name="'.
1.160.6.16 raeburn 2874: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2875: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 2876: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2877: '</span>'.$additional.
2878: '</td>'.
1.118 jms 2879: '</tr>';
2880: $itemcount ++;
1.121 raeburn 2881: }
2882: return ($datatable,$itemcount);
2883: }
2884:
2885: sub print_coursedefaults {
1.139 raeburn 2886: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2887: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2888: my $itemcount = 1;
1.160.6.16 raeburn 2889: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 2890: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 2891: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2892: coursecredits => 'Credits can be specified for courses',
1.160.6.57! raeburn 2893: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
! 2894: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
! 2895: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.16 raeburn 2896: );
1.160.6.21 raeburn 2897: my %staticdefaults = (
2898: anonsurvey_threshold => 10,
2899: uploadquota => 500,
1.160.6.57! raeburn 2900: postsubmit => 60,
1.160.6.21 raeburn 2901: );
1.139 raeburn 2902: if ($position eq 'top') {
1.160.6.57! raeburn 2903: %defaultchecked = (
! 2904: 'uselcmath' => 'on',
! 2905: 'usejsme' => 'on',
! 2906: );
! 2907: @toggles = ('uselcmath','usejsme');
1.139 raeburn 2908: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57! raeburn 2909: \%choices,$itemcount);
1.139 raeburn 2910: } else {
2911: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.57! raeburn 2912: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout);
1.160.6.16 raeburn 2913: my $currusecredits = 0;
1.160.6.57! raeburn 2914: my $postsubmitclient = 1;
1.160.6.30 raeburn 2915: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2916: if (ref($settings) eq 'HASH') {
2917: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 2918: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2919: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2920: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2921: }
2922: }
1.160.6.16 raeburn 2923: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57! raeburn 2924: foreach my $type (@types) {
! 2925: next if ($type eq 'community');
! 2926: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
! 2927: if ($defcredits{$type} ne '') {
! 2928: $currusecredits = 1;
! 2929: }
! 2930: }
! 2931: }
! 2932: if (ref($settings->{'postsubmit'}) eq 'HASH') {
! 2933: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
! 2934: $postsubmitclient = 0;
! 2935: foreach my $type (@types) {
! 2936: $deftimeout{$type} = $staticdefaults{'postsubmit'};
! 2937: }
! 2938: } else {
! 2939: foreach my $type (@types) {
! 2940: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
! 2941: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
! 2942: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
! 2943: } else {
! 2944: $deftimeout{$type} = $staticdefaults{'postsubmit'};
! 2945: }
! 2946: } else {
! 2947: $deftimeout{$type} = $staticdefaults{'postsubmit'};
! 2948: }
! 2949: }
! 2950: }
! 2951: } else {
! 2952: foreach my $type (@types) {
! 2953: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 2954: }
2955: }
1.139 raeburn 2956: }
2957: if (!$currdefresponder) {
1.160.6.21 raeburn 2958: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2959: } elsif ($currdefresponder < 1) {
2960: $currdefresponder = 1;
2961: }
1.160.6.21 raeburn 2962: foreach my $type (@types) {
2963: if ($curruploadquota{$type} eq '') {
2964: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2965: }
2966: }
1.139 raeburn 2967: $datatable .=
1.160.6.16 raeburn 2968: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2969: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2970: '</span></td>'.
2971: '<td class="LC_right_item"><span class="LC_nobreak">'.
2972: '<input type="text" name="anonsurvey_threshold"'.
2973: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 2974: '</td></tr>'."\n";
2975: $itemcount ++;
2976: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2977: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2978: $choices{'uploadquota'}.
2979: '</span></td>'.
2980: '<td align="right" class="LC_right_item">'.
2981: '<table><tr>';
1.160.6.21 raeburn 2982: foreach my $type (@types) {
2983: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2984: '<input type="text" name="uploadquota_'.$type.'"'.
2985: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2986: }
2987: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 2988: $itemcount ++;
1.160.6.40 raeburn 2989: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 2990: my $display = 'none';
2991: if ($currusecredits) {
2992: $display = 'block';
2993: }
2994: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57! raeburn 2995: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
! 2996: foreach my $type (@types) {
! 2997: next if ($type eq 'community');
! 2998: $additional .= '<td align="center">'.&mt($type).'<br />'.
! 2999: '<input type="text" name="'.$type.'_credits"'.
! 3000: ' value="'.$defcredits{$type}.'" size="3" /></td>';
! 3001: }
! 3002: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 3003: %defaultchecked = ('coursecredits' => 'off');
3004: @toggles = ('coursecredits');
3005: my $current = {
3006: 'coursecredits' => $currusecredits,
3007: };
3008: (my $table,$itemcount) =
3009: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57! raeburn 3010: \%choices,$itemcount,$onclick,$additional,'left');
! 3011: $datatable .= $table;
! 3012: $onclick = "toggleDisplay(this.form,'studentsubmission');";
! 3013: my $display = 'none';
! 3014: if ($postsubmitclient) {
! 3015: $display = 'block';
! 3016: }
! 3017: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
! 3018: '<i>'.&mt('Number of seconds submit is disabled').'</i><br /><table><tr>';
! 3019: foreach my $type (@types) {
! 3020: $additional .= '<td align="center">'.&mt($type).'<br />'.
! 3021: '<input type="text" name="'.$type.'_timeout" value="'.
! 3022: $deftimeout{$type}.'" size="5" /></td>';
! 3023: }
! 3024: $additional .= '</tr></table></div>'."\n";
! 3025: %defaultchecked = ('postsubmit' => 'on');
! 3026: @toggles = ('postsubmit');
! 3027: my $current = {
! 3028: 'postsubmit' => $postsubmitclient,
! 3029: };
! 3030: ($table,$itemcount) =
! 3031: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
! 3032: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 3033: $datatable .= $table;
1.160.6.37 raeburn 3034: }
3035: $$rowtotal += $itemcount;
3036: return $datatable;
3037: }
3038:
3039: sub print_selfenrollment {
3040: my ($position,$dom,$settings,$rowtotal) = @_;
3041: my ($css_class,$datatable);
3042: my $itemcount = 1;
3043: my @types = ('official','unofficial','community','textbook');
3044: if (($position eq 'top') || ($position eq 'middle')) {
3045: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3046: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3047: my @rows;
3048: my $key;
3049: if ($position eq 'top') {
3050: $key = 'admin';
3051: if (ref($rowsref) eq 'ARRAY') {
3052: @rows = @{$rowsref};
3053: }
3054: } elsif ($position eq 'middle') {
3055: $key = 'default';
3056: @rows = ('types','registered','approval','limit');
3057: }
3058: foreach my $row (@rows) {
3059: if (defined($titlesref->{$row})) {
3060: $itemcount ++;
3061: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3062: $datatable .= '<tr'.$css_class.'>'.
3063: '<td>'.$titlesref->{$row}.'</td>'.
3064: '<td class="LC_left_item">'.
3065: '<table><tr>';
3066: my (%current,%currentcap);
3067: if (ref($settings) eq 'HASH') {
3068: if (ref($settings->{$key}) eq 'HASH') {
3069: foreach my $type (@types) {
3070: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3071: $current{$type} = $settings->{$key}->{$type}->{$row};
3072: }
3073: if (($row eq 'limit') && ($key eq 'default')) {
3074: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3075: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3076: }
3077: }
3078: }
3079: }
3080: }
3081: my %roles = (
3082: '0' => &Apache::lonnet::plaintext('dc'),
3083: );
3084:
3085: foreach my $type (@types) {
3086: unless (($row eq 'registered') && ($key eq 'default')) {
3087: $datatable .= '<th>'.&mt($type).'</th>';
3088: }
3089: }
3090: unless (($row eq 'registered') && ($key eq 'default')) {
3091: $datatable .= '</tr><tr>';
3092: }
3093: foreach my $type (@types) {
3094: if ($type eq 'community') {
3095: $roles{'1'} = &mt('Community personnel');
3096: } else {
3097: $roles{'1'} = &mt('Course personnel');
3098: }
3099: $datatable .= '<td style="vertical-align: top">';
3100: if ($position eq 'top') {
3101: my %checked;
3102: if ($current{$type} eq '0') {
3103: $checked{'0'} = ' checked="checked"';
3104: } else {
3105: $checked{'1'} = ' checked="checked"';
3106: }
3107: foreach my $role ('1','0') {
3108: $datatable .= '<span class="LC_nobreak"><label>'.
3109: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3110: 'value="'.$role.'"'.$checked{$role}.' />'.
3111: $roles{$role}.'</label></span> ';
3112: }
3113: } else {
3114: if ($row eq 'types') {
3115: my %checked;
3116: if ($current{$type} =~ /^(all|dom)$/) {
3117: $checked{$1} = ' checked="checked"';
3118: } else {
3119: $checked{''} = ' checked="checked"';
3120: }
3121: foreach my $val ('','dom','all') {
3122: $datatable .= '<span class="LC_nobreak"><label>'.
3123: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3124: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3125: }
3126: } elsif ($row eq 'registered') {
3127: my %checked;
3128: if ($current{$type} eq '1') {
3129: $checked{'1'} = ' checked="checked"';
3130: } else {
3131: $checked{'0'} = ' checked="checked"';
3132: }
3133: foreach my $val ('0','1') {
3134: $datatable .= '<span class="LC_nobreak"><label>'.
3135: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3136: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3137: }
3138: } elsif ($row eq 'approval') {
3139: my %checked;
3140: if ($current{$type} =~ /^([12])$/) {
3141: $checked{$1} = ' checked="checked"';
3142: } else {
3143: $checked{'0'} = ' checked="checked"';
3144: }
3145: for my $val (0..2) {
3146: $datatable .= '<span class="LC_nobreak"><label>'.
3147: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3148: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3149: }
3150: } elsif ($row eq 'limit') {
3151: my %checked;
3152: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3153: $checked{$1} = ' checked="checked"';
3154: } else {
3155: $checked{'none'} = ' checked="checked"';
3156: }
3157: my $cap;
3158: if ($currentcap{$type} =~ /^\d+$/) {
3159: $cap = $currentcap{$type};
3160: }
3161: foreach my $val ('none','allstudents','selfenrolled') {
3162: $datatable .= '<span class="LC_nobreak"><label>'.
3163: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3164: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3165: }
3166: $datatable .= '<br />'.
3167: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3168: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3169: '</span>';
3170: }
3171: }
3172: $datatable .= '</td>';
3173: }
3174: $datatable .= '</tr>';
3175: }
3176: $datatable .= '</table></td></tr>';
3177: }
3178: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3179: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3180: }
3181: $$rowtotal += $itemcount;
3182: return $datatable;
3183: }
3184:
3185: sub print_validation_rows {
3186: my ($caller,$dom,$settings,$rowtotal) = @_;
3187: my ($itemsref,$namesref,$fieldsref);
3188: if ($caller eq 'selfenroll') {
3189: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3190: } elsif ($caller eq 'requestcourses') {
3191: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3192: }
3193: my %currvalidation;
3194: if (ref($settings) eq 'HASH') {
3195: if (ref($settings->{'validation'}) eq 'HASH') {
3196: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3197: }
1.160.6.39 raeburn 3198: }
3199: my $datatable;
3200: my $itemcount = 0;
3201: foreach my $item (@{$itemsref}) {
3202: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3203: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3204: $namesref->{$item}.
3205: '</span></td>'.
3206: '<td class="LC_left_item">';
3207: if (($item eq 'url') || ($item eq 'button')) {
3208: $datatable .= '<span class="LC_nobreak">'.
3209: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3210: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3211: } elsif ($item eq 'fields') {
3212: my @currfields;
3213: if (ref($currvalidation{$item}) eq 'ARRAY') {
3214: @currfields = @{$currvalidation{$item}};
3215: }
3216: foreach my $field (@{$fieldsref}) {
3217: my $check = '';
3218: if (grep(/^\Q$field\E$/,@currfields)) {
3219: $check = ' checked="checked"';
3220: }
3221: $datatable .= '<span class="LC_nobreak"><label>'.
3222: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3223: ' value="'.$field.'"'.$check.' />'.$field.
3224: '</label></span> ';
3225: }
3226: } elsif ($item eq 'markup') {
3227: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3228: $currvalidation{$item}.
1.160.6.37 raeburn 3229: '</textarea>';
1.160.6.39 raeburn 3230: }
3231: $datatable .= '</td></tr>'."\n";
3232: if (ref($rowtotal)) {
1.160.6.37 raeburn 3233: $itemcount ++;
3234: }
1.139 raeburn 3235: }
1.160.6.39 raeburn 3236: if ($caller eq 'requestcourses') {
3237: my %currhash;
1.160.6.51 raeburn 3238: if (ref($settings) eq 'HASH') {
3239: if (ref($settings->{'validation'}) eq 'HASH') {
3240: if ($settings->{'validation'}{'dc'} ne '') {
3241: $currhash{$settings->{'validation'}{'dc'}} = 1;
3242: }
1.160.6.39 raeburn 3243: }
3244: }
3245: my $numinrow = 2;
3246: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3247: 'validationdc',%currhash);
1.160.6.50 raeburn 3248: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3249: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.160.6.39 raeburn 3250: if ($numdc > 1) {
1.160.6.50 raeburn 3251: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 3252: } else {
1.160.6.50 raeburn 3253: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 3254: }
1.160.6.50 raeburn 3255: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 3256: $itemcount ++;
3257: }
3258: if (ref($rowtotal)) {
3259: $$rowtotal += $itemcount;
3260: }
1.121 raeburn 3261: return $datatable;
1.118 jms 3262: }
3263:
1.137 raeburn 3264: sub print_usersessions {
3265: my ($position,$dom,$settings,$rowtotal) = @_;
3266: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3267: my (%by_ip,%by_location,@intdoms);
3268: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3269:
3270: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3271: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3272: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3273: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3274: my $itemcount = 1;
3275: if ($position eq 'top') {
1.152 raeburn 3276: if (keys(%serverhomes) > 1) {
1.145 raeburn 3277: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 3278: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 3279: } else {
1.140 raeburn 3280: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3281: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3282: }
1.137 raeburn 3283: } else {
1.145 raeburn 3284: if (keys(%by_location) == 0) {
3285: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3286: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3287: } else {
3288: my %lt = &usersession_titles();
3289: my $numinrow = 5;
3290: my $prefix;
3291: my @types;
3292: if ($position eq 'bottom') {
3293: $prefix = 'remote';
3294: @types = ('version','excludedomain','includedomain');
3295: } else {
3296: $prefix = 'hosted';
3297: @types = ('excludedomain','includedomain');
3298: }
3299: my (%current,%checkedon,%checkedoff);
3300: my @lcversions = &Apache::lonnet::all_loncaparevs();
3301: my @locations = sort(keys(%by_location));
3302: foreach my $type (@types) {
3303: $checkedon{$type} = '';
3304: $checkedoff{$type} = ' checked="checked"';
3305: }
3306: if (ref($settings) eq 'HASH') {
3307: if (ref($settings->{$prefix}) eq 'HASH') {
3308: foreach my $key (keys(%{$settings->{$prefix}})) {
3309: $current{$key} = $settings->{$prefix}{$key};
3310: if ($key eq 'version') {
3311: if ($current{$key} ne '') {
3312: $checkedon{$key} = ' checked="checked"';
3313: $checkedoff{$key} = '';
3314: }
3315: } elsif (ref($current{$key}) eq 'ARRAY') {
3316: $checkedon{$key} = ' checked="checked"';
3317: $checkedoff{$key} = '';
3318: }
1.137 raeburn 3319: }
3320: }
3321: }
1.145 raeburn 3322: foreach my $type (@types) {
3323: next if ($type ne 'version' && !@locations);
3324: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3325: $datatable .= '<tr'.$css_class.'>
3326: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3327: <span class="LC_nobreak">
3328: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3329: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3330: if ($type eq 'version') {
3331: my $selector = '<select name="'.$prefix.'_version">';
3332: foreach my $version (@lcversions) {
3333: my $selected = '';
3334: if ($current{'version'} eq $version) {
3335: $selected = ' selected="selected"';
3336: }
3337: $selector .= ' <option value="'.$version.'"'.
3338: $selected.'>'.$version.'</option>';
3339: }
3340: $selector .= '</select> ';
3341: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3342: } else {
3343: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3344: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3345: ' />'.(' 'x2).
3346: '<input type="button" value="'.&mt('uncheck all').'" '.
3347: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3348: "\n".
3349: '</div><div><table>';
3350: my $rem;
3351: for (my $i=0; $i<@locations; $i++) {
3352: my ($showloc,$value,$checkedtype);
3353: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3354: my $ip = $by_location{$locations[$i]}->[0];
3355: if (ref($by_ip{$ip}) eq 'ARRAY') {
3356: $value = join(':',@{$by_ip{$ip}});
3357: $showloc = join(', ',@{$by_ip{$ip}});
3358: if (ref($current{$type}) eq 'ARRAY') {
3359: foreach my $loc (@{$by_ip{$ip}}) {
3360: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3361: $checkedtype = ' checked="checked"';
3362: last;
3363: }
3364: }
1.138 raeburn 3365: }
3366: }
3367: }
1.145 raeburn 3368: $rem = $i%($numinrow);
3369: if ($rem == 0) {
3370: if ($i > 0) {
3371: $datatable .= '</tr>';
3372: }
3373: $datatable .= '<tr>';
3374: }
3375: $datatable .= '<td class="LC_left_item">'.
3376: '<span class="LC_nobreak"><label>'.
3377: '<input type="checkbox" name="'.$prefix.'_'.$type.
3378: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3379: '</label></span></td>';
1.137 raeburn 3380: }
1.145 raeburn 3381: $rem = @locations%($numinrow);
3382: my $colsleft = $numinrow - $rem;
3383: if ($colsleft > 1 ) {
3384: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3385: ' </td>';
3386: } elsif ($colsleft == 1) {
3387: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3388: }
1.145 raeburn 3389: $datatable .= '</tr></table>';
1.137 raeburn 3390: }
1.145 raeburn 3391: $datatable .= '</td></tr>';
3392: $itemcount ++;
1.137 raeburn 3393: }
3394: }
3395: }
3396: $$rowtotal += $itemcount;
3397: return $datatable;
3398: }
3399:
1.138 raeburn 3400: sub build_location_hashes {
3401: my ($intdoms,$by_ip,$by_location) = @_;
3402: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3403: (ref($by_location) eq 'HASH'));
3404: my %iphost = &Apache::lonnet::get_iphost();
3405: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3406: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3407: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3408: foreach my $id (@{$iphost{$primary_ip}}) {
3409: my $intdom = &Apache::lonnet::internet_dom($id);
3410: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3411: push(@{$intdoms},$intdom);
3412: }
3413: }
3414: }
3415: foreach my $ip (keys(%iphost)) {
3416: if (ref($iphost{$ip}) eq 'ARRAY') {
3417: foreach my $id (@{$iphost{$ip}}) {
3418: my $location = &Apache::lonnet::internet_dom($id);
3419: if ($location) {
3420: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3421: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3422: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3423: push(@{$by_ip->{$ip}},$location);
3424: }
3425: } else {
3426: $by_ip->{$ip} = [$location];
3427: }
3428: }
3429: }
3430: }
3431: }
3432: foreach my $ip (sort(keys(%{$by_ip}))) {
3433: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3434: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3435: my $first = $by_ip->{$ip}->[0];
3436: if (ref($by_location->{$first}) eq 'ARRAY') {
3437: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3438: push(@{$by_location->{$first}},$ip);
3439: }
3440: } else {
3441: $by_location->{$first} = [$ip];
3442: }
3443: }
3444: }
3445: return;
3446: }
3447:
1.145 raeburn 3448: sub current_offloads_to {
3449: my ($dom,$settings,$servers) = @_;
3450: my (%spareid,%otherdomconfigs);
1.152 raeburn 3451: if (ref($servers) eq 'HASH') {
1.145 raeburn 3452: foreach my $lonhost (sort(keys(%{$servers}))) {
3453: my $gotspares;
1.152 raeburn 3454: if (ref($settings) eq 'HASH') {
3455: if (ref($settings->{'spares'}) eq 'HASH') {
3456: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3457: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3458: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3459: $gotspares = 1;
3460: }
1.145 raeburn 3461: }
3462: }
3463: unless ($gotspares) {
3464: my $gotspares;
3465: my $serverhomeID =
3466: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3467: my $serverhomedom =
3468: &Apache::lonnet::host_domain($serverhomeID);
3469: if ($serverhomedom ne $dom) {
3470: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3471: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3472: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3473: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3474: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3475: $gotspares = 1;
3476: }
3477: }
3478: } else {
3479: $otherdomconfigs{$serverhomedom} =
3480: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3481: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3482: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3483: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3484: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3485: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3486: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3487: $gotspares = 1;
3488: }
3489: }
3490: }
3491: }
3492: }
3493: }
3494: }
3495: unless ($gotspares) {
3496: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3497: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3498: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3499: } else {
3500: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3501: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3502: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3503: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3504: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3505: } else {
1.150 raeburn 3506: my %what = (
3507: spareid => 1,
3508: );
3509: my ($result,$returnhash) =
3510: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3511: if ($result eq 'ok') {
3512: if (ref($returnhash) eq 'HASH') {
3513: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3514: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3515: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3516: }
3517: }
1.145 raeburn 3518: }
3519: }
3520: }
3521: }
3522: }
3523: }
3524: return %spareid;
3525: }
3526:
3527: sub spares_row {
1.152 raeburn 3528: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3529: my $css_class;
3530: my $numinrow = 4;
3531: my $itemcount = 1;
3532: my $datatable;
1.152 raeburn 3533: my %typetitles = &sparestype_titles();
3534: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3535: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3536: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3537: my ($othercontrol,$serverdom);
3538: if ($serverhome ne $server) {
3539: $serverdom = &Apache::lonnet::host_domain($serverhome);
3540: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3541: } else {
3542: $serverdom = &Apache::lonnet::host_domain($server);
3543: if ($serverdom ne $dom) {
3544: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3545: }
3546: }
3547: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3548: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3549: $datatable .= '<tr'.$css_class.'>
3550: <td rowspan="2">
1.160.6.13 raeburn 3551: <span class="LC_nobreak">'.
3552: &mt('[_1] when busy, offloads to:'
3553: ,'<b>'.$server.'</b>').
3554: "\n";
1.145 raeburn 3555: my (%current,%canselect);
1.152 raeburn 3556: my @choices =
3557: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3558: foreach my $type ('primary','default') {
3559: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3560: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3561: my @spares = @{$spareid->{$server}{$type}};
3562: if (@spares > 0) {
1.152 raeburn 3563: if ($othercontrol) {
3564: $current{$type} = join(', ',@spares);
3565: } else {
3566: $current{$type} .= '<table>';
3567: my $numspares = scalar(@spares);
3568: for (my $i=0; $i<@spares; $i++) {
3569: my $rem = $i%($numinrow);
3570: if ($rem == 0) {
3571: if ($i > 0) {
3572: $current{$type} .= '</tr>';
3573: }
3574: $current{$type} .= '<tr>';
1.145 raeburn 3575: }
1.152 raeburn 3576: $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'".');" /> '.
3577: $spareid->{$server}{$type}[$i].
3578: '</label></td>'."\n";
3579: }
3580: my $rem = @spares%($numinrow);
3581: my $colsleft = $numinrow - $rem;
3582: if ($colsleft > 1 ) {
3583: $current{$type} .= '<td colspan="'.$colsleft.
3584: '" class="LC_left_item">'.
3585: ' </td>';
3586: } elsif ($colsleft == 1) {
3587: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3588: }
1.152 raeburn 3589: $current{$type} .= '</tr></table>';
1.150 raeburn 3590: }
1.145 raeburn 3591: }
3592: }
3593: if ($current{$type} eq '') {
3594: $current{$type} = &mt('None specified');
3595: }
1.152 raeburn 3596: if ($othercontrol) {
3597: if ($type eq 'primary') {
3598: $canselect{$type} = $othercontrol;
3599: }
3600: } else {
3601: $canselect{$type} =
3602: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3603: '<select name="newspare_'.$type.'_'.$server.'" '.
3604: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3605: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3606: if (@choices > 0) {
3607: foreach my $lonhost (@choices) {
3608: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3609: }
3610: }
3611: $canselect{$type} .= '</select>'."\n";
3612: }
3613: } else {
3614: $current{$type} = &mt('Could not be determined');
3615: if ($type eq 'primary') {
3616: $canselect{$type} = $othercontrol;
3617: }
1.145 raeburn 3618: }
1.152 raeburn 3619: if ($type eq 'default') {
3620: $datatable .= '<tr'.$css_class.'>';
3621: }
3622: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3623: '<td>'.$current{$type}.'</td>'."\n".
3624: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3625: }
3626: $itemcount ++;
3627: }
3628: }
3629: $$rowtotal += $itemcount;
3630: return $datatable;
3631: }
3632:
1.152 raeburn 3633: sub possible_newspares {
3634: my ($server,$currspares,$serverhomes,$altids) = @_;
3635: my $serverhostname = &Apache::lonnet::hostname($server);
3636: my %excluded;
3637: if ($serverhostname ne '') {
3638: %excluded = (
3639: $serverhostname => 1,
3640: );
3641: }
3642: if (ref($currspares) eq 'HASH') {
3643: foreach my $type (keys(%{$currspares})) {
3644: if (ref($currspares->{$type}) eq 'ARRAY') {
3645: if (@{$currspares->{$type}} > 0) {
3646: foreach my $curr (@{$currspares->{$type}}) {
3647: my $hostname = &Apache::lonnet::hostname($curr);
3648: $excluded{$hostname} = 1;
3649: }
3650: }
3651: }
3652: }
3653: }
3654: my @choices;
3655: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3656: if (keys(%{$serverhomes}) > 1) {
3657: foreach my $name (sort(keys(%{$serverhomes}))) {
3658: unless ($excluded{$name}) {
3659: if (exists($altids->{$serverhomes->{$name}})) {
3660: push(@choices,$altids->{$serverhomes->{$name}});
3661: } else {
3662: push(@choices,$serverhomes->{$name});
1.145 raeburn 3663: }
3664: }
3665: }
3666: }
3667: }
1.152 raeburn 3668: return sort(@choices);
1.145 raeburn 3669: }
3670:
1.150 raeburn 3671: sub print_loadbalancing {
3672: my ($dom,$settings,$rowtotal) = @_;
3673: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3674: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3675: my $numinrow = 1;
3676: my $datatable;
3677: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 3678: my (%currbalancer,%currtargets,%currrules,%existing);
3679: if (ref($settings) eq 'HASH') {
3680: %existing = %{$settings};
3681: }
3682: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3683: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3684: \%currtargets,\%currrules);
1.150 raeburn 3685: } else {
3686: return;
3687: }
3688: my ($othertitle,$usertypes,$types) =
3689: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 3690: my $rownum = 8;
1.150 raeburn 3691: if (ref($types) eq 'ARRAY') {
3692: $rownum += scalar(@{$types});
3693: }
1.160.6.7 raeburn 3694: my @css_class = ('LC_odd_row','LC_even_row');
3695: my $balnum = 0;
3696: my $islast;
3697: my (@toshow,$disabledtext);
3698: if (keys(%currbalancer) > 0) {
3699: @toshow = sort(keys(%currbalancer));
3700: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3701: push(@toshow,'');
3702: }
3703: } else {
3704: @toshow = ('');
3705: $disabledtext = &mt('No existing load balancer');
3706: }
3707: foreach my $lonhost (@toshow) {
3708: if ($balnum == scalar(@toshow)-1) {
3709: $islast = 1;
3710: } else {
3711: $islast = 0;
3712: }
3713: my $cssidx = $balnum%2;
3714: my $targets_div_style = 'display: none';
3715: my $disabled_div_style = 'display: block';
3716: my $homedom_div_style = 'display: none';
3717: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3718: '<td rowspan="'.$rownum.'" valign="top">'.
3719: '<p>';
3720: if ($lonhost eq '') {
3721: $datatable .= '<span class="LC_nobreak">';
3722: if (keys(%currbalancer) > 0) {
3723: $datatable .= &mt('Add balancer:');
3724: } else {
3725: $datatable .= &mt('Enable balancer:');
3726: }
3727: $datatable .= ' '.
3728: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3729: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3730: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3731: '<option value="" selected="selected">'.&mt('None').
3732: '</option>'."\n";
3733: foreach my $server (sort(keys(%servers))) {
3734: next if ($currbalancer{$server});
3735: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3736: }
3737: $datatable .=
3738: '</select>'."\n".
3739: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3740: } else {
3741: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3742: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3743: &mt('Stop balancing').'</label>'.
3744: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3745: $targets_div_style = 'display: block';
3746: $disabled_div_style = 'display: none';
3747: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3748: $homedom_div_style = 'display: block';
3749: }
3750: }
3751: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3752: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3753: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3754: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3755: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3756: my @sparestypes = ('primary','default');
3757: my %typetitles = &sparestype_titles();
3758: foreach my $sparetype (@sparestypes) {
3759: my $targettable;
3760: for (my $i=0; $i<$numspares; $i++) {
3761: my $checked;
3762: if (ref($currtargets{$lonhost}) eq 'HASH') {
3763: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3764: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3765: $checked = ' checked="checked"';
3766: }
3767: }
3768: }
3769: my ($chkboxval,$disabled);
3770: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3771: $chkboxval = $spares[$i];
3772: }
3773: if (exists($currbalancer{$spares[$i]})) {
3774: $disabled = ' disabled="disabled"';
3775: }
3776: $targettable .=
1.160.6.55 raeburn 3777: '<td><span class="LC_nobreak"><label>'.
3778: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 3779: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
1.160.6.55 raeburn 3780: '</span></label></span></td>';
1.160.6.7 raeburn 3781: my $rem = $i%($numinrow);
3782: if ($rem == 0) {
3783: if (($i > 0) && ($i < $numspares-1)) {
3784: $targettable .= '</tr>';
3785: }
3786: if ($i < $numspares-1) {
3787: $targettable .= '<tr>';
1.150 raeburn 3788: }
3789: }
3790: }
1.160.6.7 raeburn 3791: if ($targettable ne '') {
3792: my $rem = $numspares%($numinrow);
3793: my $colsleft = $numinrow - $rem;
3794: if ($colsleft > 1 ) {
3795: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3796: ' </td>';
3797: } elsif ($colsleft == 1) {
3798: $targettable .= '<td class="LC_left_item"> </td>';
3799: }
3800: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3801: '<table><tr>'.$targettable.'</tr></table><br />';
3802: }
3803: }
3804: $datatable .= '</div></td></tr>'.
3805: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3806: $othertitle,$usertypes,$types,\%servers,
3807: \%currbalancer,$lonhost,
3808: $targets_div_style,$homedom_div_style,
3809: $css_class[$cssidx],$balnum,$islast);
3810: $$rowtotal += $rownum;
3811: $balnum ++;
3812: }
3813: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3814: return $datatable;
3815: }
3816:
3817: sub get_loadbalancers_config {
3818: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3819: return unless ((ref($servers) eq 'HASH') &&
3820: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3821: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3822: if (keys(%{$existing}) > 0) {
3823: my $oldlonhost;
3824: foreach my $key (sort(keys(%{$existing}))) {
3825: if ($key eq 'lonhost') {
3826: $oldlonhost = $existing->{'lonhost'};
3827: $currbalancer->{$oldlonhost} = 1;
3828: } elsif ($key eq 'targets') {
3829: if ($oldlonhost) {
3830: $currtargets->{$oldlonhost} = $existing->{'targets'};
3831: }
3832: } elsif ($key eq 'rules') {
3833: if ($oldlonhost) {
3834: $currrules->{$oldlonhost} = $existing->{'rules'};
3835: }
3836: } elsif (ref($existing->{$key}) eq 'HASH') {
3837: $currbalancer->{$key} = 1;
3838: $currtargets->{$key} = $existing->{$key}{'targets'};
3839: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3840: }
3841: }
1.160.6.7 raeburn 3842: } else {
3843: my ($balancerref,$targetsref) =
3844: &Apache::lonnet::get_lonbalancer_config($servers);
3845: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3846: foreach my $server (sort(keys(%{$balancerref}))) {
3847: $currbalancer->{$server} = 1;
3848: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3849: }
3850: }
3851: }
1.160.6.7 raeburn 3852: return;
1.150 raeburn 3853: }
3854:
3855: sub loadbalancing_rules {
3856: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3857: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3858: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3859: my $output;
1.160.6.7 raeburn 3860: my $num = 0;
3861: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3862: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3863: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3864: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3865: $num ++;
1.150 raeburn 3866: my $current;
3867: if (ref($currrules) eq 'HASH') {
3868: $current = $currrules->{$type};
3869: }
1.160.6.55 raeburn 3870: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 3871: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3872: $current = '';
3873: }
3874: }
3875: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3876: $servers,$currbalancer,$lonhost,$dom,
3877: $targets_div_style,$homedom_div_style,
3878: $css_class,$balnum,$num,$islast);
1.150 raeburn 3879: }
3880: }
3881: return $output;
3882: }
3883:
3884: sub loadbalancing_titles {
3885: my ($dom,$intdom,$usertypes,$types) = @_;
3886: my %othertypes = (
3887: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3888: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3889: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3890: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 3891: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3892: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3893: );
1.160.6.26 raeburn 3894: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3895: if (ref($types) eq 'ARRAY') {
3896: unshift(@alltypes,@{$types},'default');
3897: }
3898: my %titles;
3899: foreach my $type (@alltypes) {
3900: if ($type =~ /^_LC_/) {
3901: $titles{$type} = $othertypes{$type};
3902: } elsif ($type eq 'default') {
3903: $titles{$type} = &mt('All users from [_1]',$dom);
3904: if (ref($types) eq 'ARRAY') {
3905: if (@{$types} > 0) {
3906: $titles{$type} = &mt('Other users from [_1]',$dom);
3907: }
3908: }
3909: } elsif (ref($usertypes) eq 'HASH') {
3910: $titles{$type} = $usertypes->{$type};
3911: }
3912: }
3913: return (\@alltypes,\%othertypes,\%titles);
3914: }
3915:
3916: sub loadbalance_rule_row {
1.160.6.7 raeburn 3917: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3918: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 3919: my @rulenames;
1.150 raeburn 3920: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 3921: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 3922: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 3923: } else {
1.160.6.26 raeburn 3924: @rulenames = ('default','homeserver');
3925: if ($type eq '_LC_external') {
3926: push(@rulenames,'externalbalancer');
3927: } else {
3928: push(@rulenames,'specific');
3929: }
3930: push(@rulenames,'none');
1.150 raeburn 3931: }
3932: my $style = $targets_div_style;
1.160.6.55 raeburn 3933: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 3934: $style = $homedom_div_style;
3935: }
1.160.6.7 raeburn 3936: my $space;
3937: if ($islast && $num == 1) {
3938: $space = '<div display="inline-block"> </div>';
3939: }
3940: my $output =
3941: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3942: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3943: '<td valaign="top">'.$space.
3944: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3945: for (my $i=0; $i<@rulenames; $i++) {
3946: my $rule = $rulenames[$i];
3947: my ($checked,$extra);
3948: if ($rulenames[$i] eq 'default') {
3949: $rule = '';
3950: }
3951: if ($rulenames[$i] eq 'specific') {
3952: if (ref($servers) eq 'HASH') {
3953: my $default;
3954: if (($current ne '') && (exists($servers->{$current}))) {
3955: $checked = ' checked="checked"';
3956: }
3957: unless ($checked) {
3958: $default = ' selected="selected"';
3959: }
1.160.6.7 raeburn 3960: $extra =
3961: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3962: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3963: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3964: '<option value=""'.$default.'></option>'."\n";
3965: foreach my $server (sort(keys(%{$servers}))) {
3966: if (ref($currbalancer) eq 'HASH') {
3967: next if (exists($currbalancer->{$server}));
3968: }
1.150 raeburn 3969: my $selected;
1.160.6.7 raeburn 3970: if ($server eq $current) {
1.150 raeburn 3971: $selected = ' selected="selected"';
3972: }
1.160.6.7 raeburn 3973: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3974: }
3975: $extra .= '</select>';
3976: }
3977: } elsif ($rule eq $current) {
3978: $checked = ' checked="checked"';
3979: }
3980: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3981: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3982: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3983: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 3984: ')"'.$checked.' /> ';
1.160.6.56 raeburn 3985: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 3986: $output .= $ruletitles{'particular'};
3987: } else {
3988: $output .= $ruletitles{$rulenames[$i]};
3989: }
3990: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 3991: }
3992: $output .= '</div></td></tr>'."\n";
3993: return $output;
3994: }
3995:
3996: sub offloadtype_text {
3997: my %ruletitles = &Apache::lonlocal::texthash (
3998: 'default' => 'Offloads to default destinations',
3999: 'homeserver' => "Offloads to user's home server",
4000: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4001: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 4002: 'none' => 'No offload',
1.160.6.26 raeburn 4003: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4004: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 4005: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4006: );
4007: return %ruletitles;
4008: }
4009:
4010: sub sparestype_titles {
4011: my %typestitles = &Apache::lonlocal::texthash (
4012: 'primary' => 'primary',
4013: 'default' => 'default',
4014: );
4015: return %typestitles;
4016: }
4017:
1.28 raeburn 4018: sub contact_titles {
4019: my %titles = &Apache::lonlocal::texthash (
4020: 'supportemail' => 'Support E-mail address',
1.69 raeburn 4021: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 4022: 'errormail' => 'Error reports to be e-mailed to',
4023: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 4024: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4025: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 4026: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 4027: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 4028: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4029: );
4030: my %short_titles = &Apache::lonlocal::texthash (
4031: adminemail => 'Admin E-mail address',
4032: supportemail => 'Support E-mail',
4033: );
4034: return (\%titles,\%short_titles);
4035: }
4036:
1.72 raeburn 4037: sub tool_titles {
4038: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 4039: aboutme => 'Personal web page',
1.86 raeburn 4040: blog => 'Blog',
1.160.6.4 raeburn 4041: webdav => 'WebDAV',
1.86 raeburn 4042: portfolio => 'Portfolio',
1.88 bisitz 4043: official => 'Official courses (with institutional codes)',
4044: unofficial => 'Unofficial courses',
1.98 raeburn 4045: community => 'Communities',
1.160.6.30 raeburn 4046: textbook => 'Textbook courses',
1.86 raeburn 4047: );
1.72 raeburn 4048: return %titles;
4049: }
4050:
1.101 raeburn 4051: sub courserequest_titles {
4052: my %titles = &Apache::lonlocal::texthash (
4053: official => 'Official',
4054: unofficial => 'Unofficial',
4055: community => 'Communities',
1.160.6.30 raeburn 4056: textbook => 'Textbook',
1.101 raeburn 4057: norequest => 'Not allowed',
1.104 raeburn 4058: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4059: validate => 'With validation',
4060: autolimit => 'Numerical limit',
1.103 raeburn 4061: unlimited => '(blank for unlimited)',
1.101 raeburn 4062: );
4063: return %titles;
4064: }
4065:
1.160.6.5 raeburn 4066: sub authorrequest_titles {
4067: my %titles = &Apache::lonlocal::texthash (
4068: norequest => 'Not allowed',
4069: approval => 'Approval by Dom. Coord.',
4070: automatic => 'Automatic approval',
4071: );
4072: return %titles;
4073: }
4074:
1.101 raeburn 4075: sub courserequest_conditions {
4076: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4077: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 4078: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4079: );
4080: return %conditions;
4081: }
4082:
4083:
1.27 raeburn 4084: sub print_usercreation {
1.30 raeburn 4085: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4086: my $numinrow = 4;
1.28 raeburn 4087: my $datatable;
4088: if ($position eq 'top') {
1.30 raeburn 4089: $$rowtotal ++;
1.34 raeburn 4090: my $rowcount = 0;
1.32 raeburn 4091: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4092: if (ref($rules) eq 'HASH') {
4093: if (keys(%{$rules}) > 0) {
1.32 raeburn 4094: $datatable .= &user_formats_row('username',$settings,$rules,
4095: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4096: $$rowtotal ++;
1.32 raeburn 4097: $rowcount ++;
4098: }
4099: }
4100: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4101: if (ref($idrules) eq 'HASH') {
4102: if (keys(%{$idrules}) > 0) {
4103: $datatable .= &user_formats_row('id',$settings,$idrules,
4104: $idruleorder,$numinrow,$rowcount);
4105: $$rowtotal ++;
4106: $rowcount ++;
1.28 raeburn 4107: }
4108: }
1.39 raeburn 4109: if ($rowcount == 0) {
4110: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4111: $$rowtotal ++;
4112: $rowcount ++;
4113: }
1.34 raeburn 4114: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 4115: my @creators = ('author','course','requestcrs');
1.37 raeburn 4116: my ($rules,$ruleorder) =
4117: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4118: my %lt = &usercreation_types();
4119: my %checked;
4120: if (ref($settings) eq 'HASH') {
4121: if (ref($settings->{'cancreate'}) eq 'HASH') {
4122: foreach my $item (@creators) {
4123: $checked{$item} = $settings->{'cancreate'}{$item};
4124: }
4125: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4126: foreach my $item (@creators) {
4127: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4128: $checked{$item} = 'none';
4129: }
4130: }
4131: }
4132: }
4133: my $rownum = 0;
4134: foreach my $item (@creators) {
4135: $rownum ++;
1.160.6.34 raeburn 4136: if ($checked{$item} eq '') {
4137: $checked{$item} = 'any';
1.34 raeburn 4138: }
4139: my $css_class;
4140: if ($rownum%2) {
4141: $css_class = '';
4142: } else {
4143: $css_class = ' class="LC_odd_row" ';
4144: }
4145: $datatable .= '<tr'.$css_class.'>'.
4146: '<td><span class="LC_nobreak">'.$lt{$item}.
4147: '</span></td><td align="right">';
1.160.6.34 raeburn 4148: my @options = ('any');
4149: if (ref($rules) eq 'HASH') {
4150: if (keys(%{$rules}) > 0) {
4151: push(@options,('official','unofficial'));
1.37 raeburn 4152: }
4153: }
1.160.6.34 raeburn 4154: push(@options,'none');
1.37 raeburn 4155: foreach my $option (@options) {
1.50 raeburn 4156: my $type = 'radio';
1.34 raeburn 4157: my $check = ' ';
1.160.6.34 raeburn 4158: if ($checked{$item} eq $option) {
4159: $check = ' checked="checked" ';
1.34 raeburn 4160: }
4161: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4162: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4163: $item.'" value="'.$option.'"'.$check.'/> '.
4164: $lt{$option}.'</label> </span>';
4165: }
4166: $datatable .= '</td></tr>';
4167: }
1.28 raeburn 4168: } else {
4169: my @contexts = ('author','course','domain');
4170: my @authtypes = ('int','krb4','krb5','loc');
4171: my %checked;
4172: if (ref($settings) eq 'HASH') {
4173: if (ref($settings->{'authtypes'}) eq 'HASH') {
4174: foreach my $item (@contexts) {
4175: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4176: foreach my $auth (@authtypes) {
4177: if ($settings->{'authtypes'}{$item}{$auth}) {
4178: $checked{$item}{$auth} = ' checked="checked" ';
4179: }
4180: }
4181: }
4182: }
1.27 raeburn 4183: }
1.35 raeburn 4184: } else {
4185: foreach my $item (@contexts) {
1.36 raeburn 4186: foreach my $auth (@authtypes) {
1.35 raeburn 4187: $checked{$item}{$auth} = ' checked="checked" ';
4188: }
4189: }
1.27 raeburn 4190: }
1.28 raeburn 4191: my %title = &context_names();
4192: my %authname = &authtype_names();
4193: my $rownum = 0;
4194: my $css_class;
4195: foreach my $item (@contexts) {
4196: if ($rownum%2) {
4197: $css_class = '';
4198: } else {
4199: $css_class = ' class="LC_odd_row" ';
4200: }
1.30 raeburn 4201: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4202: '<td>'.$title{$item}.
4203: '</td><td class="LC_left_item">'.
4204: '<span class="LC_nobreak">';
4205: foreach my $auth (@authtypes) {
4206: $datatable .= '<label>'.
4207: '<input type="checkbox" name="'.$item.'_auth" '.
4208: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4209: $authname{$auth}.'</label> ';
4210: }
4211: $datatable .= '</span></td></tr>';
4212: $rownum ++;
1.27 raeburn 4213: }
1.30 raeburn 4214: $$rowtotal += $rownum;
1.27 raeburn 4215: }
4216: return $datatable;
4217: }
4218:
1.160.6.34 raeburn 4219: sub print_selfcreation {
4220: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4221: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4222: if (ref($settings) eq 'HASH') {
4223: if (ref($settings->{'cancreate'}) eq 'HASH') {
4224: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4225: if (ref($createsettings) eq 'HASH') {
4226: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4227: @selfcreate = @{$createsettings->{'selfcreate'}};
4228: } elsif ($createsettings->{'selfcreate'} ne '') {
4229: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4230: @selfcreate = ('email','login','sso');
4231: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4232: @selfcreate = ($createsettings->{'selfcreate'});
4233: }
4234: }
4235: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4236: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 4237: }
4238: }
4239: }
4240: }
4241: my %radiohash;
4242: my $numinrow = 4;
4243: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4244: if ($position eq 'top') {
4245: my %choices = &Apache::lonlocal::texthash (
4246: cancreate_login => 'Institutional Login',
4247: cancreate_sso => 'Institutional Single Sign On',
4248: );
4249: my @toggles = sort(keys(%choices));
4250: my %defaultchecked = (
4251: 'cancreate_login' => 'off',
4252: 'cancreate_sso' => 'off',
4253: );
1.160.6.35 raeburn 4254: my ($onclick,$itemcount);
1.160.6.34 raeburn 4255: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4256: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 4257: $$rowtotal += $itemcount;
1.160.6.39 raeburn 4258:
1.160.6.34 raeburn 4259: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4260:
4261: if (ref($usertypes) eq 'HASH') {
4262: if (keys(%{$usertypes}) > 0) {
4263: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4264: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 4265: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 4266: $$rowtotal ++;
4267: }
4268: }
1.160.6.44 raeburn 4269: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4270: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4271: $fieldtitles{'inststatus'} = &mt('Institutional status');
4272: my $rem;
4273: my $numperrow = 2;
4274: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4275: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 4276: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 4277: '<td class="LC_left_item">'."\n".
4278: '<table><tr><td>'."\n";
4279: for (my $i=0; $i<@fields; $i++) {
4280: $rem = $i%($numperrow);
4281: if ($rem == 0) {
4282: if ($i > 0) {
4283: $datatable .= '</tr>';
4284: }
4285: $datatable .= '<tr>';
4286: }
4287: my $currval;
1.160.6.51 raeburn 4288: if (ref($createsettings) eq 'HASH') {
4289: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4290: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4291: }
1.160.6.44 raeburn 4292: }
4293: $datatable .= '<td class="LC_left_item">'.
4294: '<span class="LC_nobreak">'.
4295: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4296: 'value="'.$currval.'" size="10" /> '.
4297: $fieldtitles{$fields[$i]}.'</span></td>';
4298: }
4299: my $colsleft = $numperrow - $rem;
4300: if ($colsleft > 1 ) {
4301: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4302: ' </td>';
4303: } elsif ($colsleft == 1) {
4304: $datatable .= '<td class="LC_left_item"> </td>';
4305: }
4306: $datatable .= '</tr></table></td></tr>';
4307: $$rowtotal ++;
1.160.6.34 raeburn 4308: } elsif ($position eq 'middle') {
4309: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4310: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4311: $usertypes->{'default'} = $othertitle;
4312: if (ref($types) eq 'ARRAY') {
4313: push(@{$types},'default');
4314: $usertypes->{'default'} = $othertitle;
4315: foreach my $status (@{$types}) {
4316: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 4317: $numinrow,$$rowtotal,$usertypes);
1.160.6.44 raeburn 4318: $$rowtotal ++;
1.160.6.34 raeburn 4319: }
4320: }
4321: } else {
1.160.6.40 raeburn 4322: my %choices = &Apache::lonlocal::texthash (
4323: cancreate_email => 'E-mail address as username',
4324: );
4325: my @toggles = sort(keys(%choices));
4326: my %defaultchecked = (
4327: 'cancreate_email' => 'off',
4328: );
4329: my $itemcount = 0;
4330: my $display = 'none';
4331: if (grep(/^\Qemail\E$/,@selfcreate)) {
4332: $display = 'block';
4333: }
4334: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4335: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4336: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4337: my $usertypes = {};
4338: my $order = [];
4339: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4340: $usertypes = $domdefaults{'inststatustypes'};
4341: $order = $domdefaults{'inststatusguest'};
4342: }
4343: if (ref($order) eq 'ARRAY') {
4344: push(@{$order},'default');
4345: if (@{$order} > 1) {
4346: $usertypes->{'default'} = &mt('Other users');
4347: $additional .= '<table><tr>';
4348: foreach my $status (@{$order}) {
4349: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4350: }
4351: $additional .= '</tr><tr>';
4352: foreach my $status (@{$order}) {
4353: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 4354: }
1.160.6.40 raeburn 4355: $additional .= '</tr></table>';
1.160.6.34 raeburn 4356: } else {
1.160.6.40 raeburn 4357: $usertypes->{'default'} = &mt('All users');
4358: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 4359: }
4360: }
1.160.6.40 raeburn 4361: $additional .= '</div>'."\n";
4362:
4363: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 4364: \%choices,$$rowtotal,$onclick,$additional);
4365: $$rowtotal ++;
1.160.6.40 raeburn 4366: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 4367: $$rowtotal ++;
1.160.6.35 raeburn 4368: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4369: $numinrow = 1;
1.160.6.40 raeburn 4370: if (ref($order) eq 'ARRAY') {
4371: foreach my $status (@{$order}) {
1.160.6.35 raeburn 4372: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4373: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4374: $$rowtotal ++;
4375: }
4376: }
1.160.6.34 raeburn 4377: my ($emailrules,$emailruleorder) =
4378: &Apache::lonnet::inst_userrules($dom,'email');
4379: if (ref($emailrules) eq 'HASH') {
4380: if (keys(%{$emailrules}) > 0) {
4381: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 4382: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 4383: $$rowtotal ++;
4384: }
4385: }
1.160.6.35 raeburn 4386: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 4387: }
4388: return $datatable;
4389: }
4390:
1.160.6.40 raeburn 4391: sub email_as_username {
4392: my ($rowtotal,$processing,$type) = @_;
4393: my %choices =
4394: &Apache::lonlocal::texthash (
4395: automatic => 'Automatic approval',
4396: approval => 'Queued for approval',
4397: );
4398: my $output;
4399: foreach my $option ('automatic','approval') {
4400: my $checked;
4401: if (ref($processing) eq 'HASH') {
4402: if ($type eq '') {
4403: if (!exists($processing->{'default'})) {
4404: if ($option eq 'automatic') {
4405: $checked = ' checked="checked"';
4406: }
4407: } else {
4408: if ($processing->{'default'} eq $option) {
4409: $checked = ' checked="checked"';
4410: }
4411: }
4412: } else {
4413: if (!exists($processing->{$type})) {
4414: if ($option eq 'automatic') {
4415: $checked = ' checked="checked"';
4416: }
4417: } else {
4418: if ($processing->{$type} eq $option) {
4419: $checked = ' checked="checked"';
4420: }
4421: }
4422: }
4423: } elsif ($option eq 'automatic') {
4424: $checked = ' checked="checked"';
4425: }
4426: my $name = 'cancreate_emailprocess';
4427: if (($type ne '') && ($type ne 'default')) {
4428: $name .= '_'.$type;
4429: }
4430: $output .= '<span class="LC_nobreak"><label>'.
4431: '<input type="radio" name="'.$name.'"'.
4432: $checked.' value="'.$option.'" />'.
4433: $choices{$option}.'</label></span>';
4434: if ($type eq '') {
4435: $output .= ' ';
4436: } else {
4437: $output .= '<br />';
4438: }
4439: }
4440: $$rowtotal ++;
4441: return $output;
4442: }
4443:
1.160.6.5 raeburn 4444: sub captcha_choice {
4445: my ($context,$settings,$itemcount) = @_;
4446: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4447: my %lt = &captcha_phrases();
4448: $keyentry = 'hidden';
4449: if ($context eq 'cancreate') {
1.160.6.34 raeburn 4450: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 4451: } elsif ($context eq 'login') {
4452: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
4453: }
4454: if (ref($settings) eq 'HASH') {
4455: if ($settings->{'captcha'}) {
4456: $checked{$settings->{'captcha'}} = ' checked="checked"';
4457: } else {
4458: $checked{'original'} = ' checked="checked"';
4459: }
4460: if ($settings->{'captcha'} eq 'recaptcha') {
4461: $pubtext = $lt{'pub'};
4462: $privtext = $lt{'priv'};
4463: $keyentry = 'text';
4464: }
4465: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4466: $currpub = $settings->{'recaptchakeys'}{'public'};
4467: $currpriv = $settings->{'recaptchakeys'}{'private'};
4468: }
4469: } else {
4470: $checked{'original'} = ' checked="checked"';
4471: }
4472: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4473: my $output = '<tr'.$css_class.'>'.
4474: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
4475: '<table><tr><td>'."\n";
4476: foreach my $option ('original','recaptcha','notused') {
4477: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4478: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4479: $lt{$option}.'</label></span>';
4480: unless ($option eq 'notused') {
4481: $output .= (' 'x2)."\n";
4482: }
4483: }
4484: #
4485: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4486: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
4487: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
4488: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
4489: #
4490: $output .= '</td></tr>'."\n".
4491: '<tr><td>'."\n".
4492: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4493: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4494: $currpub.'" size="40" /></span><br />'."\n".
4495: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4496: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4497: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4498: '</td></tr>';
4499: return $output;
4500: }
4501:
1.32 raeburn 4502: sub user_formats_row {
4503: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4504: my $output;
4505: my %text = (
4506: 'username' => 'new usernames',
4507: 'id' => 'IDs',
1.45 raeburn 4508: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4509: );
4510: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4511: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4512: '<td><span class="LC_nobreak">';
4513: if ($type eq 'email') {
4514: $output .= &mt("Formats disallowed for $text{$type}: ");
4515: } else {
4516: $output .= &mt("Format rules to check for $text{$type}: ");
4517: }
4518: $output .= '</span></td>'.
4519: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4520: my $rem;
4521: if (ref($ruleorder) eq 'ARRAY') {
4522: for (my $i=0; $i<@{$ruleorder}; $i++) {
4523: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4524: my $rem = $i%($numinrow);
4525: if ($rem == 0) {
4526: if ($i > 0) {
4527: $output .= '</tr>';
4528: }
4529: $output .= '<tr>';
4530: }
4531: my $check = ' ';
1.39 raeburn 4532: if (ref($settings) eq 'HASH') {
4533: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4534: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4535: $check = ' checked="checked" ';
4536: }
1.27 raeburn 4537: }
4538: }
4539: $output .= '<td class="LC_left_item">'.
4540: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4541: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4542: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4543: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4544: }
4545: }
4546: $rem = @{$ruleorder}%($numinrow);
4547: }
4548: my $colsleft = $numinrow - $rem;
4549: if ($colsleft > 1 ) {
4550: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4551: ' </td>';
4552: } elsif ($colsleft == 1) {
4553: $output .= '<td class="LC_left_item"> </td>';
4554: }
4555: $output .= '</tr></table></td></tr>';
4556: return $output;
4557: }
4558:
1.34 raeburn 4559: sub usercreation_types {
4560: my %lt = &Apache::lonlocal::texthash (
4561: author => 'When adding a co-author',
4562: course => 'When adding a user to a course',
1.100 raeburn 4563: requestcrs => 'When requesting a course',
1.34 raeburn 4564: any => 'Any',
4565: official => 'Institutional only ',
4566: unofficial => 'Non-institutional only',
4567: none => 'None',
4568: );
4569: return %lt;
1.48 raeburn 4570: }
1.34 raeburn 4571:
1.160.6.34 raeburn 4572: sub selfcreation_types {
4573: my %lt = &Apache::lonlocal::texthash (
4574: selfcreate => 'User creates own account',
4575: any => 'Any',
4576: official => 'Institutional only ',
4577: unofficial => 'Non-institutional only',
4578: email => 'E-mail address',
4579: login => 'Institutional Login',
4580: sso => 'SSO',
4581: );
4582: }
4583:
1.28 raeburn 4584: sub authtype_names {
4585: my %lt = &Apache::lonlocal::texthash(
4586: int => 'Internal',
4587: krb4 => 'Kerberos 4',
4588: krb5 => 'Kerberos 5',
4589: loc => 'Local',
4590: );
4591: return %lt;
4592: }
4593:
4594: sub context_names {
4595: my %context_title = &Apache::lonlocal::texthash(
4596: author => 'Creating users when an Author',
4597: course => 'Creating users when in a course',
4598: domain => 'Creating users when a Domain Coordinator',
4599: );
4600: return %context_title;
4601: }
4602:
1.33 raeburn 4603: sub print_usermodification {
4604: my ($position,$dom,$settings,$rowtotal) = @_;
4605: my $numinrow = 4;
4606: my ($context,$datatable,$rowcount);
4607: if ($position eq 'top') {
4608: $rowcount = 0;
4609: $context = 'author';
4610: foreach my $role ('ca','aa') {
4611: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4612: $numinrow,$rowcount);
4613: $$rowtotal ++;
4614: $rowcount ++;
4615: }
1.160.6.37 raeburn 4616: } elsif ($position eq 'bottom') {
1.33 raeburn 4617: $context = 'course';
4618: $rowcount = 0;
4619: foreach my $role ('st','ep','ta','in','cr') {
4620: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4621: $numinrow,$rowcount);
4622: $$rowtotal ++;
4623: $rowcount ++;
4624: }
4625: }
4626: return $datatable;
4627: }
4628:
1.43 raeburn 4629: sub print_defaults {
1.160.6.40 raeburn 4630: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4631: my $rownum = 0;
4632: my ($datatable,$css_class);
1.160.6.40 raeburn 4633: if ($position eq 'top') {
4634: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4635: 'datelocale_def','portal_def');
4636: my %defaults;
4637: if (ref($settings) eq 'HASH') {
4638: %defaults = %{$settings};
1.43 raeburn 4639: } else {
1.160.6.40 raeburn 4640: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4641: foreach my $item (@items) {
4642: $defaults{$item} = $domdefaults{$item};
4643: }
1.43 raeburn 4644: }
1.160.6.40 raeburn 4645: my $titles = &defaults_titles($dom);
4646: foreach my $item (@items) {
4647: if ($rownum%2) {
4648: $css_class = '';
4649: } else {
4650: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 4651: }
1.160.6.40 raeburn 4652: $datatable .= '<tr'.$css_class.'>'.
4653: '<td><span class="LC_nobreak">'.$titles->{$item}.
4654: '</span></td><td class="LC_right_item" colspan="3">';
4655: if ($item eq 'auth_def') {
4656: my @authtypes = ('internal','krb4','krb5','localauth');
4657: my %shortauth = (
4658: internal => 'int',
4659: krb4 => 'krb4',
4660: krb5 => 'krb5',
4661: localauth => 'loc'
4662: );
4663: my %authnames = &authtype_names();
4664: foreach my $auth (@authtypes) {
4665: my $checked = ' ';
4666: if ($defaults{$item} eq $auth) {
4667: $checked = ' checked="checked" ';
4668: }
4669: $datatable .= '<label><input type="radio" name="'.$item.
4670: '" value="'.$auth.'"'.$checked.'/>'.
4671: $authnames{$shortauth{$auth}}.'</label> ';
4672: }
4673: } elsif ($item eq 'timezone_def') {
4674: my $includeempty = 1;
4675: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4676: } elsif ($item eq 'datelocale_def') {
4677: my $includeempty = 1;
4678: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4679: } elsif ($item eq 'lang_def') {
4680: my %langchoices = &get_languages_hash();
4681: $langchoices{''} = 'No language preference';
4682: %langchoices = &Apache::lonlocal::texthash(%langchoices);
4683: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
4684: \%langchoices);
4685: } else {
4686: my $size;
4687: if ($item eq 'portal_def') {
4688: $size = ' size="25"';
4689: }
4690: $datatable .= '<input type="text" name="'.$item.'" value="'.
4691: $defaults{$item}.'"'.$size.' />';
4692: }
4693: $datatable .= '</td></tr>';
4694: $rownum ++;
4695: }
4696: } else {
4697: my (%defaults);
4698: if (ref($settings) eq 'HASH') {
4699: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4700: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4701: my $maxnum = @{$settings->{'inststatusorder'}};
4702: for (my $i=0; $i<$maxnum; $i++) {
4703: $css_class = $rownum%2?' class="LC_odd_row"':'';
4704: my $item = $settings->{'inststatusorder'}->[$i];
4705: my $title = $settings->{'inststatustypes'}->{$item};
4706: my $guestok;
4707: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4708: $guestok = 1;
4709: }
4710: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4711: $datatable .= '<tr'.$css_class.'>'.
4712: '<td><span class="LC_nobreak">'.
4713: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4714: for (my $k=0; $k<=$maxnum; $k++) {
4715: my $vpos = $k+1;
4716: my $selstr;
4717: if ($k == $i) {
4718: $selstr = ' selected="selected" ';
4719: }
4720: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4721: }
4722: my ($checkedon,$checkedoff);
4723: $checkedoff = ' checked="checked"';
4724: if ($guestok) {
4725: $checkedon = $checkedoff;
4726: $checkedoff = '';
4727: }
4728: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4729: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4730: &mt('delete').'</span></td>'.
4731: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4732: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4733: '</span></td>'.
4734: '<td class="LC_right_item"><span class="LC_nobreak">'.
4735: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4736: &mt('Yes').'</label>'.(' 'x2).
4737: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4738: &mt('No').'</label></span></td></tr>';
4739: }
4740: $css_class = $rownum%2?' class="LC_odd_row"':'';
4741: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4742: $datatable .= '<tr '.$css_class.'>'.
4743: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4744: for (my $k=0; $k<=$maxnum; $k++) {
4745: my $vpos = $k+1;
4746: my $selstr;
4747: if ($k == $maxnum) {
4748: $selstr = ' selected="selected" ';
4749: }
4750: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4751: }
4752: $datatable .= '</select> '.&mt('Internal ID:').
4753: '<input type="text" size="10" name="addinststatus" value="" /></span>'.
4754: ' '.&mt('(new)').
4755: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4756: &mt('Name displayed:').
4757: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4758: '<td class="LC_right_item"><span class="LC_nobreak">'.
4759: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4760: &mt('Yes').'</label>'.(' 'x2).
4761: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4762: &mt('No').'</label></span></td></tr>';
4763: '</tr>'."\n";
4764: $rownum ++;
1.141 raeburn 4765: }
1.43 raeburn 4766: }
4767: }
4768: $$rowtotal += $rownum;
4769: return $datatable;
4770: }
4771:
1.160.6.5 raeburn 4772: sub get_languages_hash {
4773: my %langchoices;
4774: foreach my $id (&Apache::loncommon::languageids()) {
4775: my $code = &Apache::loncommon::supportedlanguagecode($id);
4776: if ($code ne '') {
4777: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4778: }
4779: }
4780: return %langchoices;
4781: }
4782:
1.43 raeburn 4783: sub defaults_titles {
1.141 raeburn 4784: my ($dom) = @_;
1.43 raeburn 4785: my %titles = &Apache::lonlocal::texthash (
4786: 'auth_def' => 'Default authentication type',
4787: 'auth_arg_def' => 'Default authentication argument',
4788: 'lang_def' => 'Default language',
1.54 raeburn 4789: 'timezone_def' => 'Default timezone',
1.68 raeburn 4790: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4791: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4792: );
1.141 raeburn 4793: if ($dom) {
4794: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4795: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4796: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4797: $protocol = 'http' if ($protocol ne 'https');
4798: if ($uint_dom) {
4799: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4800: $uint_dom);
4801: }
4802: }
1.43 raeburn 4803: return (\%titles);
4804: }
4805:
1.46 raeburn 4806: sub print_scantronformat {
4807: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4808: my $itemcount = 1;
1.60 raeburn 4809: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4810: %confhash);
1.46 raeburn 4811: my $switchserver = &check_switchserver($dom,$confname);
4812: my %lt = &Apache::lonlocal::texthash (
1.95 www 4813: default => 'Default bubblesheet format file error',
4814: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4815: );
4816: my %scantronfiles = (
4817: default => 'default.tab',
4818: custom => 'custom.tab',
4819: );
4820: foreach my $key (keys(%scantronfiles)) {
4821: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4822: .$scantronfiles{$key};
4823: }
4824: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4825: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4826: if (!$switchserver) {
4827: my $servadm = $r->dir_config('lonAdmEMail');
4828: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4829: if ($configuserok eq 'ok') {
4830: if ($author_ok eq 'ok') {
4831: my %legacyfile = (
4832: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4833: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4834: );
4835: my %md5chk;
4836: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4837: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4838: chomp($md5chk{$type});
1.46 raeburn 4839: }
4840: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4841: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4842: ($scantronurls{$type},my $error) =
1.46 raeburn 4843: &legacy_scantronformat($r,$dom,$confname,
4844: $type,$legacyfile{$type},
4845: $scantronurls{$type},
4846: $scantronfiles{$type});
1.60 raeburn 4847: if ($error ne '') {
4848: $error{$type} = $error;
4849: }
4850: }
4851: if (keys(%error) == 0) {
4852: $is_custom = 1;
4853: $confhash{'scantron'}{'scantronformat'} =
4854: $scantronurls{'custom'};
4855: my $putresult =
4856: &Apache::lonnet::put_dom('configuration',
4857: \%confhash,$dom);
4858: if ($putresult ne 'ok') {
4859: $error{'custom'} =
4860: '<span class="LC_error">'.
4861: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4862: }
1.46 raeburn 4863: }
4864: } else {
1.60 raeburn 4865: ($scantronurls{'default'},my $error) =
1.46 raeburn 4866: &legacy_scantronformat($r,$dom,$confname,
4867: 'default',$legacyfile{'default'},
4868: $scantronurls{'default'},
4869: $scantronfiles{'default'});
1.60 raeburn 4870: if ($error eq '') {
4871: $confhash{'scantron'}{'scantronformat'} = '';
4872: my $putresult =
4873: &Apache::lonnet::put_dom('configuration',
4874: \%confhash,$dom);
4875: if ($putresult ne 'ok') {
4876: $error{'default'} =
4877: '<span class="LC_error">'.
4878: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4879: }
4880: } else {
4881: $error{'default'} = $error;
4882: }
1.46 raeburn 4883: }
4884: }
4885: }
4886: } else {
1.95 www 4887: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4888: }
4889: }
4890: if (ref($settings) eq 'HASH') {
4891: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4892: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4893: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4894: $scantronurl = '';
4895: } else {
4896: $scantronurl = $settings->{'scantronformat'};
4897: }
4898: $is_custom = 1;
4899: } else {
4900: $scantronurl = $scantronurls{'default'};
4901: }
4902: } else {
1.60 raeburn 4903: if ($is_custom) {
4904: $scantronurl = $scantronurls{'custom'};
4905: } else {
4906: $scantronurl = $scantronurls{'default'};
4907: }
1.46 raeburn 4908: }
4909: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4910: $datatable .= '<tr'.$css_class.'>';
4911: if (!$is_custom) {
1.65 raeburn 4912: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4913: '<span class="LC_nobreak">';
1.46 raeburn 4914: if ($scantronurl) {
1.160.6.21 raeburn 4915: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4916: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4917: } else {
4918: $datatable = &mt('File unavailable for display');
4919: }
1.65 raeburn 4920: $datatable .= '</span></td>';
1.60 raeburn 4921: if (keys(%error) == 0) {
4922: $datatable .= '<td valign="bottom">';
4923: if (!$switchserver) {
4924: $datatable .= &mt('Upload:').'<br />';
4925: }
4926: } else {
4927: my $errorstr;
4928: foreach my $key (sort(keys(%error))) {
4929: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4930: }
4931: $datatable .= '<td>'.$errorstr;
4932: }
1.46 raeburn 4933: } else {
4934: if (keys(%error) > 0) {
4935: my $errorstr;
4936: foreach my $key (sort(keys(%error))) {
4937: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4938: }
1.60 raeburn 4939: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4940: } elsif ($scantronurl) {
1.160.6.26 raeburn 4941: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 4942: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4943: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 4944: $link.
4945: '<label><input type="checkbox" name="scantronformat_del"'.
4946: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4947: '<td><span class="LC_nobreak"> '.
4948: &mt('Replace:').'</span><br />';
1.46 raeburn 4949: }
4950: }
4951: if (keys(%error) == 0) {
4952: if ($switchserver) {
4953: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4954: } else {
1.65 raeburn 4955: $datatable .='<span class="LC_nobreak"> '.
4956: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4957: }
4958: }
4959: $datatable .= '</td></tr>';
4960: $$rowtotal ++;
4961: return $datatable;
4962: }
4963:
4964: sub legacy_scantronformat {
4965: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4966: my ($url,$error);
4967: my @statinfo = &Apache::lonnet::stat_file($newurl);
4968: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4969: (my $result,$url) =
4970: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4971: '','',$newfile);
4972: if ($result ne 'ok') {
1.130 raeburn 4973: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4974: }
4975: }
4976: return ($url,$error);
4977: }
1.43 raeburn 4978:
1.49 raeburn 4979: sub print_coursecategories {
1.57 raeburn 4980: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4981: my $datatable;
4982: if ($position eq 'top') {
1.160.6.42 raeburn 4983: my (%checked);
4984: my @catitems = ('unauth','auth');
4985: my @cattypes = ('std','domonly','codesrch','none');
4986: $checked{'unauth'} = 'std';
4987: $checked{'auth'} = 'std';
4988: if (ref($settings) eq 'HASH') {
4989: foreach my $type (@cattypes) {
4990: if ($type eq $settings->{'unauth'}) {
4991: $checked{'unauth'} = $type;
4992: }
4993: if ($type eq $settings->{'auth'}) {
4994: $checked{'auth'} = $type;
4995: }
4996: }
4997: }
4998: my %lt = &Apache::lonlocal::texthash (
4999: unauth => 'Catalog type for unauthenticated users',
5000: auth => 'Catalog type for authenticated users',
5001: none => 'No catalog',
5002: std => 'Standard catalog',
5003: domonly => 'Domain-only catalog',
5004: codesrch => "Code search form",
5005: );
5006: my $itemcount = 0;
5007: foreach my $item (@catitems) {
5008: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5009: $datatable .= '<tr '.$css_class.'>'.
5010: '<td>'.$lt{$item}.'</td>'.
5011: '<td class="LC_right_item"><span class="LC_nobreak">';
5012: foreach my $type (@cattypes) {
5013: my $ischecked;
5014: if ($checked{$item} eq $type) {
5015: $ischecked=' checked="checked"';
5016: }
5017: $datatable .= '<label>'.
5018: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5019: ' />'.$lt{$type}.'</label> ';
5020: }
5021: $datatable .= '</td></tr>';
5022: $itemcount ++;
5023: }
5024: $$rowtotal += $itemcount;
5025: } elsif ($position eq 'middle') {
1.57 raeburn 5026: my $toggle_cats_crs = ' ';
5027: my $toggle_cats_dom = ' checked="checked" ';
5028: my $can_cat_crs = ' ';
5029: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5030: my $toggle_catscomm_comm = ' ';
5031: my $toggle_catscomm_dom = ' checked="checked" ';
5032: my $can_catcomm_comm = ' ';
5033: my $can_catcomm_dom = ' checked="checked" ';
5034:
1.57 raeburn 5035: if (ref($settings) eq 'HASH') {
5036: if ($settings->{'togglecats'} eq 'crs') {
5037: $toggle_cats_crs = $toggle_cats_dom;
5038: $toggle_cats_dom = ' ';
5039: }
5040: if ($settings->{'categorize'} eq 'crs') {
5041: $can_cat_crs = $can_cat_dom;
5042: $can_cat_dom = ' ';
5043: }
1.120 raeburn 5044: if ($settings->{'togglecatscomm'} eq 'comm') {
5045: $toggle_catscomm_comm = $toggle_catscomm_dom;
5046: $toggle_catscomm_dom = ' ';
5047: }
5048: if ($settings->{'categorizecomm'} eq 'comm') {
5049: $can_catcomm_comm = $can_catcomm_dom;
5050: $can_catcomm_dom = ' ';
5051: }
1.57 raeburn 5052: }
5053: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 5054: togglecats => 'Show/Hide a course in catalog',
5055: togglecatscomm => 'Show/Hide a community in catalog',
5056: categorize => 'Assign a category to a course',
5057: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5058: );
5059: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 5060: dom => 'Set in Domain',
5061: crs => 'Set in Course',
5062: comm => 'Set in Community',
1.57 raeburn 5063: );
5064: $datatable = '<tr class="LC_odd_row">'.
5065: '<td>'.$title{'togglecats'}.'</td>'.
5066: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5067: '<input type="radio" name="togglecats"'.
5068: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5069: '<label><input type="radio" name="togglecats"'.
5070: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5071: '</tr><tr>'.
5072: '<td>'.$title{'categorize'}.'</td>'.
5073: '<td class="LC_right_item"><span class="LC_nobreak">'.
5074: '<label><input type="radio" name="categorize"'.
5075: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5076: '<label><input type="radio" name="categorize"'.
5077: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5078: '</tr><tr class="LC_odd_row">'.
5079: '<td>'.$title{'togglecatscomm'}.'</td>'.
5080: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5081: '<input type="radio" name="togglecatscomm"'.
5082: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5083: '<label><input type="radio" name="togglecatscomm"'.
5084: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5085: '</tr><tr>'.
5086: '<td>'.$title{'categorizecomm'}.'</td>'.
5087: '<td class="LC_right_item"><span class="LC_nobreak">'.
5088: '<label><input type="radio" name="categorizecomm"'.
5089: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5090: '<label><input type="radio" name="categorizecomm"'.
5091: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 5092: '</tr>';
1.120 raeburn 5093: $$rowtotal += 4;
1.57 raeburn 5094: } else {
5095: my $css_class;
5096: my $itemcount = 1;
5097: my $cathash;
5098: if (ref($settings) eq 'HASH') {
5099: $cathash = $settings->{'cats'};
5100: }
5101: if (ref($cathash) eq 'HASH') {
5102: my (@cats,@trails,%allitems,%idx,@jsarray);
5103: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5104: \%allitems,\%idx,\@jsarray);
5105: my $maxdepth = scalar(@cats);
5106: my $colattrib = '';
5107: if ($maxdepth > 2) {
5108: $colattrib = ' colspan="2" ';
5109: }
5110: my @path;
5111: if (@cats > 0) {
5112: if (ref($cats[0]) eq 'ARRAY') {
5113: my $numtop = @{$cats[0]};
5114: my $maxnum = $numtop;
1.120 raeburn 5115: my %default_names = (
5116: instcode => &mt('Official courses'),
5117: communities => &mt('Communities'),
5118: );
5119:
5120: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5121: ($cathash->{'instcode::0'} eq '') ||
5122: (!grep(/^communities$/,@{$cats[0]})) ||
5123: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5124: $maxnum ++;
5125: }
5126: my $lastidx;
5127: for (my $i=0; $i<$numtop; $i++) {
5128: my $parent = $cats[0][$i];
5129: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5130: my $item = &escape($parent).'::0';
5131: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5132: $lastidx = $idx{$item};
5133: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5134: .'<select name="'.$item.'"'.$chgstr.'>';
5135: for (my $k=0; $k<=$maxnum; $k++) {
5136: my $vpos = $k+1;
5137: my $selstr;
5138: if ($k == $i) {
5139: $selstr = ' selected="selected" ';
5140: }
5141: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5142: }
1.160.6.29 raeburn 5143: $datatable .= '</select></span></td><td>';
1.120 raeburn 5144: if ($parent eq 'instcode' || $parent eq 'communities') {
5145: $datatable .= '<span class="LC_nobreak">'
5146: .$default_names{$parent}.'</span>';
5147: if ($parent eq 'instcode') {
5148: $datatable .= '<br /><span class="LC_nobreak">('
5149: .&mt('with institutional codes')
5150: .')</span></td><td'.$colattrib.'>';
5151: } else {
5152: $datatable .= '<table><tr><td>';
5153: }
5154: $datatable .= '<span class="LC_nobreak">'
5155: .'<label><input type="radio" name="'
5156: .$parent.'" value="1" checked="checked" />'
5157: .&mt('Display').'</label>';
5158: if ($parent eq 'instcode') {
5159: $datatable .= ' ';
5160: } else {
5161: $datatable .= '</span></td></tr><tr><td>'
5162: .'<span class="LC_nobreak">';
5163: }
5164: $datatable .= '<label><input type="radio" name="'
5165: .$parent.'" value="0" />'
5166: .&mt('Do not display').'</label></span>';
5167: if ($parent eq 'communities') {
5168: $datatable .= '</td></tr></table>';
5169: }
5170: $datatable .= '</td>';
1.57 raeburn 5171: } else {
5172: $datatable .= $parent
1.160.6.29 raeburn 5173: .' <span class="LC_nobreak"><label>'
5174: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5175: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5176: }
5177: my $depth = 1;
5178: push(@path,$parent);
5179: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5180: pop(@path);
5181: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5182: $itemcount ++;
5183: }
1.48 raeburn 5184: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5185: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5186: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5187: for (my $k=0; $k<=$maxnum; $k++) {
5188: my $vpos = $k+1;
5189: my $selstr;
1.57 raeburn 5190: if ($k == $numtop) {
1.48 raeburn 5191: $selstr = ' selected="selected" ';
5192: }
5193: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5194: }
1.59 bisitz 5195: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5196: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5197: .'</tr>'."\n";
1.48 raeburn 5198: $itemcount ++;
1.120 raeburn 5199: foreach my $default ('instcode','communities') {
5200: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5201: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5202: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5203: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5204: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5205: for (my $k=0; $k<=$maxnum; $k++) {
5206: my $vpos = $k+1;
5207: my $selstr;
5208: if ($k == $maxnum) {
5209: $selstr = ' selected="selected" ';
5210: }
5211: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5212: }
1.120 raeburn 5213: $datatable .= '</select></span></td>'.
5214: '<td><span class="LC_nobreak">'.
5215: $default_names{$default}.'</span>';
5216: if ($default eq 'instcode') {
5217: $datatable .= '<br /><span class="LC_nobreak">('
5218: .&mt('with institutional codes').')</span>';
5219: }
5220: $datatable .= '</td>'
5221: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5222: .&mt('Display').'</label> '
5223: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5224: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5225: }
5226: }
5227: }
1.57 raeburn 5228: } else {
5229: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5230: }
5231: } else {
1.160.6.42 raeburn 5232: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5233: .&initialize_categories($itemcount);
1.48 raeburn 5234: }
1.57 raeburn 5235: $$rowtotal += $itemcount;
1.48 raeburn 5236: }
5237: return $datatable;
5238: }
5239:
1.69 raeburn 5240: sub print_serverstatuses {
5241: my ($dom,$settings,$rowtotal) = @_;
5242: my $datatable;
5243: my @pages = &serverstatus_pages();
5244: my (%namedaccess,%machineaccess);
5245: foreach my $type (@pages) {
5246: $namedaccess{$type} = '';
5247: $machineaccess{$type}= '';
5248: }
5249: if (ref($settings) eq 'HASH') {
5250: foreach my $type (@pages) {
5251: if (exists($settings->{$type})) {
5252: if (ref($settings->{$type}) eq 'HASH') {
5253: foreach my $key (keys(%{$settings->{$type}})) {
5254: if ($key eq 'namedusers') {
5255: $namedaccess{$type} = $settings->{$type}->{$key};
5256: } elsif ($key eq 'machines') {
5257: $machineaccess{$type} = $settings->{$type}->{$key};
5258: }
5259: }
5260: }
5261: }
5262: }
5263: }
1.81 raeburn 5264: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5265: my $rownum = 0;
5266: my $css_class;
5267: foreach my $type (@pages) {
5268: $rownum ++;
5269: $css_class = $rownum%2?' class="LC_odd_row"':'';
5270: $datatable .= '<tr'.$css_class.'>'.
5271: '<td><span class="LC_nobreak">'.
5272: $titles->{$type}.'</span></td>'.
5273: '<td class="LC_left_item">'.
5274: '<input type="text" name="'.$type.'_namedusers" '.
5275: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5276: '<td class="LC_right_item">'.
5277: '<span class="LC_nobreak">'.
5278: '<input type="text" name="'.$type.'_machines" '.
5279: 'value="'.$machineaccess{$type}.'" size="10" />'.
5280: '</td></tr>'."\n";
5281: }
5282: $$rowtotal += $rownum;
5283: return $datatable;
5284: }
5285:
5286: sub serverstatus_pages {
5287: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 5288: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 5289: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.36 raeburn 5290: 'uniquecodes','diskusage');
1.69 raeburn 5291: }
5292:
1.160.6.40 raeburn 5293: sub defaults_javascript {
5294: my ($settings) = @_;
1.160.6.51 raeburn 5295: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 5296: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5297: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5298: if ($maxnum eq '') {
5299: $maxnum = 0;
5300: }
5301: $maxnum ++;
1.160.6.51 raeburn 5302: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 5303: return <<"ENDSCRIPT";
5304: <script type="text/javascript">
5305: // <![CDATA[
5306: function reorderTypes(form,caller) {
5307: var changedVal;
5308: $jstext
5309: var newpos = 'addinststatus_pos';
5310: var current = new Array;
5311: var maxh = $maxnum;
5312: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5313: var oldVal;
5314: if (caller == newpos) {
5315: changedVal = newitemVal;
5316: } else {
5317: var curritem = 'inststatus_pos_'+caller;
5318: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5319: current[newitemVal] = newpos;
5320: }
5321: for (var i=0; i<inststatuses.length; i++) {
5322: if (inststatuses[i] != caller) {
5323: var elementName = 'inststatus_pos_'+inststatuses[i];
5324: if (form.elements[elementName]) {
5325: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5326: current[currVal] = elementName;
5327: }
5328: }
5329: }
5330: for (var j=0; j<maxh; j++) {
5331: if (current[j] == undefined) {
5332: oldVal = j;
5333: }
5334: }
5335: if (oldVal < changedVal) {
5336: for (var k=oldVal+1; k<=changedVal ; k++) {
5337: var elementName = current[k];
5338: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5339: }
5340: } else {
5341: for (var k=changedVal; k<oldVal; k++) {
5342: var elementName = current[k];
5343: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5344: }
5345: }
5346: return;
5347: }
5348:
5349: // ]]>
5350: </script>
5351:
5352: ENDSCRIPT
5353: }
5354: }
5355:
1.49 raeburn 5356: sub coursecategories_javascript {
5357: my ($settings) = @_;
1.57 raeburn 5358: my ($output,$jstext,$cathash);
1.49 raeburn 5359: if (ref($settings) eq 'HASH') {
1.57 raeburn 5360: $cathash = $settings->{'cats'};
5361: }
5362: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5363: my (@cats,@jsarray,%idx);
1.57 raeburn 5364: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5365: if (@jsarray > 0) {
5366: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5367: for (my $i=0; $i<@jsarray; $i++) {
5368: if (ref($jsarray[$i]) eq 'ARRAY') {
5369: my $catstr = join('","',@{$jsarray[$i]});
5370: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5371: }
5372: }
5373: }
5374: } else {
5375: $jstext = ' var categories = Array(1);'."\n".
5376: ' categories[0] = Array("instcode_pos");'."\n";
5377: }
1.160.6.42 raeburn 5378: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5379: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
5380: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.');
1.49 raeburn 5381: $output = <<"ENDSCRIPT";
5382: <script type="text/javascript">
1.109 raeburn 5383: // <![CDATA[
1.49 raeburn 5384: function reorderCats(form,parent,item,idx) {
5385: var changedVal;
5386: $jstext
5387: var newpos = 'addcategory_pos';
5388: if (parent == '') {
5389: var has_instcode = 0;
5390: var maxtop = categories[idx].length;
5391: for (var j=0; j<maxtop; j++) {
5392: if (categories[idx][j] == 'instcode::0') {
5393: has_instcode == 1;
5394: }
5395: }
5396: if (has_instcode == 0) {
5397: categories[idx][maxtop] = 'instcode_pos';
5398: }
5399: } else {
5400: newpos += '_'+parent;
5401: }
5402: var maxh = 1 + categories[idx].length;
5403: var current = new Array;
5404: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5405: if (item == newpos) {
5406: changedVal = newitemVal;
5407: } else {
5408: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5409: current[newitemVal] = newpos;
5410: }
5411: for (var i=0; i<categories[idx].length; i++) {
5412: var elementName = categories[idx][i];
5413: if (elementName != item) {
5414: if (form.elements[elementName]) {
5415: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5416: current[currVal] = elementName;
5417: }
5418: }
5419: }
5420: var oldVal;
5421: for (var j=0; j<maxh; j++) {
5422: if (current[j] == undefined) {
5423: oldVal = j;
5424: }
5425: }
5426: if (oldVal < changedVal) {
5427: for (var k=oldVal+1; k<=changedVal ; k++) {
5428: var elementName = current[k];
5429: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5430: }
5431: } else {
5432: for (var k=changedVal; k<oldVal; k++) {
5433: var elementName = current[k];
5434: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5435: }
5436: }
5437: return;
5438: }
1.120 raeburn 5439:
5440: function categoryCheck(form) {
5441: if (form.elements['addcategory_name'].value == 'instcode') {
5442: alert('$instcode_reserved\\n$choose_again');
5443: return false;
5444: }
5445: if (form.elements['addcategory_name'].value == 'communities') {
5446: alert('$communities_reserved\\n$choose_again');
5447: return false;
5448: }
5449: return true;
5450: }
5451:
1.109 raeburn 5452: // ]]>
1.49 raeburn 5453: </script>
5454:
5455: ENDSCRIPT
5456: return $output;
5457: }
5458:
1.48 raeburn 5459: sub initialize_categories {
5460: my ($itemcount) = @_;
1.120 raeburn 5461: my ($datatable,$css_class,$chgstr);
5462: my %default_names = (
5463: instcode => 'Official courses (with institutional codes)',
5464: communities => 'Communities',
5465: );
5466: my $select0 = ' selected="selected"';
5467: my $select1 = '';
5468: foreach my $default ('instcode','communities') {
5469: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5470: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5471: if ($default eq 'communities') {
5472: $select1 = $select0;
5473: $select0 = '';
5474: }
5475: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5476: .'<select name="'.$default.'_pos">'
5477: .'<option value="0"'.$select0.'>1</option>'
5478: .'<option value="1"'.$select1.'>2</option>'
5479: .'<option value="2">3</option></select> '
5480: .$default_names{$default}
5481: .'</span></td><td><span class="LC_nobreak">'
5482: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5483: .&mt('Display').'</label> <label>'
5484: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5485: .'</label></span></td></tr>';
1.120 raeburn 5486: $itemcount ++;
5487: }
1.48 raeburn 5488: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5489: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5490: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5491: .'<select name="addcategory_pos"'.$chgstr.'>'
5492: .'<option value="0">1</option>'
5493: .'<option value="1">2</option>'
5494: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5495: .&mt('Add category').'</td><td>'.&mt('Name:')
5496: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5497: return $datatable;
5498: }
5499:
5500: sub build_category_rows {
1.49 raeburn 5501: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5502: my ($text,$name,$item,$chgstr);
1.48 raeburn 5503: if (ref($cats) eq 'ARRAY') {
5504: my $maxdepth = scalar(@{$cats});
5505: if (ref($cats->[$depth]) eq 'HASH') {
5506: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5507: my $numchildren = @{$cats->[$depth]{$parent}};
5508: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 5509: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5510: my ($idxnum,$parent_name,$parent_item);
5511: my $higher = $depth - 1;
5512: if ($higher == 0) {
5513: $parent_name = &escape($parent).'::'.$higher;
5514: } else {
5515: if (ref($path) eq 'ARRAY') {
5516: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5517: }
5518: }
5519: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5520: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5521: if ($j < $numchildren) {
1.48 raeburn 5522: $name = $cats->[$depth]{$parent}[$j];
5523: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5524: $idxnum = $idx->{$item};
5525: } else {
5526: $name = $parent_name;
5527: $item = $parent_item;
1.48 raeburn 5528: }
1.49 raeburn 5529: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5530: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5531: for (my $i=0; $i<=$numchildren; $i++) {
5532: my $vpos = $i+1;
5533: my $selstr;
5534: if ($j == $i) {
5535: $selstr = ' selected="selected" ';
5536: }
5537: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5538: }
5539: $text .= '</select> ';
5540: if ($j < $numchildren) {
5541: my $deeper = $depth+1;
5542: $text .= $name.' '
5543: .'<label><input type="checkbox" name="deletecategory" value="'
5544: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5545: if(ref($path) eq 'ARRAY') {
5546: push(@{$path},$name);
1.49 raeburn 5547: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5548: pop(@{$path});
5549: }
5550: } else {
1.59 bisitz 5551: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5552: if ($j == $numchildren) {
5553: $text .= $name;
5554: } else {
5555: $text .= $item;
5556: }
5557: $text .= '" value="" />';
5558: }
5559: $text .= '</td></tr>';
5560: }
5561: $text .= '</table></td>';
5562: } else {
5563: my $higher = $depth-1;
5564: if ($higher == 0) {
5565: $name = &escape($parent).'::'.$higher;
5566: } else {
5567: if (ref($path) eq 'ARRAY') {
5568: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5569: }
5570: }
5571: my $colspan;
5572: if ($parent ne 'instcode') {
5573: $colspan = $maxdepth - $depth - 1;
5574: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5575: }
5576: }
5577: }
5578: }
5579: return $text;
5580: }
5581:
1.33 raeburn 5582: sub modifiable_userdata_row {
1.160.6.35 raeburn 5583: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5584: my ($role,$rolename,$statustype);
5585: $role = $item;
1.160.6.34 raeburn 5586: if ($context eq 'cancreate') {
1.160.6.35 raeburn 5587: if ($item =~ /^emailusername_(.+)$/) {
5588: $statustype = $1;
5589: $role = 'emailusername';
5590: if (ref($usertypes) eq 'HASH') {
5591: if ($usertypes->{$statustype}) {
5592: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5593: } else {
5594: $rolename = &mt('Data provided by user');
5595: }
5596: }
1.160.6.34 raeburn 5597: }
5598: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5599: if (ref($usertypes) eq 'HASH') {
5600: $rolename = $usertypes->{$role};
5601: } else {
5602: $rolename = $role;
5603: }
1.33 raeburn 5604: } else {
1.63 raeburn 5605: if ($role eq 'cr') {
5606: $rolename = &mt('Custom role');
5607: } else {
5608: $rolename = &Apache::lonnet::plaintext($role);
5609: }
1.33 raeburn 5610: }
1.160.6.34 raeburn 5611: my (@fields,%fieldtitles);
5612: if (ref($fieldsref) eq 'ARRAY') {
5613: @fields = @{$fieldsref};
5614: } else {
5615: @fields = ('lastname','firstname','middlename','generation',
5616: 'permanentemail','id');
5617: }
5618: if ((ref($titlesref) eq 'HASH')) {
5619: %fieldtitles = %{$titlesref};
5620: } else {
5621: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5622: }
1.33 raeburn 5623: my $output;
5624: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5625: $output = '<tr '.$css_class.'>'.
5626: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5627: '<td class="LC_left_item" colspan="2"><table>';
5628: my $rem;
5629: my %checks;
5630: if (ref($settings) eq 'HASH') {
5631: if (ref($settings->{$context}) eq 'HASH') {
5632: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 5633: my $hashref = $settings->{$context}->{$role};
5634: if ($role eq 'emailusername') {
5635: if ($statustype) {
5636: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5637: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 5638: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 5639: foreach my $field (@fields) {
5640: if ($hashref->{$field}) {
5641: $checks{$field} = $hashref->{$field};
5642: }
5643: }
5644: }
5645: }
5646: }
5647: } else {
5648: if (ref($hashref) eq 'HASH') {
5649: foreach my $field (@fields) {
5650: if ($hashref->{$field}) {
5651: $checks{$field} = ' checked="checked" ';
5652: }
5653: }
1.33 raeburn 5654: }
5655: }
5656: }
5657: }
5658: }
1.160.6.39 raeburn 5659:
1.33 raeburn 5660: for (my $i=0; $i<@fields; $i++) {
5661: my $rem = $i%($numinrow);
5662: if ($rem == 0) {
5663: if ($i > 0) {
5664: $output .= '</tr>';
5665: }
5666: $output .= '<tr>';
5667: }
5668: my $check = ' ';
1.160.6.35 raeburn 5669: unless ($role eq 'emailusername') {
5670: if (exists($checks{$fields[$i]})) {
5671: $check = $checks{$fields[$i]}
5672: } else {
5673: if ($role eq 'st') {
5674: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 5675: $check = ' checked="checked" ';
1.160.6.35 raeburn 5676: }
1.33 raeburn 5677: }
5678: }
5679: }
5680: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 5681: '<span class="LC_nobreak">';
5682: if ($role eq 'emailusername') {
5683: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5684: $checks{$fields[$i]} = 'omit';
5685: }
5686: foreach my $option ('required','optional','omit') {
5687: my $checked='';
5688: if ($checks{$fields[$i]} eq $option) {
5689: $checked='checked="checked" ';
5690: }
5691: $output .= '<label>'.
5692: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5693: &mt($option).'</label>'.(' ' x2);
5694: }
5695: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5696: } else {
5697: $output .= '<label>'.
5698: '<input type="checkbox" name="canmodify_'.$role.'" '.
5699: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5700: '</label>';
5701: }
5702: $output .= '</span></td>';
1.33 raeburn 5703: $rem = @fields%($numinrow);
5704: }
5705: my $colsleft = $numinrow - $rem;
5706: if ($colsleft > 1 ) {
5707: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5708: ' </td>';
5709: } elsif ($colsleft == 1) {
5710: $output .= '<td class="LC_left_item"> </td>';
5711: }
5712: $output .= '</tr></table></td></tr>';
5713: return $output;
5714: }
1.28 raeburn 5715:
1.93 raeburn 5716: sub insttypes_row {
1.160.6.34 raeburn 5717: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5718: my %lt = &Apache::lonlocal::texthash (
5719: cansearch => 'Users allowed to search',
5720: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5721: lockablenames => 'User preference to lock name',
1.93 raeburn 5722: );
5723: my $showdom;
5724: if ($context eq 'cansearch') {
5725: $showdom = ' ('.$dom.')';
5726: }
1.160.6.5 raeburn 5727: my $class = 'LC_left_item';
5728: if ($context eq 'statustocreate') {
5729: $class = 'LC_right_item';
5730: }
1.160.6.34 raeburn 5731: my $css_class = ' class="LC_odd_row"';
5732: if ($rownum ne '') {
5733: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5734: }
5735: my $output = '<tr'.$css_class.'>'.
5736: '<td>'.$lt{$context}.$showdom.
5737: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5738: my $rem;
5739: if (ref($types) eq 'ARRAY') {
5740: for (my $i=0; $i<@{$types}; $i++) {
5741: if (defined($usertypes->{$types->[$i]})) {
5742: my $rem = $i%($numinrow);
5743: if ($rem == 0) {
5744: if ($i > 0) {
5745: $output .= '</tr>';
5746: }
5747: $output .= '<tr>';
1.23 raeburn 5748: }
1.26 raeburn 5749: my $check = ' ';
1.99 raeburn 5750: if (ref($settings) eq 'HASH') {
5751: if (ref($settings->{$context}) eq 'ARRAY') {
5752: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5753: $check = ' checked="checked" ';
5754: }
5755: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5756: $check = ' checked="checked" ';
5757: }
1.23 raeburn 5758: }
1.26 raeburn 5759: $output .= '<td class="LC_left_item">'.
5760: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5761: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5762: 'value="'.$types->[$i].'"'.$check.'/>'.
5763: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5764: }
5765: }
1.26 raeburn 5766: $rem = @{$types}%($numinrow);
1.23 raeburn 5767: }
5768: my $colsleft = $numinrow - $rem;
1.131 raeburn 5769: if (($rem == 0) && (@{$types} > 0)) {
5770: $output .= '<tr>';
5771: }
1.23 raeburn 5772: if ($colsleft > 1) {
1.25 raeburn 5773: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5774: } else {
1.25 raeburn 5775: $output .= '<td class="LC_left_item">';
1.23 raeburn 5776: }
5777: my $defcheck = ' ';
1.99 raeburn 5778: if (ref($settings) eq 'HASH') {
5779: if (ref($settings->{$context}) eq 'ARRAY') {
5780: if (grep(/^default$/,@{$settings->{$context}})) {
5781: $defcheck = ' checked="checked" ';
5782: }
5783: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5784: $defcheck = ' checked="checked" ';
5785: }
1.23 raeburn 5786: }
1.25 raeburn 5787: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5788: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5789: 'value="default"'.$defcheck.'/>'.
5790: $othertitle.'</label></span></td>'.
5791: '</tr></table></td></tr>';
5792: return $output;
1.23 raeburn 5793: }
5794:
5795: sub sorted_searchtitles {
5796: my %searchtitles = &Apache::lonlocal::texthash(
5797: 'uname' => 'username',
5798: 'lastname' => 'last name',
5799: 'lastfirst' => 'last name, first name',
5800: );
5801: my @titleorder = ('uname','lastname','lastfirst');
5802: return (\%searchtitles,\@titleorder);
5803: }
5804:
1.25 raeburn 5805: sub sorted_searchtypes {
5806: my %srchtypes_desc = (
5807: exact => 'is exact match',
5808: contains => 'contains ..',
5809: begins => 'begins with ..',
5810: );
5811: my @srchtypeorder = ('exact','begins','contains');
5812: return (\%srchtypes_desc,\@srchtypeorder);
5813: }
5814:
1.3 raeburn 5815: sub usertype_update_row {
5816: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5817: my $datatable;
5818: my $numinrow = 4;
5819: foreach my $type (@{$types}) {
5820: if (defined($usertypes->{$type})) {
5821: $$rownums ++;
5822: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5823: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5824: '</td><td class="LC_left_item"><table>';
5825: for (my $i=0; $i<@{$fields}; $i++) {
5826: my $rem = $i%($numinrow);
5827: if ($rem == 0) {
5828: if ($i > 0) {
5829: $datatable .= '</tr>';
5830: }
5831: $datatable .= '<tr>';
5832: }
5833: my $check = ' ';
1.39 raeburn 5834: if (ref($settings) eq 'HASH') {
5835: if (ref($settings->{'fields'}) eq 'HASH') {
5836: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5837: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5838: $check = ' checked="checked" ';
5839: }
1.3 raeburn 5840: }
5841: }
5842: }
5843:
5844: if ($i == @{$fields}-1) {
5845: my $colsleft = $numinrow - $rem;
5846: if ($colsleft > 1) {
5847: $datatable .= '<td colspan="'.$colsleft.'">';
5848: } else {
5849: $datatable .= '<td>';
5850: }
5851: } else {
5852: $datatable .= '<td>';
5853: }
1.8 raeburn 5854: $datatable .= '<span class="LC_nobreak"><label>'.
5855: '<input type="checkbox" name="updateable_'.$type.
5856: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5857: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5858: }
5859: $datatable .= '</tr></table></td></tr>';
5860: }
5861: }
5862: return $datatable;
1.1 raeburn 5863: }
5864:
5865: sub modify_login {
1.160.6.24 raeburn 5866: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 5867: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5868: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5869: %title = ( coursecatalog => 'Display course catalog',
5870: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 5871: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 5872: newuser => 'Link for visitors to create a user account',
5873: loginheader => 'Log-in box header');
5874: @offon = ('off','on');
1.112 raeburn 5875: if (ref($domconfig{login}) eq 'HASH') {
5876: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5877: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5878: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5879: }
5880: }
5881: }
1.9 raeburn 5882: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5883: \%domconfig,\%loginhash);
1.160.6.14 raeburn 5884: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5885: foreach my $item (@toggles) {
5886: $loginhash{login}{$item} = $env{'form.'.$item};
5887: }
1.41 raeburn 5888: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5889: if (ref($colchanges{'login'}) eq 'HASH') {
5890: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5891: \%loginhash);
5892: }
1.110 raeburn 5893:
1.149 raeburn 5894: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 5895: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 5896: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5897: if (keys(%servers) > 1) {
5898: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5899: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5900: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5901: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5902: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5903: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5904: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5905: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5906: $changes{'loginvia'}{$lonhost} = 1;
5907: } else {
5908: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5909: $changes{'loginvia'}{$lonhost} = 1;
5910: }
5911: } else {
5912: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5913: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5914: $changes{'loginvia'}{$lonhost} = 1;
5915: }
5916: }
5917: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5918: foreach my $item (@loginvia_attribs) {
5919: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5920: }
5921: } else {
5922: foreach my $item (@loginvia_attribs) {
5923: my $new = $env{'form.'.$lonhost.'_'.$item};
5924: if (($item eq 'serverpath') && ($new eq 'custom')) {
5925: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5926: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5927: $new = '/';
5928: }
5929: }
5930: if (($item eq 'custompath') &&
5931: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5932: $new = '';
5933: }
5934: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5935: $changes{'loginvia'}{$lonhost} = 1;
5936: }
5937: if ($item eq 'exempt') {
1.160.6.56 raeburn 5938: $new = &check_exempt_addresses($new);
1.128 raeburn 5939: }
5940: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5941: }
5942: }
1.112 raeburn 5943: } else {
1.128 raeburn 5944: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5945: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5946: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5947: foreach my $item (@loginvia_attribs) {
5948: my $new = $env{'form.'.$lonhost.'_'.$item};
5949: if (($item eq 'serverpath') && ($new eq 'custom')) {
5950: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5951: $new = '/';
5952: }
5953: }
5954: if (($item eq 'custompath') &&
5955: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5956: $new = '';
5957: }
5958: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5959: }
1.110 raeburn 5960: }
5961: }
5962: }
5963: }
1.119 raeburn 5964:
1.160.6.5 raeburn 5965: my $servadm = $r->dir_config('lonAdmEMail');
5966: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5967: if (ref($domconfig{'login'}) eq 'HASH') {
5968: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5969: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5970: if ($lang eq 'nolang') {
5971: push(@currlangs,$lang);
5972: } elsif (defined($langchoices{$lang})) {
5973: push(@currlangs,$lang);
5974: } else {
5975: next;
5976: }
5977: }
5978: }
5979: }
5980: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5981: if (@currlangs > 0) {
5982: foreach my $lang (@currlangs) {
5983: if (grep(/^\Q$lang\E$/,@delurls)) {
5984: $changes{'helpurl'}{$lang} = 1;
5985: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5986: $changes{'helpurl'}{$lang} = 1;
5987: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5988: push(@newlangs,$lang);
5989: } else {
5990: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5991: }
5992: }
5993: }
5994: unless (grep(/^nolang$/,@currlangs)) {
5995: if ($env{'form.loginhelpurl_nolang.filename'}) {
5996: $changes{'helpurl'}{'nolang'} = 1;
5997: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5998: push(@newlangs,'nolang');
5999: }
6000: }
6001: if ($env{'form.loginhelpurl_add_lang'}) {
6002: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6003: ($env{'form.loginhelpurl_add_file.filename'})) {
6004: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6005: $addedfile = $env{'form.loginhelpurl_add_lang'};
6006: }
6007: }
6008: if ((@newlangs > 0) || ($addedfile)) {
6009: my $error;
6010: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6011: if ($configuserok eq 'ok') {
6012: if ($switchserver) {
6013: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6014: } elsif ($author_ok eq 'ok') {
6015: my @allnew = @newlangs;
6016: if ($addedfile ne '') {
6017: push(@allnew,$addedfile);
6018: }
6019: foreach my $lang (@allnew) {
6020: my $formelem = 'loginhelpurl_'.$lang;
6021: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6022: $formelem = 'loginhelpurl_add_file';
6023: }
6024: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6025: "help/$lang",'','',$newfile{$lang});
6026: if ($result eq 'ok') {
6027: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6028: $changes{'helpurl'}{$lang} = 1;
6029: } else {
6030: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6031: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6032: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
6033: (!grep(/^\Q$lang\E$/,@delurls))) {
6034:
6035: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6036: }
6037: }
6038: }
6039: } else {
6040: $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);
6041: }
6042: } else {
6043: $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);
6044: }
6045: if ($error) {
6046: &Apache::lonnet::logthis($error);
6047: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6048: }
6049: }
1.160.6.56 raeburn 6050:
6051: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6052: if (ref($domconfig{'login'}) eq 'HASH') {
6053: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6054: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6055: if ($domservers{$lonhost}) {
6056: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6057: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
6058: $currexempt{$lonhost} = $domconfig{'login'}{'headtagexempt'}{$lonhost}{'exempt'}
6059: }
6060: }
6061: }
6062: }
6063: }
6064: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6065: foreach my $lonhost (sort(keys(%domservers))) {
6066: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6067: $changes{'headtag'}{$lonhost} = 1;
6068: } else {
6069: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6070: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6071: }
6072: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6073: push(@newhosts,$lonhost);
6074: } elsif ($currheadtagurls{$lonhost}) {
6075: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6076: if ($currexempt{$lonhost}) {
6077: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6078: $changes{'headtag'}{$lonhost} = 1;
6079: }
6080: } elsif ($possexempt{$lonhost}) {
6081: $changes{'headtag'}{$lonhost} = 1;
6082: }
6083: if ($possexempt{$lonhost}) {
6084: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6085: }
6086: }
6087: }
6088: }
6089: if (@newhosts) {
6090: my $error;
6091: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6092: if ($configuserok eq 'ok') {
6093: if ($switchserver) {
6094: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6095: } elsif ($author_ok eq 'ok') {
6096: foreach my $lonhost (@newhosts) {
6097: my $formelem = 'loginheadtag_'.$lonhost;
6098: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6099: "login/headtag/$lonhost",'','',
6100: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6101: if ($result eq 'ok') {
6102: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6103: $changes{'headtag'}{$lonhost} = 1;
6104: if ($possexempt{$lonhost}) {
6105: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6106: }
6107: } else {
6108: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6109: $newheadtagurls{$lonhost},$result);
6110: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6111: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
6112: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
6113: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
6114: }
6115: }
6116: }
6117: } else {
6118: $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);
6119: }
6120: } else {
6121: $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);
6122: }
6123: if ($error) {
6124: &Apache::lonnet::logthis($error);
6125: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6126: }
6127: }
6128:
1.160.6.5 raeburn 6129: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
6130:
6131: my $defaulthelpfile = '/adm/loginproblems.html';
6132: my $defaulttext = &mt('Default in use');
6133:
1.1 raeburn 6134: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
6135: $dom);
6136: if ($putresult eq 'ok') {
1.160.6.14 raeburn 6137: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6138: my %defaultchecked = (
6139: 'coursecatalog' => 'on',
1.160.6.14 raeburn 6140: 'helpdesk' => 'on',
1.42 raeburn 6141: 'adminmail' => 'off',
1.43 raeburn 6142: 'newuser' => 'off',
1.42 raeburn 6143: );
1.55 raeburn 6144: if (ref($domconfig{'login'}) eq 'HASH') {
6145: foreach my $item (@toggles) {
6146: if ($defaultchecked{$item} eq 'on') {
6147: if (($domconfig{'login'}{$item} eq '0') &&
6148: ($env{'form.'.$item} eq '1')) {
6149: $changes{$item} = 1;
6150: } elsif (($domconfig{'login'}{$item} eq '' ||
6151: $domconfig{'login'}{$item} eq '1') &&
6152: ($env{'form.'.$item} eq '0')) {
6153: $changes{$item} = 1;
6154: }
6155: } elsif ($defaultchecked{$item} eq 'off') {
6156: if (($domconfig{'login'}{$item} eq '1') &&
6157: ($env{'form.'.$item} eq '0')) {
6158: $changes{$item} = 1;
6159: } elsif (($domconfig{'login'}{$item} eq '' ||
6160: $domconfig{'login'}{$item} eq '0') &&
6161: ($env{'form.'.$item} eq '1')) {
6162: $changes{$item} = 1;
6163: }
1.42 raeburn 6164: }
6165: }
1.41 raeburn 6166: }
1.6 raeburn 6167: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 6168: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6169: if (ref($lastactref) eq 'HASH') {
6170: $lastactref->{'domainconfig'} = 1;
6171: }
1.1 raeburn 6172: $resulttext = &mt('Changes made:').'<ul>';
6173: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 6174: if ($item eq 'loginvia') {
1.112 raeburn 6175: if (ref($changes{$item}) eq 'HASH') {
6176: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
6177: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 6178: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
6179: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
6180: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
6181: $protocol = 'http' if ($protocol ne 'https');
6182: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
6183:
6184: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6185: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6186: } else {
6187: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6188: }
6189: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6190: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
6191: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
6192: }
6193: $resulttext .= '</li>';
6194: } else {
6195: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6196: }
1.112 raeburn 6197: } else {
1.128 raeburn 6198: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 6199: }
6200: }
1.128 raeburn 6201: $resulttext .= '</ul></li>';
1.112 raeburn 6202: }
1.160.6.5 raeburn 6203: } elsif ($item eq 'helpurl') {
6204: if (ref($changes{$item}) eq 'HASH') {
6205: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6206: if (grep(/^\Q$lang\E$/,@delurls)) {
6207: my ($chg,$link);
6208: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6209: if ($lang eq 'nolang') {
6210: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6211: } else {
6212: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6213: }
6214: $resulttext .= '<li>'.$chg.'</li>';
6215: } else {
6216: my $chg;
6217: if ($lang eq 'nolang') {
6218: $chg = &mt('custom log-in help file for no preferred language');
6219: } else {
6220: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6221: }
6222: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6223: $loginhash{'login'}{'helpurl'}{$lang}.
6224: '?inhibitmenu=yes',$chg,600,500).
6225: '</li>';
6226: }
6227: }
6228: }
1.160.6.56 raeburn 6229: } elsif ($item eq 'headtag') {
6230: if (ref($changes{$item}) eq 'HASH') {
6231: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
6232: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6233: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
6234: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6235: $resulttext .= '<li><a href="'.
6236: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
6237: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
6238: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
6239: if ($possexempt{$lonhost}) {
6240: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
6241: } else {
6242: $resulttext .= &mt('included for any client IP');
6243: }
6244: $resulttext .= '</li>';
6245: }
6246: }
6247: }
1.160.6.5 raeburn 6248: } elsif ($item eq 'captcha') {
6249: if (ref($loginhash{'login'}) eq 'HASH') {
6250: my $chgtxt;
6251: if ($loginhash{'login'}{$item} eq 'notused') {
6252: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6253: } else {
6254: my %captchas = &captcha_phrases();
6255: if ($captchas{$loginhash{'login'}{$item}}) {
6256: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6257: } else {
6258: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6259: }
6260: }
6261: $resulttext .= '<li>'.$chgtxt.'</li>';
6262: }
6263: } elsif ($item eq 'recaptchakeys') {
6264: if (ref($loginhash{'login'}) eq 'HASH') {
6265: my ($privkey,$pubkey);
6266: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6267: $pubkey = $loginhash{'login'}{$item}{'public'};
6268: $privkey = $loginhash{'login'}{$item}{'private'};
6269: }
6270: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6271: if (!$pubkey) {
6272: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6273: } else {
6274: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6275: }
6276: if (!$privkey) {
6277: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6278: } else {
1.160.6.53 raeburn 6279: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 6280: }
6281: $chgtxt .= '</ul>';
6282: $resulttext .= '<li>'.$chgtxt.'</li>';
6283: }
1.41 raeburn 6284: } else {
6285: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6286: }
1.1 raeburn 6287: }
1.6 raeburn 6288: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6289: } else {
6290: $resulttext = &mt('No changes made to log-in page settings');
6291: }
6292: } else {
1.11 albertel 6293: $resulttext = '<span class="LC_error">'.
6294: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6295: }
1.6 raeburn 6296: if ($errors) {
1.9 raeburn 6297: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6298: $errors.'</ul>';
6299: }
6300: return $resulttext;
6301: }
6302:
1.160.6.56 raeburn 6303: sub check_exempt_addresses {
6304: my ($iplist) = @_;
6305: $iplist =~ s/^\s+//;
6306: $iplist =~ s/\s+$//;
6307: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
6308: my (@okips,$new);
6309: foreach my $ip (@poss_ips) {
6310: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
6311: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
6312: push(@okips,$ip);
6313: }
6314: }
6315: }
6316: if (@okips > 0) {
6317: $new = join(',',@okips);
6318: } else {
6319: $new = '';
6320: }
6321: return $new;
6322: }
6323:
1.6 raeburn 6324: sub color_font_choices {
6325: my %choices =
6326: &Apache::lonlocal::texthash (
6327: img => "Header",
6328: bgs => "Background colors",
6329: links => "Link colors",
1.55 raeburn 6330: images => "Images",
1.6 raeburn 6331: font => "Font color",
1.160.6.22 raeburn 6332: fontmenu => "Font menu",
1.76 raeburn 6333: pgbg => "Page",
1.6 raeburn 6334: tabbg => "Header",
6335: sidebg => "Border",
6336: link => "Link",
6337: alink => "Active link",
6338: vlink => "Visited link",
6339: );
6340: return %choices;
6341: }
6342:
6343: sub modify_rolecolors {
1.160.6.24 raeburn 6344: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6345: my ($resulttext,%rolehash);
6346: $rolehash{'rolecolors'} = {};
1.55 raeburn 6347: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6348: if ($domconfig{'rolecolors'} eq '') {
6349: $domconfig{'rolecolors'} = {};
6350: }
6351: }
1.9 raeburn 6352: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6353: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6354: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6355: $dom);
6356: if ($putresult eq 'ok') {
6357: if (keys(%changes) > 0) {
1.41 raeburn 6358: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6359: if (ref($lastactref) eq 'HASH') {
6360: $lastactref->{'domainconfig'} = 1;
6361: }
1.6 raeburn 6362: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6363: $rolehash{'rolecolors'});
6364: } else {
6365: $resulttext = &mt('No changes made to default color schemes');
6366: }
6367: } else {
1.11 albertel 6368: $resulttext = '<span class="LC_error">'.
6369: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6370: }
6371: if ($errors) {
6372: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6373: $errors.'</ul>';
6374: }
6375: return $resulttext;
6376: }
6377:
6378: sub modify_colors {
1.9 raeburn 6379: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6380: my (%changes,%choices);
1.51 raeburn 6381: my @bgs;
1.6 raeburn 6382: my @links = ('link','alink','vlink');
1.41 raeburn 6383: my @logintext;
1.6 raeburn 6384: my @images;
6385: my $servadm = $r->dir_config('lonAdmEMail');
6386: my $errors;
1.160.6.22 raeburn 6387: my %defaults;
1.6 raeburn 6388: foreach my $role (@{$roles}) {
6389: if ($role eq 'login') {
1.12 raeburn 6390: %choices = &login_choices();
1.41 raeburn 6391: @logintext = ('textcol','bgcol');
1.12 raeburn 6392: } else {
6393: %choices = &color_font_choices();
6394: }
6395: if ($role eq 'login') {
1.41 raeburn 6396: @images = ('img','logo','domlogo','login');
1.51 raeburn 6397: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6398: } else {
6399: @images = ('img');
1.160.6.22 raeburn 6400: @bgs = ('pgbg','tabbg','sidebg');
6401: }
6402: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6403: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6404: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6405: }
6406: if ($role eq 'login') {
6407: foreach my $item (@logintext) {
1.160.6.39 raeburn 6408: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6409: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6410: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6411: }
6412: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 6413: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6414: }
6415: }
6416: } else {
1.160.6.39 raeburn 6417: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6418: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6419: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6420: }
6421: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 6422: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6423: }
1.6 raeburn 6424: }
1.160.6.22 raeburn 6425: foreach my $item (@bgs) {
1.160.6.39 raeburn 6426: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6427: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6428: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6429: }
6430: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 6431: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6432: }
6433: }
6434: foreach my $item (@links) {
1.160.6.39 raeburn 6435: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6436: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6437: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6438: }
6439: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 6440: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6441: }
1.6 raeburn 6442: }
1.46 raeburn 6443: my ($configuserok,$author_ok,$switchserver) =
6444: &config_check($dom,$confname,$servadm);
1.9 raeburn 6445: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6446: if (ref($domconfig->{$role}) ne 'HASH') {
6447: $domconfig->{$role} = {};
6448: }
1.8 raeburn 6449: foreach my $img (@images) {
1.70 raeburn 6450: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6451: if (defined($env{'form.login_showlogo_'.$img})) {
6452: $confhash->{$role}{'showlogo'}{$img} = 1;
6453: } else {
6454: $confhash->{$role}{'showlogo'}{$img} = 0;
6455: }
6456: }
1.18 albertel 6457: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6458: && !defined($domconfig->{$role}{$img})
6459: && !$env{'form.'.$role.'_del_'.$img}
6460: && $env{'form.'.$role.'_import_'.$img}) {
6461: # import the old configured image from the .tab setting
6462: # if they haven't provided a new one
6463: $domconfig->{$role}{$img} =
6464: $env{'form.'.$role.'_import_'.$img};
6465: }
1.6 raeburn 6466: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6467: my $error;
1.6 raeburn 6468: if ($configuserok eq 'ok') {
1.9 raeburn 6469: if ($switchserver) {
1.12 raeburn 6470: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6471: } else {
6472: if ($author_ok eq 'ok') {
6473: my ($result,$logourl) =
6474: &publishlogo($r,'upload',$role.'_'.$img,
6475: $dom,$confname,$img,$width,$height);
6476: if ($result eq 'ok') {
6477: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6478: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6479: } else {
1.12 raeburn 6480: $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 6481: }
6482: } else {
1.46 raeburn 6483: $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 6484: }
6485: }
6486: } else {
1.46 raeburn 6487: $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 6488: }
6489: if ($error) {
1.8 raeburn 6490: &Apache::lonnet::logthis($error);
1.11 albertel 6491: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6492: }
6493: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6494: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6495: my $error;
6496: if ($configuserok eq 'ok') {
6497: # is confname an author?
6498: if ($switchserver eq '') {
6499: if ($author_ok eq 'ok') {
6500: my ($result,$logourl) =
6501: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6502: $dom,$confname,$img,$width,$height);
6503: if ($result eq 'ok') {
6504: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6505: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6506: }
6507: }
6508: }
6509: }
1.6 raeburn 6510: }
6511: }
6512: }
6513: if (ref($domconfig) eq 'HASH') {
6514: if (ref($domconfig->{$role}) eq 'HASH') {
6515: foreach my $img (@images) {
6516: if ($domconfig->{$role}{$img} ne '') {
6517: if ($env{'form.'.$role.'_del_'.$img}) {
6518: $confhash->{$role}{$img} = '';
1.12 raeburn 6519: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6520: } else {
1.9 raeburn 6521: if ($confhash->{$role}{$img} eq '') {
6522: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6523: }
1.6 raeburn 6524: }
6525: } else {
6526: if ($env{'form.'.$role.'_del_'.$img}) {
6527: $confhash->{$role}{$img} = '';
1.12 raeburn 6528: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6529: }
6530: }
1.70 raeburn 6531: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6532: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6533: if ($confhash->{$role}{'showlogo'}{$img} ne
6534: $domconfig->{$role}{'showlogo'}{$img}) {
6535: $changes{$role}{'showlogo'}{$img} = 1;
6536: }
6537: } else {
6538: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6539: $changes{$role}{'showlogo'}{$img} = 1;
6540: }
6541: }
6542: }
6543: }
1.6 raeburn 6544: if ($domconfig->{$role}{'font'} ne '') {
6545: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6546: $changes{$role}{'font'} = 1;
6547: }
6548: } else {
6549: if ($confhash->{$role}{'font'}) {
6550: $changes{$role}{'font'} = 1;
6551: }
6552: }
1.107 raeburn 6553: if ($role ne 'login') {
6554: if ($domconfig->{$role}{'fontmenu'} ne '') {
6555: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6556: $changes{$role}{'fontmenu'} = 1;
6557: }
6558: } else {
6559: if ($confhash->{$role}{'fontmenu'}) {
6560: $changes{$role}{'fontmenu'} = 1;
6561: }
1.97 tempelho 6562: }
6563: }
1.6 raeburn 6564: foreach my $item (@bgs) {
6565: if ($domconfig->{$role}{$item} ne '') {
6566: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6567: $changes{$role}{'bgs'}{$item} = 1;
6568: }
6569: } else {
6570: if ($confhash->{$role}{$item}) {
6571: $changes{$role}{'bgs'}{$item} = 1;
6572: }
6573: }
6574: }
6575: foreach my $item (@links) {
6576: if ($domconfig->{$role}{$item} ne '') {
6577: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6578: $changes{$role}{'links'}{$item} = 1;
6579: }
6580: } else {
6581: if ($confhash->{$role}{$item}) {
6582: $changes{$role}{'links'}{$item} = 1;
6583: }
6584: }
6585: }
1.41 raeburn 6586: foreach my $item (@logintext) {
6587: if ($domconfig->{$role}{$item} ne '') {
6588: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6589: $changes{$role}{'logintext'}{$item} = 1;
6590: }
6591: } else {
6592: if ($confhash->{$role}{$item}) {
6593: $changes{$role}{'logintext'}{$item} = 1;
6594: }
6595: }
6596: }
1.6 raeburn 6597: } else {
6598: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6599: \@logintext,$confhash,\%changes);
1.6 raeburn 6600: }
6601: } else {
6602: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6603: \@logintext,$confhash,\%changes);
1.6 raeburn 6604: }
6605: }
6606: return ($errors,%changes);
6607: }
6608:
1.46 raeburn 6609: sub config_check {
6610: my ($dom,$confname,$servadm) = @_;
6611: my ($configuserok,$author_ok,$switchserver,%currroles);
6612: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6613: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6614: $confname,$servadm);
6615: if ($configuserok eq 'ok') {
6616: $switchserver = &check_switchserver($dom,$confname);
6617: if ($switchserver eq '') {
6618: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6619: }
6620: }
6621: return ($configuserok,$author_ok,$switchserver);
6622: }
6623:
1.6 raeburn 6624: sub default_change_checker {
1.41 raeburn 6625: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6626: foreach my $item (@{$links}) {
6627: if ($confhash->{$role}{$item}) {
6628: $changes->{$role}{'links'}{$item} = 1;
6629: }
6630: }
6631: foreach my $item (@{$bgs}) {
6632: if ($confhash->{$role}{$item}) {
6633: $changes->{$role}{'bgs'}{$item} = 1;
6634: }
6635: }
1.41 raeburn 6636: foreach my $item (@{$logintext}) {
6637: if ($confhash->{$role}{$item}) {
6638: $changes->{$role}{'logintext'}{$item} = 1;
6639: }
6640: }
1.6 raeburn 6641: foreach my $img (@{$images}) {
6642: if ($env{'form.'.$role.'_del_'.$img}) {
6643: $confhash->{$role}{$img} = '';
1.12 raeburn 6644: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6645: }
1.70 raeburn 6646: if ($role eq 'login') {
6647: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6648: $changes->{$role}{'showlogo'}{$img} = 1;
6649: }
6650: }
1.6 raeburn 6651: }
6652: if ($confhash->{$role}{'font'}) {
6653: $changes->{$role}{'font'} = 1;
6654: }
1.48 raeburn 6655: }
1.6 raeburn 6656:
6657: sub display_colorchgs {
6658: my ($dom,$changes,$roles,$confhash) = @_;
6659: my (%choices,$resulttext);
6660: if (!grep(/^login$/,@{$roles})) {
6661: $resulttext = &mt('Changes made:').'<br />';
6662: }
6663: foreach my $role (@{$roles}) {
6664: if ($role eq 'login') {
6665: %choices = &login_choices();
6666: } else {
6667: %choices = &color_font_choices();
6668: }
6669: if (ref($changes->{$role}) eq 'HASH') {
6670: if ($role ne 'login') {
6671: $resulttext .= '<h4>'.&mt($role).'</h4>';
6672: }
6673: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6674: if ($role ne 'login') {
6675: $resulttext .= '<ul>';
6676: }
6677: if (ref($changes->{$role}{$key}) eq 'HASH') {
6678: if ($role ne 'login') {
6679: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6680: }
6681: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6682: if (($role eq 'login') && ($key eq 'showlogo')) {
6683: if ($confhash->{$role}{$key}{$item}) {
6684: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6685: } else {
6686: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6687: }
6688: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6689: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6690: } else {
1.12 raeburn 6691: my $newitem = $confhash->{$role}{$item};
6692: if ($key eq 'images') {
6693: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6694: }
6695: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6696: }
6697: }
6698: if ($role ne 'login') {
6699: $resulttext .= '</ul></li>';
6700: }
6701: } else {
6702: if ($confhash->{$role}{$key} eq '') {
6703: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6704: } else {
6705: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6706: }
6707: }
6708: if ($role ne 'login') {
6709: $resulttext .= '</ul>';
6710: }
6711: }
6712: }
6713: }
1.3 raeburn 6714: return $resulttext;
1.1 raeburn 6715: }
6716:
1.9 raeburn 6717: sub thumb_dimensions {
6718: return ('200','50');
6719: }
6720:
1.16 raeburn 6721: sub check_dimensions {
6722: my ($inputfile) = @_;
6723: my ($fullwidth,$fullheight);
6724: if ($inputfile =~ m|^[/\w.\-]+$|) {
6725: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6726: my $imageinfo = <PIPE>;
6727: if (!close(PIPE)) {
6728: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6729: }
6730: chomp($imageinfo);
6731: my ($fullsize) =
1.21 raeburn 6732: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6733: if ($fullsize) {
6734: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6735: }
6736: }
6737: }
6738: return ($fullwidth,$fullheight);
6739: }
6740:
1.9 raeburn 6741: sub check_configuser {
6742: my ($uhome,$dom,$confname,$servadm) = @_;
6743: my ($configuserok,%currroles);
6744: if ($uhome eq 'no_host') {
6745: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6746: my $configpass = &LONCAPA::Enrollment::create_password();
6747: $configuserok =
6748: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6749: $configpass,'','','','','',undef,$servadm);
6750: } else {
6751: $configuserok = 'ok';
6752: %currroles =
6753: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6754: }
6755: return ($configuserok,%currroles);
6756: }
6757:
6758: sub check_authorstatus {
6759: my ($dom,$confname,%currroles) = @_;
6760: my $author_ok;
1.40 raeburn 6761: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6762: my $start = time;
6763: my $end = 0;
6764: $author_ok =
6765: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6766: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6767: } else {
6768: $author_ok = 'ok';
6769: }
6770: return $author_ok;
6771: }
6772:
6773: sub publishlogo {
1.46 raeburn 6774: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6775: my ($output,$fname,$logourl);
6776: if ($action eq 'upload') {
6777: $fname=$env{'form.'.$formname.'.filename'};
6778: chop($env{'form.'.$formname});
6779: } else {
6780: ($fname) = ($formname =~ /([^\/]+)$/);
6781: }
1.46 raeburn 6782: if ($savefileas ne '') {
6783: $fname = $savefileas;
6784: }
1.9 raeburn 6785: $fname=&Apache::lonnet::clean_filename($fname);
6786: # See if there is anything left
6787: unless ($fname) { return ('error: no uploaded file'); }
6788: $fname="$subdir/$fname";
1.160.6.5 raeburn 6789: my $docroot=$r->dir_config('lonDocRoot');
6790: my $filepath="$docroot/priv";
6791: my $relpath = "$dom/$confname";
1.9 raeburn 6792: my ($fnamepath,$file,$fetchthumb);
6793: $file=$fname;
6794: if ($fname=~m|/|) {
6795: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6796: }
1.160.6.26 raeburn 6797: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6798: my $count;
1.160.6.5 raeburn 6799: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6800: $filepath.="/$parts[$count]";
6801: if ((-e $filepath)!=1) {
6802: mkdir($filepath,02770);
6803: }
6804: }
6805: # Check for bad extension and disallow upload
6806: if ($file=~/\.(\w+)$/ &&
6807: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6808: $output =
1.160.6.25 raeburn 6809: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6810: } elsif ($file=~/\.(\w+)$/ &&
6811: !defined(&Apache::loncommon::fileembstyle($1))) {
6812: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6813: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 6814: $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 6815: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 6816: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6817: } else {
6818: my $source = $filepath.'/'.$file;
6819: my $logfile;
6820: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 6821: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6822: }
6823: print $logfile
6824: "\n================= Publish ".localtime()." ================\n".
6825: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6826: # Save the file
6827: if (!open(FH,'>'.$source)) {
6828: &Apache::lonnet::logthis('Failed to create '.$source);
6829: return (&mt('Failed to create file'));
6830: }
6831: if ($action eq 'upload') {
6832: if (!print FH ($env{'form.'.$formname})) {
6833: &Apache::lonnet::logthis('Failed to write to '.$source);
6834: return (&mt('Failed to write file'));
6835: }
6836: } else {
6837: my $original = &Apache::lonnet::filelocation('',$formname);
6838: if(!copy($original,$source)) {
6839: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6840: return (&mt('Failed to write file'));
6841: }
6842: }
6843: close(FH);
6844: chmod(0660, $source); # Permissions to rw-rw---.
6845:
6846: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6847: my $copyfile=$targetdir.'/'.$file;
6848:
6849: my @parts=split(/\//,$targetdir);
6850: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6851: for (my $count=5;$count<=$#parts;$count++) {
6852: $path.="/$parts[$count]";
6853: if (!-e $path) {
6854: print $logfile "\nCreating directory ".$path;
6855: mkdir($path,02770);
6856: }
6857: }
6858: my $versionresult;
6859: if (-e $copyfile) {
6860: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6861: } else {
6862: $versionresult = 'ok';
6863: }
6864: if ($versionresult eq 'ok') {
6865: if (copy($source,$copyfile)) {
6866: print $logfile "\nCopied original source to ".$copyfile."\n";
6867: $output = 'ok';
6868: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6869: push(@{$modified_urls},[$copyfile,$source]);
6870: my $metaoutput =
6871: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6872: unless ($registered_cleanup) {
6873: my $handlers = $r->get_handlers('PerlCleanupHandler');
6874: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6875: $registered_cleanup=1;
6876: }
1.9 raeburn 6877: } else {
6878: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6879: $output = &mt('Failed to copy file to RES space').", $!";
6880: }
6881: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6882: my $inputfile = $filepath.'/'.$file;
6883: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6884: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6885: if ($fullwidth ne '' && $fullheight ne '') {
6886: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6887: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6888: system("convert -sample $thumbsize $inputfile $outfile");
6889: chmod(0660, $filepath.'/tn-'.$file);
6890: if (-e $outfile) {
6891: my $copyfile=$targetdir.'/tn-'.$file;
6892: if (copy($outfile,$copyfile)) {
6893: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6894: my $thumb_metaoutput =
6895: &write_metadata($dom,$confname,$formname,
6896: $targetdir,'tn-'.$file,$logfile);
6897: push(@{$modified_urls},[$copyfile,$outfile]);
6898: unless ($registered_cleanup) {
6899: my $handlers = $r->get_handlers('PerlCleanupHandler');
6900: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6901: $registered_cleanup=1;
6902: }
1.16 raeburn 6903: } else {
6904: print $logfile "\nUnable to write ".$copyfile.
6905: ':'.$!."\n";
6906: }
6907: }
1.9 raeburn 6908: }
6909: }
6910: }
6911: } else {
6912: $output = $versionresult;
6913: }
6914: }
6915: return ($output,$logourl);
6916: }
6917:
6918: sub logo_versioning {
6919: my ($targetdir,$file,$logfile) = @_;
6920: my $target = $targetdir.'/'.$file;
6921: my ($maxversion,$fn,$extn,$output);
6922: $maxversion = 0;
6923: if ($file =~ /^(.+)\.(\w+)$/) {
6924: $fn=$1;
6925: $extn=$2;
6926: }
6927: opendir(DIR,$targetdir);
6928: while (my $filename=readdir(DIR)) {
6929: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6930: $maxversion=($1>$maxversion)?$1:$maxversion;
6931: }
6932: }
6933: $maxversion++;
6934: print $logfile "\nCreating old version ".$maxversion."\n";
6935: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6936: if (copy($target,$copyfile)) {
6937: print $logfile "Copied old target to ".$copyfile."\n";
6938: $copyfile=$copyfile.'.meta';
6939: if (copy($target.'.meta',$copyfile)) {
6940: print $logfile "Copied old target metadata to ".$copyfile."\n";
6941: $output = 'ok';
6942: } else {
6943: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6944: $output = &mt('Failed to copy old meta').", $!, ";
6945: }
6946: } else {
6947: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6948: $output = &mt('Failed to copy old target').", $!, ";
6949: }
6950: return $output;
6951: }
6952:
6953: sub write_metadata {
6954: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6955: my (%metadatafields,%metadatakeys,$output);
6956: $metadatafields{'title'}=$formname;
6957: $metadatafields{'creationdate'}=time;
6958: $metadatafields{'lastrevisiondate'}=time;
6959: $metadatafields{'copyright'}='public';
6960: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6961: $env{'user.domain'};
6962: $metadatafields{'authorspace'}=$confname.':'.$dom;
6963: $metadatafields{'domain'}=$dom;
6964: {
6965: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6966: my $mfh;
1.155 raeburn 6967: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 6968: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6969: unless ($_=~/\./) {
6970: my $unikey=$_;
6971: $unikey=~/^([A-Za-z]+)/;
6972: my $tag=$1;
6973: $tag=~tr/A-Z/a-z/;
6974: print $mfh "\n\<$tag";
6975: foreach (split(/\,/,$metadatakeys{$unikey})) {
6976: my $value=$metadatafields{$unikey.'.'.$_};
6977: $value=~s/\"/\'\'/g;
6978: print $mfh ' '.$_.'="'.$value.'"';
6979: }
6980: print $mfh '>'.
6981: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6982: .'</'.$tag.'>';
6983: }
6984: }
6985: $output = 'ok';
6986: print $logfile "\nWrote metadata";
6987: close($mfh);
6988: } else {
6989: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6990: $output = &mt('Could not write metadata');
6991: }
6992: }
1.155 raeburn 6993: return $output;
6994: }
6995:
6996: sub notifysubscribed {
6997: foreach my $targetsource (@{$modified_urls}){
6998: next unless (ref($targetsource) eq 'ARRAY');
6999: my ($target,$source)=@{$targetsource};
7000: if ($source ne '') {
7001: if (open(my $logfh,'>>'.$source.'.log')) {
7002: print $logfh "\nCleanup phase: Notifications\n";
7003: my @subscribed=&subscribed_hosts($target);
7004: foreach my $subhost (@subscribed) {
7005: print $logfh "\nNotifying host ".$subhost.':';
7006: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7007: print $logfh $reply;
7008: }
7009: my @subscribedmeta=&subscribed_hosts("$target.meta");
7010: foreach my $subhost (@subscribedmeta) {
7011: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7012: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7013: $subhost);
7014: print $logfh $reply;
7015: }
7016: print $logfh "\n============ Done ============\n";
1.160 raeburn 7017: close($logfh);
1.155 raeburn 7018: }
7019: }
7020: }
7021: return OK;
7022: }
7023:
7024: sub subscribed_hosts {
7025: my ($target) = @_;
7026: my @subscribed;
7027: if (open(my $fh,"<$target.subscription")) {
7028: while (my $subline=<$fh>) {
7029: if ($subline =~ /^($match_lonid):/) {
7030: my $host = $1;
7031: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7032: unless (grep(/^\Q$host\E$/,@subscribed)) {
7033: push(@subscribed,$host);
7034: }
7035: }
7036: }
7037: }
7038: }
7039: return @subscribed;
1.9 raeburn 7040: }
7041:
7042: sub check_switchserver {
7043: my ($dom,$confname) = @_;
7044: my ($allowed,$switchserver);
7045: my $home = &Apache::lonnet::homeserver($confname,$dom);
7046: if ($home eq 'no_host') {
7047: $home = &Apache::lonnet::domain($dom,'primary');
7048: }
7049: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7050: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7051: if (!$allowed) {
1.160.6.11 raeburn 7052: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7053: }
7054: return $switchserver;
7055: }
7056:
1.1 raeburn 7057: sub modify_quotas {
1.160.6.30 raeburn 7058: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7059: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 7060: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 7061: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7062: $validationfieldsref);
1.86 raeburn 7063: if ($action eq 'quotas') {
7064: $context = 'tools';
1.160.6.26 raeburn 7065: } else {
1.86 raeburn 7066: $context = $action;
7067: }
7068: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 7069: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 7070: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7071: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7072: %titles = &courserequest_titles();
7073: $toolregexp = join('|',@usertools);
7074: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 7075: $confname = $dom.'-domainconfig';
7076: my $servadm = $r->dir_config('lonAdmEMail');
7077: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 7078: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7079: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 7080: } elsif ($context eq 'requestauthor') {
7081: @usertools = ('author');
7082: %titles = &authorrequest_titles();
1.86 raeburn 7083: } else {
1.160.6.4 raeburn 7084: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7085: %titles = &tool_titles();
1.86 raeburn 7086: }
1.160.6.27 raeburn 7087: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7088: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7089: foreach my $key (keys(%env)) {
1.101 raeburn 7090: if ($context eq 'requestcourses') {
7091: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7092: my $item = $1;
7093: my $type = $2;
7094: if ($type =~ /^limit_(.+)/) {
7095: $limithash{$item}{$1} = $env{$key};
7096: } else {
7097: $confhash{$item}{$type} = $env{$key};
7098: }
7099: }
1.160.6.5 raeburn 7100: } elsif ($context eq 'requestauthor') {
7101: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7102: $confhash{$1} = $env{$key};
7103: }
1.101 raeburn 7104: } else {
1.86 raeburn 7105: if ($key =~ /^form\.quota_(.+)$/) {
7106: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 7107: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7108: $confhash{'authorquota'}{$1} = $env{$key};
7109: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 7110: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7111: }
1.72 raeburn 7112: }
7113: }
1.160.6.5 raeburn 7114: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 7115: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 7116: @approvalnotify = sort(@approvalnotify);
7117: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 7118: my @crstypes = ('official','unofficial','community','textbook');
7119: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
7120: foreach my $type (@hasuniquecode) {
7121: if (grep(/^\Q$type\E$/,@crstypes)) {
7122: $confhash{'uniquecode'}{$type} = 1;
7123: }
7124: }
1.160.6.46 raeburn 7125: my (%newbook,%allpos);
1.160.6.30 raeburn 7126: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7127: foreach my $type ('textbooks','templates') {
7128: @{$allpos{$type}} = ();
7129: my $invalid;
7130: if ($type eq 'textbooks') {
7131: $invalid = &mt('Invalid LON-CAPA course for textbook');
7132: } else {
7133: $invalid = &mt('Invalid LON-CAPA course for template');
7134: }
7135: if ($env{'form.'.$type.'_addbook'}) {
7136: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
7137: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
7138: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
7139: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
7140: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7141: } else {
7142: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
7143: my $position = $env{'form.'.$type.'_addbook_pos'};
7144: $position =~ s/\D+//g;
7145: if ($position ne '') {
7146: $allpos{$type}[$position] = $newbook{$type};
7147: }
1.160.6.30 raeburn 7148: }
1.160.6.46 raeburn 7149: } else {
7150: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 7151: }
7152: }
1.160.6.46 raeburn 7153: }
1.160.6.30 raeburn 7154: }
1.102 raeburn 7155: if (ref($domconfig{$action}) eq 'HASH') {
7156: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
7157: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
7158: $changes{'notify'}{'approval'} = 1;
7159: }
7160: } else {
1.144 raeburn 7161: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7162: $changes{'notify'}{'approval'} = 1;
7163: }
7164: }
1.160.6.30 raeburn 7165: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
7166: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7167: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
7168: unless ($confhash{'uniquecode'}{$crstype}) {
7169: $changes{'uniquecode'} = 1;
7170: }
7171: }
7172: unless ($changes{'uniquecode'}) {
7173: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
7174: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
7175: $changes{'uniquecode'} = 1;
7176: }
7177: }
7178: }
7179: } else {
7180: $changes{'uniquecode'} = 1;
7181: }
7182: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
7183: $changes{'uniquecode'} = 1;
7184: }
7185: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7186: foreach my $type ('textbooks','templates') {
7187: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7188: my %deletions;
7189: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
7190: if (@todelete) {
7191: map { $deletions{$_} = 1; } @todelete;
7192: }
7193: my %imgdeletions;
7194: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
7195: if (@todeleteimages) {
7196: map { $imgdeletions{$_} = 1; } @todeleteimages;
7197: }
7198: my $maxnum = $env{'form.'.$type.'_maxnum'};
7199: for (my $i=0; $i<=$maxnum; $i++) {
7200: my $itemid = $env{'form.'.$type.'_id_'.$i};
7201: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
7202: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
7203: if ($deletions{$key}) {
7204: if ($domconfig{$action}{$type}{$key}{'image'}) {
7205: #FIXME need to obsolete item in RES space
7206: }
7207: next;
7208: } else {
7209: my $newpos = $env{'form.'.$itemid};
7210: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 7211: foreach my $item ('subject','title','publisher','author') {
7212: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7213: ($type eq 'templates'));
1.160.6.46 raeburn 7214: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
7215: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
7216: $changes{$type}{$key} = 1;
7217: }
7218: }
7219: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 7220: }
1.160.6.46 raeburn 7221: if ($imgdeletions{$key}) {
7222: $changes{$type}{$key} = 1;
7223: #FIXME need to obsolete item in RES space
7224: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
7225: my ($cdom,$cnum) = split(/_/,$key);
7226: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
7227: $cdom,$cnum,$type,$configuserok,
7228: $switchserver,$author_ok);
7229: if ($imgurl) {
7230: $confhash{$type}{$key}{'image'} = $imgurl;
7231: $changes{$type}{$key} = 1;
1.160.6.30 raeburn 7232: }
1.160.6.46 raeburn 7233: if ($error) {
7234: &Apache::lonnet::logthis($error);
7235: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7236: }
7237: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7238: $confhash{$type}{$key}{'image'} =
7239: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 7240: }
7241: }
7242: }
7243: }
7244: }
7245: }
1.102 raeburn 7246: } else {
1.144 raeburn 7247: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7248: $changes{'notify'}{'approval'} = 1;
7249: }
1.160.6.30 raeburn 7250: if (ref($confhash{'uniquecode'} eq 'HASH')) {
7251: $changes{'uniquecode'} = 1;
7252: }
7253: }
7254: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7255: foreach my $type ('textbooks','templates') {
7256: if ($newbook{$type}) {
7257: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 7258: foreach my $item ('subject','title','publisher','author') {
7259: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7260: ($type eq 'template'));
1.160.6.46 raeburn 7261: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7262: if ($env{'form.'.$type.'_addbook_'.$item}) {
7263: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7264: }
7265: }
7266: if ($type eq 'textbooks') {
7267: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7268: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7269: my ($imageurl,$error) =
7270: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7271: $configuserok,$switchserver,$author_ok);
7272: if ($imageurl) {
7273: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7274: }
7275: if ($error) {
7276: &Apache::lonnet::logthis($error);
7277: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7278: }
7279: }
1.160.6.30 raeburn 7280: }
7281: }
1.160.6.46 raeburn 7282: if (@{$allpos{$type}} > 0) {
7283: my $idx = 0;
7284: foreach my $item (@{$allpos{$type}}) {
7285: if ($item ne '') {
7286: $confhash{$type}{$item}{'order'} = $idx;
7287: if (ref($domconfig{$action}) eq 'HASH') {
7288: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7289: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7290: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7291: $changes{$type}{$item} = 1;
7292: }
1.160.6.30 raeburn 7293: }
7294: }
7295: }
1.160.6.46 raeburn 7296: $idx ++;
1.160.6.30 raeburn 7297: }
7298: }
7299: }
7300: }
1.160.6.39 raeburn 7301: if (ref($validationitemsref) eq 'ARRAY') {
7302: foreach my $item (@{$validationitemsref}) {
7303: if ($item eq 'fields') {
7304: my @changed;
7305: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7306: if (@{$confhash{'validation'}{$item}} > 0) {
7307: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7308: }
7309: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7310: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7311: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7312: $domconfig{'requestcourses'}{'validation'}{$item});
7313: } else {
7314: @changed = @{$confhash{'validation'}{$item}};
7315: }
7316: } else {
7317: @changed = @{$confhash{'validation'}{$item}};
7318: }
7319: if (@changed) {
7320: if ($confhash{'validation'}{$item}) {
7321: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7322: } else {
7323: $changes{'validation'}{$item} = &mt('None');
7324: }
7325: }
7326: } else {
7327: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7328: if ($item eq 'markup') {
7329: if ($env{'form.requestcourses_validation_'.$item}) {
7330: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7331: }
7332: }
7333: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7334: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7335: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7336: }
7337: } else {
7338: if ($confhash{'validation'}{$item} ne '') {
7339: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7340: }
7341: }
7342: }
7343: }
7344: }
7345: if ($env{'form.validationdc'}) {
7346: my $newval = $env{'form.validationdc'};
7347: my %domcoords = &get_active_dcs($dom);
7348: if (exists($domcoords{$newval})) {
7349: $confhash{'validation'}{'dc'} = $newval;
7350: }
7351: }
7352: if (ref($confhash{'validation'}) eq 'HASH') {
7353: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7354: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7355: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7356: if ($confhash{'validation'}{'dc'} eq '') {
7357: $changes{'validation'}{'dc'} = &mt('None');
7358: } else {
7359: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7360: }
7361: }
7362: } elsif ($confhash{'validation'}{'dc'} ne '') {
7363: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7364: }
7365: } elsif ($confhash{'validation'}{'dc'} ne '') {
7366: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7367: }
7368: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7369: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7370: $changes{'validation'}{'dc'} = &mt('None');
7371: }
7372: }
1.102 raeburn 7373: }
7374: } else {
1.86 raeburn 7375: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 7376: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7377: }
1.72 raeburn 7378: foreach my $item (@usertools) {
7379: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7380: my $unset;
1.101 raeburn 7381: if ($context eq 'requestcourses') {
1.104 raeburn 7382: $unset = '0';
7383: if ($type eq '_LC_adv') {
7384: $unset = '';
7385: }
1.101 raeburn 7386: if ($confhash{$item}{$type} eq 'autolimit') {
7387: $confhash{$item}{$type} .= '=';
7388: unless ($limithash{$item}{$type} =~ /\D/) {
7389: $confhash{$item}{$type} .= $limithash{$item}{$type};
7390: }
7391: }
1.160.6.5 raeburn 7392: } elsif ($context eq 'requestauthor') {
7393: $unset = '0';
7394: if ($type eq '_LC_adv') {
7395: $unset = '';
7396: }
1.72 raeburn 7397: } else {
1.101 raeburn 7398: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7399: $confhash{$item}{$type} = 1;
7400: } else {
7401: $confhash{$item}{$type} = 0;
7402: }
1.72 raeburn 7403: }
1.86 raeburn 7404: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 7405: if ($action eq 'requestauthor') {
7406: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7407: $changes{$type} = 1;
7408: }
7409: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7410: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7411: $changes{$item}{$type} = 1;
7412: }
7413: } else {
7414: if ($context eq 'requestcourses') {
1.104 raeburn 7415: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7416: $changes{$item}{$type} = 1;
7417: }
7418: } else {
7419: if (!$confhash{$item}{$type}) {
7420: $changes{$item}{$type} = 1;
7421: }
7422: }
7423: }
7424: } else {
7425: if ($context eq 'requestcourses') {
1.104 raeburn 7426: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7427: $changes{$item}{$type} = 1;
7428: }
1.160.6.5 raeburn 7429: } elsif ($context eq 'requestauthor') {
7430: if ($confhash{$type} ne $unset) {
7431: $changes{$type} = 1;
7432: }
1.72 raeburn 7433: } else {
7434: if (!$confhash{$item}{$type}) {
7435: $changes{$item}{$type} = 1;
7436: }
7437: }
7438: }
1.1 raeburn 7439: }
7440: }
1.160.6.5 raeburn 7441: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7442: if (ref($domconfig{'quotas'}) eq 'HASH') {
7443: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7444: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7445: if (exists($confhash{'defaultquota'}{$key})) {
7446: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7447: $changes{'defaultquota'}{$key} = 1;
7448: }
7449: } else {
7450: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7451: }
7452: }
1.86 raeburn 7453: } else {
7454: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7455: if (exists($confhash{'defaultquota'}{$key})) {
7456: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7457: $changes{'defaultquota'}{$key} = 1;
7458: }
7459: } else {
7460: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7461: }
1.1 raeburn 7462: }
7463: }
1.160.6.20 raeburn 7464: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7465: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7466: if (exists($confhash{'authorquota'}{$key})) {
7467: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7468: $changes{'authorquota'}{$key} = 1;
7469: }
7470: } else {
7471: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7472: }
7473: }
7474: }
1.1 raeburn 7475: }
1.86 raeburn 7476: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7477: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7478: if (ref($domconfig{'quotas'}) eq 'HASH') {
7479: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7480: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7481: $changes{'defaultquota'}{$key} = 1;
7482: }
7483: } else {
7484: if (!exists($domconfig{'quotas'}{$key})) {
7485: $changes{'defaultquota'}{$key} = 1;
7486: }
1.72 raeburn 7487: }
7488: } else {
1.86 raeburn 7489: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7490: }
1.1 raeburn 7491: }
7492: }
1.160.6.20 raeburn 7493: if (ref($confhash{'authorquota'}) eq 'HASH') {
7494: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7495: if (ref($domconfig{'quotas'}) eq 'HASH') {
7496: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7497: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7498: $changes{'authorquota'}{$key} = 1;
7499: }
7500: } else {
7501: $changes{'authorquota'}{$key} = 1;
7502: }
7503: } else {
7504: $changes{'authorquota'}{$key} = 1;
7505: }
7506: }
7507: }
1.1 raeburn 7508: }
1.72 raeburn 7509:
1.160.6.5 raeburn 7510: if ($context eq 'requestauthor') {
7511: $domdefaults{'requestauthor'} = \%confhash;
7512: } else {
7513: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 7514: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 7515: $domdefaults{$key} = $confhash{$key};
7516: }
1.160.6.5 raeburn 7517: }
1.72 raeburn 7518: }
1.160.6.5 raeburn 7519:
1.1 raeburn 7520: my %quotahash = (
1.86 raeburn 7521: $action => { %confhash }
1.1 raeburn 7522: );
7523: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7524: $dom);
7525: if ($putresult eq 'ok') {
7526: if (keys(%changes) > 0) {
1.72 raeburn 7527: my $cachetime = 24*60*60;
7528: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 7529: if (ref($lastactref) eq 'HASH') {
7530: $lastactref->{'domdefaults'} = 1;
7531: }
1.1 raeburn 7532: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 7533: unless (($context eq 'requestcourses') ||
7534: ($context eq 'requestauthor')) {
1.86 raeburn 7535: if (ref($changes{'defaultquota'}) eq 'HASH') {
7536: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7537: foreach my $type (@{$types},'default') {
7538: if (defined($changes{'defaultquota'}{$type})) {
7539: my $typetitle = $usertypes->{$type};
7540: if ($type eq 'default') {
7541: $typetitle = $othertitle;
7542: }
1.160.6.28 raeburn 7543: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7544: }
7545: }
1.86 raeburn 7546: $resulttext .= '</ul></li>';
1.72 raeburn 7547: }
1.160.6.20 raeburn 7548: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 7549: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 7550: foreach my $type (@{$types},'default') {
7551: if (defined($changes{'authorquota'}{$type})) {
7552: my $typetitle = $usertypes->{$type};
7553: if ($type eq 'default') {
7554: $typetitle = $othertitle;
7555: }
1.160.6.28 raeburn 7556: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 7557: }
7558: }
7559: $resulttext .= '</ul></li>';
7560: }
1.72 raeburn 7561: }
1.80 raeburn 7562: my %newenv;
1.72 raeburn 7563: foreach my $item (@usertools) {
1.160.6.5 raeburn 7564: my (%haschgs,%inconf);
7565: if ($context eq 'requestauthor') {
7566: %haschgs = %changes;
7567: %inconf = %confhash;
7568: } else {
7569: if (ref($changes{$item}) eq 'HASH') {
7570: %haschgs = %{$changes{$item}};
7571: }
7572: if (ref($confhash{$item}) eq 'HASH') {
7573: %inconf = %{$confhash{$item}};
7574: }
7575: }
7576: if (keys(%haschgs) > 0) {
1.80 raeburn 7577: my $newacc =
7578: &Apache::lonnet::usertools_access($env{'user.name'},
7579: $env{'user.domain'},
1.86 raeburn 7580: $item,'reload',$context);
1.160.6.5 raeburn 7581: if (($context eq 'requestcourses') ||
7582: ($context eq 'requestauthor')) {
1.108 raeburn 7583: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7584: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7585: }
7586: } else {
7587: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7588: $newenv{'environment.availabletools.'.$item} = $newacc;
7589: }
1.80 raeburn 7590: }
1.160.6.5 raeburn 7591: unless ($context eq 'requestauthor') {
7592: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7593: }
1.72 raeburn 7594: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 7595: if ($haschgs{$type}) {
1.72 raeburn 7596: my $typetitle = $usertypes->{$type};
7597: if ($type eq 'default') {
7598: $typetitle = $othertitle;
7599: } elsif ($type eq '_LC_adv') {
7600: $typetitle = 'LON-CAPA Advanced Users';
7601: }
1.160.6.5 raeburn 7602: if ($inconf{$type}) {
1.101 raeburn 7603: if ($context eq 'requestcourses') {
7604: my $cond;
1.160.6.5 raeburn 7605: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7606: if ($1 eq '') {
7607: $cond = &mt('(Automatic processing of any request).');
7608: } else {
7609: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7610: }
7611: } else {
1.160.6.5 raeburn 7612: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7613: }
7614: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 7615: } elsif ($context eq 'requestauthor') {
7616: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7617: $titles{$inconf{$type}},$typetitle);
7618:
1.101 raeburn 7619: } else {
7620: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7621: }
1.72 raeburn 7622: } else {
1.104 raeburn 7623: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 7624: if ($inconf{$type} eq '0') {
1.104 raeburn 7625: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7626: } else {
7627: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7628: }
7629: } else {
7630: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7631: }
1.72 raeburn 7632: }
7633: }
1.26 raeburn 7634: }
1.160.6.5 raeburn 7635: unless ($context eq 'requestauthor') {
7636: $resulttext .= '</ul></li>';
7637: }
1.26 raeburn 7638: }
1.1 raeburn 7639: }
1.160.6.5 raeburn 7640: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7641: if (ref($changes{'notify'}) eq 'HASH') {
7642: if ($changes{'notify'}{'approval'}) {
7643: if (ref($confhash{'notify'}) eq 'HASH') {
7644: if ($confhash{'notify'}{'approval'}) {
7645: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7646: } else {
1.160.6.5 raeburn 7647: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7648: }
7649: }
7650: }
7651: }
7652: }
1.160.6.30 raeburn 7653: if ($action eq 'requestcourses') {
7654: my @offon = ('off','on');
7655: if ($changes{'uniquecode'}) {
7656: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7657: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7658: $resulttext .= '<li>'.
7659: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7660: '</li>';
7661: } else {
7662: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7663: '</li>';
7664: }
7665: }
1.160.6.46 raeburn 7666: foreach my $type ('textbooks','templates') {
7667: if (ref($changes{$type}) eq 'HASH') {
7668: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7669: foreach my $key (sort(keys(%{$changes{$type}}))) {
7670: my %coursehash = &Apache::lonnet::coursedescription($key);
7671: my $coursetitle = $coursehash{'description'};
7672: my $position = $confhash{$type}{$key}{'order'} + 1;
7673: $resulttext .= '<li>';
1.160.6.47 raeburn 7674: foreach my $item ('subject','title','publisher','author') {
7675: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7676: ($type eq 'templates'));
1.160.6.46 raeburn 7677: my $name = $item.':';
7678: $name =~ s/^(\w)/\U$1/;
7679: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7680: }
7681: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7682: if ($type eq 'textbooks') {
7683: if ($confhash{$type}{$key}{'image'}) {
7684: $resulttext .= ' '.&mt('Image: [_1]',
7685: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
7686: ' alt="Textbook cover" />').'<br />';
7687: }
7688: }
7689: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 7690: }
1.160.6.46 raeburn 7691: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 7692: }
7693: }
1.160.6.39 raeburn 7694: if (ref($changes{'validation'}) eq 'HASH') {
7695: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7696: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7697: foreach my $item (@{$validationitemsref}) {
7698: if (exists($changes{'validation'}{$item})) {
7699: if ($item eq 'markup') {
7700: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7701: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7702: } else {
7703: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7704: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7705: }
7706: }
7707: }
7708: if (exists($changes{'validation'}{'dc'})) {
7709: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7710: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7711: }
7712: }
7713: }
1.160.6.30 raeburn 7714: }
1.1 raeburn 7715: $resulttext .= '</ul>';
1.80 raeburn 7716: if (keys(%newenv)) {
7717: &Apache::lonnet::appenv(\%newenv);
7718: }
1.1 raeburn 7719: } else {
1.86 raeburn 7720: if ($context eq 'requestcourses') {
7721: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 7722: } elsif ($context eq 'requestauthor') {
7723: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7724: } else {
1.90 weissno 7725: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7726: }
1.1 raeburn 7727: }
7728: } else {
1.11 albertel 7729: $resulttext = '<span class="LC_error">'.
7730: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7731: }
1.160.6.30 raeburn 7732: if ($errors) {
7733: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7734: '<ul>'.$errors.'</ul></p>';
7735: }
1.3 raeburn 7736: return $resulttext;
1.1 raeburn 7737: }
7738:
1.160.6.30 raeburn 7739: sub process_textbook_image {
1.160.6.46 raeburn 7740: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 7741: my $filename = $env{'form.'.$caller.'.filename'};
7742: my ($error,$url);
7743: my ($width,$height) = (50,50);
7744: if ($configuserok eq 'ok') {
7745: if ($switchserver) {
7746: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7747: $switchserver);
7748: } elsif ($author_ok eq 'ok') {
7749: my ($result,$imageurl) =
7750: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.46 raeburn 7751: "$type/$dom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 7752: if ($result eq 'ok') {
7753: $url = $imageurl;
7754: } else {
7755: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7756: }
7757: } else {
7758: $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);
7759: }
7760: } else {
7761: $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);
7762: }
7763: return ($url,$error);
7764: }
7765:
1.3 raeburn 7766: sub modify_autoenroll {
1.160.6.24 raeburn 7767: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7768: my ($resulttext,%changes);
7769: my %currautoenroll;
7770: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7771: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7772: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7773: }
7774: }
7775: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7776: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7777: sender => 'Sender for notification messages',
7778: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 7779: my @offon = ('off','on');
1.17 raeburn 7780: my $sender_uname = $env{'form.sender_uname'};
7781: my $sender_domain = $env{'form.sender_domain'};
7782: if ($sender_domain eq '') {
7783: $sender_uname = '';
7784: } elsif ($sender_uname eq '') {
7785: $sender_domain = '';
7786: }
1.129 raeburn 7787: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 7788: my %autoenrollhash = (
1.129 raeburn 7789: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7790: 'sender_uname' => $sender_uname,
7791: 'sender_domain' => $sender_domain,
7792: 'co-owners' => $coowners,
1.1 raeburn 7793: }
7794: );
1.4 raeburn 7795: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7796: $dom);
1.1 raeburn 7797: if ($putresult eq 'ok') {
7798: if (exists($currautoenroll{'run'})) {
7799: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7800: $changes{'run'} = 1;
7801: }
7802: } elsif ($autorun) {
7803: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7804: $changes{'run'} = 1;
1.1 raeburn 7805: }
7806: }
1.17 raeburn 7807: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7808: $changes{'sender'} = 1;
7809: }
1.17 raeburn 7810: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7811: $changes{'sender'} = 1;
7812: }
1.129 raeburn 7813: if ($currautoenroll{'co-owners'} ne '') {
7814: if ($currautoenroll{'co-owners'} ne $coowners) {
7815: $changes{'coowners'} = 1;
7816: }
7817: } elsif ($coowners) {
7818: $changes{'coowners'} = 1;
7819: }
1.1 raeburn 7820: if (keys(%changes) > 0) {
7821: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7822: if ($changes{'run'}) {
1.1 raeburn 7823: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7824: }
7825: if ($changes{'sender'}) {
1.17 raeburn 7826: if ($sender_uname eq '' || $sender_domain eq '') {
7827: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7828: } else {
7829: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7830: }
1.1 raeburn 7831: }
1.129 raeburn 7832: if ($changes{'coowners'}) {
7833: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7834: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7835: if (ref($lastactref) eq 'HASH') {
7836: $lastactref->{'domainconfig'} = 1;
7837: }
1.129 raeburn 7838: }
1.1 raeburn 7839: $resulttext .= '</ul>';
7840: } else {
7841: $resulttext = &mt('No changes made to auto-enrollment settings');
7842: }
7843: } else {
1.11 albertel 7844: $resulttext = '<span class="LC_error">'.
7845: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7846: }
1.3 raeburn 7847: return $resulttext;
1.1 raeburn 7848: }
7849:
7850: sub modify_autoupdate {
1.3 raeburn 7851: my ($dom,%domconfig) = @_;
1.1 raeburn 7852: my ($resulttext,%currautoupdate,%fields,%changes);
7853: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7854: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7855: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7856: }
7857: }
7858: my @offon = ('off','on');
7859: my %title = &Apache::lonlocal::texthash (
7860: run => 'Auto-update:',
7861: classlists => 'Updates to user information in classlists?'
7862: );
1.44 raeburn 7863: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7864: my %fieldtitles = &Apache::lonlocal::texthash (
7865: id => 'Student/Employee ID',
1.20 raeburn 7866: permanentemail => 'E-mail address',
1.1 raeburn 7867: lastname => 'Last Name',
7868: firstname => 'First Name',
7869: middlename => 'Middle Name',
1.132 raeburn 7870: generation => 'Generation',
1.1 raeburn 7871: );
1.142 raeburn 7872: $othertitle = &mt('All users');
1.1 raeburn 7873: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 7874: $othertitle = &mt('Other users');
1.1 raeburn 7875: }
7876: foreach my $key (keys(%env)) {
7877: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 7878: my ($usertype,$item) = ($1,$2);
7879: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7880: if ($usertype eq 'default') {
7881: push(@{$fields{$1}},$2);
7882: } elsif (ref($types) eq 'ARRAY') {
7883: if (grep(/^\Q$usertype\E$/,@{$types})) {
7884: push(@{$fields{$1}},$2);
7885: }
7886: }
7887: }
1.1 raeburn 7888: }
7889: }
1.131 raeburn 7890: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7891: @lockablenames = sort(@lockablenames);
7892: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7893: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7894: if (@changed) {
7895: $changes{'lockablenames'} = 1;
7896: }
7897: } else {
7898: if (@lockablenames) {
7899: $changes{'lockablenames'} = 1;
7900: }
7901: }
1.1 raeburn 7902: my %updatehash = (
7903: autoupdate => { run => $env{'form.autoupdate_run'},
7904: classlists => $env{'form.classlists'},
7905: fields => {%fields},
1.131 raeburn 7906: lockablenames => \@lockablenames,
1.1 raeburn 7907: }
7908: );
7909: foreach my $key (keys(%currautoupdate)) {
7910: if (($key eq 'run') || ($key eq 'classlists')) {
7911: if (exists($updatehash{autoupdate}{$key})) {
7912: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7913: $changes{$key} = 1;
7914: }
7915: }
7916: } elsif ($key eq 'fields') {
7917: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 7918: foreach my $item (@{$types},'default') {
1.1 raeburn 7919: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7920: my $change = 0;
7921: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7922: if (!exists($fields{$item})) {
7923: $change = 1;
1.132 raeburn 7924: last;
1.1 raeburn 7925: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 7926: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 7927: $change = 1;
1.132 raeburn 7928: last;
1.1 raeburn 7929: }
7930: }
7931: }
7932: if ($change) {
7933: push(@{$changes{$key}},$item);
7934: }
1.26 raeburn 7935: }
1.1 raeburn 7936: }
7937: }
1.131 raeburn 7938: } elsif ($key eq 'lockablenames') {
7939: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7940: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7941: if (@changed) {
7942: $changes{'lockablenames'} = 1;
7943: }
7944: } else {
7945: if (@lockablenames) {
7946: $changes{'lockablenames'} = 1;
7947: }
7948: }
7949: }
7950: }
7951: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7952: if (@lockablenames) {
7953: $changes{'lockablenames'} = 1;
1.1 raeburn 7954: }
7955: }
1.26 raeburn 7956: foreach my $item (@{$types},'default') {
7957: if (defined($fields{$item})) {
7958: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 7959: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7960: my $change = 0;
7961: if (ref($fields{$item}) eq 'ARRAY') {
7962: foreach my $type (@{$fields{$item}}) {
7963: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7964: $change = 1;
7965: last;
7966: }
7967: }
7968: }
7969: if ($change) {
7970: push(@{$changes{'fields'}},$item);
7971: }
7972: } else {
1.26 raeburn 7973: push(@{$changes{'fields'}},$item);
7974: }
7975: } else {
7976: push(@{$changes{'fields'}},$item);
1.1 raeburn 7977: }
7978: }
7979: }
7980: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7981: $dom);
7982: if ($putresult eq 'ok') {
7983: if (keys(%changes) > 0) {
7984: $resulttext = &mt('Changes made:').'<ul>';
7985: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 7986: if ($key eq 'lockablenames') {
7987: $resulttext .= '<li>';
7988: if (@lockablenames) {
7989: $usertypes->{'default'} = $othertitle;
7990: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7991: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7992: } else {
7993: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7994: }
7995: $resulttext .= '</li>';
7996: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 7997: foreach my $item (@{$changes{$key}}) {
7998: my @newvalues;
7999: foreach my $type (@{$fields{$item}}) {
8000: push(@newvalues,$fieldtitles{$type});
8001: }
1.3 raeburn 8002: my $newvaluestr;
8003: if (@newvalues > 0) {
8004: $newvaluestr = join(', ',@newvalues);
8005: } else {
8006: $newvaluestr = &mt('none');
1.6 raeburn 8007: }
1.1 raeburn 8008: if ($item eq 'default') {
1.26 raeburn 8009: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 8010: } else {
1.26 raeburn 8011: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 8012: }
8013: }
8014: } else {
8015: my $newvalue;
8016: if ($key eq 'run') {
8017: $newvalue = $offon[$env{'form.autoupdate_run'}];
8018: } else {
8019: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 8020: }
1.1 raeburn 8021: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
8022: }
8023: }
8024: $resulttext .= '</ul>';
8025: } else {
1.3 raeburn 8026: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 8027: }
8028: } else {
1.11 albertel 8029: $resulttext = '<span class="LC_error">'.
8030: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8031: }
1.3 raeburn 8032: return $resulttext;
1.1 raeburn 8033: }
8034:
1.125 raeburn 8035: sub modify_autocreate {
8036: my ($dom,%domconfig) = @_;
8037: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
8038: if (ref($domconfig{'autocreate'}) eq 'HASH') {
8039: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
8040: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
8041: }
8042: }
8043: my %title= ( xml => 'Auto-creation of courses in XML course description files',
8044: req => 'Auto-creation of validated requests for official courses',
8045: xmldc => 'Identity of course creator of courses from XML files',
8046: );
8047: my @types = ('xml','req');
8048: foreach my $item (@types) {
8049: $newvals{$item} = $env{'form.autocreate_'.$item};
8050: $newvals{$item} =~ s/\D//g;
8051: $newvals{$item} = 0 if ($newvals{$item} eq '');
8052: }
8053: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
8054: my %domcoords = &get_active_dcs($dom);
8055: unless (exists($domcoords{$newvals{'xmldc'}})) {
8056: $newvals{'xmldc'} = '';
8057: }
8058: %autocreatehash = (
8059: autocreate => { xml => $newvals{'xml'},
8060: req => $newvals{'req'},
8061: }
8062: );
8063: if ($newvals{'xmldc'} ne '') {
8064: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
8065: }
8066: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
8067: $dom);
8068: if ($putresult eq 'ok') {
8069: my @items = @types;
8070: if ($newvals{'xml'}) {
8071: push(@items,'xmldc');
8072: }
8073: foreach my $item (@items) {
8074: if (exists($currautocreate{$item})) {
8075: if ($currautocreate{$item} ne $newvals{$item}) {
8076: $changes{$item} = 1;
8077: }
8078: } elsif ($newvals{$item}) {
8079: $changes{$item} = 1;
8080: }
8081: }
8082: if (keys(%changes) > 0) {
8083: my @offon = ('off','on');
8084: $resulttext = &mt('Changes made:').'<ul>';
8085: foreach my $item (@types) {
8086: if ($changes{$item}) {
8087: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 8088: $resulttext .= '<li>'.
8089: &mt("$title{$item} set to [_1]$newtxt [_2]",
8090: '<b>','</b>').
8091: '</li>';
1.125 raeburn 8092: }
8093: }
8094: if ($changes{'xmldc'}) {
8095: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
8096: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 8097: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 8098: }
8099: $resulttext .= '</ul>';
8100: } else {
8101: $resulttext = &mt('No changes made to auto-creation settings');
8102: }
8103: } else {
8104: $resulttext = '<span class="LC_error">'.
8105: &mt('An error occurred: [_1]',$putresult).'</span>';
8106: }
8107: return $resulttext;
8108: }
8109:
1.23 raeburn 8110: sub modify_directorysrch {
8111: my ($dom,%domconfig) = @_;
8112: my ($resulttext,%changes);
8113: my %currdirsrch;
8114: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8115: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
8116: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
8117: }
8118: }
8119: my %title = ( available => 'Directory search available',
1.24 raeburn 8120: localonly => 'Other domains can search',
1.23 raeburn 8121: searchby => 'Search types',
8122: searchtypes => 'Search latitude');
8123: my @offon = ('off','on');
1.24 raeburn 8124: my @otherdoms = ('Yes','No');
1.23 raeburn 8125:
1.25 raeburn 8126: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 8127: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
8128: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
8129:
1.44 raeburn 8130: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 8131: if (keys(%{$usertypes}) == 0) {
8132: @cansearch = ('default');
8133: } else {
8134: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
8135: foreach my $type (@{$currdirsrch{'cansearch'}}) {
8136: if (!grep(/^\Q$type\E$/,@cansearch)) {
8137: push(@{$changes{'cansearch'}},$type);
8138: }
1.23 raeburn 8139: }
1.26 raeburn 8140: foreach my $type (@cansearch) {
8141: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
8142: push(@{$changes{'cansearch'}},$type);
8143: }
1.23 raeburn 8144: }
1.26 raeburn 8145: } else {
8146: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 8147: }
8148: }
8149:
8150: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
8151: foreach my $by (@{$currdirsrch{'searchby'}}) {
8152: if (!grep(/^\Q$by\E$/,@searchby)) {
8153: push(@{$changes{'searchby'}},$by);
8154: }
8155: }
8156: foreach my $by (@searchby) {
8157: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
8158: push(@{$changes{'searchby'}},$by);
8159: }
8160: }
8161: } else {
8162: push(@{$changes{'searchby'}},@searchby);
8163: }
1.25 raeburn 8164:
8165: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
8166: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
8167: if (!grep(/^\Q$type\E$/,@searchtypes)) {
8168: push(@{$changes{'searchtypes'}},$type);
8169: }
8170: }
8171: foreach my $type (@searchtypes) {
8172: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
8173: push(@{$changes{'searchtypes'}},$type);
8174: }
8175: }
8176: } else {
8177: if (exists($currdirsrch{'searchtypes'})) {
8178: foreach my $type (@searchtypes) {
8179: if ($type ne $currdirsrch{'searchtypes'}) {
8180: push(@{$changes{'searchtypes'}},$type);
8181: }
8182: }
8183: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
8184: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
8185: }
8186: } else {
8187: push(@{$changes{'searchtypes'}},@searchtypes);
8188: }
8189: }
8190:
1.23 raeburn 8191: my %dirsrch_hash = (
8192: directorysrch => { available => $env{'form.dirsrch_available'},
8193: cansearch => \@cansearch,
1.24 raeburn 8194: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 8195: searchby => \@searchby,
1.25 raeburn 8196: searchtypes => \@searchtypes,
1.23 raeburn 8197: }
8198: );
8199: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
8200: $dom);
8201: if ($putresult eq 'ok') {
8202: if (exists($currdirsrch{'available'})) {
8203: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
8204: $changes{'available'} = 1;
8205: }
8206: } else {
8207: if ($env{'form.dirsrch_available'} eq '1') {
8208: $changes{'available'} = 1;
8209: }
8210: }
1.24 raeburn 8211: if (exists($currdirsrch{'localonly'})) {
8212: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
8213: $changes{'localonly'} = 1;
8214: }
8215: } else {
8216: if ($env{'form.dirsrch_localonly'} eq '1') {
8217: $changes{'localonly'} = 1;
8218: }
8219: }
1.23 raeburn 8220: if (keys(%changes) > 0) {
8221: $resulttext = &mt('Changes made:').'<ul>';
8222: if ($changes{'available'}) {
8223: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
8224: }
1.24 raeburn 8225: if ($changes{'localonly'}) {
8226: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
8227: }
8228:
1.23 raeburn 8229: if (ref($changes{'cansearch'}) eq 'ARRAY') {
8230: my $chgtext;
1.26 raeburn 8231: if (ref($usertypes) eq 'HASH') {
8232: if (keys(%{$usertypes}) > 0) {
8233: foreach my $type (@{$types}) {
8234: if (grep(/^\Q$type\E$/,@cansearch)) {
8235: $chgtext .= $usertypes->{$type}.'; ';
8236: }
8237: }
8238: if (grep(/^default$/,@cansearch)) {
8239: $chgtext .= $othertitle;
8240: } else {
8241: $chgtext =~ s/\; $//;
8242: }
1.160.6.13 raeburn 8243: $resulttext .=
8244: '<li>'.
8245: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
8246: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
8247: '</li>';
1.23 raeburn 8248: }
8249: }
8250: }
8251: if (ref($changes{'searchby'}) eq 'ARRAY') {
8252: my ($searchtitles,$titleorder) = &sorted_searchtitles();
8253: my $chgtext;
8254: foreach my $type (@{$titleorder}) {
8255: if (grep(/^\Q$type\E$/,@searchby)) {
8256: if (defined($searchtitles->{$type})) {
8257: $chgtext .= $searchtitles->{$type}.'; ';
8258: }
8259: }
8260: }
8261: $chgtext =~ s/\; $//;
8262: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8263: }
1.25 raeburn 8264: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8265: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8266: my $chgtext;
8267: foreach my $type (@{$srchtypeorder}) {
8268: if (grep(/^\Q$type\E$/,@searchtypes)) {
8269: if (defined($srchtypes_desc->{$type})) {
8270: $chgtext .= $srchtypes_desc->{$type}.'; ';
8271: }
8272: }
8273: }
8274: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 8275: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 8276: }
8277: $resulttext .= '</ul>';
8278: } else {
8279: $resulttext = &mt('No changes made to institution directory search settings');
8280: }
8281: } else {
8282: $resulttext = '<span class="LC_error">'.
1.27 raeburn 8283: &mt('An error occurred: [_1]',$putresult).'</span>';
8284: }
8285: return $resulttext;
8286: }
8287:
1.28 raeburn 8288: sub modify_contacts {
1.160.6.24 raeburn 8289: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 8290: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8291: if (ref($domconfig{'contacts'}) eq 'HASH') {
8292: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8293: $currsetting{$key} = $domconfig{'contacts'}{$key};
8294: }
8295: }
1.134 raeburn 8296: my (%others,%to,%bcc);
1.28 raeburn 8297: my @contacts = ('supportemail','adminemail');
1.102 raeburn 8298: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23 raeburn 8299: 'requestsmail','updatesmail','idconflictsmail');
8300: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 8301: foreach my $type (@mailings) {
8302: @{$newsetting{$type}} =
8303: &Apache::loncommon::get_env_multiple('form.'.$type);
8304: foreach my $item (@contacts) {
8305: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8306: $contacts_hash{contacts}{$type}{$item} = 1;
8307: } else {
8308: $contacts_hash{contacts}{$type}{$item} = 0;
8309: }
8310: }
8311: $others{$type} = $env{'form.'.$type.'_others'};
8312: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 8313: if ($type eq 'helpdeskmail') {
8314: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8315: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8316: }
1.28 raeburn 8317: }
8318: foreach my $item (@contacts) {
8319: $to{$item} = $env{'form.'.$item};
8320: $contacts_hash{'contacts'}{$item} = $to{$item};
8321: }
1.160.6.23 raeburn 8322: foreach my $item (@toggles) {
8323: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8324: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8325: }
8326: }
1.28 raeburn 8327: if (keys(%currsetting) > 0) {
8328: foreach my $item (@contacts) {
8329: if ($to{$item} ne $currsetting{$item}) {
8330: $changes{$item} = 1;
8331: }
8332: }
8333: foreach my $type (@mailings) {
8334: foreach my $item (@contacts) {
8335: if (ref($currsetting{$type}) eq 'HASH') {
8336: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8337: push(@{$changes{$type}},$item);
8338: }
8339: } else {
8340: push(@{$changes{$type}},@{$newsetting{$type}});
8341: }
8342: }
8343: if ($others{$type} ne $currsetting{$type}{'others'}) {
8344: push(@{$changes{$type}},'others');
8345: }
1.134 raeburn 8346: if ($type eq 'helpdeskmail') {
8347: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8348: push(@{$changes{$type}},'bcc');
8349: }
8350: }
1.28 raeburn 8351: }
8352: } else {
8353: my %default;
8354: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8355: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8356: $default{'errormail'} = 'adminemail';
8357: $default{'packagesmail'} = 'adminemail';
8358: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8359: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8360: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 8361: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8362: foreach my $item (@contacts) {
8363: if ($to{$item} ne $default{$item}) {
8364: $changes{$item} = 1;
1.160.6.23 raeburn 8365: }
1.28 raeburn 8366: }
8367: foreach my $type (@mailings) {
8368: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8369:
8370: push(@{$changes{$type}},@{$newsetting{$type}});
8371: }
8372: if ($others{$type} ne '') {
8373: push(@{$changes{$type}},'others');
1.134 raeburn 8374: }
8375: if ($type eq 'helpdeskmail') {
8376: if ($bcc{$type} ne '') {
8377: push(@{$changes{$type}},'bcc');
8378: }
8379: }
1.28 raeburn 8380: }
8381: }
1.160.6.23 raeburn 8382: foreach my $item (@toggles) {
8383: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8384: $changes{$item} = 1;
8385: } elsif ((!$env{'form.'.$item}) &&
8386: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8387: $changes{$item} = 1;
8388: }
8389: }
1.28 raeburn 8390: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8391: $dom);
8392: if ($putresult eq 'ok') {
8393: if (keys(%changes) > 0) {
1.160.6.24 raeburn 8394: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8395: if (ref($lastactref) eq 'HASH') {
8396: $lastactref->{'domainconfig'} = 1;
8397: }
1.28 raeburn 8398: my ($titles,$short_titles) = &contact_titles();
8399: $resulttext = &mt('Changes made:').'<ul>';
8400: foreach my $item (@contacts) {
8401: if ($changes{$item}) {
8402: $resulttext .= '<li>'.$titles->{$item}.
8403: &mt(' set to: ').
8404: '<span class="LC_cusr_emph">'.
8405: $to{$item}.'</span></li>';
8406: }
8407: }
8408: foreach my $type (@mailings) {
8409: if (ref($changes{$type}) eq 'ARRAY') {
8410: $resulttext .= '<li>'.$titles->{$type}.': ';
8411: my @text;
8412: foreach my $item (@{$newsetting{$type}}) {
8413: push(@text,$short_titles->{$item});
8414: }
8415: if ($others{$type} ne '') {
8416: push(@text,$others{$type});
8417: }
8418: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8419: join(', ',@text).'</span>';
8420: if ($type eq 'helpdeskmail') {
8421: if ($bcc{$type} ne '') {
8422: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8423: }
8424: }
8425: $resulttext .= '</li>';
1.28 raeburn 8426: }
8427: }
1.160.6.23 raeburn 8428: my @offon = ('off','on');
8429: if ($changes{'reporterrors'}) {
8430: $resulttext .= '<li>'.
8431: &mt('E-mail error reports to [_1] set to "'.
8432: $offon[$env{'form.reporterrors'}].'".',
8433: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8434: &mt('LON-CAPA core group - MSU'),600,500)).
8435: '</li>';
8436: }
8437: if ($changes{'reportupdates'}) {
8438: $resulttext .= '<li>'.
8439: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8440: $offon[$env{'form.reportupdates'}].'".',
8441: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8442: &mt('LON-CAPA core group - MSU'),600,500)).
8443: '</li>';
8444: }
1.28 raeburn 8445: $resulttext .= '</ul>';
8446: } else {
1.34 raeburn 8447: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8448: }
8449: } else {
8450: $resulttext = '<span class="LC_error">'.
8451: &mt('An error occurred: [_1].',$putresult).'</span>';
8452: }
8453: return $resulttext;
8454: }
8455:
8456: sub modify_usercreation {
1.27 raeburn 8457: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 8458: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8459: my $warningmsg;
1.27 raeburn 8460: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8461: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 8462: if ($key eq 'cancreate') {
8463: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8464: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8465: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8466: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8467: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8468: } else {
8469: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8470: }
1.50 raeburn 8471: }
1.43 raeburn 8472: }
1.160.6.34 raeburn 8473: } elsif ($key eq 'email_rule') {
8474: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8475: } else {
8476: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 8477: }
8478: }
1.34 raeburn 8479: }
1.160.6.34 raeburn 8480: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
8481: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
8482: my @contexts = ('author','course','requestcrs');
8483: foreach my $item(@contexts) {
8484: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8485: }
1.34 raeburn 8486: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8487: foreach my $item (@contexts) {
1.160.6.34 raeburn 8488: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8489: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8490: }
1.27 raeburn 8491: }
1.34 raeburn 8492: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8493: foreach my $item (@contexts) {
1.43 raeburn 8494: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8495: if ($cancreate{$item} ne 'any') {
8496: push(@{$changes{'cancreate'}},$item);
8497: }
8498: } else {
8499: if ($cancreate{$item} ne 'none') {
8500: push(@{$changes{'cancreate'}},$item);
8501: }
1.27 raeburn 8502: }
8503: }
8504: } else {
1.43 raeburn 8505: foreach my $item (@contexts) {
1.34 raeburn 8506: push(@{$changes{'cancreate'}},$item);
8507: }
1.27 raeburn 8508: }
1.34 raeburn 8509:
1.27 raeburn 8510: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8511: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8512: if (!grep(/^\Q$type\E$/,@username_rule)) {
8513: push(@{$changes{'username_rule'}},$type);
8514: }
8515: }
8516: foreach my $type (@username_rule) {
8517: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8518: push(@{$changes{'username_rule'}},$type);
8519: }
8520: }
8521: } else {
8522: push(@{$changes{'username_rule'}},@username_rule);
8523: }
8524:
1.32 raeburn 8525: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8526: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8527: if (!grep(/^\Q$type\E$/,@id_rule)) {
8528: push(@{$changes{'id_rule'}},$type);
8529: }
8530: }
8531: foreach my $type (@id_rule) {
8532: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8533: push(@{$changes{'id_rule'}},$type);
8534: }
8535: }
8536: } else {
8537: push(@{$changes{'id_rule'}},@id_rule);
8538: }
8539:
1.43 raeburn 8540: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8541: my @authtypes = ('int','krb4','krb5','loc');
8542: my %authhash;
1.43 raeburn 8543: foreach my $item (@authen_contexts) {
1.28 raeburn 8544: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8545: foreach my $auth (@authtypes) {
8546: if (grep(/^\Q$auth\E$/,@authallowed)) {
8547: $authhash{$item}{$auth} = 1;
8548: } else {
8549: $authhash{$item}{$auth} = 0;
8550: }
8551: }
8552: }
8553: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8554: foreach my $item (@authen_contexts) {
1.28 raeburn 8555: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8556: foreach my $auth (@authtypes) {
8557: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8558: push(@{$changes{'authtypes'}},$item);
8559: last;
8560: }
8561: }
8562: }
8563: }
8564: } else {
1.43 raeburn 8565: foreach my $item (@authen_contexts) {
1.28 raeburn 8566: push(@{$changes{'authtypes'}},$item);
8567: }
8568: }
8569:
1.160.6.34 raeburn 8570: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8571: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8572: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8573: $save_usercreate{'id_rule'} = \@id_rule;
8574: $save_usercreate{'username_rule'} = \@username_rule,
8575: $save_usercreate{'authtypes'} = \%authhash;
8576:
1.27 raeburn 8577: my %usercreation_hash = (
1.160.6.34 raeburn 8578: usercreation => \%save_usercreate,
8579: );
1.27 raeburn 8580:
8581: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8582: $dom);
1.50 raeburn 8583:
1.160.6.34 raeburn 8584: if ($putresult eq 'ok') {
8585: if (keys(%changes) > 0) {
8586: $resulttext = &mt('Changes made:').'<ul>';
8587: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8588: my %lt = &usercreation_types();
8589: foreach my $type (@{$changes{'cancreate'}}) {
8590: my $chgtext = $lt{$type}.', ';
8591: if ($cancreate{$type} eq 'none') {
8592: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8593: } elsif ($cancreate{$type} eq 'any') {
8594: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8595: } elsif ($cancreate{$type} eq 'official') {
8596: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8597: } elsif ($cancreate{$type} eq 'unofficial') {
8598: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8599: }
8600: $resulttext .= '<li>'.$chgtext.'</li>';
8601: }
8602: }
8603: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8604: my ($rules,$ruleorder) =
8605: &Apache::lonnet::inst_userrules($dom,'username');
8606: my $chgtext = '<ul>';
8607: foreach my $type (@username_rule) {
8608: if (ref($rules->{$type}) eq 'HASH') {
8609: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8610: }
8611: }
8612: $chgtext .= '</ul>';
8613: if (@username_rule > 0) {
8614: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8615: } else {
8616: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8617: }
8618: }
8619: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8620: my ($idrules,$idruleorder) =
8621: &Apache::lonnet::inst_userrules($dom,'id');
8622: my $chgtext = '<ul>';
8623: foreach my $type (@id_rule) {
8624: if (ref($idrules->{$type}) eq 'HASH') {
8625: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8626: }
8627: }
8628: $chgtext .= '</ul>';
8629: if (@id_rule > 0) {
8630: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8631: } else {
8632: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8633: }
8634: }
8635: my %authname = &authtype_names();
8636: my %context_title = &context_names();
8637: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8638: my $chgtext = '<ul>';
8639: foreach my $type (@{$changes{'authtypes'}}) {
8640: my @allowed;
8641: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8642: foreach my $auth (@authtypes) {
8643: if ($authhash{$type}{$auth}) {
8644: push(@allowed,$authname{$auth});
8645: }
8646: }
8647: if (@allowed > 0) {
8648: $chgtext .= join(', ',@allowed).'</li>';
8649: } else {
8650: $chgtext .= &mt('none').'</li>';
8651: }
8652: }
8653: $chgtext .= '</ul>';
8654: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8655: $resulttext .= '</li>';
8656: }
8657: $resulttext .= '</ul>';
8658: } else {
8659: $resulttext = &mt('No changes made to user creation settings');
8660: }
8661: } else {
8662: $resulttext = '<span class="LC_error">'.
8663: &mt('An error occurred: [_1]',$putresult).'</span>';
8664: }
8665: if ($warningmsg ne '') {
8666: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8667: }
8668: return $resulttext;
8669: }
8670:
8671: sub modify_selfcreation {
8672: my ($dom,%domconfig) = @_;
8673: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8674: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 8675: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8676: if (ref($types) eq 'ARRAY') {
8677: $usertypes->{'default'} = $othertitle;
8678: push(@{$types},'default');
8679: }
1.160.6.34 raeburn 8680: #
8681: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8682: #
8683: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8684: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8685: if ($key eq 'cancreate') {
8686: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8687: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8688: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8689: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.40 raeburn 8690: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 8691: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 8692: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8693: } else {
8694: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8695: }
8696: }
8697: }
8698: } elsif ($key eq 'email_rule') {
8699: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8700: } else {
8701: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8702: }
8703: }
8704: }
8705: #
8706: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8707: #
8708: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8709: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8710: if ($key eq 'selfcreate') {
8711: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8712: } else {
8713: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8714: }
8715: }
8716: }
8717:
8718: my @contexts = ('selfcreate');
8719: @{$cancreate{'selfcreate'}} = ();
8720: %{$cancreate{'emailusername'}} = ();
8721: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 8722: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 8723: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 8724: my %selfcreatetypes = (
8725: sso => 'users authenticated by institutional single sign on',
8726: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 8727: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 8728: );
1.160.6.34 raeburn 8729: #
8730: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8731: # is permitted.
8732: #
1.160.6.40 raeburn 8733:
8734: my @statuses;
8735: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8736: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8737: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8738: }
8739: }
8740: push(@statuses,'default');
8741:
1.160.6.35 raeburn 8742: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 8743: if ($item eq 'email') {
1.160.6.40 raeburn 8744: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 8745: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 8746: push(@contexts,'selfcreateprocessing');
8747: foreach my $type (@statuses) {
8748: if ($type eq 'default') {
8749: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8750: } else {
8751: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8752: }
8753: }
1.160.6.34 raeburn 8754: }
8755: } else {
8756: if ($env{'form.cancreate_'.$item}) {
8757: push(@{$cancreate{'selfcreate'}},$item);
8758: }
8759: }
8760: }
8761: my (@email_rule,%userinfo,%savecaptcha);
8762: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8763: #
1.160.6.35 raeburn 8764: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8765: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.160.6.34 raeburn 8766: #
1.160.6.40 raeburn 8767:
1.160.6.48 raeburn 8768: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 8769: push(@contexts,'emailusername');
1.160.6.35 raeburn 8770: if (ref($types) eq 'ARRAY') {
8771: foreach my $type (@{$types}) {
8772: if (ref($infofields) eq 'ARRAY') {
8773: foreach my $field (@{$infofields}) {
8774: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8775: $cancreate{'emailusername'}{$type}{$field} = $1;
8776: }
8777: }
1.160.6.34 raeburn 8778: }
8779: }
8780: }
8781: #
8782: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8783: # queued requests for self-creation of account using e-mail address as username
8784: #
8785:
8786: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8787: @approvalnotify = sort(@approvalnotify);
8788: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8789: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8790: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8791: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8792: push(@{$changes{'cancreate'}},'notify');
8793: }
8794: } else {
8795: if ($cancreate{'notify'}{'approval'}) {
8796: push(@{$changes{'cancreate'}},'notify');
8797: }
8798: }
8799: } elsif ($cancreate{'notify'}{'approval'}) {
8800: push(@{$changes{'cancreate'}},'notify');
8801: }
8802:
8803: #
8804: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8805: #
8806: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8807: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8808: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8809: if (@{$curr_usercreation{'email_rule'}} > 0) {
8810: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8811: if (!grep(/^\Q$type\E$/,@email_rule)) {
8812: push(@{$changes{'email_rule'}},$type);
8813: }
8814: }
8815: }
8816: if (@email_rule > 0) {
8817: foreach my $type (@email_rule) {
8818: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8819: push(@{$changes{'email_rule'}},$type);
8820: }
8821: }
8822: }
8823: } elsif (@email_rule > 0) {
8824: push(@{$changes{'email_rule'}},@email_rule);
8825: }
8826: }
8827: #
1.160.6.40 raeburn 8828: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 8829: # institutional log-in.
8830: #
8831: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8832: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8833: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8834: ($domdefaults{'auth_def'} eq 'localauth'))) {
8835: $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.').' '.
8836: &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.');
8837: }
8838: }
8839: my @fields = ('lastname','firstname','middlename','generation',
8840: 'permanentemail','id');
1.160.6.44 raeburn 8841: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 8842: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8843: #
8844: # Where usernames may created for institutional log-in and/or institutional single sign on:
8845: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8846: # may self-create accounts
8847: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8848: # which the user may supply, if institutional data is unavailable.
8849: #
8850: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8851: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 8852: if (@{$types} > 1) {
1.160.6.34 raeburn 8853: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8854: push(@contexts,'statustocreate');
8855: } else {
8856: undef($cancreate{'statustocreate'});
8857: }
8858: foreach my $type (@{$types}) {
8859: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8860: foreach my $field (@fields) {
8861: if (grep(/^\Q$field\E$/,@modifiable)) {
8862: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8863: } else {
8864: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8865: }
8866: }
8867: }
8868: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8869: foreach my $type (@{$types}) {
8870: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8871: foreach my $field (@fields) {
8872: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8873: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8874: push(@{$changes{'selfcreate'}},$type);
8875: last;
8876: }
8877: }
8878: }
8879: }
8880: } else {
8881: foreach my $type (@{$types}) {
8882: push(@{$changes{'selfcreate'}},$type);
8883: }
8884: }
8885: }
1.160.6.44 raeburn 8886: foreach my $field (@shibfields) {
8887: if ($env{'form.shibenv_'.$field} ne '') {
8888: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
8889: }
8890: }
8891: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8892: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
8893: foreach my $field (@shibfields) {
8894: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
8895: push(@{$changes{'cancreate'}},'shibenv');
8896: }
8897: }
8898: } else {
8899: foreach my $field (@shibfields) {
8900: if ($env{'form.shibenv_'.$field}) {
8901: push(@{$changes{'cancreate'}},'shibenv');
8902: last;
8903: }
8904: }
8905: }
8906: }
1.160.6.34 raeburn 8907: }
8908: foreach my $item (@contexts) {
8909: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8910: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8911: if (ref($cancreate{$item}) eq 'ARRAY') {
8912: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8913: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8914: push(@{$changes{'cancreate'}},$item);
8915: }
8916: }
8917: }
8918: }
8919: if (ref($cancreate{$item}) eq 'ARRAY') {
8920: foreach my $type (@{$cancreate{$item}}) {
8921: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8922: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8923: push(@{$changes{'cancreate'}},$item);
8924: }
8925: }
8926: }
8927: }
8928: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8929: if (ref($cancreate{$item}) eq 'HASH') {
8930: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 8931: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8932: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8933: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8934: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8935: push(@{$changes{'cancreate'}},$item);
8936: }
8937: }
8938: }
1.160.6.40 raeburn 8939: } elsif ($item eq 'selfcreateprocessing') {
8940: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
8941: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8942: push(@{$changes{'cancreate'}},$item);
8943: }
8944: }
1.160.6.35 raeburn 8945: } else {
8946: if (!$cancreate{$item}{$curr}) {
8947: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8948: push(@{$changes{'cancreate'}},$item);
8949: }
1.160.6.34 raeburn 8950: }
8951: }
8952: }
8953: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 8954: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8955: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8956: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8957: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8958: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8959: push(@{$changes{'cancreate'}},$item);
8960: }
8961: }
8962: } else {
8963: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8964: push(@{$changes{'cancreate'}},$item);
8965: }
8966: }
8967: }
1.160.6.40 raeburn 8968: } elsif ($item eq 'selfcreateprocessing') {
8969: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
8970: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8971: push(@{$changes{'cancreate'}},$item);
8972: }
8973: }
1.160.6.35 raeburn 8974: } else {
8975: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8976: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8977: push(@{$changes{'cancreate'}},$item);
8978: }
1.160.6.34 raeburn 8979: }
8980: }
8981: }
8982: }
8983: } elsif ($curr_usercreation{'cancreate'}{$item}) {
8984: if (ref($cancreate{$item}) eq 'ARRAY') {
8985: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
8986: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8987: push(@{$changes{'cancreate'}},$item);
8988: }
8989: }
8990: } elsif (ref($cancreate{$item}) eq 'HASH') {
8991: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
8992: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8993: push(@{$changes{'cancreate'}},$item);
8994: }
8995: }
8996: }
8997: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 8998: if (ref($cancreate{$item}) eq 'HASH') {
8999: foreach my $type (keys(%{$cancreate{$item}})) {
9000: if (ref($cancreate{$item}{$type}) eq 'HASH') {
9001: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
9002: if ($cancreate{$item}{$type}{$field}) {
9003: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9004: push(@{$changes{'cancreate'}},$item);
9005: }
9006: last;
9007: }
9008: }
9009: }
9010: }
1.160.6.34 raeburn 9011: }
9012: }
9013: }
9014: #
9015: # Populate %save_usercreate hash with updates to self-creation configuration.
9016: #
9017: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
9018: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
9019: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
9020: if (ref($cancreate{'notify'}) eq 'HASH') {
9021: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
9022: }
1.160.6.40 raeburn 9023: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
9024: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
9025: }
1.160.6.34 raeburn 9026: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9027: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
9028: }
1.160.6.44 raeburn 9029: if (ref($cancreate{'shibenv'}) eq 'HASH') {
9030: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
9031: }
1.160.6.34 raeburn 9032: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
9033: $save_usercreate{'emailrule'} = \@email_rule;
9034:
9035: my %userconfig_hash = (
9036: usercreation => \%save_usercreate,
9037: usermodification => \%save_usermodify,
9038: );
9039: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
9040: $dom);
9041: #
9042: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
9043: #
1.27 raeburn 9044: if ($putresult eq 'ok') {
9045: if (keys(%changes) > 0) {
9046: $resulttext = &mt('Changes made:').'<ul>';
9047: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 9048: my %lt = &selfcreation_types();
1.34 raeburn 9049: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 9050: my $chgtext;
1.45 raeburn 9051: if ($type eq 'selfcreate') {
1.50 raeburn 9052: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 9053: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 9054: } else {
1.160.6.34 raeburn 9055: $chgtext .= &mt('Self-creation of a new account is permitted for:').
9056: '<ul>';
1.50 raeburn 9057: foreach my $case (@{$cancreate{$type}}) {
9058: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
9059: }
9060: $chgtext .= '</ul>';
1.100 raeburn 9061: if (ref($cancreate{$type}) eq 'ARRAY') {
9062: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
9063: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9064: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 9065: $chgtext .= '<br />'.
9066: '<span class="LC_warning">'.
9067: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9068: '</span>';
1.100 raeburn 9069: }
9070: }
9071: }
9072: }
1.43 raeburn 9073: }
1.160.6.44 raeburn 9074: } elsif ($type eq 'shibenv') {
9075: if (keys(%{$cancreate{$type}}) == 0) {
9076: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
9077: } else {
9078: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
9079: '<ul>';
9080: foreach my $field (@shibfields) {
9081: next if ($cancreate{$type}{$field} eq '');
9082: if ($field eq 'inststatus') {
9083: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
9084: } else {
9085: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
9086: }
9087: }
9088: $chgtext .= '</ul>';
9089: }
1.93 raeburn 9090: } elsif ($type eq 'statustocreate') {
1.96 raeburn 9091: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
9092: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
9093: if (@{$cancreate{'selfcreate'}} > 0) {
9094: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 9095: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 9096: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 9097: $chgtext .= '<br />'.
9098: '<span class="LC_warning">'.
9099: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9100: '</span>';
9101: }
1.96 raeburn 9102: } elsif (ref($usertypes) eq 'HASH') {
9103: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 9104: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
9105: } else {
9106: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
9107: }
9108: $chgtext .= '<ul>';
9109: foreach my $case (@{$cancreate{$type}}) {
9110: if ($case eq 'default') {
9111: $chgtext .= '<li>'.$othertitle.'</li>';
9112: } else {
9113: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 9114: }
9115: }
1.100 raeburn 9116: $chgtext .= '</ul>';
9117: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 9118: $chgtext .= '<br /><span class="LC_warning">'.
9119: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
9120: '</span>';
1.100 raeburn 9121: }
9122: }
9123: } else {
9124: if (@{$cancreate{$type}} == 0) {
9125: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
9126: } else {
9127: $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 9128: }
9129: }
9130: }
1.160.6.40 raeburn 9131: } elsif ($type eq 'selfcreateprocessing') {
9132: my %choices = &Apache::lonlocal::texthash (
9133: automatic => 'Automatic approval',
9134: approval => 'Queued for approval',
9135: );
9136: if (@statuses > 1) {
9137: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
9138: '<ul>';
9139: foreach my $type (@statuses) {
9140: if ($type eq 'default') {
9141: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9142: } else {
9143: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9144: }
9145: }
9146: $chgtext .= '</ul>';
9147: } else {
9148: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
9149: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
9150: }
1.160.6.5 raeburn 9151: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 9152: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 9153: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
9154: } else {
9155: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 9156: if ($captchas{$savecaptcha{$type}}) {
9157: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 9158: } else {
9159: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
9160: }
9161: }
9162: } elsif ($type eq 'recaptchakeys') {
9163: my ($privkey,$pubkey);
1.160.6.34 raeburn 9164: if (ref($savecaptcha{$type}) eq 'HASH') {
9165: $pubkey = $savecaptcha{$type}{'public'};
9166: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 9167: }
9168: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
9169: if (!$pubkey) {
9170: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
9171: } else {
9172: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9173: }
9174: if (!$privkey) {
9175: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
9176: } else {
9177: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
9178: }
9179: $chgtext .= '</ul>';
1.160.6.34 raeburn 9180: } elsif ($type eq 'emailusername') {
9181: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 9182: if (ref($types) eq 'ARRAY') {
9183: foreach my $type (@{$types}) {
9184: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
9185: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50 raeburn 9186: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.160.6.35 raeburn 9187: '<ul>';
9188: foreach my $field (@{$infofields}) {
9189: if ($cancreate{'emailusername'}{$type}{$field}) {
9190: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
9191: }
9192: }
1.160.6.50 raeburn 9193: $chgtext .= '</ul>';
9194: } else {
9195: $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.160.6.35 raeburn 9196: }
9197: } else {
1.160.6.50 raeburn 9198: $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.160.6.34 raeburn 9199: }
9200: }
9201: }
9202: }
9203: } elsif ($type eq 'notify') {
9204: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
9205: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9206: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
9207: if ($cancreate{'notify'}{'approval'}) {
9208: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
9209: }
9210: }
1.43 raeburn 9211: }
1.34 raeburn 9212: }
1.160.6.34 raeburn 9213: if ($chgtext) {
9214: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 9215: }
9216: }
9217: }
1.43 raeburn 9218: if (ref($changes{'email_rule'}) eq 'ARRAY') {
9219: my ($emailrules,$emailruleorder) =
9220: &Apache::lonnet::inst_userrules($dom,'email');
9221: my $chgtext = '<ul>';
9222: foreach my $type (@email_rule) {
9223: if (ref($emailrules->{$type}) eq 'HASH') {
9224: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
9225: }
9226: }
9227: $chgtext .= '</ul>';
9228: if (@email_rule > 0) {
1.160.6.34 raeburn 9229: $resulttext .= '<li>'.
9230: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
9231: $chgtext.
9232: '</li>';
1.43 raeburn 9233: } else {
1.160.6.34 raeburn 9234: $resulttext .= '<li>'.
9235: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
9236: '</li>';
1.43 raeburn 9237: }
9238: }
1.160.6.34 raeburn 9239: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
9240: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
9241: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9242: foreach my $type (@{$changes{'selfcreate'}}) {
9243: my $typename = $type;
9244: if (ref($usertypes) eq 'HASH') {
9245: if ($usertypes->{$type} ne '') {
9246: $typename = $usertypes->{$type};
1.28 raeburn 9247: }
9248: }
1.160.6.34 raeburn 9249: my @modifiable;
9250: $resulttext .= '<li>'.
9251: &mt('Self-creation of account by users with status: [_1]',
9252: '<span class="LC_cusr_emph">'.$typename.'</span>').
9253: ' - '.&mt('modifiable fields (if institutional data blank): ');
9254: foreach my $field (@fields) {
9255: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9256: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
9257: }
9258: }
9259: if (@modifiable > 0) {
9260: $resulttext .= join(', ',@modifiable);
1.43 raeburn 9261: } else {
1.160.6.34 raeburn 9262: $resulttext .= &mt('none');
1.43 raeburn 9263: }
1.160.6.34 raeburn 9264: $resulttext .= '</li>';
1.28 raeburn 9265: }
1.160.6.34 raeburn 9266: $resulttext .= '</ul></li>';
1.28 raeburn 9267: }
1.27 raeburn 9268: $resulttext .= '</ul>';
9269: } else {
1.160.6.34 raeburn 9270: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 9271: }
9272: } else {
9273: $resulttext = '<span class="LC_error">'.
1.23 raeburn 9274: &mt('An error occurred: [_1]',$putresult).'</span>';
9275: }
1.43 raeburn 9276: if ($warningmsg ne '') {
9277: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9278: }
1.23 raeburn 9279: return $resulttext;
9280: }
9281:
1.160.6.5 raeburn 9282: sub process_captcha {
9283: my ($container,$changes,$newsettings,$current) = @_;
9284: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9285: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9286: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9287: $newsettings->{'captcha'} = 'original';
9288: }
9289: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
9290: if ($container eq 'cancreate') {
9291: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9292: push(@{$changes->{'cancreate'}},'captcha');
9293: } elsif (!defined($changes->{'cancreate'})) {
9294: $changes->{'cancreate'} = ['captcha'];
9295: }
9296: } else {
9297: $changes->{'captcha'} = 1;
9298: }
9299: }
9300: my ($newpub,$newpriv,$currpub,$currpriv);
9301: if ($newsettings->{'captcha'} eq 'recaptcha') {
9302: $newpub = $env{'form.'.$container.'_recaptchapub'};
9303: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 9304: $newpub =~ s/[^\w\-]//g;
9305: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 9306: $newsettings->{'recaptchakeys'} = {
9307: public => $newpub,
9308: private => $newpriv,
9309: };
9310: }
9311: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9312: $currpub = $current->{'recaptchakeys'}{'public'};
9313: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 9314: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9315: $newsettings->{'recaptchakeys'} = {
9316: public => '',
9317: private => '',
9318: }
9319: }
1.160.6.5 raeburn 9320: }
9321: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
9322: if ($container eq 'cancreate') {
9323: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9324: push(@{$changes->{'cancreate'}},'recaptchakeys');
9325: } elsif (!defined($changes->{'cancreate'})) {
9326: $changes->{'cancreate'} = ['recaptchakeys'];
9327: }
9328: } else {
9329: $changes->{'recaptchakeys'} = 1;
9330: }
9331: }
9332: return;
9333: }
9334:
1.33 raeburn 9335: sub modify_usermodification {
9336: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9337: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 9338: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9339: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 9340: if ($key eq 'selfcreate') {
9341: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9342: } else {
9343: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9344: }
1.33 raeburn 9345: }
9346: }
1.160.6.34 raeburn 9347: my @contexts = ('author','course');
1.33 raeburn 9348: my %context_title = (
9349: author => 'In author context',
9350: course => 'In course context',
9351: );
9352: my @fields = ('lastname','firstname','middlename','generation',
9353: 'permanentemail','id');
9354: my %roles = (
9355: author => ['ca','aa'],
9356: course => ['st','ep','ta','in','cr'],
9357: );
9358: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9359: foreach my $context (@contexts) {
9360: foreach my $role (@{$roles{$context}}) {
9361: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9362: foreach my $item (@fields) {
9363: if (grep(/^\Q$item\E$/,@modifiable)) {
9364: $modifyhash{$context}{$role}{$item} = 1;
9365: } else {
9366: $modifyhash{$context}{$role}{$item} = 0;
9367: }
9368: }
9369: }
9370: if (ref($curr_usermodification{$context}) eq 'HASH') {
9371: foreach my $role (@{$roles{$context}}) {
9372: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9373: foreach my $field (@fields) {
9374: if ($modifyhash{$context}{$role}{$field} ne
9375: $curr_usermodification{$context}{$role}{$field}) {
9376: push(@{$changes{$context}},$role);
9377: last;
9378: }
9379: }
9380: }
9381: }
9382: } else {
9383: foreach my $context (@contexts) {
9384: foreach my $role (@{$roles{$context}}) {
9385: push(@{$changes{$context}},$role);
9386: }
9387: }
9388: }
9389: }
9390: my %usermodification_hash = (
9391: usermodification => \%modifyhash,
9392: );
9393: my $putresult = &Apache::lonnet::put_dom('configuration',
9394: \%usermodification_hash,$dom);
9395: if ($putresult eq 'ok') {
9396: if (keys(%changes) > 0) {
9397: $resulttext = &mt('Changes made: ').'<ul>';
9398: foreach my $context (@contexts) {
9399: if (ref($changes{$context}) eq 'ARRAY') {
9400: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9401: if (ref($changes{$context}) eq 'ARRAY') {
9402: foreach my $role (@{$changes{$context}}) {
9403: my $rolename;
1.160.6.34 raeburn 9404: if ($role eq 'cr') {
9405: $rolename = &mt('Custom');
1.33 raeburn 9406: } else {
1.160.6.34 raeburn 9407: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9408: }
9409: my @modifiable;
1.160.6.34 raeburn 9410: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9411: foreach my $field (@fields) {
9412: if ($modifyhash{$context}{$role}{$field}) {
9413: push(@modifiable,$fieldtitles{$field});
9414: }
9415: }
9416: if (@modifiable > 0) {
9417: $resulttext .= join(', ',@modifiable);
9418: } else {
9419: $resulttext .= &mt('none');
9420: }
9421: $resulttext .= '</li>';
9422: }
9423: $resulttext .= '</ul></li>';
9424: }
9425: }
9426: }
9427: $resulttext .= '</ul>';
9428: } else {
9429: $resulttext = &mt('No changes made to user modification settings');
9430: }
9431: } else {
9432: $resulttext = '<span class="LC_error">'.
9433: &mt('An error occurred: [_1]',$putresult).'</span>';
9434: }
9435: return $resulttext;
9436: }
9437:
1.43 raeburn 9438: sub modify_defaults {
1.160.6.27 raeburn 9439: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9440: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 9441: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9442: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9443: my @authtypes = ('internal','krb4','krb5','localauth');
9444: foreach my $item (@items) {
9445: $newvalues{$item} = $env{'form.'.$item};
9446: if ($item eq 'auth_def') {
9447: if ($newvalues{$item} ne '') {
9448: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9449: push(@errors,$item);
9450: }
9451: }
9452: } elsif ($item eq 'lang_def') {
9453: if ($newvalues{$item} ne '') {
9454: if ($newvalues{$item} =~ /^(\w+)/) {
9455: my $langcode = $1;
1.103 raeburn 9456: if ($langcode ne 'x_chef') {
9457: if (code2language($langcode) eq '') {
9458: push(@errors,$item);
9459: }
1.43 raeburn 9460: }
9461: } else {
9462: push(@errors,$item);
9463: }
9464: }
1.54 raeburn 9465: } elsif ($item eq 'timezone_def') {
9466: if ($newvalues{$item} ne '') {
1.62 raeburn 9467: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9468: push(@errors,$item);
9469: }
9470: }
1.68 raeburn 9471: } elsif ($item eq 'datelocale_def') {
9472: if ($newvalues{$item} ne '') {
9473: my @datelocale_ids = DateTime::Locale->ids();
9474: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9475: push(@errors,$item);
9476: }
9477: }
1.141 raeburn 9478: } elsif ($item eq 'portal_def') {
9479: if ($newvalues{$item} ne '') {
9480: 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])\/?$/) {
9481: push(@errors,$item);
9482: }
9483: }
1.43 raeburn 9484: }
9485: if (grep(/^\Q$item\E$/,@errors)) {
9486: $newvalues{$item} = $domdefaults{$item};
9487: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9488: $changes{$item} = 1;
9489: }
1.72 raeburn 9490: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9491: }
9492: my %defaults_hash = (
1.72 raeburn 9493: defaults => \%newvalues,
9494: );
1.43 raeburn 9495: my $title = &defaults_titles();
1.160.6.40 raeburn 9496:
9497: my $currinststatus;
9498: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9499: $currinststatus = $domconfig{'inststatus'};
9500: } else {
9501: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9502: $currinststatus = {
9503: inststatustypes => $usertypes,
9504: inststatusorder => $types,
9505: inststatusguest => [],
9506: };
9507: }
9508: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9509: my @allpos;
9510: my %guests;
9511: my %alltypes;
9512: my ($currtitles,$currguests,$currorder);
9513: if (ref($currinststatus) eq 'HASH') {
9514: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9515: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9516: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9517: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9518: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9519: }
9520: }
9521: unless (grep(/^\Q$type\E$/,@todelete)) {
9522: my $position = $env{'form.inststatus_pos_'.$type};
9523: $position =~ s/\D+//g;
9524: $allpos[$position] = $type;
9525: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9526: $alltypes{$type} =~ s/`//g;
9527: if ($env{'form.inststatus_guest_'.$type}) {
9528: $guests{$type} = 1;
9529: }
9530: }
9531: }
9532: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9533: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9534: }
9535: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9536: $currtitles =~ s/,$//;
9537: }
9538: }
9539: if ($env{'form.addinststatus'}) {
9540: my $newtype = $env{'form.addinststatus'};
9541: $newtype =~ s/\W//g;
9542: unless (exists($alltypes{$newtype})) {
9543: if ($env{'form.addinststatus_guest'}) {
9544: $guests{$newtype} = 1;
9545: }
9546: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9547: $alltypes{$newtype} =~ s/`//g;
9548: my $position = $env{'form.addinststatus_pos'};
9549: $position =~ s/\D+//g;
9550: if ($position ne '') {
9551: $allpos[$position] = $newtype;
9552: }
9553: }
9554: }
9555: my (@orderedstatus,@orderedguests);
9556: foreach my $type (@allpos) {
9557: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9558: push(@orderedstatus,$type);
9559: if ($guests{$type}) {
9560: push(@orderedguests,$type);
9561: }
9562: }
9563: }
9564: foreach my $type (keys(%alltypes)) {
9565: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9566: delete($alltypes{$type});
9567: }
9568: }
9569: $defaults_hash{'inststatus'} = {
9570: inststatustypes => \%alltypes,
9571: inststatusorder => \@orderedstatus,
9572: inststatusguest => \@orderedguests,
9573: };
9574: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9575: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9576: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9577: }
9578: }
9579: if ($currorder ne join(',',@orderedstatus)) {
9580: $changes{'inststatus'}{'inststatusorder'} = 1;
9581: }
9582: if ($currguests ne join(',',@orderedguests)) {
9583: $changes{'inststatus'}{'inststatusguest'} = 1;
9584: }
9585: my $newtitles;
9586: foreach my $item (@orderedstatus) {
9587: $newtitles .= $alltypes{$item}.',';
9588: }
9589: $newtitles =~ s/,$//;
9590: if ($currtitles ne $newtitles) {
9591: $changes{'inststatus'}{'inststatustypes'} = 1;
9592: }
1.43 raeburn 9593: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9594: $dom);
9595: if ($putresult eq 'ok') {
9596: if (keys(%changes) > 0) {
9597: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 9598: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9599: 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";
9600: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 9601: if ($item eq 'inststatus') {
9602: if (ref($changes{'inststatus'}) eq 'HASH') {
9603: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9604: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9605: foreach my $type (@orderedstatus) {
9606: $resulttext .= $alltypes{$type}.', ';
9607: }
9608: $resulttext =~ s/, $//;
9609: $resulttext .= '</li>';
9610: }
9611: if ($changes{'inststatus'}{'inststatusguest'}) {
9612: $resulttext .= '<li>';
9613: if (@orderedguests) {
9614: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9615: foreach my $type (@orderedguests) {
9616: $resulttext .= $alltypes{$type}.', ';
9617: }
9618: $resulttext =~ s/, $//;
9619: } else {
9620: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9621: }
9622: $resulttext .= '</li>';
9623: }
9624: }
9625: } else {
9626: my $value = $env{'form.'.$item};
9627: if ($value eq '') {
9628: $value = &mt('none');
9629: } elsif ($item eq 'auth_def') {
9630: my %authnames = &authtype_names();
9631: my %shortauth = (
9632: internal => 'int',
9633: krb4 => 'krb4',
9634: krb5 => 'krb5',
9635: localauth => 'loc',
9636: );
9637: $value = $authnames{$shortauth{$value}};
9638: }
9639: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9640: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 9641: }
9642: }
9643: $resulttext .= '</ul>';
9644: $mailmsgtext .= "\n";
9645: my $cachetime = 24*60*60;
1.72 raeburn 9646: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9647: if (ref($lastactref) eq 'HASH') {
9648: $lastactref->{'domdefaults'} = 1;
9649: }
1.68 raeburn 9650: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 9651: my $notify = 1;
9652: if (ref($domconfig{'contacts'}) eq 'HASH') {
9653: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9654: $notify = 0;
9655: }
9656: }
9657: if ($notify) {
9658: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9659: "LON-CAPA Domain Settings Change - $dom",
9660: $mailmsgtext);
9661: }
1.54 raeburn 9662: }
1.43 raeburn 9663: } else {
1.54 raeburn 9664: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 9665: }
9666: } else {
9667: $resulttext = '<span class="LC_error">'.
9668: &mt('An error occurred: [_1]',$putresult).'</span>';
9669: }
9670: if (@errors > 0) {
9671: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9672: foreach my $item (@errors) {
9673: $resulttext .= ' "'.$title->{$item}.'",';
9674: }
9675: $resulttext =~ s/,$//;
9676: }
9677: return $resulttext;
9678: }
9679:
1.46 raeburn 9680: sub modify_scantron {
1.160.6.24 raeburn 9681: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 9682: my ($resulttext,%confhash,%changes,$errors);
9683: my $custom = 'custom.tab';
9684: my $default = 'default.tab';
9685: my $servadm = $r->dir_config('lonAdmEMail');
9686: my ($configuserok,$author_ok,$switchserver) =
9687: &config_check($dom,$confname,$servadm);
9688: if ($env{'form.scantronformat.filename'} ne '') {
9689: my $error;
9690: if ($configuserok eq 'ok') {
9691: if ($switchserver) {
1.130 raeburn 9692: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 9693: } else {
9694: if ($author_ok eq 'ok') {
9695: my ($result,$scantronurl) =
9696: &publishlogo($r,'upload','scantronformat',$dom,
9697: $confname,'scantron','','',$custom);
9698: if ($result eq 'ok') {
9699: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 9700: $changes{'scantronformat'} = 1;
1.46 raeburn 9701: } else {
9702: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9703: }
9704: } else {
9705: $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);
9706: }
9707: }
9708: } else {
9709: $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);
9710: }
9711: if ($error) {
9712: &Apache::lonnet::logthis($error);
9713: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9714: }
9715: }
1.48 raeburn 9716: if (ref($domconfig{'scantron'}) eq 'HASH') {
9717: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9718: if ($env{'form.scantronformat_del'}) {
9719: $confhash{'scantron'}{'scantronformat'} = '';
9720: $changes{'scantronformat'} = 1;
1.46 raeburn 9721: }
9722: }
9723: }
9724: if (keys(%confhash) > 0) {
9725: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9726: $dom);
9727: if ($putresult eq 'ok') {
9728: if (keys(%changes) > 0) {
1.48 raeburn 9729: if (ref($confhash{'scantron'}) eq 'HASH') {
9730: $resulttext = &mt('Changes made:').'<ul>';
9731: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 9732: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 9733: } else {
1.130 raeburn 9734: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 9735: }
1.48 raeburn 9736: $resulttext .= '</ul>';
9737: } else {
1.130 raeburn 9738: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 9739: }
9740: $resulttext .= '</ul>';
9741: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9742: if (ref($lastactref) eq 'HASH') {
9743: $lastactref->{'domainconfig'} = 1;
9744: }
1.46 raeburn 9745: } else {
1.130 raeburn 9746: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9747: }
9748: } else {
9749: $resulttext = '<span class="LC_error">'.
9750: &mt('An error occurred: [_1]',$putresult).'</span>';
9751: }
9752: } else {
1.130 raeburn 9753: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9754: }
9755: if ($errors) {
9756: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9757: $errors.'</ul>';
9758: }
9759: return $resulttext;
9760: }
9761:
1.48 raeburn 9762: sub modify_coursecategories {
1.160.6.43 raeburn 9763: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 9764: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9765: $cathash);
1.48 raeburn 9766: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 9767: my @catitems = ('unauth','auth');
9768: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 9769: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 9770: $cathash = $domconfig{'coursecategories'}{'cats'};
9771: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9772: $changes{'togglecats'} = 1;
9773: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9774: }
9775: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9776: $changes{'categorize'} = 1;
9777: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9778: }
1.120 raeburn 9779: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9780: $changes{'togglecatscomm'} = 1;
9781: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9782: }
9783: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9784: $changes{'categorizecomm'} = 1;
9785: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9786: }
1.160.6.42 raeburn 9787: foreach my $item (@catitems) {
9788: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9789: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
9790: $changes{$item} = 1;
9791: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9792: }
9793: }
9794: }
1.57 raeburn 9795: } else {
9796: $changes{'togglecats'} = 1;
9797: $changes{'categorize'} = 1;
1.124 raeburn 9798: $changes{'togglecatscomm'} = 1;
9799: $changes{'categorizecomm'} = 1;
1.87 raeburn 9800: $domconfig{'coursecategories'} = {
9801: togglecats => $env{'form.togglecats'},
9802: categorize => $env{'form.categorize'},
1.124 raeburn 9803: togglecatscomm => $env{'form.togglecatscomm'},
9804: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 9805: };
1.160.6.42 raeburn 9806: foreach my $item (@catitems) {
9807: if ($env{'form.coursecat_'.$item} ne 'std') {
9808: $changes{$item} = 1;
9809: }
9810: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9811: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9812: }
9813: }
1.57 raeburn 9814: }
9815: if (ref($cathash) eq 'HASH') {
9816: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 9817: push (@deletecategory,'instcode::0');
9818: }
1.120 raeburn 9819: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9820: push(@deletecategory,'communities::0');
9821: }
1.48 raeburn 9822: }
1.57 raeburn 9823: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9824: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9825: if (@deletecategory > 0) {
9826: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 9827: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 9828: foreach my $item (@deletecategory) {
1.57 raeburn 9829: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9830: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 9831: $deletions{$item} = 1;
1.57 raeburn 9832: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 9833: }
9834: }
9835: }
1.57 raeburn 9836: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 9837: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 9838: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 9839: $reorderings{$item} = 1;
1.57 raeburn 9840: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 9841: }
9842: if ($env{'form.addcategory_name_'.$item} ne '') {
9843: my $newcat = $env{'form.addcategory_name_'.$item};
9844: my $newdepth = $depth+1;
9845: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9846: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 9847: $adds{$newitem} = 1;
9848: }
9849: if ($env{'form.subcat_'.$item} ne '') {
9850: my $newcat = $env{'form.subcat_'.$item};
9851: my $newdepth = $depth+1;
9852: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9853: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 9854: $adds{$newitem} = 1;
9855: }
9856: }
9857: }
9858: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 9859: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9860: my $newitem = 'instcode::0';
1.57 raeburn 9861: if ($cathash->{$newitem} eq '') {
9862: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9863: $adds{$newitem} = 1;
9864: }
9865: } else {
9866: my $newitem = 'instcode::0';
1.57 raeburn 9867: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9868: $adds{$newitem} = 1;
9869: }
9870: }
1.120 raeburn 9871: if ($env{'form.communities'} eq '1') {
9872: if (ref($cathash) eq 'HASH') {
9873: my $newitem = 'communities::0';
9874: if ($cathash->{$newitem} eq '') {
9875: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9876: $adds{$newitem} = 1;
9877: }
9878: } else {
9879: my $newitem = 'communities::0';
9880: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9881: $adds{$newitem} = 1;
9882: }
9883: }
1.48 raeburn 9884: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 9885: if (($env{'form.addcategory_name'} ne 'instcode') &&
9886: ($env{'form.addcategory_name'} ne 'communities')) {
9887: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9888: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9889: $adds{$newitem} = 1;
9890: }
1.48 raeburn 9891: }
1.57 raeburn 9892: my $putresult;
1.48 raeburn 9893: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9894: if (keys(%deletions) > 0) {
9895: foreach my $key (keys(%deletions)) {
9896: if ($predelallitems{$key} ne '') {
9897: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9898: }
9899: }
9900: }
9901: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 9902: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 9903: if (ref($chkcats[0]) eq 'ARRAY') {
9904: my $depth = 0;
9905: my $chg = 0;
9906: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9907: my $name = $chkcats[0][$i];
9908: my $item;
9909: if ($name eq '') {
9910: $chg ++;
9911: } else {
9912: $item = &escape($name).'::0';
9913: if ($chg) {
1.57 raeburn 9914: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 9915: }
9916: $depth ++;
1.57 raeburn 9917: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 9918: $depth --;
9919: }
9920: }
9921: }
1.57 raeburn 9922: }
9923: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9924: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 9925: if ($putresult eq 'ok') {
1.57 raeburn 9926: my %title = (
1.120 raeburn 9927: togglecats => 'Show/Hide a course in catalog',
9928: categorize => 'Assign a category to a course',
9929: togglecatscomm => 'Show/Hide a community in catalog',
9930: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9931: );
9932: my %level = (
1.120 raeburn 9933: dom => 'set in Domain ("Modify Course/Community")',
9934: crs => 'set in Course ("Course Configuration")',
9935: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 9936: none => 'No catalog',
9937: std => 'Standard catalog',
9938: domonly => 'Domain-only catalog',
9939: codesrch => 'Code search form',
1.57 raeburn 9940: );
1.48 raeburn 9941: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 9942: if ($changes{'togglecats'}) {
9943: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9944: }
9945: if ($changes{'categorize'}) {
9946: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 9947: }
1.120 raeburn 9948: if ($changes{'togglecatscomm'}) {
9949: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9950: }
9951: if ($changes{'categorizecomm'}) {
9952: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9953: }
1.160.6.42 raeburn 9954: if ($changes{'unauth'}) {
9955: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
9956: }
9957: if ($changes{'auth'}) {
9958: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
9959: }
1.57 raeburn 9960: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9961: my $cathash;
9962: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9963: $cathash = $domconfig{'coursecategories'}{'cats'};
9964: } else {
9965: $cathash = {};
9966: }
9967: my (@cats,@trails,%allitems);
9968: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
9969: if (keys(%deletions) > 0) {
9970: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
9971: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
9972: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
9973: }
9974: $resulttext .= '</ul></li>';
9975: }
9976: if (keys(%reorderings) > 0) {
9977: my %sort_by_trail;
9978: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
9979: foreach my $key (keys(%reorderings)) {
9980: if ($allitems{$key} ne '') {
9981: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9982: }
1.48 raeburn 9983: }
1.57 raeburn 9984: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9985: $resulttext .= '<li>'.$trails[$trail].'</li>';
9986: }
9987: $resulttext .= '</ul></li>';
1.48 raeburn 9988: }
1.57 raeburn 9989: if (keys(%adds) > 0) {
9990: my %sort_by_trail;
9991: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
9992: foreach my $key (keys(%adds)) {
9993: if ($allitems{$key} ne '') {
9994: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9995: }
9996: }
9997: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9998: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 9999: }
1.57 raeburn 10000: $resulttext .= '</ul></li>';
1.48 raeburn 10001: }
10002: }
10003: $resulttext .= '</ul>';
1.160.6.43 raeburn 10004: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 10005: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10006: if ($changes{'auth'}) {
10007: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
10008: }
10009: if ($changes{'unauth'}) {
10010: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
10011: }
10012: my $cachetime = 24*60*60;
10013: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 10014: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 10015: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 10016: }
10017: }
1.48 raeburn 10018: } else {
10019: $resulttext = '<span class="LC_error">'.
1.57 raeburn 10020: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 10021: }
10022: } else {
1.120 raeburn 10023: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 10024: }
10025: return $resulttext;
10026: }
10027:
1.69 raeburn 10028: sub modify_serverstatuses {
10029: my ($dom,%domconfig) = @_;
10030: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
10031: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
10032: %currserverstatus = %{$domconfig{'serverstatuses'}};
10033: }
10034: my @pages = &serverstatus_pages();
10035: foreach my $type (@pages) {
10036: $newserverstatus{$type}{'namedusers'} = '';
10037: $newserverstatus{$type}{'machines'} = '';
10038: if (defined($env{'form.'.$type.'_namedusers'})) {
10039: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
10040: my @okusers;
10041: foreach my $user (@users) {
10042: my ($uname,$udom) = split(/:/,$user);
10043: if (($udom =~ /^$match_domain$/) &&
10044: (&Apache::lonnet::domain($udom)) &&
10045: ($uname =~ /^$match_username$/)) {
10046: if (!grep(/^\Q$user\E/,@okusers)) {
10047: push(@okusers,$user);
10048: }
10049: }
10050: }
10051: if (@okusers > 0) {
10052: @okusers = sort(@okusers);
10053: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
10054: }
10055: }
10056: if (defined($env{'form.'.$type.'_machines'})) {
10057: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
10058: my @okmachines;
10059: foreach my $ip (@machines) {
10060: my @parts = split(/\./,$ip);
10061: next if (@parts < 4);
10062: my $badip = 0;
10063: for (my $i=0; $i<4; $i++) {
10064: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
10065: $badip = 1;
10066: last;
10067: }
10068: }
10069: if (!$badip) {
10070: push(@okmachines,$ip);
10071: }
10072: }
10073: @okmachines = sort(@okmachines);
10074: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
10075: }
10076: }
10077: my %serverstatushash = (
10078: serverstatuses => \%newserverstatus,
10079: );
10080: foreach my $type (@pages) {
1.83 raeburn 10081: foreach my $setting ('namedusers','machines') {
1.84 raeburn 10082: my (@current,@new);
1.83 raeburn 10083: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 10084: if ($currserverstatus{$type}{$setting} ne '') {
10085: @current = split(/,/,$currserverstatus{$type}{$setting});
10086: }
10087: }
10088: if ($newserverstatus{$type}{$setting} ne '') {
10089: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 10090: }
10091: if (@current > 0) {
10092: if (@new > 0) {
10093: foreach my $item (@current) {
10094: if (!grep(/^\Q$item\E$/,@new)) {
10095: $changes{$type}{$setting} = 1;
1.82 raeburn 10096: last;
10097: }
10098: }
1.84 raeburn 10099: foreach my $item (@new) {
10100: if (!grep(/^\Q$item\E$/,@current)) {
10101: $changes{$type}{$setting} = 1;
10102: last;
1.82 raeburn 10103: }
10104: }
10105: } else {
1.83 raeburn 10106: $changes{$type}{$setting} = 1;
1.69 raeburn 10107: }
1.83 raeburn 10108: } elsif (@new > 0) {
10109: $changes{$type}{$setting} = 1;
1.69 raeburn 10110: }
10111: }
10112: }
10113: if (keys(%changes) > 0) {
1.81 raeburn 10114: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10115: my $putresult = &Apache::lonnet::put_dom('configuration',
10116: \%serverstatushash,$dom);
10117: if ($putresult eq 'ok') {
10118: $resulttext .= &mt('Changes made:').'<ul>';
10119: foreach my $type (@pages) {
1.84 raeburn 10120: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 10121: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 10122: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 10123: if ($newserverstatus{$type}{'namedusers'} eq '') {
10124: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
10125: } else {
10126: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
10127: }
1.84 raeburn 10128: }
10129: if ($changes{$type}{'machines'}) {
1.69 raeburn 10130: if ($newserverstatus{$type}{'machines'} eq '') {
10131: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
10132: } else {
10133: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
10134: }
10135:
10136: }
10137: $resulttext .= '</ul></li>';
10138: }
10139: }
10140: $resulttext .= '</ul>';
10141: } else {
10142: $resulttext = '<span class="LC_error">'.
10143: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
10144:
10145: }
10146: } else {
10147: $resulttext = &mt('No changes made to access to server status pages');
10148: }
10149: return $resulttext;
10150: }
10151:
1.118 jms 10152: sub modify_helpsettings {
1.122 jms 10153: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 10154: my ($resulttext,$errors,%changes,%helphash);
10155: my %defaultchecked = ('submitbugs' => 'on');
10156: my @offon = ('off','on');
1.118 jms 10157: my @toggles = ('submitbugs');
10158: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
10159: foreach my $item (@toggles) {
1.160.6.5 raeburn 10160: if ($defaultchecked{$item} eq 'on') {
10161: if ($domconfig{'helpsettings'}{$item} eq '') {
10162: if ($env{'form.'.$item} eq '0') {
10163: $changes{$item} = 1;
10164: }
10165: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10166: $changes{$item} = 1;
10167: }
10168: } elsif ($defaultchecked{$item} eq 'off') {
10169: if ($domconfig{'helpsettings'}{$item} eq '') {
10170: if ($env{'form.'.$item} eq '1') {
10171: $changes{$item} = 1;
10172: }
10173: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10174: $changes{$item} = 1;
10175: }
1.160.6.26 raeburn 10176: }
1.160.6.5 raeburn 10177: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
10178: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 10179: }
10180: }
1.118 jms 10181: }
1.123 jms 10182: my $putresult;
10183: if (keys(%changes) > 0) {
1.160.6.5 raeburn 10184: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
10185: if ($putresult eq 'ok') {
10186: $resulttext = &mt('Changes made:').'<ul>';
10187: foreach my $item (sort(keys(%changes))) {
10188: if ($item eq 'submitbugs') {
10189: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
10190: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
10191: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
10192: }
10193: }
10194: $resulttext .= '</ul>';
10195: } else {
10196: $resulttext = &mt('No changes made to help settings');
10197: $errors .= '<li><span class="LC_error">'.
10198: &mt('An error occurred storing the settings: [_1]',
10199: $putresult).'</span></li>';
10200: }
1.118 jms 10201: }
10202: if ($errors) {
1.160.6.5 raeburn 10203: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 10204: $errors.'</ul>';
10205: }
10206: return $resulttext;
10207: }
10208:
1.121 raeburn 10209: sub modify_coursedefaults {
1.160.6.27 raeburn 10210: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 10211: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57! raeburn 10212: my %defaultchecked = (
! 10213: 'uselcmath' => 'on',
! 10214: 'usejsme' => 'on'
! 10215: );
! 10216: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 10217: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.30 raeburn 10218: 'uploadquota_community','uploadquota_textbook');
10219: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 10220: my %staticdefaults = (
10221: anonsurvey_threshold => 10,
10222: uploadquota => 500,
1.160.6.57! raeburn 10223: postsubmit => 60,
1.160.6.21 raeburn 10224: );
1.121 raeburn 10225:
10226: $defaultshash{'coursedefaults'} = {};
10227:
10228: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
10229: if ($domconfig{'coursedefaults'} eq '') {
10230: $domconfig{'coursedefaults'} = {};
10231: }
10232: }
10233:
10234: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
10235: foreach my $item (@toggles) {
10236: if ($defaultchecked{$item} eq 'on') {
10237: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10238: ($env{'form.'.$item} eq '0')) {
10239: $changes{$item} = 1;
1.160.6.16 raeburn 10240: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 10241: $changes{$item} = 1;
10242: }
10243: } elsif ($defaultchecked{$item} eq 'off') {
10244: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10245: ($env{'form.'.$item} eq '1')) {
10246: $changes{$item} = 1;
10247: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10248: $changes{$item} = 1;
10249: }
10250: }
10251: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
10252: }
1.160.6.21 raeburn 10253: foreach my $item (@numbers) {
10254: my ($currdef,$newdef);
1.160.6.26 raeburn 10255: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 10256: if ($item eq 'anonsurvey_threshold') {
10257: $currdef = $domconfig{'coursedefaults'}{$item};
10258: $newdef =~ s/\D//g;
10259: if ($newdef eq '' || $newdef < 1) {
10260: $newdef = 1;
10261: }
10262: $defaultshash{'coursedefaults'}{$item} = $newdef;
10263: } else {
10264: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
10265: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10266: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
10267: }
10268: $newdef =~ s/[^\w.\-]//g;
10269: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
10270: }
10271: if ($currdef ne $newdef) {
10272: my $staticdef;
10273: if ($item eq 'anonsurvey_threshold') {
10274: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10275: $changes{$item} = 1;
10276: }
10277: } else {
10278: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
10279: $changes{'uploadquota'} = 1;
10280: }
10281: }
1.139 raeburn 10282: }
10283: }
1.160.6.37 raeburn 10284:
1.160.6.57! raeburn 10285: my %credits;
! 10286: foreach my $type (@types) {
! 10287: unless ($type eq 'community') {
! 10288: $credits{$type} = $env{'form.'.$type.'_credits'};
! 10289: $credits{$type} =~ s/[^\d.]+//g;
! 10290: }
! 10291: }
! 10292: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
! 10293: ($env{'form.coursecredits'} eq '1')) {
! 10294: $changes{'coursecredits'} = 1;
! 10295: foreach my $type (keys(%credits)) {
! 10296: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
! 10297: }
! 10298: } else {
! 10299: if ($env{'form.coursecredits'} eq '1') {
! 10300: foreach my $type (@types) {
! 10301: unless ($type eq 'community') {
! 10302: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
! 10303: $changes{'coursecredits'} = 1;
! 10304: }
! 10305: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
! 10306: }
! 10307: }
! 10308: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
! 10309: foreach my $type (@types) {
! 10310: unless ($type eq 'community') {
! 10311: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
! 10312: $changes{'coursecredits'} = 1;
! 10313: last;
! 10314: }
! 10315: }
! 10316: }
! 10317: }
! 10318: }
! 10319: if ($env{'form.postsubmit'} eq '1') {
! 10320: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
! 10321: my %currtimeout;
! 10322: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
! 10323: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
! 10324: $changes{'postsubmit'} = 1;
! 10325: }
! 10326: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
! 10327: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
! 10328: }
! 10329: } else {
! 10330: $changes{'postsubmit'} = 1;
! 10331: }
! 10332: foreach my $type (@types) {
! 10333: my $timeout = $env{'form.'.$type.'_timeout'};
! 10334: $timeout =~ s/\D//g;
! 10335: if ($timeout == $staticdefaults{'postsubmit'}) {
! 10336: $timeout = '';
! 10337: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
! 10338: $timeout = '0';
! 10339: }
! 10340: unless ($timeout eq '') {
! 10341: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
! 10342: }
! 10343: if (exists($currtimeout{$type})) {
! 10344: if ($timeout ne $currtimeout{$type}) {
! 10345: $changes{'postsubmit'} = 1;
! 10346: }
! 10347: } elsif ($timeout ne '') {
! 10348: $changes{'postsubmit'} = 1;
! 10349: }
! 10350: }
! 10351: } else {
! 10352: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
! 10353: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
! 10354: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
! 10355: $changes{'postsubmit'} = 1;
! 10356: }
! 10357: } else {
! 10358: $changes{'postsubmit'} = 1;
! 10359: }
1.160.6.16 raeburn 10360: }
1.121 raeburn 10361: }
10362: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10363: $dom);
10364: if ($putresult eq 'ok') {
10365: if (keys(%changes) > 0) {
1.160.6.27 raeburn 10366: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57! raeburn 10367: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
! 10368: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'})) {
! 10369: foreach my $item ('uselcmath','usejsme') {
! 10370: if ($changes{$item}) {
! 10371: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
! 10372: }
1.160.6.16 raeburn 10373: }
10374: if ($changes{'coursecredits'}) {
10375: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57! raeburn 10376: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
! 10377: $domdefaults{$type.'credits'} =
! 10378: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
! 10379: }
! 10380: }
! 10381: }
! 10382: if ($changes{'postsubmit'}) {
! 10383: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
! 10384: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
! 10385: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
! 10386: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
! 10387: $domdefaults{$type.'postsubtimeout'} =
! 10388: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
! 10389: }
! 10390: }
1.160.6.16 raeburn 10391: }
10392: }
1.160.6.21 raeburn 10393: if ($changes{'uploadquota'}) {
10394: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10395: foreach my $type (@types) {
10396: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10397: }
10398: }
10399: }
1.121 raeburn 10400: my $cachetime = 24*60*60;
10401: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10402: if (ref($lastactref) eq 'HASH') {
10403: $lastactref->{'domdefaults'} = 1;
10404: }
1.121 raeburn 10405: }
10406: $resulttext = &mt('Changes made:').'<ul>';
10407: foreach my $item (sort(keys(%changes))) {
1.160.6.57! raeburn 10408: if ($item eq 'uselcmath') {
1.121 raeburn 10409: if ($env{'form.'.$item} eq '1') {
1.160.6.57! raeburn 10410: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 10411: } else {
1.160.6.57! raeburn 10412: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
! 10413: }
! 10414: } elsif ($item eq 'usejsme') {
! 10415: if ($env{'form.'.$item} eq '1') {
! 10416: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
! 10417: } else {
! 10418: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 10419: }
1.139 raeburn 10420: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 10421: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.160.6.21 raeburn 10422: } elsif ($item eq 'uploadquota') {
10423: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10424: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10425: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10426: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 10427: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10428:
1.160.6.21 raeburn 10429: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10430: '</ul>'.
10431: '</li>';
10432: } else {
10433: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10434: }
1.160.6.57! raeburn 10435: } elsif ($item eq 'postsubmit') {
! 10436: if ($domdefaults{'postsubmit'} eq 'off') {
! 10437: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
! 10438: } else {
! 10439: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
! 10440: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
! 10441: $resulttext .= &mt('durations:').'<ul>';
! 10442: foreach my $type (@types) {
! 10443: $resulttext .= '<li>';
! 10444: my $timeout;
! 10445: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
! 10446: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
! 10447: }
! 10448: my $display;
! 10449: if ($timeout eq '0') {
! 10450: $display = &mt('unlimited');
! 10451: } elsif ($timeout eq '') {
! 10452: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
! 10453: } else {
! 10454: $display = &mt('[quant,_1,second]',$timeout);
! 10455: }
! 10456: if ($type eq 'community') {
! 10457: $resulttext .= &mt('Communities');
! 10458: } elsif ($type eq 'official') {
! 10459: $resulttext .= &mt('Official courses');
! 10460: } elsif ($type eq 'unofficial') {
! 10461: $resulttext .= &mt('Unofficial courses');
! 10462: } elsif ($type eq 'textbook') {
! 10463: $resulttext .= &mt('Textbook courses');
! 10464: }
! 10465: $resulttext .= ' -- '.$display.'</li>';
! 10466: }
! 10467: $resulttext .= '</ul>';
! 10468: }
! 10469: $resulttext .= '</li>';
! 10470: }
1.160.6.16 raeburn 10471: } elsif ($item eq 'coursecredits') {
10472: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10473: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 10474: ($domdefaults{'unofficialcredits'} eq '') &&
10475: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 10476: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10477: } else {
10478: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10479: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10480: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 10481: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 10482: '</ul>'.
10483: '</li>';
10484: }
10485: } else {
10486: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10487: }
1.140 raeburn 10488: }
1.121 raeburn 10489: }
10490: $resulttext .= '</ul>';
10491: } else {
10492: $resulttext = &mt('No changes made to course defaults');
10493: }
10494: } else {
10495: $resulttext = '<span class="LC_error">'.
10496: &mt('An error occurred: [_1]',$putresult).'</span>';
10497: }
10498: return $resulttext;
10499: }
10500:
1.160.6.37 raeburn 10501: sub modify_selfenrollment {
10502: my ($dom,$lastactref,%domconfig) = @_;
10503: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10504: my @types = ('official','unofficial','community','textbook');
10505: my %titles = &tool_titles();
10506: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10507: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
10508: $ordered{'default'} = ['types','registered','approval','limit'];
10509:
10510: my (%roles,%shown,%toplevel);
10511: $roles{'0'} = &Apache::lonnet::plaintext('dc');
10512:
10513: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10514: if ($domconfig{'selfenrollment'} eq '') {
10515: $domconfig{'selfenrollment'} = {};
10516: }
10517: }
10518: %toplevel = (
10519: admin => 'Configuration Rights',
10520: default => 'Default settings',
10521: validation => 'Validation of self-enrollment requests',
10522: );
10523: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
10524:
10525: if (ref($ordered{'admin'}) eq 'ARRAY') {
10526: foreach my $item (@{$ordered{'admin'}}) {
10527: foreach my $type (@types) {
10528: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10529: $selfenrollhash{'admin'}{$type}{$item} = 1;
10530: } else {
10531: $selfenrollhash{'admin'}{$type}{$item} = 0;
10532: }
10533: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10534: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10535: if ($selfenrollhash{'admin'}{$type}{$item} ne
10536: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10537: push(@{$changes{'admin'}{$type}},$item);
10538: }
10539: } else {
10540: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10541: push(@{$changes{'admin'}{$type}},$item);
10542: }
10543: }
10544: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10545: push(@{$changes{'admin'}{$type}},$item);
10546: }
10547: }
10548: }
10549: }
10550:
10551: foreach my $item (@{$ordered{'default'}}) {
10552: foreach my $type (@types) {
10553: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10554: if ($item eq 'types') {
10555: unless (($value eq 'all') || ($value eq 'dom')) {
10556: $value = '';
10557: }
10558: } elsif ($item eq 'registered') {
10559: unless ($value eq '1') {
10560: $value = 0;
10561: }
10562: } elsif ($item eq 'approval') {
10563: unless ($value =~ /^[012]$/) {
10564: $value = 0;
10565: }
10566: } else {
10567: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10568: $value = 'none';
10569: }
10570: }
10571: $selfenrollhash{'default'}{$type}{$item} = $value;
10572: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10573: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10574: if ($selfenrollhash{'default'}{$type}{$item} ne
10575: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10576: push(@{$changes{'default'}{$type}},$item);
10577: }
10578: } else {
10579: push(@{$changes{'default'}{$type}},$item);
10580: }
10581: } else {
10582: push(@{$changes{'default'}{$type}},$item);
10583: }
10584: if ($item eq 'limit') {
10585: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10586: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10587: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10588: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10589: }
10590: } else {
10591: $selfenrollhash{'default'}{$type}{'cap'} = '';
10592: }
10593: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10594: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10595: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10596: push(@{$changes{'default'}{$type}},'cap');
10597: }
10598: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10599: push(@{$changes{'default'}{$type}},'cap');
10600: }
10601: }
10602: }
10603: }
10604:
10605: foreach my $item (@{$itemsref}) {
10606: if ($item eq 'fields') {
10607: my @changed;
10608: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10609: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10610: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10611: }
10612: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10613: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10614: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10615: $domconfig{'selfenrollment'}{'validation'}{$item});
10616: } else {
10617: @changed = @{$selfenrollhash{'validation'}{$item}};
10618: }
10619: } else {
10620: @changed = @{$selfenrollhash{'validation'}{$item}};
10621: }
10622: if (@changed) {
10623: if ($selfenrollhash{'validation'}{$item}) {
10624: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10625: } else {
10626: $changes{'validation'}{$item} = &mt('None');
10627: }
10628: }
10629: } else {
10630: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10631: if ($item eq 'markup') {
10632: if ($env{'form.selfenroll_validation_'.$item}) {
10633: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10634: }
10635: }
10636: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10637: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10638: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10639: }
10640: }
10641: }
10642: }
10643:
10644: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10645: $dom);
10646: if ($putresult eq 'ok') {
10647: if (keys(%changes) > 0) {
10648: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10649: $resulttext = &mt('Changes made:').'<ul>';
10650: foreach my $key ('admin','default','validation') {
10651: if (ref($changes{$key}) eq 'HASH') {
10652: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10653: if ($key eq 'validation') {
10654: foreach my $item (@{$itemsref}) {
10655: if (exists($changes{$key}{$item})) {
10656: if ($item eq 'markup') {
10657: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10658: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10659: } else {
10660: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10661: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10662: }
10663: }
10664: }
10665: } else {
10666: foreach my $type (@types) {
10667: if ($type eq 'community') {
10668: $roles{'1'} = &mt('Community personnel');
10669: } else {
10670: $roles{'1'} = &mt('Course personnel');
10671: }
10672: if (ref($changes{$key}{$type}) eq 'ARRAY') {
10673: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10674: if ($key eq 'admin') {
10675: my @mgrdc = ();
10676: if (ref($ordered{$key}) eq 'ARRAY') {
10677: foreach my $item (@{$ordered{'admin'}}) {
10678: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10679: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10680: push(@mgrdc,$item);
10681: }
10682: }
10683: }
10684: if (@mgrdc) {
10685: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10686: } else {
10687: delete($domdefaults{$type.'selfenrolladmdc'});
10688: }
10689: }
10690: } else {
10691: if (ref($ordered{$key}) eq 'ARRAY') {
10692: foreach my $item (@{$ordered{$key}}) {
10693: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10694: $domdefaults{$type.'selfenroll'.$item} =
10695: $selfenrollhash{$key}{$type}{$item};
10696: }
10697: }
10698: }
10699: }
10700: }
10701: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10702: foreach my $item (@{$ordered{$key}}) {
10703: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10704: $resulttext .= '<li>';
10705: if ($key eq 'admin') {
10706: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10707: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10708: } else {
10709: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10710: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10711: }
10712: $resulttext .= '</li>';
10713: }
10714: }
10715: $resulttext .= '</ul></li>';
10716: }
10717: }
10718: $resulttext .= '</ul></li>';
10719: }
10720: }
10721: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10722: my $cachetime = 24*60*60;
10723: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10724: if (ref($lastactref) eq 'HASH') {
10725: $lastactref->{'domdefaults'} = 1;
10726: }
10727: }
10728: }
10729: $resulttext .= '</ul>';
10730: } else {
10731: $resulttext = &mt('No changes made to self-enrollment settings');
10732: }
10733: } else {
10734: $resulttext = '<span class="LC_error">'.
10735: &mt('An error occurred: [_1]',$putresult).'</span>';
10736: }
10737: return $resulttext;
10738: }
10739:
1.137 raeburn 10740: sub modify_usersessions {
1.160.6.27 raeburn 10741: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 10742: my @hostingtypes = ('version','excludedomain','includedomain');
10743: my @offloadtypes = ('primary','default');
10744: my %types = (
10745: remote => \@hostingtypes,
10746: hosted => \@hostingtypes,
10747: spares => \@offloadtypes,
10748: );
10749: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 10750: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 10751: my (%by_ip,%by_location,@intdoms);
10752: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10753: my @locations = sort(keys(%by_location));
1.137 raeburn 10754: my (%defaultshash,%changes);
10755: foreach my $prefix (@prefixes) {
10756: $defaultshash{'usersessions'}{$prefix} = {};
10757: }
1.160.6.27 raeburn 10758: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 10759: my $resulttext;
1.138 raeburn 10760: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 10761: foreach my $prefix (@prefixes) {
1.145 raeburn 10762: next if ($prefix eq 'spares');
10763: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 10764: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10765: if ($type eq 'version') {
10766: my $value = $env{'form.'.$prefix.'_'.$type};
10767: my $okvalue;
10768: if ($value ne '') {
10769: if (grep(/^\Q$value\E$/,@lcversions)) {
10770: $okvalue = $value;
10771: }
10772: }
10773: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10774: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10775: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10776: if ($inuse == 0) {
10777: $changes{$prefix}{$type} = 1;
10778: } else {
10779: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10780: $changes{$prefix}{$type} = 1;
10781: }
10782: if ($okvalue ne '') {
10783: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10784: }
10785: }
10786: } else {
10787: if (($inuse == 1) && ($okvalue ne '')) {
10788: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10789: $changes{$prefix}{$type} = 1;
10790: }
10791: }
10792: } else {
10793: if (($inuse == 1) && ($okvalue ne '')) {
10794: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10795: $changes{$prefix}{$type} = 1;
10796: }
10797: }
10798: } else {
10799: if (($inuse == 1) && ($okvalue ne '')) {
10800: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10801: $changes{$prefix}{$type} = 1;
10802: }
10803: }
10804: } else {
10805: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10806: my @okvals;
10807: foreach my $val (@vals) {
1.138 raeburn 10808: if ($val =~ /:/) {
10809: my @items = split(/:/,$val);
10810: foreach my $item (@items) {
10811: if (ref($by_location{$item}) eq 'ARRAY') {
10812: push(@okvals,$item);
10813: }
10814: }
10815: } else {
10816: if (ref($by_location{$val}) eq 'ARRAY') {
10817: push(@okvals,$val);
10818: }
1.137 raeburn 10819: }
10820: }
10821: @okvals = sort(@okvals);
10822: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10823: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10824: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10825: if ($inuse == 0) {
10826: $changes{$prefix}{$type} = 1;
10827: } else {
10828: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10829: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10830: if (@changed > 0) {
10831: $changes{$prefix}{$type} = 1;
10832: }
10833: }
10834: } else {
10835: if ($inuse == 1) {
10836: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10837: $changes{$prefix}{$type} = 1;
10838: }
10839: }
10840: } else {
10841: if ($inuse == 1) {
10842: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10843: $changes{$prefix}{$type} = 1;
10844: }
10845: }
10846: } else {
10847: if ($inuse == 1) {
10848: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10849: $changes{$prefix}{$type} = 1;
10850: }
10851: }
10852: }
10853: }
10854: }
1.145 raeburn 10855:
10856: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 10857: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 10858: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10859: my $savespares;
10860:
10861: foreach my $lonhost (sort(keys(%servers))) {
10862: my $serverhomeID =
10863: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 10864: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 10865: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10866: my %spareschg;
10867: foreach my $type (@{$types{'spares'}}) {
10868: my @okspares;
10869: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10870: foreach my $server (@checked) {
1.152 raeburn 10871: if (&Apache::lonnet::hostname($server) ne '') {
10872: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10873: unless (grep(/^\Q$server\E$/,@okspares)) {
10874: push(@okspares,$server);
10875: }
1.145 raeburn 10876: }
10877: }
10878: }
10879: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10880: my $newspare;
1.152 raeburn 10881: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10882: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 10883: $newspare = $new;
10884: }
10885: }
1.152 raeburn 10886: my @spares;
10887: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10888: @spares = sort(@okspares,$newspare);
10889: } else {
10890: @spares = sort(@okspares);
10891: }
10892: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 10893: if (ref($spareid{$lonhost}) eq 'HASH') {
10894: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 10895: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 10896: if (@diffs > 0) {
10897: $spareschg{$type} = 1;
10898: }
10899: }
10900: }
10901: }
10902: if (keys(%spareschg) > 0) {
10903: $changes{'spares'}{$lonhost} = \%spareschg;
10904: }
10905: }
10906:
10907: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10908: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10909: if (ref($changes{'spares'}) eq 'HASH') {
10910: if (keys(%{$changes{'spares'}}) > 0) {
10911: $savespares = 1;
10912: }
10913: }
10914: } else {
10915: $savespares = 1;
10916: }
10917: }
10918:
1.147 raeburn 10919: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10920: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 10921: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10922: $dom);
10923: if ($putresult eq 'ok') {
10924: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10925: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
10926: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
10927: }
10928: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
10929: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
10930: }
10931: }
10932: my $cachetime = 24*60*60;
10933: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10934: if (ref($lastactref) eq 'HASH') {
10935: $lastactref->{'domdefaults'} = 1;
10936: }
1.147 raeburn 10937: if (keys(%changes) > 0) {
10938: my %lt = &usersession_titles();
10939: $resulttext = &mt('Changes made:').'<ul>';
10940: foreach my $prefix (@prefixes) {
10941: if (ref($changes{$prefix}) eq 'HASH') {
10942: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
10943: if ($prefix eq 'spares') {
10944: if (ref($changes{$prefix}) eq 'HASH') {
10945: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
10946: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 10947: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 10948: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
10949: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 10950: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
10951: foreach my $type (@{$types{$prefix}}) {
10952: if ($changes{$prefix}{$lonhost}{$type}) {
10953: my $offloadto = &mt('None');
10954: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
10955: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
10956: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
10957: }
1.145 raeburn 10958: }
1.147 raeburn 10959: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 10960: }
1.137 raeburn 10961: }
10962: }
1.147 raeburn 10963: $resulttext .= '</li>';
1.137 raeburn 10964: }
10965: }
1.147 raeburn 10966: } else {
10967: foreach my $type (@{$types{$prefix}}) {
10968: if (defined($changes{$prefix}{$type})) {
10969: my $newvalue;
10970: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10971: if (ref($defaultshash{'usersessions'}{$prefix})) {
10972: if ($type eq 'version') {
10973: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
10974: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10975: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
10976: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
10977: }
1.145 raeburn 10978: }
10979: }
10980: }
1.147 raeburn 10981: if ($newvalue eq '') {
10982: if ($type eq 'version') {
10983: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
10984: } else {
10985: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
10986: }
1.145 raeburn 10987: } else {
1.147 raeburn 10988: if ($type eq 'version') {
10989: $newvalue .= ' '.&mt('(or later)');
10990: }
10991: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 10992: }
1.137 raeburn 10993: }
10994: }
10995: }
1.147 raeburn 10996: $resulttext .= '</ul>';
1.137 raeburn 10997: }
10998: }
1.147 raeburn 10999: $resulttext .= '</ul>';
11000: } else {
11001: $resulttext = $nochgmsg;
1.137 raeburn 11002: }
11003: } else {
11004: $resulttext = '<span class="LC_error">'.
11005: &mt('An error occurred: [_1]',$putresult).'</span>';
11006: }
11007: } else {
1.147 raeburn 11008: $resulttext = $nochgmsg;
1.137 raeburn 11009: }
11010: return $resulttext;
11011: }
11012:
1.150 raeburn 11013: sub modify_loadbalancing {
11014: my ($dom,%domconfig) = @_;
11015: my $primary_id = &Apache::lonnet::domain($dom,'primary');
11016: my $intdom = &Apache::lonnet::internet_dom($primary_id);
11017: my ($othertitle,$usertypes,$types) =
11018: &Apache::loncommon::sorted_inst_types($dom);
11019: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 11020: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 11021: my @sparestypes = ('primary','default');
11022: my %typetitles = &sparestype_titles();
11023: my $resulttext;
1.160.6.7 raeburn 11024: my (%currbalancer,%currtargets,%currrules,%existing);
11025: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11026: %existing = %{$domconfig{'loadbalancing'}};
11027: }
11028: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
11029: \%currtargets,\%currrules);
11030: my ($saveloadbalancing,%defaultshash,%changes);
11031: my ($alltypes,$othertypes,$titles) =
11032: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
11033: my %ruletitles = &offloadtype_text();
11034: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
11035: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
11036: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
11037: if ($balancer eq '') {
11038: next;
11039: }
11040: if (!exists($servers{$balancer})) {
11041: if (exists($currbalancer{$balancer})) {
11042: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 11043: }
1.160.6.7 raeburn 11044: next;
11045: }
11046: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
11047: push(@{$changes{'delete'}},$balancer);
11048: next;
11049: }
11050: if (!exists($currbalancer{$balancer})) {
11051: push(@{$changes{'add'}},$balancer);
11052: }
11053: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
11054: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
11055: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
11056: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11057: $saveloadbalancing = 1;
11058: }
11059: foreach my $sparetype (@sparestypes) {
11060: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
11061: my @offloadto;
11062: foreach my $target (@targets) {
11063: if (($servers{$target}) && ($target ne $balancer)) {
11064: if ($sparetype eq 'default') {
11065: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
11066: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 11067: }
11068: }
1.160.6.7 raeburn 11069: unless(grep(/^\Q$target\E$/,@offloadto)) {
11070: push(@offloadto,$target);
11071: }
1.150 raeburn 11072: }
1.160.6.7 raeburn 11073: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 11074: }
11075: }
1.160.6.7 raeburn 11076: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 11077: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 11078: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
11079: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 11080: if (@targetdiffs > 0) {
1.160.6.7 raeburn 11081: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11082: }
1.160.6.7 raeburn 11083: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11084: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11085: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11086: }
11087: }
11088: }
11089: } else {
1.160.6.7 raeburn 11090: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
11091: foreach my $sparetype (@sparestypes) {
11092: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11093: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11094: $changes{'curr'}{$balancer}{'targets'} = 1;
11095: }
1.150 raeburn 11096: }
11097: }
1.160.6.7 raeburn 11098: }
1.150 raeburn 11099: }
11100: my $ishomedom;
1.160.6.7 raeburn 11101: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
11102: $ishomedom = 1;
1.150 raeburn 11103: }
11104: if (ref($alltypes) eq 'ARRAY') {
11105: foreach my $type (@{$alltypes}) {
11106: my $rule;
1.160.6.7 raeburn 11107: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 11108: (!$ishomedom)) {
1.160.6.7 raeburn 11109: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
11110: }
11111: if ($rule eq 'specific') {
1.160.6.55 raeburn 11112: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
11113: if (exists($servers{$specifiedhost})) {
11114: $rule = $specifiedhost;
11115: }
1.150 raeburn 11116: }
1.160.6.7 raeburn 11117: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
11118: if (ref($currrules{$balancer}) eq 'HASH') {
11119: if ($rule ne $currrules{$balancer}{$type}) {
11120: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11121: }
11122: } elsif ($rule ne '') {
1.160.6.7 raeburn 11123: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11124: }
11125: }
11126: }
1.160.6.7 raeburn 11127: }
11128: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
11129: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
11130: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
11131: $defaultshash{'loadbalancing'} = {};
11132: }
11133: my $putresult = &Apache::lonnet::put_dom('configuration',
11134: \%defaultshash,$dom);
11135: if ($putresult eq 'ok') {
11136: if (keys(%changes) > 0) {
1.160.6.54 raeburn 11137: my %toupdate;
1.160.6.7 raeburn 11138: if (ref($changes{'delete'}) eq 'ARRAY') {
11139: foreach my $balancer (sort(@{$changes{'delete'}})) {
11140: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 11141: $toupdate{$balancer} = 1;
1.150 raeburn 11142: }
1.160.6.7 raeburn 11143: }
11144: if (ref($changes{'add'}) eq 'ARRAY') {
11145: foreach my $balancer (sort(@{$changes{'add'}})) {
11146: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 11147: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 11148: }
11149: }
11150: if (ref($changes{'curr'}) eq 'HASH') {
11151: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 11152: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 11153: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
11154: if ($changes{'curr'}{$balancer}{'targets'}) {
11155: my %offloadstr;
11156: foreach my $sparetype (@sparestypes) {
11157: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11158: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11159: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11160: }
11161: }
1.150 raeburn 11162: }
1.160.6.7 raeburn 11163: if (keys(%offloadstr) == 0) {
11164: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 11165: } else {
1.160.6.7 raeburn 11166: my $showoffload;
11167: foreach my $sparetype (@sparestypes) {
11168: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
11169: if (defined($offloadstr{$sparetype})) {
11170: $showoffload .= $offloadstr{$sparetype};
11171: } else {
11172: $showoffload .= &mt('None');
11173: }
11174: $showoffload .= (' 'x3);
11175: }
11176: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 11177: }
11178: }
11179: }
1.160.6.7 raeburn 11180: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
11181: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
11182: foreach my $type (@{$alltypes}) {
11183: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
11184: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11185: my $balancetext;
11186: if ($rule eq '') {
11187: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 11188: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 11189: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
11190: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 11191: foreach my $sparetype (@sparestypes) {
11192: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11193: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11194: }
11195: }
1.160.6.55 raeburn 11196: foreach my $item (@{$alltypes}) {
11197: next if ($item =~ /^_LC_ipchange/);
11198: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
11199: if ($hasrule eq 'homeserver') {
11200: map { $toupdate{$_} = 1; } (keys(%libraryservers));
11201: } else {
11202: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
11203: if ($servers{$hasrule}) {
11204: $toupdate{$hasrule} = 1;
11205: }
11206: }
11207: }
11208: }
11209: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
11210: $balancetext = $ruletitles{$rule};
11211: } else {
11212: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11213: $balancetext = $ruletitles{'particular'}.' '.$receiver;
11214: if ($receiver) {
11215: $toupdate{$receiver};
11216: }
11217: }
11218: } else {
11219: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 11220: }
1.160.6.7 raeburn 11221: } else {
11222: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
11223: }
1.160.6.26 raeburn 11224: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 11225: }
11226: }
11227: }
11228: }
1.160.6.54 raeburn 11229: if (keys(%toupdate)) {
11230: my %thismachine;
11231: my $updatedhere;
11232: my $cachetime = 60*60*24;
11233: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
11234: foreach my $lonhost (keys(%toupdate)) {
11235: if ($thismachine{$lonhost}) {
11236: unless ($updatedhere) {
11237: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
11238: $defaultshash{'loadbalancing'},
11239: $cachetime);
11240: $updatedhere = 1;
11241: }
11242: } else {
11243: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
11244: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
11245: }
11246: }
11247: }
1.150 raeburn 11248: }
1.160.6.7 raeburn 11249: }
11250: if ($resulttext ne '') {
11251: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 11252: } else {
11253: $resulttext = $nochgmsg;
11254: }
11255: } else {
1.160.6.7 raeburn 11256: $resulttext = $nochgmsg;
1.150 raeburn 11257: }
11258: } else {
1.160.6.7 raeburn 11259: $resulttext = '<span class="LC_error">'.
11260: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 11261: }
11262: } else {
1.160.6.7 raeburn 11263: $resulttext = $nochgmsg;
1.150 raeburn 11264: }
11265: return $resulttext;
11266: }
11267:
1.48 raeburn 11268: sub recurse_check {
11269: my ($chkcats,$categories,$depth,$name) = @_;
11270: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
11271: my $chg = 0;
11272: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
11273: my $category = $chkcats->[$depth]{$name}[$j];
11274: my $item;
11275: if ($category eq '') {
11276: $chg ++;
11277: } else {
11278: my $deeper = $depth + 1;
11279: $item = &escape($category).':'.&escape($name).':'.$depth;
11280: if ($chg) {
11281: $categories->{$item} -= $chg;
11282: }
11283: &recurse_check($chkcats,$categories,$deeper,$category);
11284: $deeper --;
11285: }
11286: }
11287: }
11288: return;
11289: }
11290:
11291: sub recurse_cat_deletes {
11292: my ($item,$coursecategories,$deletions) = @_;
11293: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
11294: my $subdepth = $depth + 1;
11295: if (ref($coursecategories) eq 'HASH') {
11296: foreach my $subitem (keys(%{$coursecategories})) {
11297: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
11298: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
11299: delete($coursecategories->{$subitem});
11300: $deletions->{$subitem} = 1;
11301: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 11302: }
1.48 raeburn 11303: }
11304: }
11305: return;
11306: }
11307:
1.125 raeburn 11308: sub get_active_dcs {
11309: my ($dom) = @_;
1.160.6.16 raeburn 11310: my $now = time;
11311: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 11312: my %domcoords;
11313: my $numdcs = 0;
11314: foreach my $server (keys(%dompersonnel)) {
11315: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
11316: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 11317: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 11318: }
11319: }
11320: return %domcoords;
11321: }
11322:
11323: sub active_dc_picker {
1.160.6.16 raeburn 11324: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.39 raeburn 11325: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 11326: my @domcoord = keys(%domcoords);
11327: if (keys(%currhash)) {
11328: foreach my $dc (keys(%currhash)) {
11329: unless (exists($domcoords{$dc})) {
11330: push(@domcoord,$dc);
11331: }
11332: }
11333: }
11334: @domcoord = sort(@domcoord);
11335: my $numdcs = scalar(@domcoord);
11336: my $rows = 0;
11337: my $table;
1.125 raeburn 11338: if ($numdcs > 1) {
1.160.6.16 raeburn 11339: $table = '<table>';
11340: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 11341: my $rem = $i%($numinrow);
11342: if ($rem == 0) {
11343: if ($i > 0) {
1.160.6.16 raeburn 11344: $table .= '</tr>';
1.125 raeburn 11345: }
1.160.6.16 raeburn 11346: $table .= '<tr>';
11347: $rows ++;
1.125 raeburn 11348: }
1.160.6.16 raeburn 11349: my $check = '';
11350: if ($inputtype eq 'radio') {
11351: if (keys(%currhash) == 0) {
11352: if (!$i) {
11353: $check = ' checked="checked"';
11354: }
11355: } elsif (exists($currhash{$domcoord[$i]})) {
11356: $check = ' checked="checked"';
11357: }
11358: } else {
11359: if (exists($currhash{$domcoord[$i]})) {
11360: $check = ' checked="checked"';
1.125 raeburn 11361: }
11362: }
1.160.6.16 raeburn 11363: if ($i == @domcoord - 1) {
1.125 raeburn 11364: my $colsleft = $numinrow - $rem;
11365: if ($colsleft > 1) {
1.160.6.16 raeburn 11366: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 11367: } else {
1.160.6.16 raeburn 11368: $table .= '<td class="LC_left_item">';
1.125 raeburn 11369: }
11370: } else {
1.160.6.16 raeburn 11371: $table .= '<td class="LC_left_item">';
11372: }
11373: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
11374: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11375: $table .= '<span class="LC_nobreak"><label>'.
11376: '<input type="'.$inputtype.'" name="'.$name.'"'.
11377: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
11378: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 11379: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 11380: }
1.160.6.33 raeburn 11381: $table .= '</label></span></td>';
1.125 raeburn 11382: }
1.160.6.16 raeburn 11383: $table .= '</tr></table>';
11384: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 11385: my ($dcname,$dcdom) = split(':',$domcoord[0]);
11386: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 11387: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 11388: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 11389: if ($user ne $dcname.':'.$dcdom) {
11390: $table .= ' ('.$dcname.':'.$dcdom.')';
11391: }
1.160.6.16 raeburn 11392: } else {
11393: my $check;
11394: if (exists($currhash{$domcoord[0]})) {
11395: $check = ' checked="checked"';
11396: }
1.160.6.50 raeburn 11397: $table = '<span class="LC_nobreak"><label>'.
11398: '<input type="checkbox" name="'.$name.'" '.
11399: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 11400: if ($user ne $dcname.':'.$dcdom) {
11401: $table .= ' ('.$dcname.':'.$dcdom.')';
11402: }
11403: $table .= '</label></span>';
1.160.6.16 raeburn 11404: $rows ++;
11405: }
1.125 raeburn 11406: }
1.160.6.16 raeburn 11407: return ($numdcs,$table,$rows);
1.125 raeburn 11408: }
11409:
1.137 raeburn 11410: sub usersession_titles {
11411: return &Apache::lonlocal::texthash(
11412: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
11413: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 11414: spares => 'Servers offloaded to, when busy',
1.137 raeburn 11415: version => 'LON-CAPA version requirement',
1.138 raeburn 11416: excludedomain => 'Allow all, but exclude specific domains',
11417: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 11418: primary => 'Primary (checked first)',
1.154 raeburn 11419: default => 'Default',
1.137 raeburn 11420: );
11421: }
11422:
1.152 raeburn 11423: sub id_for_thisdom {
11424: my (%servers) = @_;
11425: my %altids;
11426: foreach my $server (keys(%servers)) {
11427: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11428: if ($serverhome ne $server) {
11429: $altids{$serverhome} = $server;
11430: }
11431: }
11432: return %altids;
11433: }
11434:
1.150 raeburn 11435: sub count_servers {
11436: my ($currbalancer,%servers) = @_;
11437: my (@spares,$numspares);
11438: foreach my $lonhost (sort(keys(%servers))) {
11439: next if ($currbalancer eq $lonhost);
11440: push(@spares,$lonhost);
11441: }
11442: if ($currbalancer) {
11443: $numspares = scalar(@spares);
11444: } else {
11445: $numspares = scalar(@spares) - 1;
11446: }
11447: return ($numspares,@spares);
11448: }
11449:
11450: sub lonbalance_targets_js {
1.160.6.7 raeburn 11451: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 11452: my $select = &mt('Select');
11453: my ($alltargets,$allishome,$allinsttypes,@alltypes);
11454: if (ref($servers) eq 'HASH') {
11455: $alltargets = join("','",sort(keys(%{$servers})));
11456: my @homedoms;
11457: foreach my $server (sort(keys(%{$servers}))) {
11458: if (&Apache::lonnet::host_domain($server) eq $dom) {
11459: push(@homedoms,'1');
11460: } else {
11461: push(@homedoms,'0');
11462: }
11463: }
11464: $allishome = join("','",@homedoms);
11465: }
11466: if (ref($types) eq 'ARRAY') {
11467: if (@{$types} > 0) {
11468: @alltypes = @{$types};
11469: }
11470: }
11471: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11472: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 11473: my (%currbalancer,%currtargets,%currrules,%existing);
11474: if (ref($settings) eq 'HASH') {
11475: %existing = %{$settings};
11476: }
11477: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11478: \%currtargets,\%currrules);
11479: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 11480: return <<"END";
11481:
11482: <script type="text/javascript">
11483: // <![CDATA[
11484:
1.160.6.7 raeburn 11485: currBalancers = new Array('$balancers');
11486:
11487: function toggleTargets(balnum) {
11488: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11489: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11490: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11491: var prevbalancer = prevhostitem.value;
11492: var baltotal = document.getElementById('loadbalancing_total').value;
11493: prevhostitem.value = balancer;
11494: if (prevbalancer != '') {
11495: var prevIdx = currBalancers.indexOf(prevbalancer);
11496: if (prevIdx != -1) {
11497: currBalancers.splice(prevIdx,1);
11498: }
11499: }
1.150 raeburn 11500: if (balancer == '') {
1.160.6.7 raeburn 11501: hideSpares(balnum);
1.150 raeburn 11502: } else {
1.160.6.7 raeburn 11503: var currIdx = currBalancers.indexOf(balancer);
11504: if (currIdx == -1) {
11505: currBalancers.push(balancer);
11506: }
1.150 raeburn 11507: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 11508: var ishomedom = homedoms[lonhostitem.selectedIndex];
11509: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 11510: }
1.160.6.7 raeburn 11511: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 11512: return;
11513: }
11514:
1.160.6.7 raeburn 11515: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 11516: var alltargets = new Array('$alltargets');
11517: var insttypes = new Array('$allinsttypes');
1.151 raeburn 11518: var offloadtypes = new Array('primary','default');
11519:
1.160.6.7 raeburn 11520: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11521: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 11522:
1.151 raeburn 11523: for (var i=0; i<offloadtypes.length; i++) {
11524: var count = 0;
11525: for (var j=0; j<alltargets.length; j++) {
11526: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 11527: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11528: item.value = alltargets[j];
11529: item.style.textAlign='left';
11530: item.style.textFace='normal';
11531: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11532: if (currBalancers.indexOf(alltargets[j]) == -1) {
11533: item.disabled = '';
11534: } else {
11535: item.disabled = 'disabled';
11536: item.checked = false;
11537: }
1.151 raeburn 11538: count ++;
11539: }
1.150 raeburn 11540: }
11541: }
1.151 raeburn 11542: for (var k=0; k<insttypes.length; k++) {
11543: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 11544: if (ishomedom == 1) {
1.160.6.7 raeburn 11545: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11546: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11547: } else {
1.160.6.7 raeburn 11548: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11549: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 11550: }
11551: } else {
1.160.6.7 raeburn 11552: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11553: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11554: }
1.151 raeburn 11555: if ((insttypes[k] != '_LC_external') &&
11556: ((insttypes[k] != '_LC_internetdom') ||
11557: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 11558: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11559: item.options.length = 0;
11560: item.options[0] = new Option("","",true,true);
11561: var idx = 0;
1.151 raeburn 11562: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 11563: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11564: idx ++;
11565: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 11566: }
11567: }
11568: }
11569: }
11570: return;
11571: }
11572:
1.160.6.7 raeburn 11573: function hideSpares(balnum) {
1.150 raeburn 11574: var alltargets = new Array('$alltargets');
11575: var insttypes = new Array('$allinsttypes');
11576: var offloadtypes = new Array('primary','default');
11577:
1.160.6.7 raeburn 11578: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11579: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 11580:
11581: var total = alltargets.length - 1;
11582: for (var i=0; i<offloadtypes; i++) {
11583: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 11584: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11585: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11586: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 11587: }
1.150 raeburn 11588: }
11589: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 11590: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11591: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 11592: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 11593: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11594: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 11595: }
11596: }
11597: return;
11598: }
11599:
1.160.6.7 raeburn 11600: function checkOffloads(item,balnum,type) {
1.150 raeburn 11601: var alltargets = new Array('$alltargets');
11602: var offloadtypes = new Array('primary','default');
11603: if (item.checked) {
11604: var total = alltargets.length - 1;
11605: var other;
11606: if (type == offloadtypes[0]) {
1.151 raeburn 11607: other = offloadtypes[1];
1.150 raeburn 11608: } else {
1.151 raeburn 11609: other = offloadtypes[0];
1.150 raeburn 11610: }
11611: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 11612: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 11613: if (server == item.value) {
1.160.6.7 raeburn 11614: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11615: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 11616: }
11617: }
11618: }
11619: }
11620: return;
11621: }
11622:
1.160.6.7 raeburn 11623: function singleServerToggle(balnum,type) {
11624: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 11625: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 11626: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11627: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11628:
11629: } else {
1.160.6.7 raeburn 11630: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11631: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 11632: }
11633: return;
11634: }
11635:
1.160.6.7 raeburn 11636: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 11637: if (type == '_LC_external') {
1.160.6.26 raeburn 11638: return;
1.150 raeburn 11639: }
1.160.6.7 raeburn 11640: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 11641: for (var i=0; i<typesRules.length; i++) {
11642: if (formname.elements[typesRules[i]].checked) {
11643: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 11644: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11645: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11646: } else {
1.160.6.7 raeburn 11647: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11648: }
11649: }
11650: }
11651: return;
11652: }
11653:
11654: function balancerDeleteChange(balnum) {
11655: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11656: var baltotal = document.getElementById('loadbalancing_total').value;
11657: var addtarget;
11658: var removetarget;
11659: var action = 'delete';
11660: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11661: var lonhost = hostitem.value;
11662: var currIdx = currBalancers.indexOf(lonhost);
11663: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11664: if (currIdx != -1) {
11665: currBalancers.splice(currIdx,1);
11666: }
11667: addtarget = lonhost;
11668: } else {
11669: if (currIdx == -1) {
11670: currBalancers.push(lonhost);
11671: }
11672: removetarget = lonhost;
11673: action = 'undelete';
11674: }
11675: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11676: }
11677: return;
11678: }
11679:
11680: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11681: if (baltotal > 1) {
11682: var offloadtypes = new Array('primary','default');
11683: var alltargets = new Array('$alltargets');
11684: var insttypes = new Array('$allinsttypes');
11685: for (var i=0; i<baltotal; i++) {
11686: if (i != balnum) {
11687: for (var j=0; j<offloadtypes.length; j++) {
11688: var total = alltargets.length - 1;
11689: for (var k=0; k<total; k++) {
11690: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11691: var server = serveritem.value;
11692: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11693: if (server == addtarget) {
11694: serveritem.disabled = '';
11695: }
11696: }
11697: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11698: if (server == removetarget) {
11699: serveritem.disabled = 'disabled';
11700: serveritem.checked = false;
11701: }
11702: }
11703: }
11704: }
11705: for (var j=0; j<insttypes.length; j++) {
11706: if (insttypes[j] != '_LC_external') {
11707: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11708: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11709: var currSel = singleserver.selectedIndex;
11710: var currVal = singleserver.options[currSel].value;
11711: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11712: var numoptions = singleserver.options.length;
11713: var needsnew = 1;
11714: for (var k=0; k<numoptions; k++) {
11715: if (singleserver.options[k] == addtarget) {
11716: needsnew = 0;
11717: break;
11718: }
11719: }
11720: if (needsnew == 1) {
11721: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11722: }
11723: }
11724: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11725: singleserver.options.length = 0;
11726: if ((currVal) && (currVal != removetarget)) {
11727: singleserver.options[0] = new Option("","",false,false);
11728: } else {
11729: singleserver.options[0] = new Option("","",true,true);
11730: }
11731: var idx = 0;
11732: for (var m=0; m<alltargets.length; m++) {
11733: if (currBalancers.indexOf(alltargets[m]) == -1) {
11734: idx ++;
11735: if (currVal == alltargets[m]) {
11736: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11737: } else {
11738: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11739: }
11740: }
11741: }
11742: }
11743: }
11744: }
11745: }
1.150 raeburn 11746: }
11747: }
11748: }
11749: return;
11750: }
11751:
1.152 raeburn 11752: // ]]>
11753: </script>
11754:
11755: END
11756: }
11757:
11758: sub new_spares_js {
11759: my @sparestypes = ('primary','default');
11760: my $types = join("','",@sparestypes);
11761: my $select = &mt('Select');
11762: return <<"END";
11763:
11764: <script type="text/javascript">
11765: // <![CDATA[
11766:
11767: function updateNewSpares(formname,lonhost) {
11768: var types = new Array('$types');
11769: var include = new Array();
11770: var exclude = new Array();
11771: for (var i=0; i<types.length; i++) {
11772: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11773: for (var j=0; j<spareboxes.length; j++) {
11774: if (formname.elements[spareboxes[j]].checked) {
11775: exclude.push(formname.elements[spareboxes[j]].value);
11776: } else {
11777: include.push(formname.elements[spareboxes[j]].value);
11778: }
11779: }
11780: }
11781: for (var i=0; i<types.length; i++) {
11782: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11783: var selIdx = newSpare.selectedIndex;
11784: var currnew = newSpare.options[selIdx].value;
11785: var okSpares = new Array();
11786: for (var j=0; j<newSpare.options.length; j++) {
11787: var possible = newSpare.options[j].value;
11788: if (possible != '') {
11789: if (exclude.indexOf(possible) == -1) {
11790: okSpares.push(possible);
11791: } else {
11792: if (currnew == possible) {
11793: selIdx = 0;
11794: }
11795: }
11796: }
11797: }
11798: for (var k=0; k<include.length; k++) {
11799: if (okSpares.indexOf(include[k]) == -1) {
11800: okSpares.push(include[k]);
11801: }
11802: }
11803: okSpares.sort();
11804: newSpare.options.length = 0;
11805: if (selIdx == 0) {
11806: newSpare.options[0] = new Option("$select","",true,true);
11807: } else {
11808: newSpare.options[0] = new Option("$select","",false,false);
11809: }
11810: for (var m=0; m<okSpares.length; m++) {
11811: var idx = m+1;
11812: var selThis = 0;
11813: if (selIdx != 0) {
11814: if (okSpares[m] == currnew) {
11815: selThis = 1;
11816: }
11817: }
11818: if (selThis == 1) {
11819: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11820: } else {
11821: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11822: }
11823: }
11824: }
11825: return;
11826: }
11827:
11828: function checkNewSpares(lonhost,type) {
11829: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11830: var chosen = newSpare.options[newSpare.selectedIndex].value;
11831: if (chosen != '') {
11832: var othertype;
11833: var othernewSpare;
11834: if (type == 'primary') {
11835: othernewSpare = document.getElementById('newspare_default_'+lonhost);
11836: }
11837: if (type == 'default') {
11838: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11839: }
11840: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11841: othernewSpare.selectedIndex = 0;
11842: }
11843: }
11844: return;
11845: }
11846:
11847: // ]]>
11848: </script>
11849:
11850: END
11851:
11852: }
11853:
11854: sub common_domprefs_js {
11855: return <<"END";
11856:
11857: <script type="text/javascript">
11858: // <![CDATA[
11859:
1.150 raeburn 11860: function getIndicesByName(formname,item) {
1.152 raeburn 11861: var group = new Array();
1.150 raeburn 11862: for (var i=0;i<formname.elements.length;i++) {
11863: if (formname.elements[i].name == item) {
1.152 raeburn 11864: group.push(formname.elements[i].id);
1.150 raeburn 11865: }
11866: }
1.152 raeburn 11867: return group;
1.150 raeburn 11868: }
11869:
11870: // ]]>
11871: </script>
11872:
11873: END
1.152 raeburn 11874:
1.150 raeburn 11875: }
11876:
1.160.6.5 raeburn 11877: sub recaptcha_js {
11878: my %lt = &captcha_phrases();
11879: return <<"END";
11880:
11881: <script type="text/javascript">
11882: // <![CDATA[
11883:
11884: function updateCaptcha(caller,context) {
11885: var privitem;
11886: var pubitem;
11887: var privtext;
11888: var pubtext;
11889: if (document.getElementById(context+'_recaptchapub')) {
11890: pubitem = document.getElementById(context+'_recaptchapub');
11891: } else {
11892: return;
11893: }
11894: if (document.getElementById(context+'_recaptchapriv')) {
11895: privitem = document.getElementById(context+'_recaptchapriv');
11896: } else {
11897: return;
11898: }
11899: if (document.getElementById(context+'_recaptchapubtxt')) {
11900: pubtext = document.getElementById(context+'_recaptchapubtxt');
11901: } else {
11902: return;
11903: }
11904: if (document.getElementById(context+'_recaptchaprivtxt')) {
11905: privtext = document.getElementById(context+'_recaptchaprivtxt');
11906: } else {
11907: return;
11908: }
11909: if (caller.checked) {
11910: if (caller.value == 'recaptcha') {
11911: pubitem.type = 'text';
11912: privitem.type = 'text';
11913: pubitem.size = '40';
11914: privitem.size = '40';
11915: pubtext.innerHTML = "$lt{'pub'}";
11916: privtext.innerHTML = "$lt{'priv'}";
11917: } else {
11918: pubitem.type = 'hidden';
11919: privitem.type = 'hidden';
11920: pubtext.innerHTML = '';
11921: privtext.innerHTML = '';
11922: }
11923: }
11924: return;
11925: }
11926:
11927: // ]]>
11928: </script>
11929:
11930: END
11931:
11932: }
11933:
1.160.6.40 raeburn 11934: sub toggle_display_js {
1.160.6.16 raeburn 11935: return <<"END";
11936:
11937: <script type="text/javascript">
11938: // <![CDATA[
11939:
1.160.6.40 raeburn 11940: function toggleDisplay(domForm,caller) {
11941: if (document.getElementById(caller)) {
11942: var divitem = document.getElementById(caller);
11943: var optionsElement = domForm.coursecredits;
11944: if (caller == 'emailoptions') {
11945: optionsElement = domForm.cancreate_email;
11946: }
1.160.6.57! raeburn 11947: if (caller == 'studentsubmission') {
! 11948: optionsElement = domForm.postsubmit;
! 11949: }
1.160.6.40 raeburn 11950: if (optionsElement.length) {
1.160.6.16 raeburn 11951: var currval;
1.160.6.40 raeburn 11952: for (var i=0; i<optionsElement.length; i++) {
11953: if (optionsElement[i].checked) {
11954: currval = optionsElement[i].value;
1.160.6.16 raeburn 11955: }
11956: }
11957: if (currval == 1) {
1.160.6.40 raeburn 11958: divitem.style.display = 'block';
1.160.6.16 raeburn 11959: } else {
1.160.6.40 raeburn 11960: divitem.style.display = 'none';
1.160.6.16 raeburn 11961: }
11962: }
11963: }
11964: return;
11965: }
11966:
11967: // ]]>
11968: </script>
11969:
11970: END
11971:
11972: }
11973:
1.160.6.5 raeburn 11974: sub captcha_phrases {
11975: return &Apache::lonlocal::texthash (
11976: priv => 'Private key',
11977: pub => 'Public key',
11978: original => 'original (CAPTCHA)',
11979: recaptcha => 'successor (ReCAPTCHA)',
11980: notused => 'unused',
11981: );
11982: }
11983:
1.160.6.24 raeburn 11984: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 11985: my ($dom,$cachekeys) = @_;
11986: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 11987: my %servers = &Apache::lonnet::internet_dom_servers($dom);
11988: my %thismachine;
11989: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.27 raeburn 11990: my @posscached = ('domainconfig','domdefaults');
1.160.6.24 raeburn 11991: if (keys(%servers) > 1) {
11992: foreach my $server (keys(%servers)) {
11993: next if ($thismachine{$server});
1.160.6.27 raeburn 11994: my @cached;
11995: foreach my $name (@posscached) {
11996: if ($cachekeys->{$name}) {
11997: push(@cached,&escape($name).':'.&escape($dom));
11998: }
11999: }
12000: if (@cached) {
12001: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
12002: }
1.160.6.24 raeburn 12003: }
12004: }
12005: return;
12006: }
12007:
1.3 raeburn 12008: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>