Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.60
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.60! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.59 2015/03/16 13:19:09 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.121 raeburn 895: }
1.3 raeburn 896: }
1.30 raeburn 897: $output .= '
1.3 raeburn 898: </table>
899: </td>
900: </tr>
1.30 raeburn 901: </table><br />';
902: return ($output,$rowtotal);
1.1 raeburn 903: }
904:
1.3 raeburn 905: sub print_login {
1.160.6.5 raeburn 906: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 907: my ($css_class,$datatable);
1.6 raeburn 908: my %choices = &login_choices();
1.110 raeburn 909:
1.160.6.5 raeburn 910: if ($caller eq 'service') {
1.149 raeburn 911: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 912: my $choice = $choices{'disallowlogin'};
913: $css_class = ' class="LC_odd_row"';
1.128 raeburn 914: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 915: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 916: '<th>'.$choices{'server'}.'</th>'.
917: '<th>'.$choices{'serverpath'}.'</th>'.
918: '<th>'.$choices{'custompath'}.'</th>'.
919: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 920: my %disallowed;
921: if (ref($settings) eq 'HASH') {
922: if (ref($settings->{'loginvia'}) eq 'HASH') {
923: %disallowed = %{$settings->{'loginvia'}};
924: }
925: }
926: foreach my $lonhost (sort(keys(%servers))) {
927: my $direct = 'selected="selected"';
1.128 raeburn 928: if (ref($disallowed{$lonhost}) eq 'HASH') {
929: if ($disallowed{$lonhost}{'server'} ne '') {
930: $direct = '';
931: }
1.110 raeburn 932: }
1.115 raeburn 933: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 934: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 935: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
936: '</option>';
1.160.6.13 raeburn 937: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 938: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 939: my $selected = '';
1.128 raeburn 940: if (ref($disallowed{$lonhost}) eq 'HASH') {
941: if ($hostid eq $disallowed{$lonhost}{'server'}) {
942: $selected = 'selected="selected"';
943: }
1.110 raeburn 944: }
945: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
946: $servers{$hostid}.'</option>';
947: }
1.128 raeburn 948: $datatable .= '</select></td>'.
949: '<td><select name="'.$lonhost.'_serverpath">';
950: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
951: my $pathname = $path;
952: if ($path eq 'custom') {
953: $pathname = &mt('Custom Path').' ->';
954: }
955: my $selected = '';
956: if (ref($disallowed{$lonhost}) eq 'HASH') {
957: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
958: $selected = 'selected="selected"';
959: }
960: } elsif ($path eq '') {
961: $selected = 'selected="selected"';
962: }
963: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
964: }
965: $datatable .= '</select></td>';
966: my ($custom,$exempt);
967: if (ref($disallowed{$lonhost}) eq 'HASH') {
968: $custom = $disallowed{$lonhost}{'custompath'};
969: $exempt = $disallowed{$lonhost}{'exempt'};
970: }
971: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
972: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
973: '</tr>';
1.110 raeburn 974: }
975: $datatable .= '</table></td></tr>';
976: return $datatable;
1.160.6.5 raeburn 977: } elsif ($caller eq 'page') {
978: my %defaultchecked = (
979: 'coursecatalog' => 'on',
1.160.6.14 raeburn 980: 'helpdesk' => 'on',
1.160.6.5 raeburn 981: 'adminmail' => 'off',
982: 'newuser' => 'off',
983: );
1.160.6.14 raeburn 984: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 985: my (%checkedon,%checkedoff);
1.42 raeburn 986: foreach my $item (@toggles) {
1.160.6.5 raeburn 987: if ($defaultchecked{$item} eq 'on') {
988: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 989: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 990: } elsif ($defaultchecked{$item} eq 'off') {
991: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 992: $checkedon{$item} = ' ';
993: }
1.1 raeburn 994: }
1.160.6.5 raeburn 995: my @images = ('img','logo','domlogo','login');
996: my @logintext = ('textcol','bgcol');
997: my @bgs = ('pgbg','mainbg','sidebg');
998: my @links = ('link','alink','vlink');
999: my %designhash = &Apache::loncommon::get_domainconf($dom);
1000: my %defaultdesign = %Apache::loncommon::defaultdesign;
1001: my (%is_custom,%designs);
1002: my %defaults = (
1003: font => $defaultdesign{'login.font'},
1004: );
1.6 raeburn 1005: foreach my $item (@images) {
1.160.6.5 raeburn 1006: $defaults{$item} = $defaultdesign{'login.'.$item};
1007: $defaults{'showlogo'}{$item} = 1;
1008: }
1009: foreach my $item (@bgs) {
1010: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1011: }
1.41 raeburn 1012: foreach my $item (@logintext) {
1.160.6.5 raeburn 1013: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1014: }
1.160.6.5 raeburn 1015: foreach my $item (@links) {
1016: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1017: }
1.160.6.5 raeburn 1018: if (ref($settings) eq 'HASH') {
1019: foreach my $item (@toggles) {
1020: if ($settings->{$item} eq '1') {
1021: $checkedon{$item} = ' checked="checked" ';
1022: $checkedoff{$item} = ' ';
1023: } elsif ($settings->{$item} eq '0') {
1024: $checkedoff{$item} = ' checked="checked" ';
1025: $checkedon{$item} = ' ';
1026: }
1.6 raeburn 1027: }
1.160.6.5 raeburn 1028: foreach my $item (@images) {
1029: if (defined($settings->{$item})) {
1030: $designs{$item} = $settings->{$item};
1031: $is_custom{$item} = 1;
1032: }
1033: if (defined($settings->{'showlogo'}{$item})) {
1034: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1035: }
1036: }
1037: foreach my $item (@logintext) {
1038: if ($settings->{$item} ne '') {
1039: $designs{'logintext'}{$item} = $settings->{$item};
1040: $is_custom{$item} = 1;
1041: }
1042: }
1043: if ($settings->{'font'} ne '') {
1044: $designs{'font'} = $settings->{'font'};
1045: $is_custom{'font'} = 1;
1046: }
1047: foreach my $item (@bgs) {
1048: if ($settings->{$item} ne '') {
1049: $designs{'bgs'}{$item} = $settings->{$item};
1050: $is_custom{$item} = 1;
1051: }
1052: }
1053: foreach my $item (@links) {
1054: if ($settings->{$item} ne '') {
1055: $designs{'links'}{$item} = $settings->{$item};
1056: $is_custom{$item} = 1;
1057: }
1058: }
1059: } else {
1060: if ($designhash{$dom.'.login.font'} ne '') {
1061: $designs{'font'} = $designhash{$dom.'.login.font'};
1062: $is_custom{'font'} = 1;
1063: }
1064: foreach my $item (@images) {
1065: if ($designhash{$dom.'.login.'.$item} ne '') {
1066: $designs{$item} = $designhash{$dom.'.login.'.$item};
1067: $is_custom{$item} = 1;
1068: }
1069: }
1070: foreach my $item (@bgs) {
1071: if ($designhash{$dom.'.login.'.$item} ne '') {
1072: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1073: $is_custom{$item} = 1;
1074: }
1075: }
1076: foreach my $item (@links) {
1077: if ($designhash{$dom.'.login.'.$item} ne '') {
1078: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1079: $is_custom{$item} = 1;
1080: }
1.6 raeburn 1081: }
1082: }
1.160.6.5 raeburn 1083: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1084: logo => 'Institution Logo',
1085: domlogo => 'Domain Logo',
1086: login => 'Login box');
1087: my $itemcount = 1;
1088: foreach my $item (@toggles) {
1089: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1090: $datatable .=
1091: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1092: '</td><td>'.
1093: '<span class="LC_nobreak"><label><input type="radio" name="'.
1094: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1095: '</label> <label><input type="radio" name="'.$item.'"'.
1096: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1097: '</tr>';
1098: $itemcount ++;
1.6 raeburn 1099: }
1.160.6.5 raeburn 1100: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1101: $datatable .= '</tr></table></td></tr>';
1102: } elsif ($caller eq 'help') {
1103: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1104: my $switchserver = &check_switchserver($dom,$confname);
1105: my $itemcount = 1;
1106: $defaulturl = '/adm/loginproblems.html';
1107: $defaulttype = 'default';
1108: %lt = &Apache::lonlocal::texthash (
1109: del => 'Delete?',
1110: rep => 'Replace:',
1111: upl => 'Upload:',
1112: default => 'Default',
1113: custom => 'Custom',
1114: );
1115: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1116: my @currlangs;
1117: if (ref($settings) eq 'HASH') {
1118: if (ref($settings->{'helpurl'}) eq 'HASH') {
1119: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1120: next if ($settings->{'helpurl'}{$key} eq '');
1121: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1122: $type{$key} = 'custom';
1123: unless ($key eq 'nolang') {
1124: push(@currlangs,$key);
1125: }
1126: }
1127: } elsif ($settings->{'helpurl'} ne '') {
1128: $type{'nolang'} = 'custom';
1129: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1130: }
1131: }
1.160.6.5 raeburn 1132: foreach my $lang ('nolang',sort(@currlangs)) {
1133: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1134: $datatable .= '<tr'.$css_class.'>';
1135: if ($url{$lang} eq '') {
1136: $url{$lang} = $defaulturl;
1137: }
1138: if ($type{$lang} eq '') {
1139: $type{$lang} = $defaulttype;
1140: }
1141: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1142: if ($lang eq 'nolang') {
1143: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1144: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1145: } else {
1146: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1147: $langchoices{$lang},
1148: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1149: }
1150: $datatable .= '</span></td>'."\n".
1151: '<td class="LC_left_item">';
1152: if ($type{$lang} eq 'custom') {
1153: $datatable .= '<span class="LC_nobreak"><label>'.
1154: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1155: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1156: } else {
1157: $datatable .= $lt{'upl'};
1158: }
1159: $datatable .='<br />';
1160: if ($switchserver) {
1161: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1162: } else {
1163: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1164: }
1.160.6.5 raeburn 1165: $datatable .= '</td></tr>';
1166: $itemcount ++;
1.6 raeburn 1167: }
1.160.6.5 raeburn 1168: my @addlangs;
1169: foreach my $lang (sort(keys(%langchoices))) {
1170: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1171: push(@addlangs,$lang);
1172: }
1173: if (@addlangs > 0) {
1174: my %toadd;
1175: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1176: $toadd{''} = &mt('Select');
1177: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1178: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1179: &mt('Add log-in help page for a specific language:').' '.
1180: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1181: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1182: if ($switchserver) {
1183: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1184: } else {
1185: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1186: }
1.160.6.5 raeburn 1187: $datatable .= '</td></tr>';
1188: $itemcount ++;
1.6 raeburn 1189: }
1.160.6.5 raeburn 1190: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1191: } elsif ($caller eq 'headtag') {
1192: my %domservers = &Apache::lonnet::get_servers($dom);
1193: my $choice = $choices{'headtag'};
1194: $css_class = ' class="LC_odd_row"';
1195: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1196: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1197: '<th>'.$choices{'current'}.'</th>'.
1198: '<th>'.$choices{'action'}.'</th>'.
1199: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1200: my (%currurls,%currexempt);
1201: if (ref($settings) eq 'HASH') {
1202: if (ref($settings->{'headtag'}) eq 'HASH') {
1203: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1204: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1205: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1206: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1207: }
1208: }
1209: }
1210: }
1211: my %lt = &Apache::lonlocal::texthash(
1212: del => 'Delete?',
1213: rep => 'Replace:',
1214: upl => 'Upload:',
1215: curr => 'View contents',
1216: none => 'None',
1217: );
1218: my $switchserver = &check_switchserver($dom,$confname);
1219: foreach my $lonhost (sort(keys(%domservers))) {
1220: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1221: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1222: if ($currurls{$lonhost}) {
1223: $datatable .= '<td class="LC_right_item"><a href="'.
1224: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1225: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1226: '">'.$lt{'curr'}.'</a></td>'.
1227: '<td><span class="LC_nobreak"><label>'.
1228: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1229: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1230: } else {
1231: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1232: }
1233: $datatable .='<br />';
1234: if ($switchserver) {
1235: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1236: } else {
1237: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1238: }
1239: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1240: }
1241: $datatable .= '</table></td></tr>';
1.1 raeburn 1242: }
1.6 raeburn 1243: return $datatable;
1244: }
1245:
1246: sub login_choices {
1247: my %choices =
1248: &Apache::lonlocal::texthash (
1.116 bisitz 1249: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1250: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1251: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1252: disallowlogin => "Login page requests redirected",
1253: hostid => "Server",
1.128 raeburn 1254: server => "Redirect to:",
1255: serverpath => "Path",
1256: custompath => "Custom",
1257: exempt => "Exempt IP(s)",
1.110 raeburn 1258: directlogin => "No redirect",
1259: newuser => "Link to create a user account",
1260: img => "Header",
1261: logo => "Main Logo",
1262: domlogo => "Domain Logo",
1263: login => "Log-in Header",
1264: textcol => "Text color",
1265: bgcol => "Box color",
1266: bgs => "Background colors",
1267: links => "Link colors",
1268: font => "Font color",
1269: pgbg => "Header",
1270: mainbg => "Page",
1271: sidebg => "Login box",
1272: link => "Link",
1273: alink => "Active link",
1274: vlink => "Visited link",
1.160.6.56 raeburn 1275: headtag => "Custom markup",
1276: action => "Action",
1277: current => "Current",
1.6 raeburn 1278: );
1279: return %choices;
1280: }
1281:
1282: sub print_rolecolors {
1.30 raeburn 1283: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1284: my %choices = &color_font_choices();
1285: my @bgs = ('pgbg','tabbg','sidebg');
1286: my @links = ('link','alink','vlink');
1287: my @images = ('img');
1288: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1289: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1290: my %defaultdesign = %Apache::loncommon::defaultdesign;
1291: my (%is_custom,%designs);
1.160.6.22 raeburn 1292: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1293: if (ref($settings) eq 'HASH') {
1294: if (ref($settings->{$role}) eq 'HASH') {
1295: if ($settings->{$role}->{'img'} ne '') {
1296: $designs{'img'} = $settings->{$role}->{'img'};
1297: $is_custom{'img'} = 1;
1298: }
1299: if ($settings->{$role}->{'font'} ne '') {
1300: $designs{'font'} = $settings->{$role}->{'font'};
1301: $is_custom{'font'} = 1;
1302: }
1.97 tempelho 1303: if ($settings->{$role}->{'fontmenu'} ne '') {
1304: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1305: $is_custom{'fontmenu'} = 1;
1306: }
1.6 raeburn 1307: foreach my $item (@bgs) {
1308: if ($settings->{$role}->{$item} ne '') {
1309: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1310: $is_custom{$item} = 1;
1311: }
1312: }
1313: foreach my $item (@links) {
1314: if ($settings->{$role}->{$item} ne '') {
1315: $designs{'links'}{$item} = $settings->{$role}->{$item};
1316: $is_custom{$item} = 1;
1317: }
1318: }
1319: }
1320: } else {
1321: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1322: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1323: $is_custom{'img'} = 1;
1324: }
1.97 tempelho 1325: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1326: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1327: $is_custom{'fontmenu'} = 1;
1328: }
1.6 raeburn 1329: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1330: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1331: $is_custom{'font'} = 1;
1332: }
1333: foreach my $item (@bgs) {
1334: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1335: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1336: $is_custom{$item} = 1;
1337:
1338: }
1339: }
1340: foreach my $item (@links) {
1341: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1342: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1343: $is_custom{$item} = 1;
1344: }
1345: }
1346: }
1347: my $itemcount = 1;
1.30 raeburn 1348: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1349: $datatable .= '</tr></table></td></tr>';
1350: return $datatable;
1351: }
1352:
1.160.6.22 raeburn 1353: sub role_defaults {
1354: my ($role,$bgs,$links,$images,$logintext) = @_;
1355: my %defaults;
1356: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1357: return %defaults;
1358: }
1359: my %defaultdesign = %Apache::loncommon::defaultdesign;
1360: if ($role eq 'login') {
1361: %defaults = (
1362: font => $defaultdesign{$role.'.font'},
1363: );
1364: if (ref($logintext) eq 'ARRAY') {
1365: foreach my $item (@{$logintext}) {
1366: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1367: }
1368: }
1369: foreach my $item (@{$images}) {
1370: $defaults{'showlogo'}{$item} = 1;
1371: }
1372: } else {
1373: %defaults = (
1374: img => $defaultdesign{$role.'.img'},
1375: font => $defaultdesign{$role.'.font'},
1376: fontmenu => $defaultdesign{$role.'.fontmenu'},
1377: );
1378: }
1379: foreach my $item (@{$bgs}) {
1380: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1381: }
1382: foreach my $item (@{$links}) {
1383: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1384: }
1385: foreach my $item (@{$images}) {
1386: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1387: }
1388: return %defaults;
1389: }
1390:
1.6 raeburn 1391: sub display_color_options {
1.9 raeburn 1392: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1393: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1394: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1395: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1396: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1397: '<td>'.$choices->{'font'}.'</td>';
1398: if (!$is_custom->{'font'}) {
1.30 raeburn 1399: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1400: } else {
1401: $datatable .= '<td> </td>';
1402: }
1.160.6.9 raeburn 1403: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1404:
1.8 raeburn 1405: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1406: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1407: ' value="'.$current_color.'" /> '.
1408: ' </td></tr>';
1.107 raeburn 1409: unless ($role eq 'login') {
1410: $datatable .= '<tr'.$css_class.'>'.
1411: '<td>'.$choices->{'fontmenu'}.'</td>';
1412: if (!$is_custom->{'fontmenu'}) {
1413: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1414: } else {
1415: $datatable .= '<td> </td>';
1416: }
1.160.6.22 raeburn 1417: $current_color = $designs->{'fontmenu'} ?
1418: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1419: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1420: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1421: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1422: ' value="'.$current_color.'" /> '.
1423: ' </td></tr>';
1.97 tempelho 1424: }
1.9 raeburn 1425: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1426: foreach my $img (@{$images}) {
1.18 albertel 1427: $itemcount ++;
1.6 raeburn 1428: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1429: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1430: '<td>'.$choices->{$img};
1.41 raeburn 1431: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1432: if ($role eq 'login') {
1433: if ($img eq 'login') {
1434: $login_hdr_pick =
1.135 bisitz 1435: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1436: $logincolors =
1437: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1438: $designs,$defaults);
1.70 raeburn 1439: } elsif ($img ne 'domlogo') {
1440: $datatable.= &logo_display_options($img,$defaults,$designs);
1441: }
1442: }
1443: $datatable .= '</td>';
1.6 raeburn 1444: if ($designs->{$img} ne '') {
1445: $imgfile = $designs->{$img};
1.18 albertel 1446: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1447: } else {
1448: $imgfile = $defaults->{$img};
1449: }
1450: if ($imgfile) {
1.9 raeburn 1451: my ($showfile,$fullsize);
1452: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1453: my $urldir = $1;
1454: my $filename = $2;
1455: my @info = &Apache::lonnet::stat_file($designs->{$img});
1456: if (@info) {
1457: my $thumbfile = 'tn-'.$filename;
1458: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1459: if (@thumb) {
1460: $showfile = $urldir.'/'.$thumbfile;
1461: } else {
1462: $showfile = $imgfile;
1463: }
1464: } else {
1465: $showfile = '';
1466: }
1467: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1468: $showfile = $imgfile;
1.6 raeburn 1469: my $imgdir = $1;
1470: my $filename = $2;
1.159 raeburn 1471: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1472: $showfile = "/$imgdir/tn-".$filename;
1473: } else {
1.159 raeburn 1474: my $input = $londocroot.$imgfile;
1475: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1476: if (!-e $output) {
1.9 raeburn 1477: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1478: my ($fullwidth,$fullheight) = &check_dimensions($input);
1479: if ($fullwidth ne '' && $fullheight ne '') {
1480: if ($fullwidth > $width && $fullheight > $height) {
1481: my $size = $width.'x'.$height;
1482: system("convert -sample $size $input $output");
1.159 raeburn 1483: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1484: }
1485: }
1.6 raeburn 1486: }
1487: }
1.16 raeburn 1488: }
1.6 raeburn 1489: if ($showfile) {
1.40 raeburn 1490: if ($showfile =~ m{^/(adm|res)/}) {
1491: if ($showfile =~ m{^/res/}) {
1492: my $local_showfile =
1493: &Apache::lonnet::filelocation('',$showfile);
1494: &Apache::lonnet::repcopy($local_showfile);
1495: }
1496: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1497: }
1498: if ($imgfile) {
1499: if ($imgfile =~ m{^/(adm|res)/}) {
1500: if ($imgfile =~ m{^/res/}) {
1501: my $local_imgfile =
1502: &Apache::lonnet::filelocation('',$imgfile);
1503: &Apache::lonnet::repcopy($local_imgfile);
1504: }
1505: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1506: } else {
1507: $fullsize = $imgfile;
1508: }
1509: }
1.41 raeburn 1510: $datatable .= '<td>';
1511: if ($img eq 'login') {
1.135 bisitz 1512: $datatable .= $login_hdr_pick;
1513: }
1.41 raeburn 1514: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1515: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1516: } else {
1.160.6.22 raeburn 1517: $datatable .= '<td> </td><td class="LC_left_item">'.
1518: &mt('Upload:').'<br />';
1.6 raeburn 1519: }
1520: } else {
1.160.6.22 raeburn 1521: $datatable .= '<td> </td><td class="LC_left_item">'.
1522: &mt('Upload:').'<br />';
1.6 raeburn 1523: }
1.9 raeburn 1524: if ($switchserver) {
1525: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1526: } else {
1.135 bisitz 1527: if ($img ne 'login') { # suppress file selection for Log-in header
1528: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1529: }
1.9 raeburn 1530: }
1531: $datatable .= '</td></tr>';
1.6 raeburn 1532: }
1533: $itemcount ++;
1534: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1535: $datatable .= '<tr'.$css_class.'>'.
1536: '<td>'.$choices->{'bgs'}.'</td>';
1537: my $bgs_def;
1538: foreach my $item (@{$bgs}) {
1539: if (!$is_custom->{$item}) {
1.70 raeburn 1540: $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 1541: }
1542: }
1543: if ($bgs_def) {
1.8 raeburn 1544: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1545: } else {
1546: $datatable .= '<td> </td>';
1547: }
1548: $datatable .= '<td class="LC_right_item">'.
1549: '<table border="0"><tr>';
1.160.6.13 raeburn 1550:
1.6 raeburn 1551: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1552: $datatable .= '<td align="center">'.$choices->{$item};
1553: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1554: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1555: $datatable .= ' ';
1.6 raeburn 1556: }
1.160.6.9 raeburn 1557: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1558: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1559: }
1560: $datatable .= '</tr></table></td></tr>';
1561: $itemcount ++;
1562: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1563: $datatable .= '<tr'.$css_class.'>'.
1564: '<td>'.$choices->{'links'}.'</td>';
1565: my $links_def;
1566: foreach my $item (@{$links}) {
1567: if (!$is_custom->{$item}) {
1.30 raeburn 1568: $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 1569: }
1570: }
1571: if ($links_def) {
1.8 raeburn 1572: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1573: } else {
1574: $datatable .= '<td> </td>';
1575: }
1576: $datatable .= '<td class="LC_right_item">'.
1577: '<table border="0"><tr>';
1578: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1579: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1580: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1581: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1582: $datatable.=' ';
1.6 raeburn 1583: }
1.160.6.9 raeburn 1584: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1585: '" /></td>';
1586: }
1.30 raeburn 1587: $$rowtotal += $itemcount;
1.3 raeburn 1588: return $datatable;
1589: }
1590:
1.70 raeburn 1591: sub logo_display_options {
1592: my ($img,$defaults,$designs) = @_;
1593: my $checkedon;
1594: if (ref($defaults) eq 'HASH') {
1595: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1596: if ($defaults->{'showlogo'}{$img}) {
1597: $checkedon = 'checked="checked" ';
1598: }
1599: }
1600: }
1601: if (ref($designs) eq 'HASH') {
1602: if (ref($designs->{'showlogo'}) eq 'HASH') {
1603: if (defined($designs->{'showlogo'}{$img})) {
1604: if ($designs->{'showlogo'}{$img} == 0) {
1605: $checkedon = '';
1606: } elsif ($designs->{'showlogo'}{$img} == 1) {
1607: $checkedon = 'checked="checked" ';
1608: }
1609: }
1610: }
1611: }
1612: return '<br /><label> <input type="checkbox" name="'.
1613: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1614: &mt('show').'</label>'."\n";
1615: }
1616:
1.41 raeburn 1617: sub login_header_options {
1.135 bisitz 1618: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1619: my $output = '';
1.41 raeburn 1620: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1621: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1622: if (!$is_custom->{'textcol'}) {
1623: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1624: ' ';
1625: }
1626: if (!$is_custom->{'bgcol'}) {
1627: $output .= $choices->{'bgcol'}.': '.
1628: '<span id="css_'.$role.'_font" style="background-color: '.
1629: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1630: }
1631: $output .= '<br />';
1632: }
1633: $output .='<br />';
1634: return $output;
1635: }
1636:
1637: sub login_text_colors {
1.160.6.22 raeburn 1638: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1639: my $color_menu = '<table border="0"><tr>';
1640: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1641: $color_menu .= '<td align="center">'.$choices->{$item};
1642: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1643: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1644: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1645: }
1646: $color_menu .= '</tr></table><br />';
1647: return $color_menu;
1648: }
1649:
1650: sub image_changes {
1651: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1652: my $output;
1.135 bisitz 1653: if ($img eq 'login') {
1654: # suppress image for Log-in header
1655: } elsif (!$is_custom) {
1.70 raeburn 1656: if ($img ne 'domlogo') {
1.41 raeburn 1657: $output .= &mt('Default image:').'<br />';
1658: } else {
1659: $output .= &mt('Default in use:').'<br />';
1660: }
1661: }
1.135 bisitz 1662: if ($img eq 'login') { # suppress image for Log-in header
1663: $output .= '<td>'.$logincolors;
1.41 raeburn 1664: } else {
1.135 bisitz 1665: if ($img_import) {
1666: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1667: }
1668: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1669: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1670: if ($is_custom) {
1671: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1672: '<input type="checkbox" name="'.
1673: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1674: '</label> '.&mt('Replace:').'</span><br />';
1675: } else {
1.160.6.22 raeburn 1676: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1677: }
1.41 raeburn 1678: }
1679: return $output;
1680: }
1681:
1.3 raeburn 1682: sub print_quotas {
1.86 raeburn 1683: my ($dom,$settings,$rowtotal,$action) = @_;
1684: my $context;
1685: if ($action eq 'quotas') {
1686: $context = 'tools';
1687: } else {
1688: $context = $action;
1689: }
1.160.6.20 raeburn 1690: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1691: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1692: my $typecount = 0;
1.101 raeburn 1693: my ($css_class,%titles);
1.86 raeburn 1694: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1695: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1696: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1697: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1698: %titles = &courserequest_titles();
1.160.6.5 raeburn 1699: } elsif ($context eq 'requestauthor') {
1700: @usertools = ('author');
1701: @options = ('norequest','approval','automatic');
1702: %titles = &authorrequest_titles();
1.86 raeburn 1703: } else {
1.160.6.4 raeburn 1704: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1705: %titles = &tool_titles();
1.86 raeburn 1706: }
1.26 raeburn 1707: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1708: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1709: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1710: unless (($context eq 'requestcourses') ||
1711: ($context eq 'requestauthor')) {
1.86 raeburn 1712: if (ref($settings) eq 'HASH') {
1713: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1714: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1715: } else {
1716: $currdefquota = $settings->{$type};
1717: }
1.160.6.20 raeburn 1718: if (ref($settings->{authorquota}) eq 'HASH') {
1719: $currauthorquota = $settings->{authorquota}->{$type};
1720: }
1.78 raeburn 1721: }
1.72 raeburn 1722: }
1.3 raeburn 1723: if (defined($usertypes->{$type})) {
1724: $typecount ++;
1725: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1726: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1727: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1728: '<td class="LC_left_item">';
1.101 raeburn 1729: if ($context eq 'requestcourses') {
1730: $datatable .= '<table><tr>';
1731: }
1732: my %cell;
1.72 raeburn 1733: foreach my $item (@usertools) {
1.101 raeburn 1734: if ($context eq 'requestcourses') {
1735: my ($curroption,$currlimit);
1736: if (ref($settings) eq 'HASH') {
1737: if (ref($settings->{$item}) eq 'HASH') {
1738: $curroption = $settings->{$item}->{$type};
1739: if ($curroption =~ /^autolimit=(\d*)$/) {
1740: $currlimit = $1;
1741: }
1742: }
1743: }
1744: if (!$curroption) {
1745: $curroption = 'norequest';
1746: }
1747: $datatable .= '<th>'.$titles{$item}.'</th>';
1748: foreach my $option (@options) {
1749: my $val = $option;
1750: if ($option eq 'norequest') {
1751: $val = 0;
1752: }
1753: if ($option eq 'validate') {
1754: my $canvalidate = 0;
1755: if (ref($validations{$item}) eq 'HASH') {
1756: if ($validations{$item}{$type}) {
1757: $canvalidate = 1;
1758: }
1759: }
1760: next if (!$canvalidate);
1761: }
1762: my $checked = '';
1763: if ($option eq $curroption) {
1764: $checked = ' checked="checked"';
1765: } elsif ($option eq 'autolimit') {
1766: if ($curroption =~ /^autolimit/) {
1767: $checked = ' checked="checked"';
1768: }
1769: }
1770: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1771: '<input type="radio" name="crsreq_'.$item.
1772: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1773: $titles{$option}.'</label>';
1.101 raeburn 1774: if ($option eq 'autolimit') {
1.127 raeburn 1775: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1776: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1777: 'value="'.$currlimit.'" />';
1.101 raeburn 1778: }
1.127 raeburn 1779: $cell{$item} .= '</span> ';
1.103 raeburn 1780: if ($option eq 'autolimit') {
1.127 raeburn 1781: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1782: }
1.101 raeburn 1783: }
1.160.6.5 raeburn 1784: } elsif ($context eq 'requestauthor') {
1785: my $curroption;
1786: if (ref($settings) eq 'HASH') {
1787: $curroption = $settings->{$type};
1788: }
1789: if (!$curroption) {
1790: $curroption = 'norequest';
1791: }
1792: foreach my $option (@options) {
1793: my $val = $option;
1794: if ($option eq 'norequest') {
1795: $val = 0;
1796: }
1797: my $checked = '';
1798: if ($option eq $curroption) {
1799: $checked = ' checked="checked"';
1800: }
1801: $datatable .= '<span class="LC_nobreak"><label>'.
1802: '<input type="radio" name="authorreq_'.$type.
1803: '" value="'.$val.'"'.$checked.' />'.
1804: $titles{$option}.'</label></span> ';
1805: }
1.101 raeburn 1806: } else {
1807: my $checked = 'checked="checked" ';
1808: if (ref($settings) eq 'HASH') {
1809: if (ref($settings->{$item}) eq 'HASH') {
1810: if ($settings->{$item}->{$type} == 0) {
1811: $checked = '';
1812: } elsif ($settings->{$item}->{$type} == 1) {
1813: $checked = 'checked="checked" ';
1814: }
1.78 raeburn 1815: }
1.72 raeburn 1816: }
1.101 raeburn 1817: $datatable .= '<span class="LC_nobreak"><label>'.
1818: '<input type="checkbox" name="'.$context.'_'.$item.
1819: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1820: '</label></span> ';
1.72 raeburn 1821: }
1.101 raeburn 1822: }
1823: if ($context eq 'requestcourses') {
1824: $datatable .= '</tr><tr>';
1825: foreach my $item (@usertools) {
1.106 raeburn 1826: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1827: }
1828: $datatable .= '</tr></table>';
1.72 raeburn 1829: }
1.86 raeburn 1830: $datatable .= '</td>';
1.160.6.5 raeburn 1831: unless (($context eq 'requestcourses') ||
1832: ($context eq 'requestauthor')) {
1.86 raeburn 1833: $datatable .=
1.160.6.20 raeburn 1834: '<td class="LC_right_item">'.
1835: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1836: '<input type="text" name="quota_'.$type.
1.72 raeburn 1837: '" value="'.$currdefquota.
1.160.6.20 raeburn 1838: '" size="5" /></span>'.(' ' x 2).
1839: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1840: '<input type="text" name="authorquota_'.$type.
1841: '" value="'.$currauthorquota.
1842: '" size="5" /></span></td>';
1.86 raeburn 1843: }
1844: $datatable .= '</tr>';
1.3 raeburn 1845: }
1846: }
1847: }
1.160.6.5 raeburn 1848: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1849: $defaultquota = '20';
1.160.6.20 raeburn 1850: $authorquota = '500';
1.86 raeburn 1851: if (ref($settings) eq 'HASH') {
1852: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1853: $defaultquota = $settings->{'defaultquota'}->{'default'};
1854: } elsif (defined($settings->{'default'})) {
1855: $defaultquota = $settings->{'default'};
1856: }
1.160.6.20 raeburn 1857: if (ref($settings->{'authorquota'}) eq 'HASH') {
1858: $authorquota = $settings->{'authorquota'}->{'default'};
1859: }
1.3 raeburn 1860: }
1861: }
1862: $typecount ++;
1863: $css_class = $typecount%2?' class="LC_odd_row"':'';
1864: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1865: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1866: '<td class="LC_left_item">';
1.101 raeburn 1867: if ($context eq 'requestcourses') {
1868: $datatable .= '<table><tr>';
1869: }
1870: my %defcell;
1.72 raeburn 1871: foreach my $item (@usertools) {
1.101 raeburn 1872: if ($context eq 'requestcourses') {
1873: my ($curroption,$currlimit);
1874: if (ref($settings) eq 'HASH') {
1875: if (ref($settings->{$item}) eq 'HASH') {
1876: $curroption = $settings->{$item}->{'default'};
1877: if ($curroption =~ /^autolimit=(\d*)$/) {
1878: $currlimit = $1;
1879: }
1880: }
1881: }
1882: if (!$curroption) {
1883: $curroption = 'norequest';
1884: }
1885: $datatable .= '<th>'.$titles{$item}.'</th>';
1886: foreach my $option (@options) {
1887: my $val = $option;
1888: if ($option eq 'norequest') {
1889: $val = 0;
1890: }
1891: if ($option eq 'validate') {
1892: my $canvalidate = 0;
1893: if (ref($validations{$item}) eq 'HASH') {
1894: if ($validations{$item}{'default'}) {
1895: $canvalidate = 1;
1896: }
1897: }
1898: next if (!$canvalidate);
1899: }
1900: my $checked = '';
1901: if ($option eq $curroption) {
1902: $checked = ' checked="checked"';
1903: } elsif ($option eq 'autolimit') {
1904: if ($curroption =~ /^autolimit/) {
1905: $checked = ' checked="checked"';
1906: }
1907: }
1908: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1909: '<input type="radio" name="crsreq_'.$item.
1910: '_default" value="'.$val.'"'.$checked.' />'.
1911: $titles{$option}.'</label>';
1912: if ($option eq 'autolimit') {
1.127 raeburn 1913: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1914: $item.'_limit_default" size="1" '.
1915: 'value="'.$currlimit.'" />';
1916: }
1.127 raeburn 1917: $defcell{$item} .= '</span> ';
1.104 raeburn 1918: if ($option eq 'autolimit') {
1.127 raeburn 1919: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1920: }
1.101 raeburn 1921: }
1.160.6.5 raeburn 1922: } elsif ($context eq 'requestauthor') {
1923: my $curroption;
1924: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1925: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1926: }
1927: if (!$curroption) {
1928: $curroption = 'norequest';
1929: }
1930: foreach my $option (@options) {
1931: my $val = $option;
1932: if ($option eq 'norequest') {
1933: $val = 0;
1934: }
1935: my $checked = '';
1936: if ($option eq $curroption) {
1937: $checked = ' checked="checked"';
1938: }
1939: $datatable .= '<span class="LC_nobreak"><label>'.
1940: '<input type="radio" name="authorreq_default"'.
1941: ' value="'.$val.'"'.$checked.' />'.
1942: $titles{$option}.'</label></span> ';
1943: }
1.101 raeburn 1944: } else {
1945: my $checked = 'checked="checked" ';
1946: if (ref($settings) eq 'HASH') {
1947: if (ref($settings->{$item}) eq 'HASH') {
1948: if ($settings->{$item}->{'default'} == 0) {
1949: $checked = '';
1950: } elsif ($settings->{$item}->{'default'} == 1) {
1951: $checked = 'checked="checked" ';
1952: }
1.78 raeburn 1953: }
1.72 raeburn 1954: }
1.101 raeburn 1955: $datatable .= '<span class="LC_nobreak"><label>'.
1956: '<input type="checkbox" name="'.$context.'_'.$item.
1957: '" value="default" '.$checked.'/>'.$titles{$item}.
1958: '</label></span> ';
1959: }
1960: }
1961: if ($context eq 'requestcourses') {
1962: $datatable .= '</tr><tr>';
1963: foreach my $item (@usertools) {
1.106 raeburn 1964: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1965: }
1.101 raeburn 1966: $datatable .= '</tr></table>';
1.72 raeburn 1967: }
1.86 raeburn 1968: $datatable .= '</td>';
1.160.6.5 raeburn 1969: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 1970: $datatable .= '<td class="LC_right_item">'.
1971: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1972: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 1973: $defaultquota.'" size="5" /></span>'.(' ' x2).
1974: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1975: '<input type="text" name="authorquota" value="'.
1976: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1977: }
1978: $datatable .= '</tr>';
1.72 raeburn 1979: $typecount ++;
1980: $css_class = $typecount%2?' class="LC_odd_row"':'';
1981: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 1982: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1983: if ($context eq 'requestcourses') {
1.109 raeburn 1984: $datatable .= &mt('(overrides affiliation, if set)').
1985: '</td>'.
1986: '<td class="LC_left_item">'.
1987: '<table><tr>';
1.101 raeburn 1988: } else {
1.109 raeburn 1989: $datatable .= &mt('(overrides affiliation, if checked)').
1990: '</td>'.
1991: '<td class="LC_left_item" colspan="2">'.
1992: '<br />';
1.101 raeburn 1993: }
1994: my %advcell;
1.72 raeburn 1995: foreach my $item (@usertools) {
1.101 raeburn 1996: if ($context eq 'requestcourses') {
1997: my ($curroption,$currlimit);
1998: if (ref($settings) eq 'HASH') {
1999: if (ref($settings->{$item}) eq 'HASH') {
2000: $curroption = $settings->{$item}->{'_LC_adv'};
2001: if ($curroption =~ /^autolimit=(\d*)$/) {
2002: $currlimit = $1;
2003: }
2004: }
2005: }
2006: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2007: my $checked = '';
2008: if ($curroption eq '') {
2009: $checked = ' checked="checked"';
2010: }
2011: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2012: '<input type="radio" name="crsreq_'.$item.
2013: '__LC_adv" value=""'.$checked.' />'.
2014: &mt('No override set').'</label></span> ';
1.101 raeburn 2015: foreach my $option (@options) {
2016: my $val = $option;
2017: if ($option eq 'norequest') {
2018: $val = 0;
2019: }
2020: if ($option eq 'validate') {
2021: my $canvalidate = 0;
2022: if (ref($validations{$item}) eq 'HASH') {
2023: if ($validations{$item}{'_LC_adv'}) {
2024: $canvalidate = 1;
2025: }
2026: }
2027: next if (!$canvalidate);
2028: }
2029: my $checked = '';
1.104 raeburn 2030: if ($val eq $curroption) {
1.101 raeburn 2031: $checked = ' checked="checked"';
2032: } elsif ($option eq 'autolimit') {
2033: if ($curroption =~ /^autolimit/) {
2034: $checked = ' checked="checked"';
2035: }
2036: }
2037: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2038: '<input type="radio" name="crsreq_'.$item.
2039: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2040: $titles{$option}.'</label>';
2041: if ($option eq 'autolimit') {
1.127 raeburn 2042: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2043: $item.'_limit__LC_adv" size="1" '.
2044: 'value="'.$currlimit.'" />';
2045: }
1.127 raeburn 2046: $advcell{$item} .= '</span> ';
1.104 raeburn 2047: if ($option eq 'autolimit') {
1.127 raeburn 2048: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2049: }
1.101 raeburn 2050: }
1.160.6.5 raeburn 2051: } elsif ($context eq 'requestauthor') {
2052: my $curroption;
2053: if (ref($settings) eq 'HASH') {
2054: $curroption = $settings->{'_LC_adv'};
2055: }
2056: my $checked = '';
2057: if ($curroption eq '') {
2058: $checked = ' checked="checked"';
2059: }
2060: $datatable .= '<span class="LC_nobreak"><label>'.
2061: '<input type="radio" name="authorreq__LC_adv"'.
2062: ' value=""'.$checked.' />'.
2063: &mt('No override set').'</label></span> ';
2064: foreach my $option (@options) {
2065: my $val = $option;
2066: if ($option eq 'norequest') {
2067: $val = 0;
2068: }
2069: my $checked = '';
2070: if ($val eq $curroption) {
2071: $checked = ' checked="checked"';
2072: }
2073: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2074: '<input type="radio" name="authorreq__LC_adv"'.
2075: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2076: $titles{$option}.'</label></span> ';
2077: }
1.101 raeburn 2078: } else {
2079: my $checked = 'checked="checked" ';
2080: if (ref($settings) eq 'HASH') {
2081: if (ref($settings->{$item}) eq 'HASH') {
2082: if ($settings->{$item}->{'_LC_adv'} == 0) {
2083: $checked = '';
2084: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2085: $checked = 'checked="checked" ';
2086: }
1.79 raeburn 2087: }
1.72 raeburn 2088: }
1.101 raeburn 2089: $datatable .= '<span class="LC_nobreak"><label>'.
2090: '<input type="checkbox" name="'.$context.'_'.$item.
2091: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2092: '</label></span> ';
2093: }
2094: }
2095: if ($context eq 'requestcourses') {
2096: $datatable .= '</tr><tr>';
2097: foreach my $item (@usertools) {
1.106 raeburn 2098: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2099: }
1.101 raeburn 2100: $datatable .= '</tr></table>';
1.72 raeburn 2101: }
1.98 raeburn 2102: $datatable .= '</td></tr>';
1.30 raeburn 2103: $$rowtotal += $typecount;
1.3 raeburn 2104: return $datatable;
2105: }
2106:
1.160.6.5 raeburn 2107: sub print_requestmail {
2108: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2109: my ($now,$datatable,%currapp);
1.102 raeburn 2110: $now = time;
2111: if (ref($settings) eq 'HASH') {
2112: if (ref($settings->{'notify'}) eq 'HASH') {
2113: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2114: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2115: }
2116: }
2117: }
1.160.6.16 raeburn 2118: my $numinrow = 2;
1.160.6.34 raeburn 2119: my $css_class;
2120: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2121: my $text;
2122: if ($action eq 'requestcourses') {
2123: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2124: } elsif ($action eq 'requestauthor') {
2125: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2126: } else {
1.160.6.34 raeburn 2127: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2128: }
1.160.6.34 raeburn 2129: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2130: ' <td>'.$text.'</td>'.
1.102 raeburn 2131: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2132: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2133: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2134: if ($numdc > 0) {
2135: $datatable .= $table;
1.102 raeburn 2136: } else {
2137: $datatable .= &mt('There are no active Domain Coordinators');
2138: }
2139: $datatable .='</td></tr>';
2140: return $datatable;
2141: }
2142:
1.160.6.30 raeburn 2143: sub print_studentcode {
2144: my ($settings,$rowtotal) = @_;
2145: my $rownum = 0;
2146: my ($output,%current);
2147: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2148: if (ref($settings) eq 'HASH') {
2149: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2150: foreach my $type (@crstypes) {
2151: $current{$type} = $settings->{'uniquecode'}{$type};
2152: }
1.160.6.30 raeburn 2153: }
2154: }
2155: $output .= '<tr>'.
2156: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2157: '<td class="LC_left_item">';
2158: foreach my $type (@crstypes) {
2159: my $check = ' ';
2160: if ($current{$type}) {
2161: $check = ' checked="checked" ';
2162: }
2163: $output .= '<span class="LC_nobreak"><label>'.
2164: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2165: &mt($type).'</label></span>'.(' 'x2).' ';
2166: }
2167: $output .= '</td></tr>';
2168: $$rowtotal ++;
2169: return $output;
2170: }
2171:
2172: sub print_textbookcourses {
1.160.6.46 raeburn 2173: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2174: my $rownum = 0;
2175: my $css_class;
2176: my $itemcount = 1;
2177: my $maxnum = 0;
2178: my $bookshash;
2179: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2180: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2181: }
2182: my %ordered;
2183: if (ref($bookshash) eq 'HASH') {
2184: foreach my $item (keys(%{$bookshash})) {
2185: if (ref($bookshash->{$item}) eq 'HASH') {
2186: my $num = $bookshash->{$item}{'order'};
2187: $ordered{$num} = $item;
2188: }
2189: }
2190: }
2191: my $confname = $dom.'-domainconfig';
2192: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2193: my $maxnum = scalar(keys(%ordered));
2194: my $datatable;
1.160.6.30 raeburn 2195: if (keys(%ordered)) {
2196: my @items = sort { $a <=> $b } keys(%ordered);
2197: for (my $i=0; $i<@items; $i++) {
2198: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2199: my $key = $ordered{$items[$i]};
2200: my %coursehash=&Apache::lonnet::coursedescription($key);
2201: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2202: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2203: if (ref($bookshash->{$key}) eq 'HASH') {
2204: $subject = $bookshash->{$key}->{'subject'};
2205: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2206: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2207: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2208: $author = $bookshash->{$key}->{'author'};
2209: $image = $bookshash->{$key}->{'image'};
2210: if ($image ne '') {
2211: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2212: my $imagethumb = "$path/tn-".$imagefile;
2213: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2214: }
1.160.6.30 raeburn 2215: }
2216: }
1.160.6.46 raeburn 2217: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2218: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2219: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2220: for (my $k=0; $k<=$maxnum; $k++) {
2221: my $vpos = $k+1;
2222: my $selstr;
2223: if ($k == $i) {
2224: $selstr = ' selected="selected" ';
2225: }
2226: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2227: }
2228: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2229: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2230: &mt('Delete?').'</label></span></td>'.
2231: '<td colspan="2">'.
1.160.6.46 raeburn 2232: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2233: (' 'x2).
1.160.6.46 raeburn 2234: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2235: if ($type eq 'textbooks') {
2236: $datatable .= (' 'x2).
1.160.6.47 raeburn 2237: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2238: (' 'x2).
1.160.6.46 raeburn 2239: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2240: (' 'x2).
2241: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2242: if ($image) {
2243: $datatable .= '<span class="LC_nobreak">'.
2244: $imgsrc.
2245: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2246: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2247: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2248: }
2249: if ($switchserver) {
2250: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2251: } else {
2252: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2253: }
1.160.6.30 raeburn 2254: }
1.160.6.46 raeburn 2255: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2256: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2257: $coursetitle.'</span></td></tr>'."\n";
2258: $itemcount ++;
2259: }
2260: }
2261: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2262: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2263: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2264: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2265: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2266: for (my $k=0; $k<$maxnum+1; $k++) {
2267: my $vpos = $k+1;
2268: my $selstr;
2269: if ($k == $maxnum) {
2270: $selstr = ' selected="selected" ';
2271: }
2272: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2273: }
2274: $datatable .= '</select> '."\n".
1.160.6.46 raeburn 2275: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.160.6.30 raeburn 2276: '<td colspan="2">'.
1.160.6.46 raeburn 2277: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2278: (' 'x2).
1.160.6.46 raeburn 2279: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2280: (' 'x2);
2281: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2282: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2283: (' 'x2).
2284: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2285: (' 'x2).
2286: '<span class="LC_nobreak">'.&mt('Image:').' ';
2287: if ($switchserver) {
2288: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2289: } else {
2290: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2291: }
1.160.6.30 raeburn 2292: }
2293: $datatable .= '</span>'."\n".
2294: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2295: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2296: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2297: &Apache::loncommon::selectcourse_link
1.160.6.46 raeburn 2298: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.160.6.30 raeburn 2299: '</span></td>'."\n".
2300: '</tr>'."\n";
2301: $itemcount ++;
2302: return $datatable;
2303: }
2304:
2305: sub textbookcourses_javascript {
1.160.6.46 raeburn 2306: my ($settings) = @_;
2307: return unless(ref($settings) eq 'HASH');
2308: my (%ordered,%total,%jstext);
2309: foreach my $type ('textbooks','templates') {
2310: $total{$type} = 0;
2311: if (ref($settings->{$type}) eq 'HASH') {
2312: foreach my $item (keys(%{$settings->{$type}})) {
2313: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2314: my $num = $settings->{$type}->{$item}{'order'};
2315: $ordered{$type}{$num} = $item;
2316: }
2317: }
2318: $total{$type} = scalar(keys(%{$settings->{$type}}));
2319: }
2320: my @jsarray = ();
2321: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2322: push(@jsarray,$ordered{$type}{$item});
2323: }
2324: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2325: }
2326: return <<"ENDSCRIPT";
2327: <script type="text/javascript">
2328: // <![CDATA[
1.160.6.46 raeburn 2329: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2330: var changedVal;
1.160.6.46 raeburn 2331: $jstext{'textbooks'};
2332: $jstext{'templates'};
2333: var newpos;
2334: var maxh;
2335: if (caller == 'textbooks') {
2336: newpos = 'textbooks_addbook_pos';
2337: maxh = 1 + $total{'textbooks'};
2338: } else {
2339: newpos = 'templates_addbook_pos';
2340: maxh = 1 + $total{'templates'};
2341: }
1.160.6.30 raeburn 2342: var current = new Array;
2343: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2344: if (item == newpos) {
2345: changedVal = newitemVal;
2346: } else {
2347: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2348: current[newitemVal] = newpos;
2349: }
1.160.6.46 raeburn 2350: if (caller == 'textbooks') {
2351: for (var i=0; i<textbooks.length; i++) {
2352: var elementName = 'textbooks_'+textbooks[i];
2353: if (elementName != item) {
2354: if (form.elements[elementName]) {
2355: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2356: current[currVal] = elementName;
2357: }
2358: }
2359: }
2360: }
2361: if (caller == 'templates') {
2362: for (var i=0; i<templates.length; i++) {
2363: var elementName = 'templates_'+templates[i];
2364: if (elementName != item) {
2365: if (form.elements[elementName]) {
2366: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2367: current[currVal] = elementName;
2368: }
1.160.6.30 raeburn 2369: }
2370: }
2371: }
2372: var oldVal;
2373: for (var j=0; j<maxh; j++) {
2374: if (current[j] == undefined) {
2375: oldVal = j;
2376: }
2377: }
2378: if (oldVal < changedVal) {
2379: for (var k=oldVal+1; k<=changedVal ; k++) {
2380: var elementName = current[k];
2381: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2382: }
2383: } else {
2384: for (var k=changedVal; k<oldVal; k++) {
2385: var elementName = current[k];
2386: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2387: }
2388: }
2389: return;
2390: }
2391:
2392: // ]]>
2393: </script>
2394:
2395: ENDSCRIPT
2396: }
2397:
1.3 raeburn 2398: sub print_autoenroll {
1.30 raeburn 2399: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2400: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2401: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2402: if (ref($settings) eq 'HASH') {
2403: if (exists($settings->{'run'})) {
2404: if ($settings->{'run'} eq '0') {
2405: $runoff = ' checked="checked" ';
2406: $runon = ' ';
2407: } else {
2408: $runon = ' checked="checked" ';
2409: $runoff = ' ';
2410: }
2411: } else {
2412: if ($autorun) {
2413: $runon = ' checked="checked" ';
2414: $runoff = ' ';
2415: } else {
2416: $runoff = ' checked="checked" ';
2417: $runon = ' ';
2418: }
2419: }
1.129 raeburn 2420: if (exists($settings->{'co-owners'})) {
2421: if ($settings->{'co-owners'} eq '0') {
2422: $coownersoff = ' checked="checked" ';
2423: $coownerson = ' ';
2424: } else {
2425: $coownerson = ' checked="checked" ';
2426: $coownersoff = ' ';
2427: }
2428: } else {
2429: $coownersoff = ' checked="checked" ';
2430: $coownerson = ' ';
2431: }
1.3 raeburn 2432: if (exists($settings->{'sender_domain'})) {
2433: $defdom = $settings->{'sender_domain'};
2434: }
1.14 raeburn 2435: } else {
2436: if ($autorun) {
2437: $runon = ' checked="checked" ';
2438: $runoff = ' ';
2439: } else {
2440: $runoff = ' checked="checked" ';
2441: $runon = ' ';
2442: }
1.3 raeburn 2443: }
2444: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2445: my $notif_sender;
2446: if (ref($settings) eq 'HASH') {
2447: $notif_sender = $settings->{'sender_uname'};
2448: }
1.3 raeburn 2449: my $datatable='<tr class="LC_odd_row">'.
2450: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2451: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2452: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2453: $runon.' value="1" />'.&mt('Yes').'</label> '.
2454: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2455: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2456: '</tr><tr>'.
2457: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2458: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2459: &mt('username').': '.
2460: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2461: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2462: ': '.$domform.'</span></td></tr>'.
2463: '<tr class="LC_odd_row">'.
2464: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2465: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2466: '<input type="radio" name="autoassign_coowners"'.
2467: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2468: '<label><input type="radio" name="autoassign_coowners"'.
2469: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2470: '</tr>';
2471: $$rowtotal += 3;
1.3 raeburn 2472: return $datatable;
2473: }
2474:
2475: sub print_autoupdate {
1.30 raeburn 2476: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2477: my $datatable;
2478: if ($position eq 'top') {
2479: my $updateon = ' ';
2480: my $updateoff = ' checked="checked" ';
2481: my $classlistson = ' ';
2482: my $classlistsoff = ' checked="checked" ';
2483: if (ref($settings) eq 'HASH') {
2484: if ($settings->{'run'} eq '1') {
2485: $updateon = $updateoff;
2486: $updateoff = ' ';
2487: }
2488: if ($settings->{'classlists'} eq '1') {
2489: $classlistson = $classlistsoff;
2490: $classlistsoff = ' ';
2491: }
2492: }
2493: my %title = (
2494: run => 'Auto-update active?',
2495: classlists => 'Update information in classlists?',
2496: );
2497: $datatable = '<tr class="LC_odd_row">'.
2498: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2499: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2500: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2501: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2502: '<label><input type="radio" name="autoupdate_run"'.
2503: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2504: '</tr><tr>'.
2505: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2506: '<td class="LC_right_item"><span class="LC_nobreak">'.
2507: '<label><input type="radio" name="classlists"'.
2508: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2509: '<label><input type="radio" name="classlists"'.
2510: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2511: '</tr>';
1.30 raeburn 2512: $$rowtotal += 2;
1.131 raeburn 2513: } elsif ($position eq 'middle') {
2514: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2515: my $numinrow = 3;
2516: my $locknamesettings;
2517: $datatable .= &insttypes_row($settings,$types,$usertypes,
2518: $dom,$numinrow,$othertitle,
2519: 'lockablenames');
2520: $$rowtotal ++;
1.3 raeburn 2521: } else {
1.44 raeburn 2522: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2523: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2524: 'permanentemail','id');
1.33 raeburn 2525: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2526: my $numrows = 0;
1.26 raeburn 2527: if (ref($types) eq 'ARRAY') {
2528: if (@{$types} > 0) {
2529: $datatable =
2530: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2531: \@fields,$types,\$numrows);
1.30 raeburn 2532: $$rowtotal += @{$types};
1.26 raeburn 2533: }
1.3 raeburn 2534: }
2535: $datatable .=
2536: &usertype_update_row($settings,{'default' => $othertitle},
2537: \%fieldtitles,\@fields,['default'],
2538: \$numrows);
1.30 raeburn 2539: $$rowtotal ++;
1.3 raeburn 2540: }
2541: return $datatable;
2542: }
2543:
1.125 raeburn 2544: sub print_autocreate {
2545: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2546: my (%createon,%createoff,%currhash);
1.125 raeburn 2547: my @types = ('xml','req');
2548: if (ref($settings) eq 'HASH') {
2549: foreach my $item (@types) {
2550: $createoff{$item} = ' checked="checked" ';
2551: $createon{$item} = ' ';
2552: if (exists($settings->{$item})) {
2553: if ($settings->{$item}) {
2554: $createon{$item} = ' checked="checked" ';
2555: $createoff{$item} = ' ';
2556: }
2557: }
2558: }
1.160.6.16 raeburn 2559: if ($settings->{'xmldc'} ne '') {
2560: $currhash{$settings->{'xmldc'}} = 1;
2561: }
1.125 raeburn 2562: } else {
2563: foreach my $item (@types) {
2564: $createoff{$item} = ' checked="checked" ';
2565: $createon{$item} = ' ';
2566: }
2567: }
2568: $$rowtotal += 2;
1.160.6.16 raeburn 2569: my $numinrow = 2;
1.125 raeburn 2570: my $datatable='<tr class="LC_odd_row">'.
2571: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2572: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2573: '<input type="radio" name="autocreate_xml"'.
2574: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2575: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2576: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2577: '</td></tr><tr>'.
2578: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2579: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2580: '<input type="radio" name="autocreate_req"'.
2581: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2582: '<label><input type="radio" name="autocreate_req"'.
2583: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2584: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2585: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2586: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2587: if ($numdc > 1) {
1.160.6.50 raeburn 2588: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2589: '</td><td class="LC_left_item">';
1.125 raeburn 2590: } else {
1.160.6.50 raeburn 2591: $datatable .= &mt('Course creation processed as:').
2592: '</td><td class="LC_right_item">';
1.125 raeburn 2593: }
1.160.6.50 raeburn 2594: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2595: $$rowtotal += $rows;
1.125 raeburn 2596: return $datatable;
2597: }
2598:
1.23 raeburn 2599: sub print_directorysrch {
1.30 raeburn 2600: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2601: my $srchon = ' ';
2602: my $srchoff = ' checked="checked" ';
1.25 raeburn 2603: my ($exacton,$containson,$beginson);
1.24 raeburn 2604: my $localon = ' ';
2605: my $localoff = ' checked="checked" ';
1.23 raeburn 2606: if (ref($settings) eq 'HASH') {
2607: if ($settings->{'available'} eq '1') {
2608: $srchon = $srchoff;
2609: $srchoff = ' ';
2610: }
1.24 raeburn 2611: if ($settings->{'localonly'} eq '1') {
2612: $localon = $localoff;
2613: $localoff = ' ';
2614: }
1.25 raeburn 2615: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2616: foreach my $type (@{$settings->{'searchtypes'}}) {
2617: if ($type eq 'exact') {
2618: $exacton = ' checked="checked" ';
2619: } elsif ($type eq 'contains') {
2620: $containson = ' checked="checked" ';
2621: } elsif ($type eq 'begins') {
2622: $beginson = ' checked="checked" ';
2623: }
2624: }
2625: } else {
2626: if ($settings->{'searchtypes'} eq 'exact') {
2627: $exacton = ' checked="checked" ';
2628: } elsif ($settings->{'searchtypes'} eq 'contains') {
2629: $containson = ' checked="checked" ';
2630: } elsif ($settings->{'searchtypes'} eq 'specify') {
2631: $exacton = ' checked="checked" ';
2632: $containson = ' checked="checked" ';
2633: }
1.23 raeburn 2634: }
2635: }
2636: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2637: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2638:
2639: my $numinrow = 4;
1.26 raeburn 2640: my $cansrchrow = 0;
1.23 raeburn 2641: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2642: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2643: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2644: '<input type="radio" name="dirsrch_available"'.
2645: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2646: '<label><input type="radio" name="dirsrch_available"'.
2647: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2648: '</tr><tr>'.
1.30 raeburn 2649: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2650: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2651: '<input type="radio" name="dirsrch_localonly"'.
2652: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2653: '<label><input type="radio" name="dirsrch_localonly"'.
2654: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2655: '</tr>';
1.30 raeburn 2656: $$rowtotal += 2;
1.26 raeburn 2657: if (ref($usertypes) eq 'HASH') {
2658: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2659: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2660: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2661: $cansrchrow = 1;
2662: }
2663: }
2664: if ($cansrchrow) {
1.30 raeburn 2665: $$rowtotal ++;
1.26 raeburn 2666: $datatable .= '<tr>';
2667: } else {
2668: $datatable .= '<tr class="LC_odd_row">';
2669: }
1.30 raeburn 2670: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2671: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2672: foreach my $title (@{$titleorder}) {
2673: if (defined($searchtitles->{$title})) {
2674: my $check = ' ';
1.93 raeburn 2675: if (ref($settings) eq 'HASH') {
1.39 raeburn 2676: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2677: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2678: $check = ' checked="checked" ';
2679: }
1.25 raeburn 2680: }
2681: }
2682: $datatable .= '<td class="LC_left_item">'.
2683: '<span class="LC_nobreak"><label>'.
2684: '<input type="checkbox" name="searchby" '.
2685: 'value="'.$title.'"'.$check.'/>'.
2686: $searchtitles->{$title}.'</label></span></td>';
2687: }
2688: }
1.26 raeburn 2689: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2690: $$rowtotal ++;
1.26 raeburn 2691: if ($cansrchrow) {
2692: $datatable .= '<tr class="LC_odd_row">';
2693: } else {
2694: $datatable .= '<tr>';
2695: }
1.30 raeburn 2696: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2697: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2698: '<span class="LC_nobreak"><label>'.
2699: '<input type="checkbox" name="searchtypes" '.
2700: $exacton.' value="exact" />'.&mt('Exact match').
2701: '</label> '.
2702: '<label><input type="checkbox" name="searchtypes" '.
2703: $beginson.' value="begins" />'.&mt('Begins with').
2704: '</label> '.
2705: '<label><input type="checkbox" name="searchtypes" '.
2706: $containson.' value="contains" />'.&mt('Contains').
2707: '</label></span></td></tr>';
1.30 raeburn 2708: $$rowtotal ++;
1.25 raeburn 2709: return $datatable;
2710: }
2711:
1.28 raeburn 2712: sub print_contacts {
1.30 raeburn 2713: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2714: my $datatable;
2715: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2716: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2717: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.23 raeburn 2718: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2719: foreach my $type (@mailings) {
2720: $otheremails{$type} = '';
2721: }
1.134 raeburn 2722: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2723: if (ref($settings) eq 'HASH') {
2724: foreach my $item (@contacts) {
2725: if (exists($settings->{$item})) {
2726: $to{$item} = $settings->{$item};
2727: }
2728: }
2729: foreach my $type (@mailings) {
2730: if (exists($settings->{$type})) {
2731: if (ref($settings->{$type}) eq 'HASH') {
2732: foreach my $item (@contacts) {
2733: if ($settings->{$type}{$item}) {
2734: $checked{$type}{$item} = ' checked="checked" ';
2735: }
2736: }
2737: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2738: if ($type eq 'helpdeskmail') {
2739: $bccemails{$type} = $settings->{$type}{'bcc'};
2740: }
1.28 raeburn 2741: }
1.89 raeburn 2742: } elsif ($type eq 'lonstatusmail') {
2743: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2744: }
2745: }
2746: } else {
2747: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2748: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2749: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2750: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2751: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2752: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2753: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.23 raeburn 2754: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2755: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2756: }
2757: my ($titles,$short_titles) = &contact_titles();
2758: my $rownum = 0;
2759: my $css_class;
2760: foreach my $item (@contacts) {
1.69 raeburn 2761: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2762: $datatable .= '<tr'.$css_class.'>'.
2763: '<td><span class="LC_nobreak">'.$titles->{$item}.
2764: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2765: '<input type="text" name="'.$item.'" value="'.
2766: $to{$item}.'" /></td></tr>';
1.160.6.23 raeburn 2767: $rownum ++;
1.28 raeburn 2768: }
2769: foreach my $type (@mailings) {
1.69 raeburn 2770: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2771: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2772: '<td><span class="LC_nobreak">'.
2773: $titles->{$type}.': </span></td>'.
1.28 raeburn 2774: '<td class="LC_left_item">'.
2775: '<span class="LC_nobreak">';
2776: foreach my $item (@contacts) {
2777: $datatable .= '<label>'.
2778: '<input type="checkbox" name="'.$type.'"'.
2779: $checked{$type}{$item}.
2780: ' value="'.$item.'" />'.$short_titles->{$item}.
2781: '</label> ';
2782: }
2783: $datatable .= '</span><br />'.&mt('Others').': '.
2784: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2785: 'value="'.$otheremails{$type}.'" />';
2786: if ($type eq 'helpdeskmail') {
1.136 raeburn 2787: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2788: '<input type="text" name="'.$type.'_bcc" '.
2789: 'value="'.$bccemails{$type}.'" />';
2790: }
2791: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 2792: $rownum ++;
1.28 raeburn 2793: }
1.160.6.23 raeburn 2794: my %choices;
2795: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2796: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2797: &mt('LON-CAPA core group - MSU'),600,500));
2798: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2799: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2800: &mt('LON-CAPA core group - MSU'),600,500));
2801: my @toggles = ('reporterrors','reportupdates');
2802: my %defaultchecked = ('reporterrors' => 'on',
2803: 'reportupdates' => 'on');
2804: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2805: \%choices,$rownum);
2806: $datatable .= $reports;
1.30 raeburn 2807: $$rowtotal += $rownum;
1.28 raeburn 2808: return $datatable;
2809: }
2810:
1.118 jms 2811: sub print_helpsettings {
1.160.6.5 raeburn 2812: my ($dom,$confname,$settings,$rowtotal) = @_;
2813: my ($datatable,$itemcount);
2814: $itemcount = 1;
2815: my (%choices,%defaultchecked,@toggles);
2816: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2817: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2818: &mt('LON-CAPA bug tracker'),600,500));
2819: %defaultchecked = ('submitbugs' => 'on');
2820: @toggles = ('submitbugs',);
1.122 jms 2821:
1.160.6.5 raeburn 2822: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2823: \%choices,$itemcount);
2824: return $datatable;
1.121 raeburn 2825: }
2826:
2827: sub radiobutton_prefs {
1.160.6.16 raeburn 2828: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 2829: $additional,$align) = @_;
1.121 raeburn 2830: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2831: (ref($choices) eq 'HASH'));
2832:
2833: my (%checkedon,%checkedoff,$datatable,$css_class);
2834:
2835: foreach my $item (@{$toggles}) {
2836: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2837: $checkedon{$item} = ' checked="checked" ';
2838: $checkedoff{$item} = ' ';
1.121 raeburn 2839: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2840: $checkedoff{$item} = ' checked="checked" ';
2841: $checkedon{$item} = ' ';
2842: }
2843: }
2844: if (ref($settings) eq 'HASH') {
1.121 raeburn 2845: foreach my $item (@{$toggles}) {
1.118 jms 2846: if ($settings->{$item} eq '1') {
2847: $checkedon{$item} = ' checked="checked" ';
2848: $checkedoff{$item} = ' ';
2849: } elsif ($settings->{$item} eq '0') {
2850: $checkedoff{$item} = ' checked="checked" ';
2851: $checkedon{$item} = ' ';
2852: }
2853: }
1.121 raeburn 2854: }
1.160.6.16 raeburn 2855: if ($onclick) {
2856: $onclick = ' onclick="'.$onclick.'"';
2857: }
1.121 raeburn 2858: foreach my $item (@{$toggles}) {
1.118 jms 2859: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2860: $datatable .=
1.160.6.16 raeburn 2861: '<tr'.$css_class.'><td valign="top">'.
2862: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 2863: '</span></td>';
2864: if ($align eq 'left') {
2865: $datatable .= '<td class="LC_left_item">';
2866: } else {
2867: $datatable .= '<td class="LC_right_item">';
2868: }
2869: $datatable .=
2870: '<span class="LC_nobreak">'.
1.118 jms 2871: '<label><input type="radio" name="'.
1.160.6.16 raeburn 2872: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2873: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 2874: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2875: '</span>'.$additional.
2876: '</td>'.
1.118 jms 2877: '</tr>';
2878: $itemcount ++;
1.121 raeburn 2879: }
2880: return ($datatable,$itemcount);
2881: }
2882:
2883: sub print_coursedefaults {
1.139 raeburn 2884: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2885: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2886: my $itemcount = 1;
1.160.6.16 raeburn 2887: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 2888: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 2889: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2890: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 2891: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
2892: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
2893: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.16 raeburn 2894: );
1.160.6.21 raeburn 2895: my %staticdefaults = (
2896: anonsurvey_threshold => 10,
2897: uploadquota => 500,
1.160.6.57 raeburn 2898: postsubmit => 60,
1.160.6.21 raeburn 2899: );
1.139 raeburn 2900: if ($position eq 'top') {
1.160.6.57 raeburn 2901: %defaultchecked = (
2902: 'uselcmath' => 'on',
2903: 'usejsme' => 'on',
2904: );
2905: @toggles = ('uselcmath','usejsme');
1.139 raeburn 2906: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 2907: \%choices,$itemcount);
1.139 raeburn 2908: } else {
2909: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.57 raeburn 2910: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout);
1.160.6.16 raeburn 2911: my $currusecredits = 0;
1.160.6.57 raeburn 2912: my $postsubmitclient = 1;
1.160.6.30 raeburn 2913: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2914: if (ref($settings) eq 'HASH') {
2915: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 2916: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2917: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2918: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2919: }
2920: }
1.160.6.16 raeburn 2921: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 2922: foreach my $type (@types) {
2923: next if ($type eq 'community');
2924: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
2925: if ($defcredits{$type} ne '') {
2926: $currusecredits = 1;
2927: }
2928: }
2929: }
2930: if (ref($settings->{'postsubmit'}) eq 'HASH') {
2931: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
2932: $postsubmitclient = 0;
2933: foreach my $type (@types) {
2934: $deftimeout{$type} = $staticdefaults{'postsubmit'};
2935: }
2936: } else {
2937: foreach my $type (@types) {
2938: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
2939: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
2940: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
2941: } else {
2942: $deftimeout{$type} = $staticdefaults{'postsubmit'};
2943: }
2944: } else {
2945: $deftimeout{$type} = $staticdefaults{'postsubmit'};
2946: }
2947: }
2948: }
2949: } else {
2950: foreach my $type (@types) {
2951: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 2952: }
2953: }
1.160.6.58 raeburn 2954: } else {
2955: foreach my $type (@types) {
2956: $deftimeout{$type} = $staticdefaults{'postsubmit'};
2957: }
1.139 raeburn 2958: }
2959: if (!$currdefresponder) {
1.160.6.21 raeburn 2960: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2961: } elsif ($currdefresponder < 1) {
2962: $currdefresponder = 1;
2963: }
1.160.6.21 raeburn 2964: foreach my $type (@types) {
2965: if ($curruploadquota{$type} eq '') {
2966: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2967: }
2968: }
1.139 raeburn 2969: $datatable .=
1.160.6.16 raeburn 2970: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2971: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2972: '</span></td>'.
2973: '<td class="LC_right_item"><span class="LC_nobreak">'.
2974: '<input type="text" name="anonsurvey_threshold"'.
2975: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 2976: '</td></tr>'."\n";
2977: $itemcount ++;
2978: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2979: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2980: $choices{'uploadquota'}.
2981: '</span></td>'.
2982: '<td align="right" class="LC_right_item">'.
2983: '<table><tr>';
1.160.6.21 raeburn 2984: foreach my $type (@types) {
2985: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2986: '<input type="text" name="uploadquota_'.$type.'"'.
2987: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2988: }
2989: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 2990: $itemcount ++;
1.160.6.40 raeburn 2991: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 2992: my $display = 'none';
2993: if ($currusecredits) {
2994: $display = 'block';
2995: }
2996: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 2997: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
2998: foreach my $type (@types) {
2999: next if ($type eq 'community');
3000: $additional .= '<td align="center">'.&mt($type).'<br />'.
3001: '<input type="text" name="'.$type.'_credits"'.
3002: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3003: }
3004: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 3005: %defaultchecked = ('coursecredits' => 'off');
3006: @toggles = ('coursecredits');
3007: my $current = {
3008: 'coursecredits' => $currusecredits,
3009: };
3010: (my $table,$itemcount) =
3011: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3012: \%choices,$itemcount,$onclick,$additional,'left');
3013: $datatable .= $table;
3014: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3015: my $display = 'none';
3016: if ($postsubmitclient) {
3017: $display = 'block';
3018: }
3019: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 3020: &mt('Number of seconds submit is disabled').'<br />'.
3021: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3022: '<table><tr>';
1.160.6.57 raeburn 3023: foreach my $type (@types) {
3024: $additional .= '<td align="center">'.&mt($type).'<br />'.
3025: '<input type="text" name="'.$type.'_timeout" value="'.
3026: $deftimeout{$type}.'" size="5" /></td>';
3027: }
3028: $additional .= '</tr></table></div>'."\n";
3029: %defaultchecked = ('postsubmit' => 'on');
3030: @toggles = ('postsubmit');
3031: my $current = {
3032: 'postsubmit' => $postsubmitclient,
3033: };
3034: ($table,$itemcount) =
3035: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3036: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 3037: $datatable .= $table;
1.160.6.37 raeburn 3038: }
3039: $$rowtotal += $itemcount;
3040: return $datatable;
3041: }
3042:
3043: sub print_selfenrollment {
3044: my ($position,$dom,$settings,$rowtotal) = @_;
3045: my ($css_class,$datatable);
3046: my $itemcount = 1;
3047: my @types = ('official','unofficial','community','textbook');
3048: if (($position eq 'top') || ($position eq 'middle')) {
3049: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3050: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3051: my @rows;
3052: my $key;
3053: if ($position eq 'top') {
3054: $key = 'admin';
3055: if (ref($rowsref) eq 'ARRAY') {
3056: @rows = @{$rowsref};
3057: }
3058: } elsif ($position eq 'middle') {
3059: $key = 'default';
3060: @rows = ('types','registered','approval','limit');
3061: }
3062: foreach my $row (@rows) {
3063: if (defined($titlesref->{$row})) {
3064: $itemcount ++;
3065: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3066: $datatable .= '<tr'.$css_class.'>'.
3067: '<td>'.$titlesref->{$row}.'</td>'.
3068: '<td class="LC_left_item">'.
3069: '<table><tr>';
3070: my (%current,%currentcap);
3071: if (ref($settings) eq 'HASH') {
3072: if (ref($settings->{$key}) eq 'HASH') {
3073: foreach my $type (@types) {
3074: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3075: $current{$type} = $settings->{$key}->{$type}->{$row};
3076: }
3077: if (($row eq 'limit') && ($key eq 'default')) {
3078: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3079: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3080: }
3081: }
3082: }
3083: }
3084: }
3085: my %roles = (
3086: '0' => &Apache::lonnet::plaintext('dc'),
3087: );
3088:
3089: foreach my $type (@types) {
3090: unless (($row eq 'registered') && ($key eq 'default')) {
3091: $datatable .= '<th>'.&mt($type).'</th>';
3092: }
3093: }
3094: unless (($row eq 'registered') && ($key eq 'default')) {
3095: $datatable .= '</tr><tr>';
3096: }
3097: foreach my $type (@types) {
3098: if ($type eq 'community') {
3099: $roles{'1'} = &mt('Community personnel');
3100: } else {
3101: $roles{'1'} = &mt('Course personnel');
3102: }
3103: $datatable .= '<td style="vertical-align: top">';
3104: if ($position eq 'top') {
3105: my %checked;
3106: if ($current{$type} eq '0') {
3107: $checked{'0'} = ' checked="checked"';
3108: } else {
3109: $checked{'1'} = ' checked="checked"';
3110: }
3111: foreach my $role ('1','0') {
3112: $datatable .= '<span class="LC_nobreak"><label>'.
3113: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3114: 'value="'.$role.'"'.$checked{$role}.' />'.
3115: $roles{$role}.'</label></span> ';
3116: }
3117: } else {
3118: if ($row eq 'types') {
3119: my %checked;
3120: if ($current{$type} =~ /^(all|dom)$/) {
3121: $checked{$1} = ' checked="checked"';
3122: } else {
3123: $checked{''} = ' checked="checked"';
3124: }
3125: foreach my $val ('','dom','all') {
3126: $datatable .= '<span class="LC_nobreak"><label>'.
3127: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3128: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3129: }
3130: } elsif ($row eq 'registered') {
3131: my %checked;
3132: if ($current{$type} eq '1') {
3133: $checked{'1'} = ' checked="checked"';
3134: } else {
3135: $checked{'0'} = ' checked="checked"';
3136: }
3137: foreach my $val ('0','1') {
3138: $datatable .= '<span class="LC_nobreak"><label>'.
3139: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3140: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3141: }
3142: } elsif ($row eq 'approval') {
3143: my %checked;
3144: if ($current{$type} =~ /^([12])$/) {
3145: $checked{$1} = ' checked="checked"';
3146: } else {
3147: $checked{'0'} = ' checked="checked"';
3148: }
3149: for my $val (0..2) {
3150: $datatable .= '<span class="LC_nobreak"><label>'.
3151: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3152: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3153: }
3154: } elsif ($row eq 'limit') {
3155: my %checked;
3156: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3157: $checked{$1} = ' checked="checked"';
3158: } else {
3159: $checked{'none'} = ' checked="checked"';
3160: }
3161: my $cap;
3162: if ($currentcap{$type} =~ /^\d+$/) {
3163: $cap = $currentcap{$type};
3164: }
3165: foreach my $val ('none','allstudents','selfenrolled') {
3166: $datatable .= '<span class="LC_nobreak"><label>'.
3167: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3168: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3169: }
3170: $datatable .= '<br />'.
3171: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3172: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3173: '</span>';
3174: }
3175: }
3176: $datatable .= '</td>';
3177: }
3178: $datatable .= '</tr>';
3179: }
3180: $datatable .= '</table></td></tr>';
3181: }
3182: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3183: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3184: }
3185: $$rowtotal += $itemcount;
3186: return $datatable;
3187: }
3188:
3189: sub print_validation_rows {
3190: my ($caller,$dom,$settings,$rowtotal) = @_;
3191: my ($itemsref,$namesref,$fieldsref);
3192: if ($caller eq 'selfenroll') {
3193: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3194: } elsif ($caller eq 'requestcourses') {
3195: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3196: }
3197: my %currvalidation;
3198: if (ref($settings) eq 'HASH') {
3199: if (ref($settings->{'validation'}) eq 'HASH') {
3200: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3201: }
1.160.6.39 raeburn 3202: }
3203: my $datatable;
3204: my $itemcount = 0;
3205: foreach my $item (@{$itemsref}) {
3206: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3207: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3208: $namesref->{$item}.
3209: '</span></td>'.
3210: '<td class="LC_left_item">';
3211: if (($item eq 'url') || ($item eq 'button')) {
3212: $datatable .= '<span class="LC_nobreak">'.
3213: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3214: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3215: } elsif ($item eq 'fields') {
3216: my @currfields;
3217: if (ref($currvalidation{$item}) eq 'ARRAY') {
3218: @currfields = @{$currvalidation{$item}};
3219: }
3220: foreach my $field (@{$fieldsref}) {
3221: my $check = '';
3222: if (grep(/^\Q$field\E$/,@currfields)) {
3223: $check = ' checked="checked"';
3224: }
3225: $datatable .= '<span class="LC_nobreak"><label>'.
3226: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3227: ' value="'.$field.'"'.$check.' />'.$field.
3228: '</label></span> ';
3229: }
3230: } elsif ($item eq 'markup') {
3231: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3232: $currvalidation{$item}.
1.160.6.37 raeburn 3233: '</textarea>';
1.160.6.39 raeburn 3234: }
3235: $datatable .= '</td></tr>'."\n";
3236: if (ref($rowtotal)) {
1.160.6.37 raeburn 3237: $itemcount ++;
3238: }
1.139 raeburn 3239: }
1.160.6.39 raeburn 3240: if ($caller eq 'requestcourses') {
3241: my %currhash;
1.160.6.51 raeburn 3242: if (ref($settings) eq 'HASH') {
3243: if (ref($settings->{'validation'}) eq 'HASH') {
3244: if ($settings->{'validation'}{'dc'} ne '') {
3245: $currhash{$settings->{'validation'}{'dc'}} = 1;
3246: }
1.160.6.39 raeburn 3247: }
3248: }
3249: my $numinrow = 2;
3250: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3251: 'validationdc',%currhash);
1.160.6.50 raeburn 3252: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3253: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.160.6.39 raeburn 3254: if ($numdc > 1) {
1.160.6.50 raeburn 3255: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 3256: } else {
1.160.6.50 raeburn 3257: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 3258: }
1.160.6.50 raeburn 3259: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 3260: $itemcount ++;
3261: }
3262: if (ref($rowtotal)) {
3263: $$rowtotal += $itemcount;
3264: }
1.121 raeburn 3265: return $datatable;
1.118 jms 3266: }
3267:
1.137 raeburn 3268: sub print_usersessions {
3269: my ($position,$dom,$settings,$rowtotal) = @_;
3270: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3271: my (%by_ip,%by_location,@intdoms);
3272: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3273:
3274: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3275: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3276: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3277: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3278: my $itemcount = 1;
3279: if ($position eq 'top') {
1.152 raeburn 3280: if (keys(%serverhomes) > 1) {
1.145 raeburn 3281: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 3282: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 3283: } else {
1.140 raeburn 3284: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3285: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3286: }
1.137 raeburn 3287: } else {
1.145 raeburn 3288: if (keys(%by_location) == 0) {
3289: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3290: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3291: } else {
3292: my %lt = &usersession_titles();
3293: my $numinrow = 5;
3294: my $prefix;
3295: my @types;
3296: if ($position eq 'bottom') {
3297: $prefix = 'remote';
3298: @types = ('version','excludedomain','includedomain');
3299: } else {
3300: $prefix = 'hosted';
3301: @types = ('excludedomain','includedomain');
3302: }
3303: my (%current,%checkedon,%checkedoff);
3304: my @lcversions = &Apache::lonnet::all_loncaparevs();
3305: my @locations = sort(keys(%by_location));
3306: foreach my $type (@types) {
3307: $checkedon{$type} = '';
3308: $checkedoff{$type} = ' checked="checked"';
3309: }
3310: if (ref($settings) eq 'HASH') {
3311: if (ref($settings->{$prefix}) eq 'HASH') {
3312: foreach my $key (keys(%{$settings->{$prefix}})) {
3313: $current{$key} = $settings->{$prefix}{$key};
3314: if ($key eq 'version') {
3315: if ($current{$key} ne '') {
3316: $checkedon{$key} = ' checked="checked"';
3317: $checkedoff{$key} = '';
3318: }
3319: } elsif (ref($current{$key}) eq 'ARRAY') {
3320: $checkedon{$key} = ' checked="checked"';
3321: $checkedoff{$key} = '';
3322: }
1.137 raeburn 3323: }
3324: }
3325: }
1.145 raeburn 3326: foreach my $type (@types) {
3327: next if ($type ne 'version' && !@locations);
3328: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3329: $datatable .= '<tr'.$css_class.'>
3330: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3331: <span class="LC_nobreak">
3332: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3333: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3334: if ($type eq 'version') {
3335: my $selector = '<select name="'.$prefix.'_version">';
3336: foreach my $version (@lcversions) {
3337: my $selected = '';
3338: if ($current{'version'} eq $version) {
3339: $selected = ' selected="selected"';
3340: }
3341: $selector .= ' <option value="'.$version.'"'.
3342: $selected.'>'.$version.'</option>';
3343: }
3344: $selector .= '</select> ';
3345: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3346: } else {
3347: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3348: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3349: ' />'.(' 'x2).
3350: '<input type="button" value="'.&mt('uncheck all').'" '.
3351: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3352: "\n".
3353: '</div><div><table>';
3354: my $rem;
3355: for (my $i=0; $i<@locations; $i++) {
3356: my ($showloc,$value,$checkedtype);
3357: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3358: my $ip = $by_location{$locations[$i]}->[0];
3359: if (ref($by_ip{$ip}) eq 'ARRAY') {
3360: $value = join(':',@{$by_ip{$ip}});
3361: $showloc = join(', ',@{$by_ip{$ip}});
3362: if (ref($current{$type}) eq 'ARRAY') {
3363: foreach my $loc (@{$by_ip{$ip}}) {
3364: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3365: $checkedtype = ' checked="checked"';
3366: last;
3367: }
3368: }
1.138 raeburn 3369: }
3370: }
3371: }
1.145 raeburn 3372: $rem = $i%($numinrow);
3373: if ($rem == 0) {
3374: if ($i > 0) {
3375: $datatable .= '</tr>';
3376: }
3377: $datatable .= '<tr>';
3378: }
3379: $datatable .= '<td class="LC_left_item">'.
3380: '<span class="LC_nobreak"><label>'.
3381: '<input type="checkbox" name="'.$prefix.'_'.$type.
3382: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3383: '</label></span></td>';
1.137 raeburn 3384: }
1.145 raeburn 3385: $rem = @locations%($numinrow);
3386: my $colsleft = $numinrow - $rem;
3387: if ($colsleft > 1 ) {
3388: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3389: ' </td>';
3390: } elsif ($colsleft == 1) {
3391: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3392: }
1.145 raeburn 3393: $datatable .= '</tr></table>';
1.137 raeburn 3394: }
1.145 raeburn 3395: $datatable .= '</td></tr>';
3396: $itemcount ++;
1.137 raeburn 3397: }
3398: }
3399: }
3400: $$rowtotal += $itemcount;
3401: return $datatable;
3402: }
3403:
1.138 raeburn 3404: sub build_location_hashes {
3405: my ($intdoms,$by_ip,$by_location) = @_;
3406: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3407: (ref($by_location) eq 'HASH'));
3408: my %iphost = &Apache::lonnet::get_iphost();
3409: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3410: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3411: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3412: foreach my $id (@{$iphost{$primary_ip}}) {
3413: my $intdom = &Apache::lonnet::internet_dom($id);
3414: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3415: push(@{$intdoms},$intdom);
3416: }
3417: }
3418: }
3419: foreach my $ip (keys(%iphost)) {
3420: if (ref($iphost{$ip}) eq 'ARRAY') {
3421: foreach my $id (@{$iphost{$ip}}) {
3422: my $location = &Apache::lonnet::internet_dom($id);
3423: if ($location) {
3424: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3425: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3426: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3427: push(@{$by_ip->{$ip}},$location);
3428: }
3429: } else {
3430: $by_ip->{$ip} = [$location];
3431: }
3432: }
3433: }
3434: }
3435: }
3436: foreach my $ip (sort(keys(%{$by_ip}))) {
3437: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3438: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3439: my $first = $by_ip->{$ip}->[0];
3440: if (ref($by_location->{$first}) eq 'ARRAY') {
3441: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3442: push(@{$by_location->{$first}},$ip);
3443: }
3444: } else {
3445: $by_location->{$first} = [$ip];
3446: }
3447: }
3448: }
3449: return;
3450: }
3451:
1.145 raeburn 3452: sub current_offloads_to {
3453: my ($dom,$settings,$servers) = @_;
3454: my (%spareid,%otherdomconfigs);
1.152 raeburn 3455: if (ref($servers) eq 'HASH') {
1.145 raeburn 3456: foreach my $lonhost (sort(keys(%{$servers}))) {
3457: my $gotspares;
1.152 raeburn 3458: if (ref($settings) eq 'HASH') {
3459: if (ref($settings->{'spares'}) eq 'HASH') {
3460: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3461: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3462: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3463: $gotspares = 1;
3464: }
1.145 raeburn 3465: }
3466: }
3467: unless ($gotspares) {
3468: my $gotspares;
3469: my $serverhomeID =
3470: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3471: my $serverhomedom =
3472: &Apache::lonnet::host_domain($serverhomeID);
3473: if ($serverhomedom ne $dom) {
3474: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3475: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3476: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3477: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3478: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3479: $gotspares = 1;
3480: }
3481: }
3482: } else {
3483: $otherdomconfigs{$serverhomedom} =
3484: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3485: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3486: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3487: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3488: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3489: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3490: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3491: $gotspares = 1;
3492: }
3493: }
3494: }
3495: }
3496: }
3497: }
3498: }
3499: unless ($gotspares) {
3500: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3501: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3502: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3503: } else {
3504: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3505: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3506: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3507: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3508: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3509: } else {
1.150 raeburn 3510: my %what = (
3511: spareid => 1,
3512: );
3513: my ($result,$returnhash) =
3514: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3515: if ($result eq 'ok') {
3516: if (ref($returnhash) eq 'HASH') {
3517: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3518: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3519: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3520: }
3521: }
1.145 raeburn 3522: }
3523: }
3524: }
3525: }
3526: }
3527: }
3528: return %spareid;
3529: }
3530:
3531: sub spares_row {
1.152 raeburn 3532: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3533: my $css_class;
3534: my $numinrow = 4;
3535: my $itemcount = 1;
3536: my $datatable;
1.152 raeburn 3537: my %typetitles = &sparestype_titles();
3538: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3539: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3540: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3541: my ($othercontrol,$serverdom);
3542: if ($serverhome ne $server) {
3543: $serverdom = &Apache::lonnet::host_domain($serverhome);
3544: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3545: } else {
3546: $serverdom = &Apache::lonnet::host_domain($server);
3547: if ($serverdom ne $dom) {
3548: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3549: }
3550: }
3551: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3552: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3553: $datatable .= '<tr'.$css_class.'>
3554: <td rowspan="2">
1.160.6.13 raeburn 3555: <span class="LC_nobreak">'.
3556: &mt('[_1] when busy, offloads to:'
3557: ,'<b>'.$server.'</b>').
3558: "\n";
1.145 raeburn 3559: my (%current,%canselect);
1.152 raeburn 3560: my @choices =
3561: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3562: foreach my $type ('primary','default') {
3563: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3564: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3565: my @spares = @{$spareid->{$server}{$type}};
3566: if (@spares > 0) {
1.152 raeburn 3567: if ($othercontrol) {
3568: $current{$type} = join(', ',@spares);
3569: } else {
3570: $current{$type} .= '<table>';
3571: my $numspares = scalar(@spares);
3572: for (my $i=0; $i<@spares; $i++) {
3573: my $rem = $i%($numinrow);
3574: if ($rem == 0) {
3575: if ($i > 0) {
3576: $current{$type} .= '</tr>';
3577: }
3578: $current{$type} .= '<tr>';
1.145 raeburn 3579: }
1.152 raeburn 3580: $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'".');" /> '.
3581: $spareid->{$server}{$type}[$i].
3582: '</label></td>'."\n";
3583: }
3584: my $rem = @spares%($numinrow);
3585: my $colsleft = $numinrow - $rem;
3586: if ($colsleft > 1 ) {
3587: $current{$type} .= '<td colspan="'.$colsleft.
3588: '" class="LC_left_item">'.
3589: ' </td>';
3590: } elsif ($colsleft == 1) {
3591: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3592: }
1.152 raeburn 3593: $current{$type} .= '</tr></table>';
1.150 raeburn 3594: }
1.145 raeburn 3595: }
3596: }
3597: if ($current{$type} eq '') {
3598: $current{$type} = &mt('None specified');
3599: }
1.152 raeburn 3600: if ($othercontrol) {
3601: if ($type eq 'primary') {
3602: $canselect{$type} = $othercontrol;
3603: }
3604: } else {
3605: $canselect{$type} =
3606: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3607: '<select name="newspare_'.$type.'_'.$server.'" '.
3608: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3609: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3610: if (@choices > 0) {
3611: foreach my $lonhost (@choices) {
3612: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3613: }
3614: }
3615: $canselect{$type} .= '</select>'."\n";
3616: }
3617: } else {
3618: $current{$type} = &mt('Could not be determined');
3619: if ($type eq 'primary') {
3620: $canselect{$type} = $othercontrol;
3621: }
1.145 raeburn 3622: }
1.152 raeburn 3623: if ($type eq 'default') {
3624: $datatable .= '<tr'.$css_class.'>';
3625: }
3626: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3627: '<td>'.$current{$type}.'</td>'."\n".
3628: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3629: }
3630: $itemcount ++;
3631: }
3632: }
3633: $$rowtotal += $itemcount;
3634: return $datatable;
3635: }
3636:
1.152 raeburn 3637: sub possible_newspares {
3638: my ($server,$currspares,$serverhomes,$altids) = @_;
3639: my $serverhostname = &Apache::lonnet::hostname($server);
3640: my %excluded;
3641: if ($serverhostname ne '') {
3642: %excluded = (
3643: $serverhostname => 1,
3644: );
3645: }
3646: if (ref($currspares) eq 'HASH') {
3647: foreach my $type (keys(%{$currspares})) {
3648: if (ref($currspares->{$type}) eq 'ARRAY') {
3649: if (@{$currspares->{$type}} > 0) {
3650: foreach my $curr (@{$currspares->{$type}}) {
3651: my $hostname = &Apache::lonnet::hostname($curr);
3652: $excluded{$hostname} = 1;
3653: }
3654: }
3655: }
3656: }
3657: }
3658: my @choices;
3659: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3660: if (keys(%{$serverhomes}) > 1) {
3661: foreach my $name (sort(keys(%{$serverhomes}))) {
3662: unless ($excluded{$name}) {
3663: if (exists($altids->{$serverhomes->{$name}})) {
3664: push(@choices,$altids->{$serverhomes->{$name}});
3665: } else {
3666: push(@choices,$serverhomes->{$name});
1.145 raeburn 3667: }
3668: }
3669: }
3670: }
3671: }
1.152 raeburn 3672: return sort(@choices);
1.145 raeburn 3673: }
3674:
1.150 raeburn 3675: sub print_loadbalancing {
3676: my ($dom,$settings,$rowtotal) = @_;
3677: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3678: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3679: my $numinrow = 1;
3680: my $datatable;
3681: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 3682: my (%currbalancer,%currtargets,%currrules,%existing);
3683: if (ref($settings) eq 'HASH') {
3684: %existing = %{$settings};
3685: }
3686: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3687: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3688: \%currtargets,\%currrules);
1.150 raeburn 3689: } else {
3690: return;
3691: }
3692: my ($othertitle,$usertypes,$types) =
3693: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 3694: my $rownum = 8;
1.150 raeburn 3695: if (ref($types) eq 'ARRAY') {
3696: $rownum += scalar(@{$types});
3697: }
1.160.6.7 raeburn 3698: my @css_class = ('LC_odd_row','LC_even_row');
3699: my $balnum = 0;
3700: my $islast;
3701: my (@toshow,$disabledtext);
3702: if (keys(%currbalancer) > 0) {
3703: @toshow = sort(keys(%currbalancer));
3704: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3705: push(@toshow,'');
3706: }
3707: } else {
3708: @toshow = ('');
3709: $disabledtext = &mt('No existing load balancer');
3710: }
3711: foreach my $lonhost (@toshow) {
3712: if ($balnum == scalar(@toshow)-1) {
3713: $islast = 1;
3714: } else {
3715: $islast = 0;
3716: }
3717: my $cssidx = $balnum%2;
3718: my $targets_div_style = 'display: none';
3719: my $disabled_div_style = 'display: block';
3720: my $homedom_div_style = 'display: none';
3721: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3722: '<td rowspan="'.$rownum.'" valign="top">'.
3723: '<p>';
3724: if ($lonhost eq '') {
3725: $datatable .= '<span class="LC_nobreak">';
3726: if (keys(%currbalancer) > 0) {
3727: $datatable .= &mt('Add balancer:');
3728: } else {
3729: $datatable .= &mt('Enable balancer:');
3730: }
3731: $datatable .= ' '.
3732: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3733: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3734: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3735: '<option value="" selected="selected">'.&mt('None').
3736: '</option>'."\n";
3737: foreach my $server (sort(keys(%servers))) {
3738: next if ($currbalancer{$server});
3739: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3740: }
3741: $datatable .=
3742: '</select>'."\n".
3743: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3744: } else {
3745: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3746: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3747: &mt('Stop balancing').'</label>'.
3748: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3749: $targets_div_style = 'display: block';
3750: $disabled_div_style = 'display: none';
3751: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3752: $homedom_div_style = 'display: block';
3753: }
3754: }
3755: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3756: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3757: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3758: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3759: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3760: my @sparestypes = ('primary','default');
3761: my %typetitles = &sparestype_titles();
3762: foreach my $sparetype (@sparestypes) {
3763: my $targettable;
3764: for (my $i=0; $i<$numspares; $i++) {
3765: my $checked;
3766: if (ref($currtargets{$lonhost}) eq 'HASH') {
3767: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3768: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3769: $checked = ' checked="checked"';
3770: }
3771: }
3772: }
3773: my ($chkboxval,$disabled);
3774: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3775: $chkboxval = $spares[$i];
3776: }
3777: if (exists($currbalancer{$spares[$i]})) {
3778: $disabled = ' disabled="disabled"';
3779: }
3780: $targettable .=
1.160.6.55 raeburn 3781: '<td><span class="LC_nobreak"><label>'.
3782: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 3783: $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 3784: '</span></label></span></td>';
1.160.6.7 raeburn 3785: my $rem = $i%($numinrow);
3786: if ($rem == 0) {
3787: if (($i > 0) && ($i < $numspares-1)) {
3788: $targettable .= '</tr>';
3789: }
3790: if ($i < $numspares-1) {
3791: $targettable .= '<tr>';
1.150 raeburn 3792: }
3793: }
3794: }
1.160.6.7 raeburn 3795: if ($targettable ne '') {
3796: my $rem = $numspares%($numinrow);
3797: my $colsleft = $numinrow - $rem;
3798: if ($colsleft > 1 ) {
3799: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3800: ' </td>';
3801: } elsif ($colsleft == 1) {
3802: $targettable .= '<td class="LC_left_item"> </td>';
3803: }
3804: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3805: '<table><tr>'.$targettable.'</tr></table><br />';
3806: }
3807: }
3808: $datatable .= '</div></td></tr>'.
3809: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3810: $othertitle,$usertypes,$types,\%servers,
3811: \%currbalancer,$lonhost,
3812: $targets_div_style,$homedom_div_style,
3813: $css_class[$cssidx],$balnum,$islast);
3814: $$rowtotal += $rownum;
3815: $balnum ++;
3816: }
3817: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3818: return $datatable;
3819: }
3820:
3821: sub get_loadbalancers_config {
3822: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3823: return unless ((ref($servers) eq 'HASH') &&
3824: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3825: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3826: if (keys(%{$existing}) > 0) {
3827: my $oldlonhost;
3828: foreach my $key (sort(keys(%{$existing}))) {
3829: if ($key eq 'lonhost') {
3830: $oldlonhost = $existing->{'lonhost'};
3831: $currbalancer->{$oldlonhost} = 1;
3832: } elsif ($key eq 'targets') {
3833: if ($oldlonhost) {
3834: $currtargets->{$oldlonhost} = $existing->{'targets'};
3835: }
3836: } elsif ($key eq 'rules') {
3837: if ($oldlonhost) {
3838: $currrules->{$oldlonhost} = $existing->{'rules'};
3839: }
3840: } elsif (ref($existing->{$key}) eq 'HASH') {
3841: $currbalancer->{$key} = 1;
3842: $currtargets->{$key} = $existing->{$key}{'targets'};
3843: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3844: }
3845: }
1.160.6.7 raeburn 3846: } else {
3847: my ($balancerref,$targetsref) =
3848: &Apache::lonnet::get_lonbalancer_config($servers);
3849: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3850: foreach my $server (sort(keys(%{$balancerref}))) {
3851: $currbalancer->{$server} = 1;
3852: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3853: }
3854: }
3855: }
1.160.6.7 raeburn 3856: return;
1.150 raeburn 3857: }
3858:
3859: sub loadbalancing_rules {
3860: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3861: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3862: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3863: my $output;
1.160.6.7 raeburn 3864: my $num = 0;
3865: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3866: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3867: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3868: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3869: $num ++;
1.150 raeburn 3870: my $current;
3871: if (ref($currrules) eq 'HASH') {
3872: $current = $currrules->{$type};
3873: }
1.160.6.55 raeburn 3874: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 3875: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3876: $current = '';
3877: }
3878: }
3879: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3880: $servers,$currbalancer,$lonhost,$dom,
3881: $targets_div_style,$homedom_div_style,
3882: $css_class,$balnum,$num,$islast);
1.150 raeburn 3883: }
3884: }
3885: return $output;
3886: }
3887:
3888: sub loadbalancing_titles {
3889: my ($dom,$intdom,$usertypes,$types) = @_;
3890: my %othertypes = (
3891: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3892: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3893: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3894: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 3895: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3896: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3897: );
1.160.6.26 raeburn 3898: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3899: if (ref($types) eq 'ARRAY') {
3900: unshift(@alltypes,@{$types},'default');
3901: }
3902: my %titles;
3903: foreach my $type (@alltypes) {
3904: if ($type =~ /^_LC_/) {
3905: $titles{$type} = $othertypes{$type};
3906: } elsif ($type eq 'default') {
3907: $titles{$type} = &mt('All users from [_1]',$dom);
3908: if (ref($types) eq 'ARRAY') {
3909: if (@{$types} > 0) {
3910: $titles{$type} = &mt('Other users from [_1]',$dom);
3911: }
3912: }
3913: } elsif (ref($usertypes) eq 'HASH') {
3914: $titles{$type} = $usertypes->{$type};
3915: }
3916: }
3917: return (\@alltypes,\%othertypes,\%titles);
3918: }
3919:
3920: sub loadbalance_rule_row {
1.160.6.7 raeburn 3921: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3922: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 3923: my @rulenames;
1.150 raeburn 3924: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 3925: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 3926: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 3927: } else {
1.160.6.26 raeburn 3928: @rulenames = ('default','homeserver');
3929: if ($type eq '_LC_external') {
3930: push(@rulenames,'externalbalancer');
3931: } else {
3932: push(@rulenames,'specific');
3933: }
3934: push(@rulenames,'none');
1.150 raeburn 3935: }
3936: my $style = $targets_div_style;
1.160.6.55 raeburn 3937: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 3938: $style = $homedom_div_style;
3939: }
1.160.6.7 raeburn 3940: my $space;
3941: if ($islast && $num == 1) {
3942: $space = '<div display="inline-block"> </div>';
3943: }
3944: my $output =
3945: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3946: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3947: '<td valaign="top">'.$space.
3948: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3949: for (my $i=0; $i<@rulenames; $i++) {
3950: my $rule = $rulenames[$i];
3951: my ($checked,$extra);
3952: if ($rulenames[$i] eq 'default') {
3953: $rule = '';
3954: }
3955: if ($rulenames[$i] eq 'specific') {
3956: if (ref($servers) eq 'HASH') {
3957: my $default;
3958: if (($current ne '') && (exists($servers->{$current}))) {
3959: $checked = ' checked="checked"';
3960: }
3961: unless ($checked) {
3962: $default = ' selected="selected"';
3963: }
1.160.6.7 raeburn 3964: $extra =
3965: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3966: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3967: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3968: '<option value=""'.$default.'></option>'."\n";
3969: foreach my $server (sort(keys(%{$servers}))) {
3970: if (ref($currbalancer) eq 'HASH') {
3971: next if (exists($currbalancer->{$server}));
3972: }
1.150 raeburn 3973: my $selected;
1.160.6.7 raeburn 3974: if ($server eq $current) {
1.150 raeburn 3975: $selected = ' selected="selected"';
3976: }
1.160.6.7 raeburn 3977: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3978: }
3979: $extra .= '</select>';
3980: }
3981: } elsif ($rule eq $current) {
3982: $checked = ' checked="checked"';
3983: }
3984: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3985: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3986: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3987: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 3988: ')"'.$checked.' /> ';
1.160.6.56 raeburn 3989: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 3990: $output .= $ruletitles{'particular'};
3991: } else {
3992: $output .= $ruletitles{$rulenames[$i]};
3993: }
3994: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 3995: }
3996: $output .= '</div></td></tr>'."\n";
3997: return $output;
3998: }
3999:
4000: sub offloadtype_text {
4001: my %ruletitles = &Apache::lonlocal::texthash (
4002: 'default' => 'Offloads to default destinations',
4003: 'homeserver' => "Offloads to user's home server",
4004: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4005: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 4006: 'none' => 'No offload',
1.160.6.26 raeburn 4007: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4008: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 4009: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4010: );
4011: return %ruletitles;
4012: }
4013:
4014: sub sparestype_titles {
4015: my %typestitles = &Apache::lonlocal::texthash (
4016: 'primary' => 'primary',
4017: 'default' => 'default',
4018: );
4019: return %typestitles;
4020: }
4021:
1.28 raeburn 4022: sub contact_titles {
4023: my %titles = &Apache::lonlocal::texthash (
4024: 'supportemail' => 'Support E-mail address',
1.69 raeburn 4025: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 4026: 'errormail' => 'Error reports to be e-mailed to',
4027: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 4028: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4029: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 4030: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 4031: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 4032: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4033: );
4034: my %short_titles = &Apache::lonlocal::texthash (
4035: adminemail => 'Admin E-mail address',
4036: supportemail => 'Support E-mail',
4037: );
4038: return (\%titles,\%short_titles);
4039: }
4040:
1.72 raeburn 4041: sub tool_titles {
4042: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 4043: aboutme => 'Personal web page',
1.86 raeburn 4044: blog => 'Blog',
1.160.6.4 raeburn 4045: webdav => 'WebDAV',
1.86 raeburn 4046: portfolio => 'Portfolio',
1.88 bisitz 4047: official => 'Official courses (with institutional codes)',
4048: unofficial => 'Unofficial courses',
1.98 raeburn 4049: community => 'Communities',
1.160.6.30 raeburn 4050: textbook => 'Textbook courses',
1.86 raeburn 4051: );
1.72 raeburn 4052: return %titles;
4053: }
4054:
1.101 raeburn 4055: sub courserequest_titles {
4056: my %titles = &Apache::lonlocal::texthash (
4057: official => 'Official',
4058: unofficial => 'Unofficial',
4059: community => 'Communities',
1.160.6.30 raeburn 4060: textbook => 'Textbook',
1.101 raeburn 4061: norequest => 'Not allowed',
1.104 raeburn 4062: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4063: validate => 'With validation',
4064: autolimit => 'Numerical limit',
1.103 raeburn 4065: unlimited => '(blank for unlimited)',
1.101 raeburn 4066: );
4067: return %titles;
4068: }
4069:
1.160.6.5 raeburn 4070: sub authorrequest_titles {
4071: my %titles = &Apache::lonlocal::texthash (
4072: norequest => 'Not allowed',
4073: approval => 'Approval by Dom. Coord.',
4074: automatic => 'Automatic approval',
4075: );
4076: return %titles;
4077: }
4078:
1.101 raeburn 4079: sub courserequest_conditions {
4080: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4081: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 4082: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4083: );
4084: return %conditions;
4085: }
4086:
4087:
1.27 raeburn 4088: sub print_usercreation {
1.30 raeburn 4089: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4090: my $numinrow = 4;
1.28 raeburn 4091: my $datatable;
4092: if ($position eq 'top') {
1.30 raeburn 4093: $$rowtotal ++;
1.34 raeburn 4094: my $rowcount = 0;
1.32 raeburn 4095: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4096: if (ref($rules) eq 'HASH') {
4097: if (keys(%{$rules}) > 0) {
1.32 raeburn 4098: $datatable .= &user_formats_row('username',$settings,$rules,
4099: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4100: $$rowtotal ++;
1.32 raeburn 4101: $rowcount ++;
4102: }
4103: }
4104: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4105: if (ref($idrules) eq 'HASH') {
4106: if (keys(%{$idrules}) > 0) {
4107: $datatable .= &user_formats_row('id',$settings,$idrules,
4108: $idruleorder,$numinrow,$rowcount);
4109: $$rowtotal ++;
4110: $rowcount ++;
1.28 raeburn 4111: }
4112: }
1.39 raeburn 4113: if ($rowcount == 0) {
4114: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4115: $$rowtotal ++;
4116: $rowcount ++;
4117: }
1.34 raeburn 4118: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 4119: my @creators = ('author','course','requestcrs');
1.37 raeburn 4120: my ($rules,$ruleorder) =
4121: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4122: my %lt = &usercreation_types();
4123: my %checked;
4124: if (ref($settings) eq 'HASH') {
4125: if (ref($settings->{'cancreate'}) eq 'HASH') {
4126: foreach my $item (@creators) {
4127: $checked{$item} = $settings->{'cancreate'}{$item};
4128: }
4129: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4130: foreach my $item (@creators) {
4131: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4132: $checked{$item} = 'none';
4133: }
4134: }
4135: }
4136: }
4137: my $rownum = 0;
4138: foreach my $item (@creators) {
4139: $rownum ++;
1.160.6.34 raeburn 4140: if ($checked{$item} eq '') {
4141: $checked{$item} = 'any';
1.34 raeburn 4142: }
4143: my $css_class;
4144: if ($rownum%2) {
4145: $css_class = '';
4146: } else {
4147: $css_class = ' class="LC_odd_row" ';
4148: }
4149: $datatable .= '<tr'.$css_class.'>'.
4150: '<td><span class="LC_nobreak">'.$lt{$item}.
4151: '</span></td><td align="right">';
1.160.6.34 raeburn 4152: my @options = ('any');
4153: if (ref($rules) eq 'HASH') {
4154: if (keys(%{$rules}) > 0) {
4155: push(@options,('official','unofficial'));
1.37 raeburn 4156: }
4157: }
1.160.6.34 raeburn 4158: push(@options,'none');
1.37 raeburn 4159: foreach my $option (@options) {
1.50 raeburn 4160: my $type = 'radio';
1.34 raeburn 4161: my $check = ' ';
1.160.6.34 raeburn 4162: if ($checked{$item} eq $option) {
4163: $check = ' checked="checked" ';
1.34 raeburn 4164: }
4165: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4166: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4167: $item.'" value="'.$option.'"'.$check.'/> '.
4168: $lt{$option}.'</label> </span>';
4169: }
4170: $datatable .= '</td></tr>';
4171: }
1.28 raeburn 4172: } else {
4173: my @contexts = ('author','course','domain');
4174: my @authtypes = ('int','krb4','krb5','loc');
4175: my %checked;
4176: if (ref($settings) eq 'HASH') {
4177: if (ref($settings->{'authtypes'}) eq 'HASH') {
4178: foreach my $item (@contexts) {
4179: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4180: foreach my $auth (@authtypes) {
4181: if ($settings->{'authtypes'}{$item}{$auth}) {
4182: $checked{$item}{$auth} = ' checked="checked" ';
4183: }
4184: }
4185: }
4186: }
1.27 raeburn 4187: }
1.35 raeburn 4188: } else {
4189: foreach my $item (@contexts) {
1.36 raeburn 4190: foreach my $auth (@authtypes) {
1.35 raeburn 4191: $checked{$item}{$auth} = ' checked="checked" ';
4192: }
4193: }
1.27 raeburn 4194: }
1.28 raeburn 4195: my %title = &context_names();
4196: my %authname = &authtype_names();
4197: my $rownum = 0;
4198: my $css_class;
4199: foreach my $item (@contexts) {
4200: if ($rownum%2) {
4201: $css_class = '';
4202: } else {
4203: $css_class = ' class="LC_odd_row" ';
4204: }
1.30 raeburn 4205: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4206: '<td>'.$title{$item}.
4207: '</td><td class="LC_left_item">'.
4208: '<span class="LC_nobreak">';
4209: foreach my $auth (@authtypes) {
4210: $datatable .= '<label>'.
4211: '<input type="checkbox" name="'.$item.'_auth" '.
4212: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4213: $authname{$auth}.'</label> ';
4214: }
4215: $datatable .= '</span></td></tr>';
4216: $rownum ++;
1.27 raeburn 4217: }
1.30 raeburn 4218: $$rowtotal += $rownum;
1.27 raeburn 4219: }
4220: return $datatable;
4221: }
4222:
1.160.6.34 raeburn 4223: sub print_selfcreation {
4224: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4225: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4226: if (ref($settings) eq 'HASH') {
4227: if (ref($settings->{'cancreate'}) eq 'HASH') {
4228: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4229: if (ref($createsettings) eq 'HASH') {
4230: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4231: @selfcreate = @{$createsettings->{'selfcreate'}};
4232: } elsif ($createsettings->{'selfcreate'} ne '') {
4233: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4234: @selfcreate = ('email','login','sso');
4235: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4236: @selfcreate = ($createsettings->{'selfcreate'});
4237: }
4238: }
4239: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4240: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 4241: }
4242: }
4243: }
4244: }
4245: my %radiohash;
4246: my $numinrow = 4;
4247: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4248: if ($position eq 'top') {
4249: my %choices = &Apache::lonlocal::texthash (
4250: cancreate_login => 'Institutional Login',
4251: cancreate_sso => 'Institutional Single Sign On',
4252: );
4253: my @toggles = sort(keys(%choices));
4254: my %defaultchecked = (
4255: 'cancreate_login' => 'off',
4256: 'cancreate_sso' => 'off',
4257: );
1.160.6.35 raeburn 4258: my ($onclick,$itemcount);
1.160.6.34 raeburn 4259: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4260: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 4261: $$rowtotal += $itemcount;
1.160.6.39 raeburn 4262:
1.160.6.34 raeburn 4263: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4264:
4265: if (ref($usertypes) eq 'HASH') {
4266: if (keys(%{$usertypes}) > 0) {
4267: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4268: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 4269: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 4270: $$rowtotal ++;
4271: }
4272: }
1.160.6.44 raeburn 4273: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4274: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4275: $fieldtitles{'inststatus'} = &mt('Institutional status');
4276: my $rem;
4277: my $numperrow = 2;
4278: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4279: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 4280: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 4281: '<td class="LC_left_item">'."\n".
4282: '<table><tr><td>'."\n";
4283: for (my $i=0; $i<@fields; $i++) {
4284: $rem = $i%($numperrow);
4285: if ($rem == 0) {
4286: if ($i > 0) {
4287: $datatable .= '</tr>';
4288: }
4289: $datatable .= '<tr>';
4290: }
4291: my $currval;
1.160.6.51 raeburn 4292: if (ref($createsettings) eq 'HASH') {
4293: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4294: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4295: }
1.160.6.44 raeburn 4296: }
4297: $datatable .= '<td class="LC_left_item">'.
4298: '<span class="LC_nobreak">'.
4299: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4300: 'value="'.$currval.'" size="10" /> '.
4301: $fieldtitles{$fields[$i]}.'</span></td>';
4302: }
4303: my $colsleft = $numperrow - $rem;
4304: if ($colsleft > 1 ) {
4305: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4306: ' </td>';
4307: } elsif ($colsleft == 1) {
4308: $datatable .= '<td class="LC_left_item"> </td>';
4309: }
4310: $datatable .= '</tr></table></td></tr>';
4311: $$rowtotal ++;
1.160.6.34 raeburn 4312: } elsif ($position eq 'middle') {
4313: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4314: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4315: $usertypes->{'default'} = $othertitle;
4316: if (ref($types) eq 'ARRAY') {
4317: push(@{$types},'default');
4318: $usertypes->{'default'} = $othertitle;
4319: foreach my $status (@{$types}) {
4320: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 4321: $numinrow,$$rowtotal,$usertypes);
1.160.6.44 raeburn 4322: $$rowtotal ++;
1.160.6.34 raeburn 4323: }
4324: }
4325: } else {
1.160.6.40 raeburn 4326: my %choices = &Apache::lonlocal::texthash (
4327: cancreate_email => 'E-mail address as username',
4328: );
4329: my @toggles = sort(keys(%choices));
4330: my %defaultchecked = (
4331: 'cancreate_email' => 'off',
4332: );
4333: my $itemcount = 0;
4334: my $display = 'none';
4335: if (grep(/^\Qemail\E$/,@selfcreate)) {
4336: $display = 'block';
4337: }
4338: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4339: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4340: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4341: my $usertypes = {};
4342: my $order = [];
4343: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4344: $usertypes = $domdefaults{'inststatustypes'};
4345: $order = $domdefaults{'inststatusguest'};
4346: }
4347: if (ref($order) eq 'ARRAY') {
4348: push(@{$order},'default');
4349: if (@{$order} > 1) {
4350: $usertypes->{'default'} = &mt('Other users');
4351: $additional .= '<table><tr>';
4352: foreach my $status (@{$order}) {
4353: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4354: }
4355: $additional .= '</tr><tr>';
4356: foreach my $status (@{$order}) {
4357: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 4358: }
1.160.6.40 raeburn 4359: $additional .= '</tr></table>';
1.160.6.34 raeburn 4360: } else {
1.160.6.40 raeburn 4361: $usertypes->{'default'} = &mt('All users');
4362: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 4363: }
4364: }
1.160.6.40 raeburn 4365: $additional .= '</div>'."\n";
4366:
4367: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 4368: \%choices,$$rowtotal,$onclick,$additional);
4369: $$rowtotal ++;
1.160.6.40 raeburn 4370: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 4371: $$rowtotal ++;
1.160.6.35 raeburn 4372: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4373: $numinrow = 1;
1.160.6.40 raeburn 4374: if (ref($order) eq 'ARRAY') {
4375: foreach my $status (@{$order}) {
1.160.6.35 raeburn 4376: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4377: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4378: $$rowtotal ++;
4379: }
4380: }
1.160.6.34 raeburn 4381: my ($emailrules,$emailruleorder) =
4382: &Apache::lonnet::inst_userrules($dom,'email');
4383: if (ref($emailrules) eq 'HASH') {
4384: if (keys(%{$emailrules}) > 0) {
4385: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 4386: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 4387: $$rowtotal ++;
4388: }
4389: }
1.160.6.35 raeburn 4390: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 4391: }
4392: return $datatable;
4393: }
4394:
1.160.6.40 raeburn 4395: sub email_as_username {
4396: my ($rowtotal,$processing,$type) = @_;
4397: my %choices =
4398: &Apache::lonlocal::texthash (
4399: automatic => 'Automatic approval',
4400: approval => 'Queued for approval',
4401: );
4402: my $output;
4403: foreach my $option ('automatic','approval') {
4404: my $checked;
4405: if (ref($processing) eq 'HASH') {
4406: if ($type eq '') {
4407: if (!exists($processing->{'default'})) {
4408: if ($option eq 'automatic') {
4409: $checked = ' checked="checked"';
4410: }
4411: } else {
4412: if ($processing->{'default'} eq $option) {
4413: $checked = ' checked="checked"';
4414: }
4415: }
4416: } else {
4417: if (!exists($processing->{$type})) {
4418: if ($option eq 'automatic') {
4419: $checked = ' checked="checked"';
4420: }
4421: } else {
4422: if ($processing->{$type} eq $option) {
4423: $checked = ' checked="checked"';
4424: }
4425: }
4426: }
4427: } elsif ($option eq 'automatic') {
4428: $checked = ' checked="checked"';
4429: }
4430: my $name = 'cancreate_emailprocess';
4431: if (($type ne '') && ($type ne 'default')) {
4432: $name .= '_'.$type;
4433: }
4434: $output .= '<span class="LC_nobreak"><label>'.
4435: '<input type="radio" name="'.$name.'"'.
4436: $checked.' value="'.$option.'" />'.
4437: $choices{$option}.'</label></span>';
4438: if ($type eq '') {
4439: $output .= ' ';
4440: } else {
4441: $output .= '<br />';
4442: }
4443: }
4444: $$rowtotal ++;
4445: return $output;
4446: }
4447:
1.160.6.5 raeburn 4448: sub captcha_choice {
4449: my ($context,$settings,$itemcount) = @_;
4450: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4451: my %lt = &captcha_phrases();
4452: $keyentry = 'hidden';
4453: if ($context eq 'cancreate') {
1.160.6.34 raeburn 4454: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 4455: } elsif ($context eq 'login') {
4456: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
4457: }
4458: if (ref($settings) eq 'HASH') {
4459: if ($settings->{'captcha'}) {
4460: $checked{$settings->{'captcha'}} = ' checked="checked"';
4461: } else {
4462: $checked{'original'} = ' checked="checked"';
4463: }
4464: if ($settings->{'captcha'} eq 'recaptcha') {
4465: $pubtext = $lt{'pub'};
4466: $privtext = $lt{'priv'};
4467: $keyentry = 'text';
4468: }
4469: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4470: $currpub = $settings->{'recaptchakeys'}{'public'};
4471: $currpriv = $settings->{'recaptchakeys'}{'private'};
4472: }
4473: } else {
4474: $checked{'original'} = ' checked="checked"';
4475: }
4476: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4477: my $output = '<tr'.$css_class.'>'.
4478: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
4479: '<table><tr><td>'."\n";
4480: foreach my $option ('original','recaptcha','notused') {
4481: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4482: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4483: $lt{$option}.'</label></span>';
4484: unless ($option eq 'notused') {
4485: $output .= (' 'x2)."\n";
4486: }
4487: }
4488: #
4489: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4490: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
4491: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
4492: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
4493: #
4494: $output .= '</td></tr>'."\n".
4495: '<tr><td>'."\n".
4496: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4497: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4498: $currpub.'" size="40" /></span><br />'."\n".
4499: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4500: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4501: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4502: '</td></tr>';
4503: return $output;
4504: }
4505:
1.32 raeburn 4506: sub user_formats_row {
4507: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4508: my $output;
4509: my %text = (
4510: 'username' => 'new usernames',
4511: 'id' => 'IDs',
1.45 raeburn 4512: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4513: );
4514: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4515: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4516: '<td><span class="LC_nobreak">';
4517: if ($type eq 'email') {
4518: $output .= &mt("Formats disallowed for $text{$type}: ");
4519: } else {
4520: $output .= &mt("Format rules to check for $text{$type}: ");
4521: }
4522: $output .= '</span></td>'.
4523: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4524: my $rem;
4525: if (ref($ruleorder) eq 'ARRAY') {
4526: for (my $i=0; $i<@{$ruleorder}; $i++) {
4527: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4528: my $rem = $i%($numinrow);
4529: if ($rem == 0) {
4530: if ($i > 0) {
4531: $output .= '</tr>';
4532: }
4533: $output .= '<tr>';
4534: }
4535: my $check = ' ';
1.39 raeburn 4536: if (ref($settings) eq 'HASH') {
4537: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4538: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4539: $check = ' checked="checked" ';
4540: }
1.27 raeburn 4541: }
4542: }
4543: $output .= '<td class="LC_left_item">'.
4544: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4545: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4546: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4547: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4548: }
4549: }
4550: $rem = @{$ruleorder}%($numinrow);
4551: }
4552: my $colsleft = $numinrow - $rem;
4553: if ($colsleft > 1 ) {
4554: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4555: ' </td>';
4556: } elsif ($colsleft == 1) {
4557: $output .= '<td class="LC_left_item"> </td>';
4558: }
4559: $output .= '</tr></table></td></tr>';
4560: return $output;
4561: }
4562:
1.34 raeburn 4563: sub usercreation_types {
4564: my %lt = &Apache::lonlocal::texthash (
4565: author => 'When adding a co-author',
4566: course => 'When adding a user to a course',
1.100 raeburn 4567: requestcrs => 'When requesting a course',
1.34 raeburn 4568: any => 'Any',
4569: official => 'Institutional only ',
4570: unofficial => 'Non-institutional only',
4571: none => 'None',
4572: );
4573: return %lt;
1.48 raeburn 4574: }
1.34 raeburn 4575:
1.160.6.34 raeburn 4576: sub selfcreation_types {
4577: my %lt = &Apache::lonlocal::texthash (
4578: selfcreate => 'User creates own account',
4579: any => 'Any',
4580: official => 'Institutional only ',
4581: unofficial => 'Non-institutional only',
4582: email => 'E-mail address',
4583: login => 'Institutional Login',
4584: sso => 'SSO',
4585: );
4586: }
4587:
1.28 raeburn 4588: sub authtype_names {
4589: my %lt = &Apache::lonlocal::texthash(
4590: int => 'Internal',
4591: krb4 => 'Kerberos 4',
4592: krb5 => 'Kerberos 5',
4593: loc => 'Local',
4594: );
4595: return %lt;
4596: }
4597:
4598: sub context_names {
4599: my %context_title = &Apache::lonlocal::texthash(
4600: author => 'Creating users when an Author',
4601: course => 'Creating users when in a course',
4602: domain => 'Creating users when a Domain Coordinator',
4603: );
4604: return %context_title;
4605: }
4606:
1.33 raeburn 4607: sub print_usermodification {
4608: my ($position,$dom,$settings,$rowtotal) = @_;
4609: my $numinrow = 4;
4610: my ($context,$datatable,$rowcount);
4611: if ($position eq 'top') {
4612: $rowcount = 0;
4613: $context = 'author';
4614: foreach my $role ('ca','aa') {
4615: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4616: $numinrow,$rowcount);
4617: $$rowtotal ++;
4618: $rowcount ++;
4619: }
1.160.6.37 raeburn 4620: } elsif ($position eq 'bottom') {
1.33 raeburn 4621: $context = 'course';
4622: $rowcount = 0;
4623: foreach my $role ('st','ep','ta','in','cr') {
4624: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4625: $numinrow,$rowcount);
4626: $$rowtotal ++;
4627: $rowcount ++;
4628: }
4629: }
4630: return $datatable;
4631: }
4632:
1.43 raeburn 4633: sub print_defaults {
1.160.6.40 raeburn 4634: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4635: my $rownum = 0;
4636: my ($datatable,$css_class);
1.160.6.40 raeburn 4637: if ($position eq 'top') {
4638: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4639: 'datelocale_def','portal_def');
4640: my %defaults;
4641: if (ref($settings) eq 'HASH') {
4642: %defaults = %{$settings};
1.43 raeburn 4643: } else {
1.160.6.40 raeburn 4644: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4645: foreach my $item (@items) {
4646: $defaults{$item} = $domdefaults{$item};
4647: }
1.43 raeburn 4648: }
1.160.6.40 raeburn 4649: my $titles = &defaults_titles($dom);
4650: foreach my $item (@items) {
4651: if ($rownum%2) {
4652: $css_class = '';
4653: } else {
4654: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 4655: }
1.160.6.40 raeburn 4656: $datatable .= '<tr'.$css_class.'>'.
4657: '<td><span class="LC_nobreak">'.$titles->{$item}.
4658: '</span></td><td class="LC_right_item" colspan="3">';
4659: if ($item eq 'auth_def') {
4660: my @authtypes = ('internal','krb4','krb5','localauth');
4661: my %shortauth = (
4662: internal => 'int',
4663: krb4 => 'krb4',
4664: krb5 => 'krb5',
4665: localauth => 'loc'
4666: );
4667: my %authnames = &authtype_names();
4668: foreach my $auth (@authtypes) {
4669: my $checked = ' ';
4670: if ($defaults{$item} eq $auth) {
4671: $checked = ' checked="checked" ';
4672: }
4673: $datatable .= '<label><input type="radio" name="'.$item.
4674: '" value="'.$auth.'"'.$checked.'/>'.
4675: $authnames{$shortauth{$auth}}.'</label> ';
4676: }
4677: } elsif ($item eq 'timezone_def') {
4678: my $includeempty = 1;
4679: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4680: } elsif ($item eq 'datelocale_def') {
4681: my $includeempty = 1;
4682: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4683: } elsif ($item eq 'lang_def') {
4684: my %langchoices = &get_languages_hash();
4685: $langchoices{''} = 'No language preference';
4686: %langchoices = &Apache::lonlocal::texthash(%langchoices);
4687: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
4688: \%langchoices);
4689: } else {
4690: my $size;
4691: if ($item eq 'portal_def') {
4692: $size = ' size="25"';
4693: }
4694: $datatable .= '<input type="text" name="'.$item.'" value="'.
4695: $defaults{$item}.'"'.$size.' />';
4696: }
4697: $datatable .= '</td></tr>';
4698: $rownum ++;
4699: }
4700: } else {
4701: my (%defaults);
4702: if (ref($settings) eq 'HASH') {
4703: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4704: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4705: my $maxnum = @{$settings->{'inststatusorder'}};
4706: for (my $i=0; $i<$maxnum; $i++) {
4707: $css_class = $rownum%2?' class="LC_odd_row"':'';
4708: my $item = $settings->{'inststatusorder'}->[$i];
4709: my $title = $settings->{'inststatustypes'}->{$item};
4710: my $guestok;
4711: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4712: $guestok = 1;
4713: }
4714: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4715: $datatable .= '<tr'.$css_class.'>'.
4716: '<td><span class="LC_nobreak">'.
4717: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4718: for (my $k=0; $k<=$maxnum; $k++) {
4719: my $vpos = $k+1;
4720: my $selstr;
4721: if ($k == $i) {
4722: $selstr = ' selected="selected" ';
4723: }
4724: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4725: }
4726: my ($checkedon,$checkedoff);
4727: $checkedoff = ' checked="checked"';
4728: if ($guestok) {
4729: $checkedon = $checkedoff;
4730: $checkedoff = '';
4731: }
4732: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4733: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4734: &mt('delete').'</span></td>'.
4735: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4736: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4737: '</span></td>'.
4738: '<td class="LC_right_item"><span class="LC_nobreak">'.
4739: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4740: &mt('Yes').'</label>'.(' 'x2).
4741: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4742: &mt('No').'</label></span></td></tr>';
4743: }
4744: $css_class = $rownum%2?' class="LC_odd_row"':'';
4745: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4746: $datatable .= '<tr '.$css_class.'>'.
4747: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4748: for (my $k=0; $k<=$maxnum; $k++) {
4749: my $vpos = $k+1;
4750: my $selstr;
4751: if ($k == $maxnum) {
4752: $selstr = ' selected="selected" ';
4753: }
4754: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4755: }
4756: $datatable .= '</select> '.&mt('Internal ID:').
4757: '<input type="text" size="10" name="addinststatus" value="" /></span>'.
4758: ' '.&mt('(new)').
4759: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4760: &mt('Name displayed:').
4761: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4762: '<td class="LC_right_item"><span class="LC_nobreak">'.
4763: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4764: &mt('Yes').'</label>'.(' 'x2).
4765: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4766: &mt('No').'</label></span></td></tr>';
4767: '</tr>'."\n";
4768: $rownum ++;
1.141 raeburn 4769: }
1.43 raeburn 4770: }
4771: }
4772: $$rowtotal += $rownum;
4773: return $datatable;
4774: }
4775:
1.160.6.5 raeburn 4776: sub get_languages_hash {
4777: my %langchoices;
4778: foreach my $id (&Apache::loncommon::languageids()) {
4779: my $code = &Apache::loncommon::supportedlanguagecode($id);
4780: if ($code ne '') {
4781: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4782: }
4783: }
4784: return %langchoices;
4785: }
4786:
1.43 raeburn 4787: sub defaults_titles {
1.141 raeburn 4788: my ($dom) = @_;
1.43 raeburn 4789: my %titles = &Apache::lonlocal::texthash (
4790: 'auth_def' => 'Default authentication type',
4791: 'auth_arg_def' => 'Default authentication argument',
4792: 'lang_def' => 'Default language',
1.54 raeburn 4793: 'timezone_def' => 'Default timezone',
1.68 raeburn 4794: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4795: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4796: );
1.141 raeburn 4797: if ($dom) {
4798: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4799: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4800: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4801: $protocol = 'http' if ($protocol ne 'https');
4802: if ($uint_dom) {
4803: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4804: $uint_dom);
4805: }
4806: }
1.43 raeburn 4807: return (\%titles);
4808: }
4809:
1.46 raeburn 4810: sub print_scantronformat {
4811: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4812: my $itemcount = 1;
1.60 raeburn 4813: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4814: %confhash);
1.46 raeburn 4815: my $switchserver = &check_switchserver($dom,$confname);
4816: my %lt = &Apache::lonlocal::texthash (
1.95 www 4817: default => 'Default bubblesheet format file error',
4818: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4819: );
4820: my %scantronfiles = (
4821: default => 'default.tab',
4822: custom => 'custom.tab',
4823: );
4824: foreach my $key (keys(%scantronfiles)) {
4825: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4826: .$scantronfiles{$key};
4827: }
4828: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4829: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4830: if (!$switchserver) {
4831: my $servadm = $r->dir_config('lonAdmEMail');
4832: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4833: if ($configuserok eq 'ok') {
4834: if ($author_ok eq 'ok') {
4835: my %legacyfile = (
4836: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4837: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4838: );
4839: my %md5chk;
4840: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4841: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4842: chomp($md5chk{$type});
1.46 raeburn 4843: }
4844: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4845: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4846: ($scantronurls{$type},my $error) =
1.46 raeburn 4847: &legacy_scantronformat($r,$dom,$confname,
4848: $type,$legacyfile{$type},
4849: $scantronurls{$type},
4850: $scantronfiles{$type});
1.60 raeburn 4851: if ($error ne '') {
4852: $error{$type} = $error;
4853: }
4854: }
4855: if (keys(%error) == 0) {
4856: $is_custom = 1;
4857: $confhash{'scantron'}{'scantronformat'} =
4858: $scantronurls{'custom'};
4859: my $putresult =
4860: &Apache::lonnet::put_dom('configuration',
4861: \%confhash,$dom);
4862: if ($putresult ne 'ok') {
4863: $error{'custom'} =
4864: '<span class="LC_error">'.
4865: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4866: }
1.46 raeburn 4867: }
4868: } else {
1.60 raeburn 4869: ($scantronurls{'default'},my $error) =
1.46 raeburn 4870: &legacy_scantronformat($r,$dom,$confname,
4871: 'default',$legacyfile{'default'},
4872: $scantronurls{'default'},
4873: $scantronfiles{'default'});
1.60 raeburn 4874: if ($error eq '') {
4875: $confhash{'scantron'}{'scantronformat'} = '';
4876: my $putresult =
4877: &Apache::lonnet::put_dom('configuration',
4878: \%confhash,$dom);
4879: if ($putresult ne 'ok') {
4880: $error{'default'} =
4881: '<span class="LC_error">'.
4882: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4883: }
4884: } else {
4885: $error{'default'} = $error;
4886: }
1.46 raeburn 4887: }
4888: }
4889: }
4890: } else {
1.95 www 4891: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4892: }
4893: }
4894: if (ref($settings) eq 'HASH') {
4895: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4896: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4897: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4898: $scantronurl = '';
4899: } else {
4900: $scantronurl = $settings->{'scantronformat'};
4901: }
4902: $is_custom = 1;
4903: } else {
4904: $scantronurl = $scantronurls{'default'};
4905: }
4906: } else {
1.60 raeburn 4907: if ($is_custom) {
4908: $scantronurl = $scantronurls{'custom'};
4909: } else {
4910: $scantronurl = $scantronurls{'default'};
4911: }
1.46 raeburn 4912: }
4913: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4914: $datatable .= '<tr'.$css_class.'>';
4915: if (!$is_custom) {
1.65 raeburn 4916: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4917: '<span class="LC_nobreak">';
1.46 raeburn 4918: if ($scantronurl) {
1.160.6.21 raeburn 4919: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4920: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4921: } else {
4922: $datatable = &mt('File unavailable for display');
4923: }
1.65 raeburn 4924: $datatable .= '</span></td>';
1.60 raeburn 4925: if (keys(%error) == 0) {
4926: $datatable .= '<td valign="bottom">';
4927: if (!$switchserver) {
4928: $datatable .= &mt('Upload:').'<br />';
4929: }
4930: } else {
4931: my $errorstr;
4932: foreach my $key (sort(keys(%error))) {
4933: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4934: }
4935: $datatable .= '<td>'.$errorstr;
4936: }
1.46 raeburn 4937: } else {
4938: if (keys(%error) > 0) {
4939: my $errorstr;
4940: foreach my $key (sort(keys(%error))) {
4941: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4942: }
1.60 raeburn 4943: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4944: } elsif ($scantronurl) {
1.160.6.26 raeburn 4945: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 4946: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4947: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 4948: $link.
4949: '<label><input type="checkbox" name="scantronformat_del"'.
4950: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4951: '<td><span class="LC_nobreak"> '.
4952: &mt('Replace:').'</span><br />';
1.46 raeburn 4953: }
4954: }
4955: if (keys(%error) == 0) {
4956: if ($switchserver) {
4957: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4958: } else {
1.65 raeburn 4959: $datatable .='<span class="LC_nobreak"> '.
4960: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4961: }
4962: }
4963: $datatable .= '</td></tr>';
4964: $$rowtotal ++;
4965: return $datatable;
4966: }
4967:
4968: sub legacy_scantronformat {
4969: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4970: my ($url,$error);
4971: my @statinfo = &Apache::lonnet::stat_file($newurl);
4972: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4973: (my $result,$url) =
4974: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4975: '','',$newfile);
4976: if ($result ne 'ok') {
1.130 raeburn 4977: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4978: }
4979: }
4980: return ($url,$error);
4981: }
1.43 raeburn 4982:
1.49 raeburn 4983: sub print_coursecategories {
1.57 raeburn 4984: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4985: my $datatable;
4986: if ($position eq 'top') {
1.160.6.42 raeburn 4987: my (%checked);
4988: my @catitems = ('unauth','auth');
4989: my @cattypes = ('std','domonly','codesrch','none');
4990: $checked{'unauth'} = 'std';
4991: $checked{'auth'} = 'std';
4992: if (ref($settings) eq 'HASH') {
4993: foreach my $type (@cattypes) {
4994: if ($type eq $settings->{'unauth'}) {
4995: $checked{'unauth'} = $type;
4996: }
4997: if ($type eq $settings->{'auth'}) {
4998: $checked{'auth'} = $type;
4999: }
5000: }
5001: }
5002: my %lt = &Apache::lonlocal::texthash (
5003: unauth => 'Catalog type for unauthenticated users',
5004: auth => 'Catalog type for authenticated users',
5005: none => 'No catalog',
5006: std => 'Standard catalog',
5007: domonly => 'Domain-only catalog',
5008: codesrch => "Code search form",
5009: );
5010: my $itemcount = 0;
5011: foreach my $item (@catitems) {
5012: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5013: $datatable .= '<tr '.$css_class.'>'.
5014: '<td>'.$lt{$item}.'</td>'.
5015: '<td class="LC_right_item"><span class="LC_nobreak">';
5016: foreach my $type (@cattypes) {
5017: my $ischecked;
5018: if ($checked{$item} eq $type) {
5019: $ischecked=' checked="checked"';
5020: }
5021: $datatable .= '<label>'.
5022: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5023: ' />'.$lt{$type}.'</label> ';
5024: }
5025: $datatable .= '</td></tr>';
5026: $itemcount ++;
5027: }
5028: $$rowtotal += $itemcount;
5029: } elsif ($position eq 'middle') {
1.57 raeburn 5030: my $toggle_cats_crs = ' ';
5031: my $toggle_cats_dom = ' checked="checked" ';
5032: my $can_cat_crs = ' ';
5033: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5034: my $toggle_catscomm_comm = ' ';
5035: my $toggle_catscomm_dom = ' checked="checked" ';
5036: my $can_catcomm_comm = ' ';
5037: my $can_catcomm_dom = ' checked="checked" ';
5038:
1.57 raeburn 5039: if (ref($settings) eq 'HASH') {
5040: if ($settings->{'togglecats'} eq 'crs') {
5041: $toggle_cats_crs = $toggle_cats_dom;
5042: $toggle_cats_dom = ' ';
5043: }
5044: if ($settings->{'categorize'} eq 'crs') {
5045: $can_cat_crs = $can_cat_dom;
5046: $can_cat_dom = ' ';
5047: }
1.120 raeburn 5048: if ($settings->{'togglecatscomm'} eq 'comm') {
5049: $toggle_catscomm_comm = $toggle_catscomm_dom;
5050: $toggle_catscomm_dom = ' ';
5051: }
5052: if ($settings->{'categorizecomm'} eq 'comm') {
5053: $can_catcomm_comm = $can_catcomm_dom;
5054: $can_catcomm_dom = ' ';
5055: }
1.57 raeburn 5056: }
5057: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 5058: togglecats => 'Show/Hide a course in catalog',
5059: togglecatscomm => 'Show/Hide a community in catalog',
5060: categorize => 'Assign a category to a course',
5061: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5062: );
5063: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 5064: dom => 'Set in Domain',
5065: crs => 'Set in Course',
5066: comm => 'Set in Community',
1.57 raeburn 5067: );
5068: $datatable = '<tr class="LC_odd_row">'.
5069: '<td>'.$title{'togglecats'}.'</td>'.
5070: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5071: '<input type="radio" name="togglecats"'.
5072: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5073: '<label><input type="radio" name="togglecats"'.
5074: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5075: '</tr><tr>'.
5076: '<td>'.$title{'categorize'}.'</td>'.
5077: '<td class="LC_right_item"><span class="LC_nobreak">'.
5078: '<label><input type="radio" name="categorize"'.
5079: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5080: '<label><input type="radio" name="categorize"'.
5081: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5082: '</tr><tr class="LC_odd_row">'.
5083: '<td>'.$title{'togglecatscomm'}.'</td>'.
5084: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5085: '<input type="radio" name="togglecatscomm"'.
5086: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5087: '<label><input type="radio" name="togglecatscomm"'.
5088: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5089: '</tr><tr>'.
5090: '<td>'.$title{'categorizecomm'}.'</td>'.
5091: '<td class="LC_right_item"><span class="LC_nobreak">'.
5092: '<label><input type="radio" name="categorizecomm"'.
5093: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5094: '<label><input type="radio" name="categorizecomm"'.
5095: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 5096: '</tr>';
1.120 raeburn 5097: $$rowtotal += 4;
1.57 raeburn 5098: } else {
5099: my $css_class;
5100: my $itemcount = 1;
5101: my $cathash;
5102: if (ref($settings) eq 'HASH') {
5103: $cathash = $settings->{'cats'};
5104: }
5105: if (ref($cathash) eq 'HASH') {
5106: my (@cats,@trails,%allitems,%idx,@jsarray);
5107: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5108: \%allitems,\%idx,\@jsarray);
5109: my $maxdepth = scalar(@cats);
5110: my $colattrib = '';
5111: if ($maxdepth > 2) {
5112: $colattrib = ' colspan="2" ';
5113: }
5114: my @path;
5115: if (@cats > 0) {
5116: if (ref($cats[0]) eq 'ARRAY') {
5117: my $numtop = @{$cats[0]};
5118: my $maxnum = $numtop;
1.120 raeburn 5119: my %default_names = (
5120: instcode => &mt('Official courses'),
5121: communities => &mt('Communities'),
5122: );
5123:
5124: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5125: ($cathash->{'instcode::0'} eq '') ||
5126: (!grep(/^communities$/,@{$cats[0]})) ||
5127: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5128: $maxnum ++;
5129: }
5130: my $lastidx;
5131: for (my $i=0; $i<$numtop; $i++) {
5132: my $parent = $cats[0][$i];
5133: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5134: my $item = &escape($parent).'::0';
5135: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5136: $lastidx = $idx{$item};
5137: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5138: .'<select name="'.$item.'"'.$chgstr.'>';
5139: for (my $k=0; $k<=$maxnum; $k++) {
5140: my $vpos = $k+1;
5141: my $selstr;
5142: if ($k == $i) {
5143: $selstr = ' selected="selected" ';
5144: }
5145: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5146: }
1.160.6.29 raeburn 5147: $datatable .= '</select></span></td><td>';
1.120 raeburn 5148: if ($parent eq 'instcode' || $parent eq 'communities') {
5149: $datatable .= '<span class="LC_nobreak">'
5150: .$default_names{$parent}.'</span>';
5151: if ($parent eq 'instcode') {
5152: $datatable .= '<br /><span class="LC_nobreak">('
5153: .&mt('with institutional codes')
5154: .')</span></td><td'.$colattrib.'>';
5155: } else {
5156: $datatable .= '<table><tr><td>';
5157: }
5158: $datatable .= '<span class="LC_nobreak">'
5159: .'<label><input type="radio" name="'
5160: .$parent.'" value="1" checked="checked" />'
5161: .&mt('Display').'</label>';
5162: if ($parent eq 'instcode') {
5163: $datatable .= ' ';
5164: } else {
5165: $datatable .= '</span></td></tr><tr><td>'
5166: .'<span class="LC_nobreak">';
5167: }
5168: $datatable .= '<label><input type="radio" name="'
5169: .$parent.'" value="0" />'
5170: .&mt('Do not display').'</label></span>';
5171: if ($parent eq 'communities') {
5172: $datatable .= '</td></tr></table>';
5173: }
5174: $datatable .= '</td>';
1.57 raeburn 5175: } else {
5176: $datatable .= $parent
1.160.6.29 raeburn 5177: .' <span class="LC_nobreak"><label>'
5178: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5179: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5180: }
5181: my $depth = 1;
5182: push(@path,$parent);
5183: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5184: pop(@path);
5185: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5186: $itemcount ++;
5187: }
1.48 raeburn 5188: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5189: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5190: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5191: for (my $k=0; $k<=$maxnum; $k++) {
5192: my $vpos = $k+1;
5193: my $selstr;
1.57 raeburn 5194: if ($k == $numtop) {
1.48 raeburn 5195: $selstr = ' selected="selected" ';
5196: }
5197: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5198: }
1.59 bisitz 5199: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5200: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5201: .'</tr>'."\n";
1.48 raeburn 5202: $itemcount ++;
1.120 raeburn 5203: foreach my $default ('instcode','communities') {
5204: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5205: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5206: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5207: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5208: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5209: for (my $k=0; $k<=$maxnum; $k++) {
5210: my $vpos = $k+1;
5211: my $selstr;
5212: if ($k == $maxnum) {
5213: $selstr = ' selected="selected" ';
5214: }
5215: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5216: }
1.120 raeburn 5217: $datatable .= '</select></span></td>'.
5218: '<td><span class="LC_nobreak">'.
5219: $default_names{$default}.'</span>';
5220: if ($default eq 'instcode') {
5221: $datatable .= '<br /><span class="LC_nobreak">('
5222: .&mt('with institutional codes').')</span>';
5223: }
5224: $datatable .= '</td>'
5225: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5226: .&mt('Display').'</label> '
5227: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5228: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5229: }
5230: }
5231: }
1.57 raeburn 5232: } else {
5233: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5234: }
5235: } else {
1.160.6.42 raeburn 5236: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5237: .&initialize_categories($itemcount);
1.48 raeburn 5238: }
1.57 raeburn 5239: $$rowtotal += $itemcount;
1.48 raeburn 5240: }
5241: return $datatable;
5242: }
5243:
1.69 raeburn 5244: sub print_serverstatuses {
5245: my ($dom,$settings,$rowtotal) = @_;
5246: my $datatable;
5247: my @pages = &serverstatus_pages();
5248: my (%namedaccess,%machineaccess);
5249: foreach my $type (@pages) {
5250: $namedaccess{$type} = '';
5251: $machineaccess{$type}= '';
5252: }
5253: if (ref($settings) eq 'HASH') {
5254: foreach my $type (@pages) {
5255: if (exists($settings->{$type})) {
5256: if (ref($settings->{$type}) eq 'HASH') {
5257: foreach my $key (keys(%{$settings->{$type}})) {
5258: if ($key eq 'namedusers') {
5259: $namedaccess{$type} = $settings->{$type}->{$key};
5260: } elsif ($key eq 'machines') {
5261: $machineaccess{$type} = $settings->{$type}->{$key};
5262: }
5263: }
5264: }
5265: }
5266: }
5267: }
1.81 raeburn 5268: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5269: my $rownum = 0;
5270: my $css_class;
5271: foreach my $type (@pages) {
5272: $rownum ++;
5273: $css_class = $rownum%2?' class="LC_odd_row"':'';
5274: $datatable .= '<tr'.$css_class.'>'.
5275: '<td><span class="LC_nobreak">'.
5276: $titles->{$type}.'</span></td>'.
5277: '<td class="LC_left_item">'.
5278: '<input type="text" name="'.$type.'_namedusers" '.
5279: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5280: '<td class="LC_right_item">'.
5281: '<span class="LC_nobreak">'.
5282: '<input type="text" name="'.$type.'_machines" '.
5283: 'value="'.$machineaccess{$type}.'" size="10" />'.
5284: '</td></tr>'."\n";
5285: }
5286: $$rowtotal += $rownum;
5287: return $datatable;
5288: }
5289:
5290: sub serverstatus_pages {
5291: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 5292: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 5293: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.36 raeburn 5294: 'uniquecodes','diskusage');
1.69 raeburn 5295: }
5296:
1.160.6.40 raeburn 5297: sub defaults_javascript {
5298: my ($settings) = @_;
1.160.6.51 raeburn 5299: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 5300: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5301: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5302: if ($maxnum eq '') {
5303: $maxnum = 0;
5304: }
5305: $maxnum ++;
1.160.6.51 raeburn 5306: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 5307: return <<"ENDSCRIPT";
5308: <script type="text/javascript">
5309: // <![CDATA[
5310: function reorderTypes(form,caller) {
5311: var changedVal;
5312: $jstext
5313: var newpos = 'addinststatus_pos';
5314: var current = new Array;
5315: var maxh = $maxnum;
5316: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5317: var oldVal;
5318: if (caller == newpos) {
5319: changedVal = newitemVal;
5320: } else {
5321: var curritem = 'inststatus_pos_'+caller;
5322: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5323: current[newitemVal] = newpos;
5324: }
5325: for (var i=0; i<inststatuses.length; i++) {
5326: if (inststatuses[i] != caller) {
5327: var elementName = 'inststatus_pos_'+inststatuses[i];
5328: if (form.elements[elementName]) {
5329: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5330: current[currVal] = elementName;
5331: }
5332: }
5333: }
5334: for (var j=0; j<maxh; j++) {
5335: if (current[j] == undefined) {
5336: oldVal = j;
5337: }
5338: }
5339: if (oldVal < changedVal) {
5340: for (var k=oldVal+1; k<=changedVal ; k++) {
5341: var elementName = current[k];
5342: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5343: }
5344: } else {
5345: for (var k=changedVal; k<oldVal; k++) {
5346: var elementName = current[k];
5347: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5348: }
5349: }
5350: return;
5351: }
5352:
5353: // ]]>
5354: </script>
5355:
5356: ENDSCRIPT
5357: }
5358: }
5359:
1.49 raeburn 5360: sub coursecategories_javascript {
5361: my ($settings) = @_;
1.57 raeburn 5362: my ($output,$jstext,$cathash);
1.49 raeburn 5363: if (ref($settings) eq 'HASH') {
1.57 raeburn 5364: $cathash = $settings->{'cats'};
5365: }
5366: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5367: my (@cats,@jsarray,%idx);
1.57 raeburn 5368: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5369: if (@jsarray > 0) {
5370: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5371: for (my $i=0; $i<@jsarray; $i++) {
5372: if (ref($jsarray[$i]) eq 'ARRAY') {
5373: my $catstr = join('","',@{$jsarray[$i]});
5374: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5375: }
5376: }
5377: }
5378: } else {
5379: $jstext = ' var categories = Array(1);'."\n".
5380: ' categories[0] = Array("instcode_pos");'."\n";
5381: }
1.160.6.42 raeburn 5382: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5383: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
5384: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.');
1.49 raeburn 5385: $output = <<"ENDSCRIPT";
5386: <script type="text/javascript">
1.109 raeburn 5387: // <![CDATA[
1.49 raeburn 5388: function reorderCats(form,parent,item,idx) {
5389: var changedVal;
5390: $jstext
5391: var newpos = 'addcategory_pos';
5392: if (parent == '') {
5393: var has_instcode = 0;
5394: var maxtop = categories[idx].length;
5395: for (var j=0; j<maxtop; j++) {
5396: if (categories[idx][j] == 'instcode::0') {
5397: has_instcode == 1;
5398: }
5399: }
5400: if (has_instcode == 0) {
5401: categories[idx][maxtop] = 'instcode_pos';
5402: }
5403: } else {
5404: newpos += '_'+parent;
5405: }
5406: var maxh = 1 + categories[idx].length;
5407: var current = new Array;
5408: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5409: if (item == newpos) {
5410: changedVal = newitemVal;
5411: } else {
5412: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5413: current[newitemVal] = newpos;
5414: }
5415: for (var i=0; i<categories[idx].length; i++) {
5416: var elementName = categories[idx][i];
5417: if (elementName != item) {
5418: if (form.elements[elementName]) {
5419: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5420: current[currVal] = elementName;
5421: }
5422: }
5423: }
5424: var oldVal;
5425: for (var j=0; j<maxh; j++) {
5426: if (current[j] == undefined) {
5427: oldVal = j;
5428: }
5429: }
5430: if (oldVal < changedVal) {
5431: for (var k=oldVal+1; k<=changedVal ; k++) {
5432: var elementName = current[k];
5433: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5434: }
5435: } else {
5436: for (var k=changedVal; k<oldVal; k++) {
5437: var elementName = current[k];
5438: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5439: }
5440: }
5441: return;
5442: }
1.120 raeburn 5443:
5444: function categoryCheck(form) {
5445: if (form.elements['addcategory_name'].value == 'instcode') {
5446: alert('$instcode_reserved\\n$choose_again');
5447: return false;
5448: }
5449: if (form.elements['addcategory_name'].value == 'communities') {
5450: alert('$communities_reserved\\n$choose_again');
5451: return false;
5452: }
5453: return true;
5454: }
5455:
1.109 raeburn 5456: // ]]>
1.49 raeburn 5457: </script>
5458:
5459: ENDSCRIPT
5460: return $output;
5461: }
5462:
1.48 raeburn 5463: sub initialize_categories {
5464: my ($itemcount) = @_;
1.120 raeburn 5465: my ($datatable,$css_class,$chgstr);
5466: my %default_names = (
5467: instcode => 'Official courses (with institutional codes)',
5468: communities => 'Communities',
5469: );
5470: my $select0 = ' selected="selected"';
5471: my $select1 = '';
5472: foreach my $default ('instcode','communities') {
5473: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5474: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5475: if ($default eq 'communities') {
5476: $select1 = $select0;
5477: $select0 = '';
5478: }
5479: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5480: .'<select name="'.$default.'_pos">'
5481: .'<option value="0"'.$select0.'>1</option>'
5482: .'<option value="1"'.$select1.'>2</option>'
5483: .'<option value="2">3</option></select> '
5484: .$default_names{$default}
5485: .'</span></td><td><span class="LC_nobreak">'
5486: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5487: .&mt('Display').'</label> <label>'
5488: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5489: .'</label></span></td></tr>';
1.120 raeburn 5490: $itemcount ++;
5491: }
1.48 raeburn 5492: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5493: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5494: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5495: .'<select name="addcategory_pos"'.$chgstr.'>'
5496: .'<option value="0">1</option>'
5497: .'<option value="1">2</option>'
5498: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5499: .&mt('Add category').'</td><td>'.&mt('Name:')
5500: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5501: return $datatable;
5502: }
5503:
5504: sub build_category_rows {
1.49 raeburn 5505: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5506: my ($text,$name,$item,$chgstr);
1.48 raeburn 5507: if (ref($cats) eq 'ARRAY') {
5508: my $maxdepth = scalar(@{$cats});
5509: if (ref($cats->[$depth]) eq 'HASH') {
5510: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5511: my $numchildren = @{$cats->[$depth]{$parent}};
5512: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 5513: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5514: my ($idxnum,$parent_name,$parent_item);
5515: my $higher = $depth - 1;
5516: if ($higher == 0) {
5517: $parent_name = &escape($parent).'::'.$higher;
5518: } else {
5519: if (ref($path) eq 'ARRAY') {
5520: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5521: }
5522: }
5523: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5524: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5525: if ($j < $numchildren) {
1.48 raeburn 5526: $name = $cats->[$depth]{$parent}[$j];
5527: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5528: $idxnum = $idx->{$item};
5529: } else {
5530: $name = $parent_name;
5531: $item = $parent_item;
1.48 raeburn 5532: }
1.49 raeburn 5533: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5534: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5535: for (my $i=0; $i<=$numchildren; $i++) {
5536: my $vpos = $i+1;
5537: my $selstr;
5538: if ($j == $i) {
5539: $selstr = ' selected="selected" ';
5540: }
5541: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5542: }
5543: $text .= '</select> ';
5544: if ($j < $numchildren) {
5545: my $deeper = $depth+1;
5546: $text .= $name.' '
5547: .'<label><input type="checkbox" name="deletecategory" value="'
5548: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5549: if(ref($path) eq 'ARRAY') {
5550: push(@{$path},$name);
1.49 raeburn 5551: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5552: pop(@{$path});
5553: }
5554: } else {
1.59 bisitz 5555: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5556: if ($j == $numchildren) {
5557: $text .= $name;
5558: } else {
5559: $text .= $item;
5560: }
5561: $text .= '" value="" />';
5562: }
5563: $text .= '</td></tr>';
5564: }
5565: $text .= '</table></td>';
5566: } else {
5567: my $higher = $depth-1;
5568: if ($higher == 0) {
5569: $name = &escape($parent).'::'.$higher;
5570: } else {
5571: if (ref($path) eq 'ARRAY') {
5572: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5573: }
5574: }
5575: my $colspan;
5576: if ($parent ne 'instcode') {
5577: $colspan = $maxdepth - $depth - 1;
5578: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5579: }
5580: }
5581: }
5582: }
5583: return $text;
5584: }
5585:
1.33 raeburn 5586: sub modifiable_userdata_row {
1.160.6.35 raeburn 5587: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5588: my ($role,$rolename,$statustype);
5589: $role = $item;
1.160.6.34 raeburn 5590: if ($context eq 'cancreate') {
1.160.6.35 raeburn 5591: if ($item =~ /^emailusername_(.+)$/) {
5592: $statustype = $1;
5593: $role = 'emailusername';
5594: if (ref($usertypes) eq 'HASH') {
5595: if ($usertypes->{$statustype}) {
5596: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5597: } else {
5598: $rolename = &mt('Data provided by user');
5599: }
5600: }
1.160.6.34 raeburn 5601: }
5602: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5603: if (ref($usertypes) eq 'HASH') {
5604: $rolename = $usertypes->{$role};
5605: } else {
5606: $rolename = $role;
5607: }
1.33 raeburn 5608: } else {
1.63 raeburn 5609: if ($role eq 'cr') {
5610: $rolename = &mt('Custom role');
5611: } else {
5612: $rolename = &Apache::lonnet::plaintext($role);
5613: }
1.33 raeburn 5614: }
1.160.6.34 raeburn 5615: my (@fields,%fieldtitles);
5616: if (ref($fieldsref) eq 'ARRAY') {
5617: @fields = @{$fieldsref};
5618: } else {
5619: @fields = ('lastname','firstname','middlename','generation',
5620: 'permanentemail','id');
5621: }
5622: if ((ref($titlesref) eq 'HASH')) {
5623: %fieldtitles = %{$titlesref};
5624: } else {
5625: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5626: }
1.33 raeburn 5627: my $output;
5628: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5629: $output = '<tr '.$css_class.'>'.
5630: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5631: '<td class="LC_left_item" colspan="2"><table>';
5632: my $rem;
5633: my %checks;
5634: if (ref($settings) eq 'HASH') {
5635: if (ref($settings->{$context}) eq 'HASH') {
5636: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 5637: my $hashref = $settings->{$context}->{$role};
5638: if ($role eq 'emailusername') {
5639: if ($statustype) {
5640: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5641: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 5642: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 5643: foreach my $field (@fields) {
5644: if ($hashref->{$field}) {
5645: $checks{$field} = $hashref->{$field};
5646: }
5647: }
5648: }
5649: }
5650: }
5651: } else {
5652: if (ref($hashref) eq 'HASH') {
5653: foreach my $field (@fields) {
5654: if ($hashref->{$field}) {
5655: $checks{$field} = ' checked="checked" ';
5656: }
5657: }
1.33 raeburn 5658: }
5659: }
5660: }
5661: }
5662: }
1.160.6.39 raeburn 5663:
1.33 raeburn 5664: for (my $i=0; $i<@fields; $i++) {
5665: my $rem = $i%($numinrow);
5666: if ($rem == 0) {
5667: if ($i > 0) {
5668: $output .= '</tr>';
5669: }
5670: $output .= '<tr>';
5671: }
5672: my $check = ' ';
1.160.6.35 raeburn 5673: unless ($role eq 'emailusername') {
5674: if (exists($checks{$fields[$i]})) {
5675: $check = $checks{$fields[$i]}
5676: } else {
5677: if ($role eq 'st') {
5678: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 5679: $check = ' checked="checked" ';
1.160.6.35 raeburn 5680: }
1.33 raeburn 5681: }
5682: }
5683: }
5684: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 5685: '<span class="LC_nobreak">';
5686: if ($role eq 'emailusername') {
5687: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5688: $checks{$fields[$i]} = 'omit';
5689: }
5690: foreach my $option ('required','optional','omit') {
5691: my $checked='';
5692: if ($checks{$fields[$i]} eq $option) {
5693: $checked='checked="checked" ';
5694: }
5695: $output .= '<label>'.
5696: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5697: &mt($option).'</label>'.(' ' x2);
5698: }
5699: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5700: } else {
5701: $output .= '<label>'.
5702: '<input type="checkbox" name="canmodify_'.$role.'" '.
5703: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5704: '</label>';
5705: }
5706: $output .= '</span></td>';
1.33 raeburn 5707: $rem = @fields%($numinrow);
5708: }
5709: my $colsleft = $numinrow - $rem;
5710: if ($colsleft > 1 ) {
5711: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5712: ' </td>';
5713: } elsif ($colsleft == 1) {
5714: $output .= '<td class="LC_left_item"> </td>';
5715: }
5716: $output .= '</tr></table></td></tr>';
5717: return $output;
5718: }
1.28 raeburn 5719:
1.93 raeburn 5720: sub insttypes_row {
1.160.6.34 raeburn 5721: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5722: my %lt = &Apache::lonlocal::texthash (
5723: cansearch => 'Users allowed to search',
5724: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5725: lockablenames => 'User preference to lock name',
1.93 raeburn 5726: );
5727: my $showdom;
5728: if ($context eq 'cansearch') {
5729: $showdom = ' ('.$dom.')';
5730: }
1.160.6.5 raeburn 5731: my $class = 'LC_left_item';
5732: if ($context eq 'statustocreate') {
5733: $class = 'LC_right_item';
5734: }
1.160.6.34 raeburn 5735: my $css_class = ' class="LC_odd_row"';
5736: if ($rownum ne '') {
5737: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5738: }
5739: my $output = '<tr'.$css_class.'>'.
5740: '<td>'.$lt{$context}.$showdom.
5741: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5742: my $rem;
5743: if (ref($types) eq 'ARRAY') {
5744: for (my $i=0; $i<@{$types}; $i++) {
5745: if (defined($usertypes->{$types->[$i]})) {
5746: my $rem = $i%($numinrow);
5747: if ($rem == 0) {
5748: if ($i > 0) {
5749: $output .= '</tr>';
5750: }
5751: $output .= '<tr>';
1.23 raeburn 5752: }
1.26 raeburn 5753: my $check = ' ';
1.99 raeburn 5754: if (ref($settings) eq 'HASH') {
5755: if (ref($settings->{$context}) eq 'ARRAY') {
5756: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5757: $check = ' checked="checked" ';
5758: }
5759: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5760: $check = ' checked="checked" ';
5761: }
1.23 raeburn 5762: }
1.26 raeburn 5763: $output .= '<td class="LC_left_item">'.
5764: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5765: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5766: 'value="'.$types->[$i].'"'.$check.'/>'.
5767: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5768: }
5769: }
1.26 raeburn 5770: $rem = @{$types}%($numinrow);
1.23 raeburn 5771: }
5772: my $colsleft = $numinrow - $rem;
1.131 raeburn 5773: if (($rem == 0) && (@{$types} > 0)) {
5774: $output .= '<tr>';
5775: }
1.23 raeburn 5776: if ($colsleft > 1) {
1.25 raeburn 5777: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5778: } else {
1.25 raeburn 5779: $output .= '<td class="LC_left_item">';
1.23 raeburn 5780: }
5781: my $defcheck = ' ';
1.99 raeburn 5782: if (ref($settings) eq 'HASH') {
5783: if (ref($settings->{$context}) eq 'ARRAY') {
5784: if (grep(/^default$/,@{$settings->{$context}})) {
5785: $defcheck = ' checked="checked" ';
5786: }
5787: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5788: $defcheck = ' checked="checked" ';
5789: }
1.23 raeburn 5790: }
1.25 raeburn 5791: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5792: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5793: 'value="default"'.$defcheck.'/>'.
5794: $othertitle.'</label></span></td>'.
5795: '</tr></table></td></tr>';
5796: return $output;
1.23 raeburn 5797: }
5798:
5799: sub sorted_searchtitles {
5800: my %searchtitles = &Apache::lonlocal::texthash(
5801: 'uname' => 'username',
5802: 'lastname' => 'last name',
5803: 'lastfirst' => 'last name, first name',
5804: );
5805: my @titleorder = ('uname','lastname','lastfirst');
5806: return (\%searchtitles,\@titleorder);
5807: }
5808:
1.25 raeburn 5809: sub sorted_searchtypes {
5810: my %srchtypes_desc = (
5811: exact => 'is exact match',
5812: contains => 'contains ..',
5813: begins => 'begins with ..',
5814: );
5815: my @srchtypeorder = ('exact','begins','contains');
5816: return (\%srchtypes_desc,\@srchtypeorder);
5817: }
5818:
1.3 raeburn 5819: sub usertype_update_row {
5820: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5821: my $datatable;
5822: my $numinrow = 4;
5823: foreach my $type (@{$types}) {
5824: if (defined($usertypes->{$type})) {
5825: $$rownums ++;
5826: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5827: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5828: '</td><td class="LC_left_item"><table>';
5829: for (my $i=0; $i<@{$fields}; $i++) {
5830: my $rem = $i%($numinrow);
5831: if ($rem == 0) {
5832: if ($i > 0) {
5833: $datatable .= '</tr>';
5834: }
5835: $datatable .= '<tr>';
5836: }
5837: my $check = ' ';
1.39 raeburn 5838: if (ref($settings) eq 'HASH') {
5839: if (ref($settings->{'fields'}) eq 'HASH') {
5840: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5841: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5842: $check = ' checked="checked" ';
5843: }
1.3 raeburn 5844: }
5845: }
5846: }
5847:
5848: if ($i == @{$fields}-1) {
5849: my $colsleft = $numinrow - $rem;
5850: if ($colsleft > 1) {
5851: $datatable .= '<td colspan="'.$colsleft.'">';
5852: } else {
5853: $datatable .= '<td>';
5854: }
5855: } else {
5856: $datatable .= '<td>';
5857: }
1.8 raeburn 5858: $datatable .= '<span class="LC_nobreak"><label>'.
5859: '<input type="checkbox" name="updateable_'.$type.
5860: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5861: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5862: }
5863: $datatable .= '</tr></table></td></tr>';
5864: }
5865: }
5866: return $datatable;
1.1 raeburn 5867: }
5868:
5869: sub modify_login {
1.160.6.24 raeburn 5870: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 5871: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5872: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5873: %title = ( coursecatalog => 'Display course catalog',
5874: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 5875: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 5876: newuser => 'Link for visitors to create a user account',
5877: loginheader => 'Log-in box header');
5878: @offon = ('off','on');
1.112 raeburn 5879: if (ref($domconfig{login}) eq 'HASH') {
5880: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5881: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5882: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5883: }
5884: }
5885: }
1.9 raeburn 5886: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5887: \%domconfig,\%loginhash);
1.160.6.14 raeburn 5888: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5889: foreach my $item (@toggles) {
5890: $loginhash{login}{$item} = $env{'form.'.$item};
5891: }
1.41 raeburn 5892: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5893: if (ref($colchanges{'login'}) eq 'HASH') {
5894: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5895: \%loginhash);
5896: }
1.110 raeburn 5897:
1.149 raeburn 5898: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 5899: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 5900: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5901: if (keys(%servers) > 1) {
5902: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5903: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5904: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5905: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5906: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5907: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5908: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5909: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5910: $changes{'loginvia'}{$lonhost} = 1;
5911: } else {
5912: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5913: $changes{'loginvia'}{$lonhost} = 1;
5914: }
5915: } else {
5916: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5917: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5918: $changes{'loginvia'}{$lonhost} = 1;
5919: }
5920: }
5921: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5922: foreach my $item (@loginvia_attribs) {
5923: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5924: }
5925: } else {
5926: foreach my $item (@loginvia_attribs) {
5927: my $new = $env{'form.'.$lonhost.'_'.$item};
5928: if (($item eq 'serverpath') && ($new eq 'custom')) {
5929: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5930: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5931: $new = '/';
5932: }
5933: }
5934: if (($item eq 'custompath') &&
5935: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5936: $new = '';
5937: }
5938: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5939: $changes{'loginvia'}{$lonhost} = 1;
5940: }
5941: if ($item eq 'exempt') {
1.160.6.56 raeburn 5942: $new = &check_exempt_addresses($new);
1.128 raeburn 5943: }
5944: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5945: }
5946: }
1.112 raeburn 5947: } else {
1.128 raeburn 5948: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5949: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5950: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5951: foreach my $item (@loginvia_attribs) {
5952: my $new = $env{'form.'.$lonhost.'_'.$item};
5953: if (($item eq 'serverpath') && ($new eq 'custom')) {
5954: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5955: $new = '/';
5956: }
5957: }
5958: if (($item eq 'custompath') &&
5959: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5960: $new = '';
5961: }
5962: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5963: }
1.110 raeburn 5964: }
5965: }
5966: }
5967: }
1.119 raeburn 5968:
1.160.6.5 raeburn 5969: my $servadm = $r->dir_config('lonAdmEMail');
5970: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5971: if (ref($domconfig{'login'}) eq 'HASH') {
5972: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5973: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5974: if ($lang eq 'nolang') {
5975: push(@currlangs,$lang);
5976: } elsif (defined($langchoices{$lang})) {
5977: push(@currlangs,$lang);
5978: } else {
5979: next;
5980: }
5981: }
5982: }
5983: }
5984: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5985: if (@currlangs > 0) {
5986: foreach my $lang (@currlangs) {
5987: if (grep(/^\Q$lang\E$/,@delurls)) {
5988: $changes{'helpurl'}{$lang} = 1;
5989: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5990: $changes{'helpurl'}{$lang} = 1;
5991: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5992: push(@newlangs,$lang);
5993: } else {
5994: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5995: }
5996: }
5997: }
5998: unless (grep(/^nolang$/,@currlangs)) {
5999: if ($env{'form.loginhelpurl_nolang.filename'}) {
6000: $changes{'helpurl'}{'nolang'} = 1;
6001: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6002: push(@newlangs,'nolang');
6003: }
6004: }
6005: if ($env{'form.loginhelpurl_add_lang'}) {
6006: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6007: ($env{'form.loginhelpurl_add_file.filename'})) {
6008: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6009: $addedfile = $env{'form.loginhelpurl_add_lang'};
6010: }
6011: }
6012: if ((@newlangs > 0) || ($addedfile)) {
6013: my $error;
6014: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6015: if ($configuserok eq 'ok') {
6016: if ($switchserver) {
6017: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6018: } elsif ($author_ok eq 'ok') {
6019: my @allnew = @newlangs;
6020: if ($addedfile ne '') {
6021: push(@allnew,$addedfile);
6022: }
6023: foreach my $lang (@allnew) {
6024: my $formelem = 'loginhelpurl_'.$lang;
6025: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6026: $formelem = 'loginhelpurl_add_file';
6027: }
6028: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6029: "help/$lang",'','',$newfile{$lang});
6030: if ($result eq 'ok') {
6031: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6032: $changes{'helpurl'}{$lang} = 1;
6033: } else {
6034: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6035: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6036: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
6037: (!grep(/^\Q$lang\E$/,@delurls))) {
6038:
6039: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6040: }
6041: }
6042: }
6043: } else {
6044: $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);
6045: }
6046: } else {
6047: $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);
6048: }
6049: if ($error) {
6050: &Apache::lonnet::logthis($error);
6051: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6052: }
6053: }
1.160.6.56 raeburn 6054:
6055: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6056: if (ref($domconfig{'login'}) eq 'HASH') {
6057: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6058: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6059: if ($domservers{$lonhost}) {
6060: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6061: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
6062: $currexempt{$lonhost} = $domconfig{'login'}{'headtagexempt'}{$lonhost}{'exempt'}
6063: }
6064: }
6065: }
6066: }
6067: }
6068: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6069: foreach my $lonhost (sort(keys(%domservers))) {
6070: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6071: $changes{'headtag'}{$lonhost} = 1;
6072: } else {
6073: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6074: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6075: }
6076: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6077: push(@newhosts,$lonhost);
6078: } elsif ($currheadtagurls{$lonhost}) {
6079: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6080: if ($currexempt{$lonhost}) {
6081: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6082: $changes{'headtag'}{$lonhost} = 1;
6083: }
6084: } elsif ($possexempt{$lonhost}) {
6085: $changes{'headtag'}{$lonhost} = 1;
6086: }
6087: if ($possexempt{$lonhost}) {
6088: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6089: }
6090: }
6091: }
6092: }
6093: if (@newhosts) {
6094: my $error;
6095: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6096: if ($configuserok eq 'ok') {
6097: if ($switchserver) {
6098: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6099: } elsif ($author_ok eq 'ok') {
6100: foreach my $lonhost (@newhosts) {
6101: my $formelem = 'loginheadtag_'.$lonhost;
6102: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6103: "login/headtag/$lonhost",'','',
6104: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6105: if ($result eq 'ok') {
6106: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6107: $changes{'headtag'}{$lonhost} = 1;
6108: if ($possexempt{$lonhost}) {
6109: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6110: }
6111: } else {
6112: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6113: $newheadtagurls{$lonhost},$result);
6114: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6115: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
6116: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
6117: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
6118: }
6119: }
6120: }
6121: } else {
6122: $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);
6123: }
6124: } else {
6125: $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);
6126: }
6127: if ($error) {
6128: &Apache::lonnet::logthis($error);
6129: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6130: }
6131: }
6132:
1.160.6.5 raeburn 6133: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
6134:
6135: my $defaulthelpfile = '/adm/loginproblems.html';
6136: my $defaulttext = &mt('Default in use');
6137:
1.1 raeburn 6138: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
6139: $dom);
6140: if ($putresult eq 'ok') {
1.160.6.14 raeburn 6141: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6142: my %defaultchecked = (
6143: 'coursecatalog' => 'on',
1.160.6.14 raeburn 6144: 'helpdesk' => 'on',
1.42 raeburn 6145: 'adminmail' => 'off',
1.43 raeburn 6146: 'newuser' => 'off',
1.42 raeburn 6147: );
1.55 raeburn 6148: if (ref($domconfig{'login'}) eq 'HASH') {
6149: foreach my $item (@toggles) {
6150: if ($defaultchecked{$item} eq 'on') {
6151: if (($domconfig{'login'}{$item} eq '0') &&
6152: ($env{'form.'.$item} eq '1')) {
6153: $changes{$item} = 1;
6154: } elsif (($domconfig{'login'}{$item} eq '' ||
6155: $domconfig{'login'}{$item} eq '1') &&
6156: ($env{'form.'.$item} eq '0')) {
6157: $changes{$item} = 1;
6158: }
6159: } elsif ($defaultchecked{$item} eq 'off') {
6160: if (($domconfig{'login'}{$item} eq '1') &&
6161: ($env{'form.'.$item} eq '0')) {
6162: $changes{$item} = 1;
6163: } elsif (($domconfig{'login'}{$item} eq '' ||
6164: $domconfig{'login'}{$item} eq '0') &&
6165: ($env{'form.'.$item} eq '1')) {
6166: $changes{$item} = 1;
6167: }
1.42 raeburn 6168: }
6169: }
1.41 raeburn 6170: }
1.6 raeburn 6171: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 6172: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6173: if (ref($lastactref) eq 'HASH') {
6174: $lastactref->{'domainconfig'} = 1;
6175: }
1.1 raeburn 6176: $resulttext = &mt('Changes made:').'<ul>';
6177: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 6178: if ($item eq 'loginvia') {
1.112 raeburn 6179: if (ref($changes{$item}) eq 'HASH') {
6180: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
6181: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 6182: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
6183: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
6184: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
6185: $protocol = 'http' if ($protocol ne 'https');
6186: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
6187:
6188: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6189: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6190: } else {
6191: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6192: }
6193: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6194: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
6195: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
6196: }
6197: $resulttext .= '</li>';
6198: } else {
6199: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6200: }
1.112 raeburn 6201: } else {
1.128 raeburn 6202: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 6203: }
6204: }
1.128 raeburn 6205: $resulttext .= '</ul></li>';
1.112 raeburn 6206: }
1.160.6.5 raeburn 6207: } elsif ($item eq 'helpurl') {
6208: if (ref($changes{$item}) eq 'HASH') {
6209: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6210: if (grep(/^\Q$lang\E$/,@delurls)) {
6211: my ($chg,$link);
6212: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6213: if ($lang eq 'nolang') {
6214: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6215: } else {
6216: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6217: }
6218: $resulttext .= '<li>'.$chg.'</li>';
6219: } else {
6220: my $chg;
6221: if ($lang eq 'nolang') {
6222: $chg = &mt('custom log-in help file for no preferred language');
6223: } else {
6224: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6225: }
6226: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6227: $loginhash{'login'}{'helpurl'}{$lang}.
6228: '?inhibitmenu=yes',$chg,600,500).
6229: '</li>';
6230: }
6231: }
6232: }
1.160.6.56 raeburn 6233: } elsif ($item eq 'headtag') {
6234: if (ref($changes{$item}) eq 'HASH') {
6235: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
6236: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6237: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
6238: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6239: $resulttext .= '<li><a href="'.
6240: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
6241: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
6242: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
6243: if ($possexempt{$lonhost}) {
6244: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
6245: } else {
6246: $resulttext .= &mt('included for any client IP');
6247: }
6248: $resulttext .= '</li>';
6249: }
6250: }
6251: }
1.160.6.5 raeburn 6252: } elsif ($item eq 'captcha') {
6253: if (ref($loginhash{'login'}) eq 'HASH') {
6254: my $chgtxt;
6255: if ($loginhash{'login'}{$item} eq 'notused') {
6256: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6257: } else {
6258: my %captchas = &captcha_phrases();
6259: if ($captchas{$loginhash{'login'}{$item}}) {
6260: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6261: } else {
6262: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6263: }
6264: }
6265: $resulttext .= '<li>'.$chgtxt.'</li>';
6266: }
6267: } elsif ($item eq 'recaptchakeys') {
6268: if (ref($loginhash{'login'}) eq 'HASH') {
6269: my ($privkey,$pubkey);
6270: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6271: $pubkey = $loginhash{'login'}{$item}{'public'};
6272: $privkey = $loginhash{'login'}{$item}{'private'};
6273: }
6274: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6275: if (!$pubkey) {
6276: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6277: } else {
6278: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6279: }
6280: if (!$privkey) {
6281: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6282: } else {
1.160.6.53 raeburn 6283: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 6284: }
6285: $chgtxt .= '</ul>';
6286: $resulttext .= '<li>'.$chgtxt.'</li>';
6287: }
1.41 raeburn 6288: } else {
6289: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6290: }
1.1 raeburn 6291: }
1.6 raeburn 6292: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6293: } else {
6294: $resulttext = &mt('No changes made to log-in page settings');
6295: }
6296: } else {
1.11 albertel 6297: $resulttext = '<span class="LC_error">'.
6298: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6299: }
1.6 raeburn 6300: if ($errors) {
1.9 raeburn 6301: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6302: $errors.'</ul>';
6303: }
6304: return $resulttext;
6305: }
6306:
1.160.6.56 raeburn 6307: sub check_exempt_addresses {
6308: my ($iplist) = @_;
6309: $iplist =~ s/^\s+//;
6310: $iplist =~ s/\s+$//;
6311: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
6312: my (@okips,$new);
6313: foreach my $ip (@poss_ips) {
6314: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
6315: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
6316: push(@okips,$ip);
6317: }
6318: }
6319: }
6320: if (@okips > 0) {
6321: $new = join(',',@okips);
6322: } else {
6323: $new = '';
6324: }
6325: return $new;
6326: }
6327:
1.6 raeburn 6328: sub color_font_choices {
6329: my %choices =
6330: &Apache::lonlocal::texthash (
6331: img => "Header",
6332: bgs => "Background colors",
6333: links => "Link colors",
1.55 raeburn 6334: images => "Images",
1.6 raeburn 6335: font => "Font color",
1.160.6.22 raeburn 6336: fontmenu => "Font menu",
1.76 raeburn 6337: pgbg => "Page",
1.6 raeburn 6338: tabbg => "Header",
6339: sidebg => "Border",
6340: link => "Link",
6341: alink => "Active link",
6342: vlink => "Visited link",
6343: );
6344: return %choices;
6345: }
6346:
6347: sub modify_rolecolors {
1.160.6.24 raeburn 6348: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6349: my ($resulttext,%rolehash);
6350: $rolehash{'rolecolors'} = {};
1.55 raeburn 6351: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6352: if ($domconfig{'rolecolors'} eq '') {
6353: $domconfig{'rolecolors'} = {};
6354: }
6355: }
1.9 raeburn 6356: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6357: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6358: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6359: $dom);
6360: if ($putresult eq 'ok') {
6361: if (keys(%changes) > 0) {
1.41 raeburn 6362: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6363: if (ref($lastactref) eq 'HASH') {
6364: $lastactref->{'domainconfig'} = 1;
6365: }
1.6 raeburn 6366: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6367: $rolehash{'rolecolors'});
6368: } else {
6369: $resulttext = &mt('No changes made to default color schemes');
6370: }
6371: } else {
1.11 albertel 6372: $resulttext = '<span class="LC_error">'.
6373: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6374: }
6375: if ($errors) {
6376: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6377: $errors.'</ul>';
6378: }
6379: return $resulttext;
6380: }
6381:
6382: sub modify_colors {
1.9 raeburn 6383: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6384: my (%changes,%choices);
1.51 raeburn 6385: my @bgs;
1.6 raeburn 6386: my @links = ('link','alink','vlink');
1.41 raeburn 6387: my @logintext;
1.6 raeburn 6388: my @images;
6389: my $servadm = $r->dir_config('lonAdmEMail');
6390: my $errors;
1.160.6.22 raeburn 6391: my %defaults;
1.6 raeburn 6392: foreach my $role (@{$roles}) {
6393: if ($role eq 'login') {
1.12 raeburn 6394: %choices = &login_choices();
1.41 raeburn 6395: @logintext = ('textcol','bgcol');
1.12 raeburn 6396: } else {
6397: %choices = &color_font_choices();
6398: }
6399: if ($role eq 'login') {
1.41 raeburn 6400: @images = ('img','logo','domlogo','login');
1.51 raeburn 6401: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6402: } else {
6403: @images = ('img');
1.160.6.22 raeburn 6404: @bgs = ('pgbg','tabbg','sidebg');
6405: }
6406: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6407: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6408: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6409: }
6410: if ($role eq 'login') {
6411: foreach my $item (@logintext) {
1.160.6.39 raeburn 6412: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6413: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6414: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6415: }
6416: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 6417: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6418: }
6419: }
6420: } else {
1.160.6.39 raeburn 6421: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6422: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6423: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6424: }
6425: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 6426: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6427: }
1.6 raeburn 6428: }
1.160.6.22 raeburn 6429: foreach my $item (@bgs) {
1.160.6.39 raeburn 6430: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6431: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6432: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6433: }
6434: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 6435: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6436: }
6437: }
6438: foreach my $item (@links) {
1.160.6.39 raeburn 6439: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6440: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6441: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6442: }
6443: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 6444: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6445: }
1.6 raeburn 6446: }
1.46 raeburn 6447: my ($configuserok,$author_ok,$switchserver) =
6448: &config_check($dom,$confname,$servadm);
1.9 raeburn 6449: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6450: if (ref($domconfig->{$role}) ne 'HASH') {
6451: $domconfig->{$role} = {};
6452: }
1.8 raeburn 6453: foreach my $img (@images) {
1.70 raeburn 6454: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6455: if (defined($env{'form.login_showlogo_'.$img})) {
6456: $confhash->{$role}{'showlogo'}{$img} = 1;
6457: } else {
6458: $confhash->{$role}{'showlogo'}{$img} = 0;
6459: }
6460: }
1.18 albertel 6461: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6462: && !defined($domconfig->{$role}{$img})
6463: && !$env{'form.'.$role.'_del_'.$img}
6464: && $env{'form.'.$role.'_import_'.$img}) {
6465: # import the old configured image from the .tab setting
6466: # if they haven't provided a new one
6467: $domconfig->{$role}{$img} =
6468: $env{'form.'.$role.'_import_'.$img};
6469: }
1.6 raeburn 6470: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6471: my $error;
1.6 raeburn 6472: if ($configuserok eq 'ok') {
1.9 raeburn 6473: if ($switchserver) {
1.12 raeburn 6474: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6475: } else {
6476: if ($author_ok eq 'ok') {
6477: my ($result,$logourl) =
6478: &publishlogo($r,'upload',$role.'_'.$img,
6479: $dom,$confname,$img,$width,$height);
6480: if ($result eq 'ok') {
6481: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6482: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6483: } else {
1.12 raeburn 6484: $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 6485: }
6486: } else {
1.46 raeburn 6487: $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 6488: }
6489: }
6490: } else {
1.46 raeburn 6491: $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 6492: }
6493: if ($error) {
1.8 raeburn 6494: &Apache::lonnet::logthis($error);
1.11 albertel 6495: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6496: }
6497: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6498: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6499: my $error;
6500: if ($configuserok eq 'ok') {
6501: # is confname an author?
6502: if ($switchserver eq '') {
6503: if ($author_ok eq 'ok') {
6504: my ($result,$logourl) =
6505: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6506: $dom,$confname,$img,$width,$height);
6507: if ($result eq 'ok') {
6508: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6509: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6510: }
6511: }
6512: }
6513: }
1.6 raeburn 6514: }
6515: }
6516: }
6517: if (ref($domconfig) eq 'HASH') {
6518: if (ref($domconfig->{$role}) eq 'HASH') {
6519: foreach my $img (@images) {
6520: if ($domconfig->{$role}{$img} ne '') {
6521: if ($env{'form.'.$role.'_del_'.$img}) {
6522: $confhash->{$role}{$img} = '';
1.12 raeburn 6523: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6524: } else {
1.9 raeburn 6525: if ($confhash->{$role}{$img} eq '') {
6526: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6527: }
1.6 raeburn 6528: }
6529: } else {
6530: if ($env{'form.'.$role.'_del_'.$img}) {
6531: $confhash->{$role}{$img} = '';
1.12 raeburn 6532: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6533: }
6534: }
1.70 raeburn 6535: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6536: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6537: if ($confhash->{$role}{'showlogo'}{$img} ne
6538: $domconfig->{$role}{'showlogo'}{$img}) {
6539: $changes{$role}{'showlogo'}{$img} = 1;
6540: }
6541: } else {
6542: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6543: $changes{$role}{'showlogo'}{$img} = 1;
6544: }
6545: }
6546: }
6547: }
1.6 raeburn 6548: if ($domconfig->{$role}{'font'} ne '') {
6549: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6550: $changes{$role}{'font'} = 1;
6551: }
6552: } else {
6553: if ($confhash->{$role}{'font'}) {
6554: $changes{$role}{'font'} = 1;
6555: }
6556: }
1.107 raeburn 6557: if ($role ne 'login') {
6558: if ($domconfig->{$role}{'fontmenu'} ne '') {
6559: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6560: $changes{$role}{'fontmenu'} = 1;
6561: }
6562: } else {
6563: if ($confhash->{$role}{'fontmenu'}) {
6564: $changes{$role}{'fontmenu'} = 1;
6565: }
1.97 tempelho 6566: }
6567: }
1.6 raeburn 6568: foreach my $item (@bgs) {
6569: if ($domconfig->{$role}{$item} ne '') {
6570: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6571: $changes{$role}{'bgs'}{$item} = 1;
6572: }
6573: } else {
6574: if ($confhash->{$role}{$item}) {
6575: $changes{$role}{'bgs'}{$item} = 1;
6576: }
6577: }
6578: }
6579: foreach my $item (@links) {
6580: if ($domconfig->{$role}{$item} ne '') {
6581: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6582: $changes{$role}{'links'}{$item} = 1;
6583: }
6584: } else {
6585: if ($confhash->{$role}{$item}) {
6586: $changes{$role}{'links'}{$item} = 1;
6587: }
6588: }
6589: }
1.41 raeburn 6590: foreach my $item (@logintext) {
6591: if ($domconfig->{$role}{$item} ne '') {
6592: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6593: $changes{$role}{'logintext'}{$item} = 1;
6594: }
6595: } else {
6596: if ($confhash->{$role}{$item}) {
6597: $changes{$role}{'logintext'}{$item} = 1;
6598: }
6599: }
6600: }
1.6 raeburn 6601: } else {
6602: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6603: \@logintext,$confhash,\%changes);
1.6 raeburn 6604: }
6605: } else {
6606: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6607: \@logintext,$confhash,\%changes);
1.6 raeburn 6608: }
6609: }
6610: return ($errors,%changes);
6611: }
6612:
1.46 raeburn 6613: sub config_check {
6614: my ($dom,$confname,$servadm) = @_;
6615: my ($configuserok,$author_ok,$switchserver,%currroles);
6616: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6617: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6618: $confname,$servadm);
6619: if ($configuserok eq 'ok') {
6620: $switchserver = &check_switchserver($dom,$confname);
6621: if ($switchserver eq '') {
6622: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6623: }
6624: }
6625: return ($configuserok,$author_ok,$switchserver);
6626: }
6627:
1.6 raeburn 6628: sub default_change_checker {
1.41 raeburn 6629: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6630: foreach my $item (@{$links}) {
6631: if ($confhash->{$role}{$item}) {
6632: $changes->{$role}{'links'}{$item} = 1;
6633: }
6634: }
6635: foreach my $item (@{$bgs}) {
6636: if ($confhash->{$role}{$item}) {
6637: $changes->{$role}{'bgs'}{$item} = 1;
6638: }
6639: }
1.41 raeburn 6640: foreach my $item (@{$logintext}) {
6641: if ($confhash->{$role}{$item}) {
6642: $changes->{$role}{'logintext'}{$item} = 1;
6643: }
6644: }
1.6 raeburn 6645: foreach my $img (@{$images}) {
6646: if ($env{'form.'.$role.'_del_'.$img}) {
6647: $confhash->{$role}{$img} = '';
1.12 raeburn 6648: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6649: }
1.70 raeburn 6650: if ($role eq 'login') {
6651: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6652: $changes->{$role}{'showlogo'}{$img} = 1;
6653: }
6654: }
1.6 raeburn 6655: }
6656: if ($confhash->{$role}{'font'}) {
6657: $changes->{$role}{'font'} = 1;
6658: }
1.48 raeburn 6659: }
1.6 raeburn 6660:
6661: sub display_colorchgs {
6662: my ($dom,$changes,$roles,$confhash) = @_;
6663: my (%choices,$resulttext);
6664: if (!grep(/^login$/,@{$roles})) {
6665: $resulttext = &mt('Changes made:').'<br />';
6666: }
6667: foreach my $role (@{$roles}) {
6668: if ($role eq 'login') {
6669: %choices = &login_choices();
6670: } else {
6671: %choices = &color_font_choices();
6672: }
6673: if (ref($changes->{$role}) eq 'HASH') {
6674: if ($role ne 'login') {
6675: $resulttext .= '<h4>'.&mt($role).'</h4>';
6676: }
6677: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6678: if ($role ne 'login') {
6679: $resulttext .= '<ul>';
6680: }
6681: if (ref($changes->{$role}{$key}) eq 'HASH') {
6682: if ($role ne 'login') {
6683: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6684: }
6685: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6686: if (($role eq 'login') && ($key eq 'showlogo')) {
6687: if ($confhash->{$role}{$key}{$item}) {
6688: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6689: } else {
6690: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6691: }
6692: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6693: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6694: } else {
1.12 raeburn 6695: my $newitem = $confhash->{$role}{$item};
6696: if ($key eq 'images') {
6697: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6698: }
6699: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6700: }
6701: }
6702: if ($role ne 'login') {
6703: $resulttext .= '</ul></li>';
6704: }
6705: } else {
6706: if ($confhash->{$role}{$key} eq '') {
6707: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6708: } else {
6709: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6710: }
6711: }
6712: if ($role ne 'login') {
6713: $resulttext .= '</ul>';
6714: }
6715: }
6716: }
6717: }
1.3 raeburn 6718: return $resulttext;
1.1 raeburn 6719: }
6720:
1.9 raeburn 6721: sub thumb_dimensions {
6722: return ('200','50');
6723: }
6724:
1.16 raeburn 6725: sub check_dimensions {
6726: my ($inputfile) = @_;
6727: my ($fullwidth,$fullheight);
6728: if ($inputfile =~ m|^[/\w.\-]+$|) {
6729: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6730: my $imageinfo = <PIPE>;
6731: if (!close(PIPE)) {
6732: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6733: }
6734: chomp($imageinfo);
6735: my ($fullsize) =
1.21 raeburn 6736: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6737: if ($fullsize) {
6738: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6739: }
6740: }
6741: }
6742: return ($fullwidth,$fullheight);
6743: }
6744:
1.9 raeburn 6745: sub check_configuser {
6746: my ($uhome,$dom,$confname,$servadm) = @_;
6747: my ($configuserok,%currroles);
6748: if ($uhome eq 'no_host') {
6749: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6750: my $configpass = &LONCAPA::Enrollment::create_password();
6751: $configuserok =
6752: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6753: $configpass,'','','','','',undef,$servadm);
6754: } else {
6755: $configuserok = 'ok';
6756: %currroles =
6757: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6758: }
6759: return ($configuserok,%currroles);
6760: }
6761:
6762: sub check_authorstatus {
6763: my ($dom,$confname,%currroles) = @_;
6764: my $author_ok;
1.40 raeburn 6765: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6766: my $start = time;
6767: my $end = 0;
6768: $author_ok =
6769: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6770: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6771: } else {
6772: $author_ok = 'ok';
6773: }
6774: return $author_ok;
6775: }
6776:
6777: sub publishlogo {
1.46 raeburn 6778: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6779: my ($output,$fname,$logourl);
6780: if ($action eq 'upload') {
6781: $fname=$env{'form.'.$formname.'.filename'};
6782: chop($env{'form.'.$formname});
6783: } else {
6784: ($fname) = ($formname =~ /([^\/]+)$/);
6785: }
1.46 raeburn 6786: if ($savefileas ne '') {
6787: $fname = $savefileas;
6788: }
1.9 raeburn 6789: $fname=&Apache::lonnet::clean_filename($fname);
6790: # See if there is anything left
6791: unless ($fname) { return ('error: no uploaded file'); }
6792: $fname="$subdir/$fname";
1.160.6.5 raeburn 6793: my $docroot=$r->dir_config('lonDocRoot');
6794: my $filepath="$docroot/priv";
6795: my $relpath = "$dom/$confname";
1.9 raeburn 6796: my ($fnamepath,$file,$fetchthumb);
6797: $file=$fname;
6798: if ($fname=~m|/|) {
6799: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6800: }
1.160.6.26 raeburn 6801: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6802: my $count;
1.160.6.5 raeburn 6803: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6804: $filepath.="/$parts[$count]";
6805: if ((-e $filepath)!=1) {
6806: mkdir($filepath,02770);
6807: }
6808: }
6809: # Check for bad extension and disallow upload
6810: if ($file=~/\.(\w+)$/ &&
6811: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6812: $output =
1.160.6.25 raeburn 6813: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6814: } elsif ($file=~/\.(\w+)$/ &&
6815: !defined(&Apache::loncommon::fileembstyle($1))) {
6816: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6817: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 6818: $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 6819: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 6820: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6821: } else {
6822: my $source = $filepath.'/'.$file;
6823: my $logfile;
6824: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 6825: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6826: }
6827: print $logfile
6828: "\n================= Publish ".localtime()." ================\n".
6829: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6830: # Save the file
6831: if (!open(FH,'>'.$source)) {
6832: &Apache::lonnet::logthis('Failed to create '.$source);
6833: return (&mt('Failed to create file'));
6834: }
6835: if ($action eq 'upload') {
6836: if (!print FH ($env{'form.'.$formname})) {
6837: &Apache::lonnet::logthis('Failed to write to '.$source);
6838: return (&mt('Failed to write file'));
6839: }
6840: } else {
6841: my $original = &Apache::lonnet::filelocation('',$formname);
6842: if(!copy($original,$source)) {
6843: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6844: return (&mt('Failed to write file'));
6845: }
6846: }
6847: close(FH);
6848: chmod(0660, $source); # Permissions to rw-rw---.
6849:
6850: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6851: my $copyfile=$targetdir.'/'.$file;
6852:
6853: my @parts=split(/\//,$targetdir);
6854: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6855: for (my $count=5;$count<=$#parts;$count++) {
6856: $path.="/$parts[$count]";
6857: if (!-e $path) {
6858: print $logfile "\nCreating directory ".$path;
6859: mkdir($path,02770);
6860: }
6861: }
6862: my $versionresult;
6863: if (-e $copyfile) {
6864: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6865: } else {
6866: $versionresult = 'ok';
6867: }
6868: if ($versionresult eq 'ok') {
6869: if (copy($source,$copyfile)) {
6870: print $logfile "\nCopied original source to ".$copyfile."\n";
6871: $output = 'ok';
6872: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6873: push(@{$modified_urls},[$copyfile,$source]);
6874: my $metaoutput =
6875: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6876: unless ($registered_cleanup) {
6877: my $handlers = $r->get_handlers('PerlCleanupHandler');
6878: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6879: $registered_cleanup=1;
6880: }
1.9 raeburn 6881: } else {
6882: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6883: $output = &mt('Failed to copy file to RES space').", $!";
6884: }
6885: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6886: my $inputfile = $filepath.'/'.$file;
6887: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6888: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6889: if ($fullwidth ne '' && $fullheight ne '') {
6890: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6891: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6892: system("convert -sample $thumbsize $inputfile $outfile");
6893: chmod(0660, $filepath.'/tn-'.$file);
6894: if (-e $outfile) {
6895: my $copyfile=$targetdir.'/tn-'.$file;
6896: if (copy($outfile,$copyfile)) {
6897: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6898: my $thumb_metaoutput =
6899: &write_metadata($dom,$confname,$formname,
6900: $targetdir,'tn-'.$file,$logfile);
6901: push(@{$modified_urls},[$copyfile,$outfile]);
6902: unless ($registered_cleanup) {
6903: my $handlers = $r->get_handlers('PerlCleanupHandler');
6904: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6905: $registered_cleanup=1;
6906: }
1.16 raeburn 6907: } else {
6908: print $logfile "\nUnable to write ".$copyfile.
6909: ':'.$!."\n";
6910: }
6911: }
1.9 raeburn 6912: }
6913: }
6914: }
6915: } else {
6916: $output = $versionresult;
6917: }
6918: }
6919: return ($output,$logourl);
6920: }
6921:
6922: sub logo_versioning {
6923: my ($targetdir,$file,$logfile) = @_;
6924: my $target = $targetdir.'/'.$file;
6925: my ($maxversion,$fn,$extn,$output);
6926: $maxversion = 0;
6927: if ($file =~ /^(.+)\.(\w+)$/) {
6928: $fn=$1;
6929: $extn=$2;
6930: }
6931: opendir(DIR,$targetdir);
6932: while (my $filename=readdir(DIR)) {
6933: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6934: $maxversion=($1>$maxversion)?$1:$maxversion;
6935: }
6936: }
6937: $maxversion++;
6938: print $logfile "\nCreating old version ".$maxversion."\n";
6939: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6940: if (copy($target,$copyfile)) {
6941: print $logfile "Copied old target to ".$copyfile."\n";
6942: $copyfile=$copyfile.'.meta';
6943: if (copy($target.'.meta',$copyfile)) {
6944: print $logfile "Copied old target metadata to ".$copyfile."\n";
6945: $output = 'ok';
6946: } else {
6947: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6948: $output = &mt('Failed to copy old meta').", $!, ";
6949: }
6950: } else {
6951: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6952: $output = &mt('Failed to copy old target').", $!, ";
6953: }
6954: return $output;
6955: }
6956:
6957: sub write_metadata {
6958: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6959: my (%metadatafields,%metadatakeys,$output);
6960: $metadatafields{'title'}=$formname;
6961: $metadatafields{'creationdate'}=time;
6962: $metadatafields{'lastrevisiondate'}=time;
6963: $metadatafields{'copyright'}='public';
6964: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6965: $env{'user.domain'};
6966: $metadatafields{'authorspace'}=$confname.':'.$dom;
6967: $metadatafields{'domain'}=$dom;
6968: {
6969: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6970: my $mfh;
1.155 raeburn 6971: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 6972: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6973: unless ($_=~/\./) {
6974: my $unikey=$_;
6975: $unikey=~/^([A-Za-z]+)/;
6976: my $tag=$1;
6977: $tag=~tr/A-Z/a-z/;
6978: print $mfh "\n\<$tag";
6979: foreach (split(/\,/,$metadatakeys{$unikey})) {
6980: my $value=$metadatafields{$unikey.'.'.$_};
6981: $value=~s/\"/\'\'/g;
6982: print $mfh ' '.$_.'="'.$value.'"';
6983: }
6984: print $mfh '>'.
6985: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6986: .'</'.$tag.'>';
6987: }
6988: }
6989: $output = 'ok';
6990: print $logfile "\nWrote metadata";
6991: close($mfh);
6992: } else {
6993: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6994: $output = &mt('Could not write metadata');
6995: }
6996: }
1.155 raeburn 6997: return $output;
6998: }
6999:
7000: sub notifysubscribed {
7001: foreach my $targetsource (@{$modified_urls}){
7002: next unless (ref($targetsource) eq 'ARRAY');
7003: my ($target,$source)=@{$targetsource};
7004: if ($source ne '') {
7005: if (open(my $logfh,'>>'.$source.'.log')) {
7006: print $logfh "\nCleanup phase: Notifications\n";
7007: my @subscribed=&subscribed_hosts($target);
7008: foreach my $subhost (@subscribed) {
7009: print $logfh "\nNotifying host ".$subhost.':';
7010: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7011: print $logfh $reply;
7012: }
7013: my @subscribedmeta=&subscribed_hosts("$target.meta");
7014: foreach my $subhost (@subscribedmeta) {
7015: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7016: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7017: $subhost);
7018: print $logfh $reply;
7019: }
7020: print $logfh "\n============ Done ============\n";
1.160 raeburn 7021: close($logfh);
1.155 raeburn 7022: }
7023: }
7024: }
7025: return OK;
7026: }
7027:
7028: sub subscribed_hosts {
7029: my ($target) = @_;
7030: my @subscribed;
7031: if (open(my $fh,"<$target.subscription")) {
7032: while (my $subline=<$fh>) {
7033: if ($subline =~ /^($match_lonid):/) {
7034: my $host = $1;
7035: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7036: unless (grep(/^\Q$host\E$/,@subscribed)) {
7037: push(@subscribed,$host);
7038: }
7039: }
7040: }
7041: }
7042: }
7043: return @subscribed;
1.9 raeburn 7044: }
7045:
7046: sub check_switchserver {
7047: my ($dom,$confname) = @_;
7048: my ($allowed,$switchserver);
7049: my $home = &Apache::lonnet::homeserver($confname,$dom);
7050: if ($home eq 'no_host') {
7051: $home = &Apache::lonnet::domain($dom,'primary');
7052: }
7053: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7054: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7055: if (!$allowed) {
1.160.6.11 raeburn 7056: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7057: }
7058: return $switchserver;
7059: }
7060:
1.1 raeburn 7061: sub modify_quotas {
1.160.6.30 raeburn 7062: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7063: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 7064: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 7065: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7066: $validationfieldsref);
1.86 raeburn 7067: if ($action eq 'quotas') {
7068: $context = 'tools';
1.160.6.26 raeburn 7069: } else {
1.86 raeburn 7070: $context = $action;
7071: }
7072: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 7073: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 7074: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7075: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7076: %titles = &courserequest_titles();
7077: $toolregexp = join('|',@usertools);
7078: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 7079: $confname = $dom.'-domainconfig';
7080: my $servadm = $r->dir_config('lonAdmEMail');
7081: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 7082: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7083: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 7084: } elsif ($context eq 'requestauthor') {
7085: @usertools = ('author');
7086: %titles = &authorrequest_titles();
1.86 raeburn 7087: } else {
1.160.6.4 raeburn 7088: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7089: %titles = &tool_titles();
1.86 raeburn 7090: }
1.160.6.27 raeburn 7091: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7092: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7093: foreach my $key (keys(%env)) {
1.101 raeburn 7094: if ($context eq 'requestcourses') {
7095: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7096: my $item = $1;
7097: my $type = $2;
7098: if ($type =~ /^limit_(.+)/) {
7099: $limithash{$item}{$1} = $env{$key};
7100: } else {
7101: $confhash{$item}{$type} = $env{$key};
7102: }
7103: }
1.160.6.5 raeburn 7104: } elsif ($context eq 'requestauthor') {
7105: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7106: $confhash{$1} = $env{$key};
7107: }
1.101 raeburn 7108: } else {
1.86 raeburn 7109: if ($key =~ /^form\.quota_(.+)$/) {
7110: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 7111: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7112: $confhash{'authorquota'}{$1} = $env{$key};
7113: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 7114: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7115: }
1.72 raeburn 7116: }
7117: }
1.160.6.5 raeburn 7118: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 7119: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 7120: @approvalnotify = sort(@approvalnotify);
7121: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 7122: my @crstypes = ('official','unofficial','community','textbook');
7123: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
7124: foreach my $type (@hasuniquecode) {
7125: if (grep(/^\Q$type\E$/,@crstypes)) {
7126: $confhash{'uniquecode'}{$type} = 1;
7127: }
7128: }
1.160.6.46 raeburn 7129: my (%newbook,%allpos);
1.160.6.30 raeburn 7130: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7131: foreach my $type ('textbooks','templates') {
7132: @{$allpos{$type}} = ();
7133: my $invalid;
7134: if ($type eq 'textbooks') {
7135: $invalid = &mt('Invalid LON-CAPA course for textbook');
7136: } else {
7137: $invalid = &mt('Invalid LON-CAPA course for template');
7138: }
7139: if ($env{'form.'.$type.'_addbook'}) {
7140: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
7141: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
7142: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
7143: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
7144: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7145: } else {
7146: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
7147: my $position = $env{'form.'.$type.'_addbook_pos'};
7148: $position =~ s/\D+//g;
7149: if ($position ne '') {
7150: $allpos{$type}[$position] = $newbook{$type};
7151: }
1.160.6.30 raeburn 7152: }
1.160.6.46 raeburn 7153: } else {
7154: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 7155: }
7156: }
1.160.6.46 raeburn 7157: }
1.160.6.30 raeburn 7158: }
1.102 raeburn 7159: if (ref($domconfig{$action}) eq 'HASH') {
7160: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
7161: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
7162: $changes{'notify'}{'approval'} = 1;
7163: }
7164: } else {
1.144 raeburn 7165: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7166: $changes{'notify'}{'approval'} = 1;
7167: }
7168: }
1.160.6.30 raeburn 7169: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
7170: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7171: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
7172: unless ($confhash{'uniquecode'}{$crstype}) {
7173: $changes{'uniquecode'} = 1;
7174: }
7175: }
7176: unless ($changes{'uniquecode'}) {
7177: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
7178: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
7179: $changes{'uniquecode'} = 1;
7180: }
7181: }
7182: }
7183: } else {
7184: $changes{'uniquecode'} = 1;
7185: }
7186: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
7187: $changes{'uniquecode'} = 1;
7188: }
7189: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7190: foreach my $type ('textbooks','templates') {
7191: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7192: my %deletions;
7193: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
7194: if (@todelete) {
7195: map { $deletions{$_} = 1; } @todelete;
7196: }
7197: my %imgdeletions;
7198: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
7199: if (@todeleteimages) {
7200: map { $imgdeletions{$_} = 1; } @todeleteimages;
7201: }
7202: my $maxnum = $env{'form.'.$type.'_maxnum'};
7203: for (my $i=0; $i<=$maxnum; $i++) {
7204: my $itemid = $env{'form.'.$type.'_id_'.$i};
7205: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
7206: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
7207: if ($deletions{$key}) {
7208: if ($domconfig{$action}{$type}{$key}{'image'}) {
7209: #FIXME need to obsolete item in RES space
7210: }
7211: next;
7212: } else {
7213: my $newpos = $env{'form.'.$itemid};
7214: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 7215: foreach my $item ('subject','title','publisher','author') {
7216: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7217: ($type eq 'templates'));
1.160.6.46 raeburn 7218: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
7219: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
7220: $changes{$type}{$key} = 1;
7221: }
7222: }
7223: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 7224: }
1.160.6.46 raeburn 7225: if ($imgdeletions{$key}) {
7226: $changes{$type}{$key} = 1;
7227: #FIXME need to obsolete item in RES space
7228: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
7229: my ($cdom,$cnum) = split(/_/,$key);
7230: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
7231: $cdom,$cnum,$type,$configuserok,
7232: $switchserver,$author_ok);
7233: if ($imgurl) {
7234: $confhash{$type}{$key}{'image'} = $imgurl;
7235: $changes{$type}{$key} = 1;
1.160.6.30 raeburn 7236: }
1.160.6.46 raeburn 7237: if ($error) {
7238: &Apache::lonnet::logthis($error);
7239: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7240: }
7241: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7242: $confhash{$type}{$key}{'image'} =
7243: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 7244: }
7245: }
7246: }
7247: }
7248: }
7249: }
1.102 raeburn 7250: } else {
1.144 raeburn 7251: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7252: $changes{'notify'}{'approval'} = 1;
7253: }
1.160.6.30 raeburn 7254: if (ref($confhash{'uniquecode'} eq 'HASH')) {
7255: $changes{'uniquecode'} = 1;
7256: }
7257: }
7258: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7259: foreach my $type ('textbooks','templates') {
7260: if ($newbook{$type}) {
7261: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 7262: foreach my $item ('subject','title','publisher','author') {
7263: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7264: ($type eq 'template'));
1.160.6.46 raeburn 7265: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7266: if ($env{'form.'.$type.'_addbook_'.$item}) {
7267: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7268: }
7269: }
7270: if ($type eq 'textbooks') {
7271: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7272: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7273: my ($imageurl,$error) =
7274: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7275: $configuserok,$switchserver,$author_ok);
7276: if ($imageurl) {
7277: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7278: }
7279: if ($error) {
7280: &Apache::lonnet::logthis($error);
7281: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7282: }
7283: }
1.160.6.30 raeburn 7284: }
7285: }
1.160.6.46 raeburn 7286: if (@{$allpos{$type}} > 0) {
7287: my $idx = 0;
7288: foreach my $item (@{$allpos{$type}}) {
7289: if ($item ne '') {
7290: $confhash{$type}{$item}{'order'} = $idx;
7291: if (ref($domconfig{$action}) eq 'HASH') {
7292: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7293: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7294: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7295: $changes{$type}{$item} = 1;
7296: }
1.160.6.30 raeburn 7297: }
7298: }
7299: }
1.160.6.46 raeburn 7300: $idx ++;
1.160.6.30 raeburn 7301: }
7302: }
7303: }
7304: }
1.160.6.39 raeburn 7305: if (ref($validationitemsref) eq 'ARRAY') {
7306: foreach my $item (@{$validationitemsref}) {
7307: if ($item eq 'fields') {
7308: my @changed;
7309: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7310: if (@{$confhash{'validation'}{$item}} > 0) {
7311: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7312: }
7313: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7314: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7315: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7316: $domconfig{'requestcourses'}{'validation'}{$item});
7317: } else {
7318: @changed = @{$confhash{'validation'}{$item}};
7319: }
7320: } else {
7321: @changed = @{$confhash{'validation'}{$item}};
7322: }
7323: if (@changed) {
7324: if ($confhash{'validation'}{$item}) {
7325: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7326: } else {
7327: $changes{'validation'}{$item} = &mt('None');
7328: }
7329: }
7330: } else {
7331: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7332: if ($item eq 'markup') {
7333: if ($env{'form.requestcourses_validation_'.$item}) {
7334: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7335: }
7336: }
7337: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7338: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7339: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7340: }
7341: } else {
7342: if ($confhash{'validation'}{$item} ne '') {
7343: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7344: }
7345: }
7346: }
7347: }
7348: }
7349: if ($env{'form.validationdc'}) {
7350: my $newval = $env{'form.validationdc'};
7351: my %domcoords = &get_active_dcs($dom);
7352: if (exists($domcoords{$newval})) {
7353: $confhash{'validation'}{'dc'} = $newval;
7354: }
7355: }
7356: if (ref($confhash{'validation'}) eq 'HASH') {
7357: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7358: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7359: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7360: if ($confhash{'validation'}{'dc'} eq '') {
7361: $changes{'validation'}{'dc'} = &mt('None');
7362: } else {
7363: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7364: }
7365: }
7366: } elsif ($confhash{'validation'}{'dc'} ne '') {
7367: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7368: }
7369: } elsif ($confhash{'validation'}{'dc'} ne '') {
7370: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7371: }
7372: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7373: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7374: $changes{'validation'}{'dc'} = &mt('None');
7375: }
7376: }
1.102 raeburn 7377: }
7378: } else {
1.86 raeburn 7379: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 7380: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7381: }
1.72 raeburn 7382: foreach my $item (@usertools) {
7383: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7384: my $unset;
1.101 raeburn 7385: if ($context eq 'requestcourses') {
1.104 raeburn 7386: $unset = '0';
7387: if ($type eq '_LC_adv') {
7388: $unset = '';
7389: }
1.101 raeburn 7390: if ($confhash{$item}{$type} eq 'autolimit') {
7391: $confhash{$item}{$type} .= '=';
7392: unless ($limithash{$item}{$type} =~ /\D/) {
7393: $confhash{$item}{$type} .= $limithash{$item}{$type};
7394: }
7395: }
1.160.6.5 raeburn 7396: } elsif ($context eq 'requestauthor') {
7397: $unset = '0';
7398: if ($type eq '_LC_adv') {
7399: $unset = '';
7400: }
1.72 raeburn 7401: } else {
1.101 raeburn 7402: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7403: $confhash{$item}{$type} = 1;
7404: } else {
7405: $confhash{$item}{$type} = 0;
7406: }
1.72 raeburn 7407: }
1.86 raeburn 7408: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 7409: if ($action eq 'requestauthor') {
7410: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7411: $changes{$type} = 1;
7412: }
7413: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7414: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7415: $changes{$item}{$type} = 1;
7416: }
7417: } else {
7418: if ($context eq 'requestcourses') {
1.104 raeburn 7419: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7420: $changes{$item}{$type} = 1;
7421: }
7422: } else {
7423: if (!$confhash{$item}{$type}) {
7424: $changes{$item}{$type} = 1;
7425: }
7426: }
7427: }
7428: } else {
7429: if ($context eq 'requestcourses') {
1.104 raeburn 7430: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7431: $changes{$item}{$type} = 1;
7432: }
1.160.6.5 raeburn 7433: } elsif ($context eq 'requestauthor') {
7434: if ($confhash{$type} ne $unset) {
7435: $changes{$type} = 1;
7436: }
1.72 raeburn 7437: } else {
7438: if (!$confhash{$item}{$type}) {
7439: $changes{$item}{$type} = 1;
7440: }
7441: }
7442: }
1.1 raeburn 7443: }
7444: }
1.160.6.5 raeburn 7445: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7446: if (ref($domconfig{'quotas'}) eq 'HASH') {
7447: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7448: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7449: if (exists($confhash{'defaultquota'}{$key})) {
7450: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7451: $changes{'defaultquota'}{$key} = 1;
7452: }
7453: } else {
7454: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7455: }
7456: }
1.86 raeburn 7457: } else {
7458: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7459: if (exists($confhash{'defaultquota'}{$key})) {
7460: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7461: $changes{'defaultquota'}{$key} = 1;
7462: }
7463: } else {
7464: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7465: }
1.1 raeburn 7466: }
7467: }
1.160.6.20 raeburn 7468: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7469: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7470: if (exists($confhash{'authorquota'}{$key})) {
7471: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7472: $changes{'authorquota'}{$key} = 1;
7473: }
7474: } else {
7475: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7476: }
7477: }
7478: }
1.1 raeburn 7479: }
1.86 raeburn 7480: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7481: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7482: if (ref($domconfig{'quotas'}) eq 'HASH') {
7483: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7484: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7485: $changes{'defaultquota'}{$key} = 1;
7486: }
7487: } else {
7488: if (!exists($domconfig{'quotas'}{$key})) {
7489: $changes{'defaultquota'}{$key} = 1;
7490: }
1.72 raeburn 7491: }
7492: } else {
1.86 raeburn 7493: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7494: }
1.1 raeburn 7495: }
7496: }
1.160.6.20 raeburn 7497: if (ref($confhash{'authorquota'}) eq 'HASH') {
7498: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7499: if (ref($domconfig{'quotas'}) eq 'HASH') {
7500: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7501: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7502: $changes{'authorquota'}{$key} = 1;
7503: }
7504: } else {
7505: $changes{'authorquota'}{$key} = 1;
7506: }
7507: } else {
7508: $changes{'authorquota'}{$key} = 1;
7509: }
7510: }
7511: }
1.1 raeburn 7512: }
1.72 raeburn 7513:
1.160.6.5 raeburn 7514: if ($context eq 'requestauthor') {
7515: $domdefaults{'requestauthor'} = \%confhash;
7516: } else {
7517: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 7518: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 7519: $domdefaults{$key} = $confhash{$key};
7520: }
1.160.6.5 raeburn 7521: }
1.72 raeburn 7522: }
1.160.6.5 raeburn 7523:
1.1 raeburn 7524: my %quotahash = (
1.86 raeburn 7525: $action => { %confhash }
1.1 raeburn 7526: );
7527: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7528: $dom);
7529: if ($putresult eq 'ok') {
7530: if (keys(%changes) > 0) {
1.72 raeburn 7531: my $cachetime = 24*60*60;
7532: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 7533: if (ref($lastactref) eq 'HASH') {
7534: $lastactref->{'domdefaults'} = 1;
7535: }
1.1 raeburn 7536: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 7537: unless (($context eq 'requestcourses') ||
7538: ($context eq 'requestauthor')) {
1.86 raeburn 7539: if (ref($changes{'defaultquota'}) eq 'HASH') {
7540: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7541: foreach my $type (@{$types},'default') {
7542: if (defined($changes{'defaultquota'}{$type})) {
7543: my $typetitle = $usertypes->{$type};
7544: if ($type eq 'default') {
7545: $typetitle = $othertitle;
7546: }
1.160.6.28 raeburn 7547: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7548: }
7549: }
1.86 raeburn 7550: $resulttext .= '</ul></li>';
1.72 raeburn 7551: }
1.160.6.20 raeburn 7552: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 7553: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 7554: foreach my $type (@{$types},'default') {
7555: if (defined($changes{'authorquota'}{$type})) {
7556: my $typetitle = $usertypes->{$type};
7557: if ($type eq 'default') {
7558: $typetitle = $othertitle;
7559: }
1.160.6.28 raeburn 7560: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 7561: }
7562: }
7563: $resulttext .= '</ul></li>';
7564: }
1.72 raeburn 7565: }
1.80 raeburn 7566: my %newenv;
1.72 raeburn 7567: foreach my $item (@usertools) {
1.160.6.5 raeburn 7568: my (%haschgs,%inconf);
7569: if ($context eq 'requestauthor') {
7570: %haschgs = %changes;
7571: %inconf = %confhash;
7572: } else {
7573: if (ref($changes{$item}) eq 'HASH') {
7574: %haschgs = %{$changes{$item}};
7575: }
7576: if (ref($confhash{$item}) eq 'HASH') {
7577: %inconf = %{$confhash{$item}};
7578: }
7579: }
7580: if (keys(%haschgs) > 0) {
1.80 raeburn 7581: my $newacc =
7582: &Apache::lonnet::usertools_access($env{'user.name'},
7583: $env{'user.domain'},
1.86 raeburn 7584: $item,'reload',$context);
1.160.6.5 raeburn 7585: if (($context eq 'requestcourses') ||
7586: ($context eq 'requestauthor')) {
1.108 raeburn 7587: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7588: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7589: }
7590: } else {
7591: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7592: $newenv{'environment.availabletools.'.$item} = $newacc;
7593: }
1.80 raeburn 7594: }
1.160.6.5 raeburn 7595: unless ($context eq 'requestauthor') {
7596: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7597: }
1.72 raeburn 7598: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 7599: if ($haschgs{$type}) {
1.72 raeburn 7600: my $typetitle = $usertypes->{$type};
7601: if ($type eq 'default') {
7602: $typetitle = $othertitle;
7603: } elsif ($type eq '_LC_adv') {
7604: $typetitle = 'LON-CAPA Advanced Users';
7605: }
1.160.6.5 raeburn 7606: if ($inconf{$type}) {
1.101 raeburn 7607: if ($context eq 'requestcourses') {
7608: my $cond;
1.160.6.5 raeburn 7609: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7610: if ($1 eq '') {
7611: $cond = &mt('(Automatic processing of any request).');
7612: } else {
7613: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7614: }
7615: } else {
1.160.6.5 raeburn 7616: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7617: }
7618: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 7619: } elsif ($context eq 'requestauthor') {
7620: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7621: $titles{$inconf{$type}},$typetitle);
7622:
1.101 raeburn 7623: } else {
7624: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7625: }
1.72 raeburn 7626: } else {
1.104 raeburn 7627: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 7628: if ($inconf{$type} eq '0') {
1.104 raeburn 7629: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7630: } else {
7631: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7632: }
7633: } else {
7634: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7635: }
1.72 raeburn 7636: }
7637: }
1.26 raeburn 7638: }
1.160.6.5 raeburn 7639: unless ($context eq 'requestauthor') {
7640: $resulttext .= '</ul></li>';
7641: }
1.26 raeburn 7642: }
1.1 raeburn 7643: }
1.160.6.5 raeburn 7644: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7645: if (ref($changes{'notify'}) eq 'HASH') {
7646: if ($changes{'notify'}{'approval'}) {
7647: if (ref($confhash{'notify'}) eq 'HASH') {
7648: if ($confhash{'notify'}{'approval'}) {
7649: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7650: } else {
1.160.6.5 raeburn 7651: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7652: }
7653: }
7654: }
7655: }
7656: }
1.160.6.30 raeburn 7657: if ($action eq 'requestcourses') {
7658: my @offon = ('off','on');
7659: if ($changes{'uniquecode'}) {
7660: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7661: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7662: $resulttext .= '<li>'.
7663: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7664: '</li>';
7665: } else {
7666: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7667: '</li>';
7668: }
7669: }
1.160.6.46 raeburn 7670: foreach my $type ('textbooks','templates') {
7671: if (ref($changes{$type}) eq 'HASH') {
7672: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7673: foreach my $key (sort(keys(%{$changes{$type}}))) {
7674: my %coursehash = &Apache::lonnet::coursedescription($key);
7675: my $coursetitle = $coursehash{'description'};
7676: my $position = $confhash{$type}{$key}{'order'} + 1;
7677: $resulttext .= '<li>';
1.160.6.47 raeburn 7678: foreach my $item ('subject','title','publisher','author') {
7679: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7680: ($type eq 'templates'));
1.160.6.46 raeburn 7681: my $name = $item.':';
7682: $name =~ s/^(\w)/\U$1/;
7683: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7684: }
7685: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7686: if ($type eq 'textbooks') {
7687: if ($confhash{$type}{$key}{'image'}) {
7688: $resulttext .= ' '.&mt('Image: [_1]',
7689: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
7690: ' alt="Textbook cover" />').'<br />';
7691: }
7692: }
7693: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 7694: }
1.160.6.46 raeburn 7695: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 7696: }
7697: }
1.160.6.39 raeburn 7698: if (ref($changes{'validation'}) eq 'HASH') {
7699: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7700: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7701: foreach my $item (@{$validationitemsref}) {
7702: if (exists($changes{'validation'}{$item})) {
7703: if ($item eq 'markup') {
7704: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7705: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7706: } else {
7707: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7708: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7709: }
7710: }
7711: }
7712: if (exists($changes{'validation'}{'dc'})) {
7713: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7714: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7715: }
7716: }
7717: }
1.160.6.30 raeburn 7718: }
1.1 raeburn 7719: $resulttext .= '</ul>';
1.80 raeburn 7720: if (keys(%newenv)) {
7721: &Apache::lonnet::appenv(\%newenv);
7722: }
1.1 raeburn 7723: } else {
1.86 raeburn 7724: if ($context eq 'requestcourses') {
7725: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 7726: } elsif ($context eq 'requestauthor') {
7727: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7728: } else {
1.90 weissno 7729: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7730: }
1.1 raeburn 7731: }
7732: } else {
1.11 albertel 7733: $resulttext = '<span class="LC_error">'.
7734: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7735: }
1.160.6.30 raeburn 7736: if ($errors) {
7737: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7738: '<ul>'.$errors.'</ul></p>';
7739: }
1.3 raeburn 7740: return $resulttext;
1.1 raeburn 7741: }
7742:
1.160.6.30 raeburn 7743: sub process_textbook_image {
1.160.6.46 raeburn 7744: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 7745: my $filename = $env{'form.'.$caller.'.filename'};
7746: my ($error,$url);
7747: my ($width,$height) = (50,50);
7748: if ($configuserok eq 'ok') {
7749: if ($switchserver) {
7750: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7751: $switchserver);
7752: } elsif ($author_ok eq 'ok') {
7753: my ($result,$imageurl) =
7754: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.46 raeburn 7755: "$type/$dom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 7756: if ($result eq 'ok') {
7757: $url = $imageurl;
7758: } else {
7759: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7760: }
7761: } else {
7762: $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);
7763: }
7764: } else {
7765: $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);
7766: }
7767: return ($url,$error);
7768: }
7769:
1.3 raeburn 7770: sub modify_autoenroll {
1.160.6.24 raeburn 7771: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7772: my ($resulttext,%changes);
7773: my %currautoenroll;
7774: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7775: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7776: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7777: }
7778: }
7779: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7780: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7781: sender => 'Sender for notification messages',
7782: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 7783: my @offon = ('off','on');
1.17 raeburn 7784: my $sender_uname = $env{'form.sender_uname'};
7785: my $sender_domain = $env{'form.sender_domain'};
7786: if ($sender_domain eq '') {
7787: $sender_uname = '';
7788: } elsif ($sender_uname eq '') {
7789: $sender_domain = '';
7790: }
1.129 raeburn 7791: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 7792: my %autoenrollhash = (
1.129 raeburn 7793: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7794: 'sender_uname' => $sender_uname,
7795: 'sender_domain' => $sender_domain,
7796: 'co-owners' => $coowners,
1.1 raeburn 7797: }
7798: );
1.4 raeburn 7799: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7800: $dom);
1.1 raeburn 7801: if ($putresult eq 'ok') {
7802: if (exists($currautoenroll{'run'})) {
7803: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7804: $changes{'run'} = 1;
7805: }
7806: } elsif ($autorun) {
7807: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7808: $changes{'run'} = 1;
1.1 raeburn 7809: }
7810: }
1.17 raeburn 7811: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7812: $changes{'sender'} = 1;
7813: }
1.17 raeburn 7814: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7815: $changes{'sender'} = 1;
7816: }
1.129 raeburn 7817: if ($currautoenroll{'co-owners'} ne '') {
7818: if ($currautoenroll{'co-owners'} ne $coowners) {
7819: $changes{'coowners'} = 1;
7820: }
7821: } elsif ($coowners) {
7822: $changes{'coowners'} = 1;
7823: }
1.1 raeburn 7824: if (keys(%changes) > 0) {
7825: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7826: if ($changes{'run'}) {
1.1 raeburn 7827: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7828: }
7829: if ($changes{'sender'}) {
1.17 raeburn 7830: if ($sender_uname eq '' || $sender_domain eq '') {
7831: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7832: } else {
7833: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7834: }
1.1 raeburn 7835: }
1.129 raeburn 7836: if ($changes{'coowners'}) {
7837: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7838: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7839: if (ref($lastactref) eq 'HASH') {
7840: $lastactref->{'domainconfig'} = 1;
7841: }
1.129 raeburn 7842: }
1.1 raeburn 7843: $resulttext .= '</ul>';
7844: } else {
7845: $resulttext = &mt('No changes made to auto-enrollment settings');
7846: }
7847: } else {
1.11 albertel 7848: $resulttext = '<span class="LC_error">'.
7849: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7850: }
1.3 raeburn 7851: return $resulttext;
1.1 raeburn 7852: }
7853:
7854: sub modify_autoupdate {
1.3 raeburn 7855: my ($dom,%domconfig) = @_;
1.1 raeburn 7856: my ($resulttext,%currautoupdate,%fields,%changes);
7857: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7858: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7859: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7860: }
7861: }
7862: my @offon = ('off','on');
7863: my %title = &Apache::lonlocal::texthash (
7864: run => 'Auto-update:',
7865: classlists => 'Updates to user information in classlists?'
7866: );
1.44 raeburn 7867: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7868: my %fieldtitles = &Apache::lonlocal::texthash (
7869: id => 'Student/Employee ID',
1.20 raeburn 7870: permanentemail => 'E-mail address',
1.1 raeburn 7871: lastname => 'Last Name',
7872: firstname => 'First Name',
7873: middlename => 'Middle Name',
1.132 raeburn 7874: generation => 'Generation',
1.1 raeburn 7875: );
1.142 raeburn 7876: $othertitle = &mt('All users');
1.1 raeburn 7877: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 7878: $othertitle = &mt('Other users');
1.1 raeburn 7879: }
7880: foreach my $key (keys(%env)) {
7881: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 7882: my ($usertype,$item) = ($1,$2);
7883: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7884: if ($usertype eq 'default') {
7885: push(@{$fields{$1}},$2);
7886: } elsif (ref($types) eq 'ARRAY') {
7887: if (grep(/^\Q$usertype\E$/,@{$types})) {
7888: push(@{$fields{$1}},$2);
7889: }
7890: }
7891: }
1.1 raeburn 7892: }
7893: }
1.131 raeburn 7894: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7895: @lockablenames = sort(@lockablenames);
7896: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7897: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7898: if (@changed) {
7899: $changes{'lockablenames'} = 1;
7900: }
7901: } else {
7902: if (@lockablenames) {
7903: $changes{'lockablenames'} = 1;
7904: }
7905: }
1.1 raeburn 7906: my %updatehash = (
7907: autoupdate => { run => $env{'form.autoupdate_run'},
7908: classlists => $env{'form.classlists'},
7909: fields => {%fields},
1.131 raeburn 7910: lockablenames => \@lockablenames,
1.1 raeburn 7911: }
7912: );
7913: foreach my $key (keys(%currautoupdate)) {
7914: if (($key eq 'run') || ($key eq 'classlists')) {
7915: if (exists($updatehash{autoupdate}{$key})) {
7916: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7917: $changes{$key} = 1;
7918: }
7919: }
7920: } elsif ($key eq 'fields') {
7921: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 7922: foreach my $item (@{$types},'default') {
1.1 raeburn 7923: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7924: my $change = 0;
7925: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7926: if (!exists($fields{$item})) {
7927: $change = 1;
1.132 raeburn 7928: last;
1.1 raeburn 7929: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 7930: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 7931: $change = 1;
1.132 raeburn 7932: last;
1.1 raeburn 7933: }
7934: }
7935: }
7936: if ($change) {
7937: push(@{$changes{$key}},$item);
7938: }
1.26 raeburn 7939: }
1.1 raeburn 7940: }
7941: }
1.131 raeburn 7942: } elsif ($key eq 'lockablenames') {
7943: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7944: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7945: if (@changed) {
7946: $changes{'lockablenames'} = 1;
7947: }
7948: } else {
7949: if (@lockablenames) {
7950: $changes{'lockablenames'} = 1;
7951: }
7952: }
7953: }
7954: }
7955: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7956: if (@lockablenames) {
7957: $changes{'lockablenames'} = 1;
1.1 raeburn 7958: }
7959: }
1.26 raeburn 7960: foreach my $item (@{$types},'default') {
7961: if (defined($fields{$item})) {
7962: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 7963: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7964: my $change = 0;
7965: if (ref($fields{$item}) eq 'ARRAY') {
7966: foreach my $type (@{$fields{$item}}) {
7967: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7968: $change = 1;
7969: last;
7970: }
7971: }
7972: }
7973: if ($change) {
7974: push(@{$changes{'fields'}},$item);
7975: }
7976: } else {
1.26 raeburn 7977: push(@{$changes{'fields'}},$item);
7978: }
7979: } else {
7980: push(@{$changes{'fields'}},$item);
1.1 raeburn 7981: }
7982: }
7983: }
7984: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7985: $dom);
7986: if ($putresult eq 'ok') {
7987: if (keys(%changes) > 0) {
7988: $resulttext = &mt('Changes made:').'<ul>';
7989: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 7990: if ($key eq 'lockablenames') {
7991: $resulttext .= '<li>';
7992: if (@lockablenames) {
7993: $usertypes->{'default'} = $othertitle;
7994: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7995: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7996: } else {
7997: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7998: }
7999: $resulttext .= '</li>';
8000: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 8001: foreach my $item (@{$changes{$key}}) {
8002: my @newvalues;
8003: foreach my $type (@{$fields{$item}}) {
8004: push(@newvalues,$fieldtitles{$type});
8005: }
1.3 raeburn 8006: my $newvaluestr;
8007: if (@newvalues > 0) {
8008: $newvaluestr = join(', ',@newvalues);
8009: } else {
8010: $newvaluestr = &mt('none');
1.6 raeburn 8011: }
1.1 raeburn 8012: if ($item eq 'default') {
1.26 raeburn 8013: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 8014: } else {
1.26 raeburn 8015: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 8016: }
8017: }
8018: } else {
8019: my $newvalue;
8020: if ($key eq 'run') {
8021: $newvalue = $offon[$env{'form.autoupdate_run'}];
8022: } else {
8023: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 8024: }
1.1 raeburn 8025: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
8026: }
8027: }
8028: $resulttext .= '</ul>';
8029: } else {
1.3 raeburn 8030: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 8031: }
8032: } else {
1.11 albertel 8033: $resulttext = '<span class="LC_error">'.
8034: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8035: }
1.3 raeburn 8036: return $resulttext;
1.1 raeburn 8037: }
8038:
1.125 raeburn 8039: sub modify_autocreate {
8040: my ($dom,%domconfig) = @_;
8041: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
8042: if (ref($domconfig{'autocreate'}) eq 'HASH') {
8043: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
8044: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
8045: }
8046: }
8047: my %title= ( xml => 'Auto-creation of courses in XML course description files',
8048: req => 'Auto-creation of validated requests for official courses',
8049: xmldc => 'Identity of course creator of courses from XML files',
8050: );
8051: my @types = ('xml','req');
8052: foreach my $item (@types) {
8053: $newvals{$item} = $env{'form.autocreate_'.$item};
8054: $newvals{$item} =~ s/\D//g;
8055: $newvals{$item} = 0 if ($newvals{$item} eq '');
8056: }
8057: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
8058: my %domcoords = &get_active_dcs($dom);
8059: unless (exists($domcoords{$newvals{'xmldc'}})) {
8060: $newvals{'xmldc'} = '';
8061: }
8062: %autocreatehash = (
8063: autocreate => { xml => $newvals{'xml'},
8064: req => $newvals{'req'},
8065: }
8066: );
8067: if ($newvals{'xmldc'} ne '') {
8068: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
8069: }
8070: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
8071: $dom);
8072: if ($putresult eq 'ok') {
8073: my @items = @types;
8074: if ($newvals{'xml'}) {
8075: push(@items,'xmldc');
8076: }
8077: foreach my $item (@items) {
8078: if (exists($currautocreate{$item})) {
8079: if ($currautocreate{$item} ne $newvals{$item}) {
8080: $changes{$item} = 1;
8081: }
8082: } elsif ($newvals{$item}) {
8083: $changes{$item} = 1;
8084: }
8085: }
8086: if (keys(%changes) > 0) {
8087: my @offon = ('off','on');
8088: $resulttext = &mt('Changes made:').'<ul>';
8089: foreach my $item (@types) {
8090: if ($changes{$item}) {
8091: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 8092: $resulttext .= '<li>'.
8093: &mt("$title{$item} set to [_1]$newtxt [_2]",
8094: '<b>','</b>').
8095: '</li>';
1.125 raeburn 8096: }
8097: }
8098: if ($changes{'xmldc'}) {
8099: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
8100: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 8101: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 8102: }
8103: $resulttext .= '</ul>';
8104: } else {
8105: $resulttext = &mt('No changes made to auto-creation settings');
8106: }
8107: } else {
8108: $resulttext = '<span class="LC_error">'.
8109: &mt('An error occurred: [_1]',$putresult).'</span>';
8110: }
8111: return $resulttext;
8112: }
8113:
1.23 raeburn 8114: sub modify_directorysrch {
8115: my ($dom,%domconfig) = @_;
8116: my ($resulttext,%changes);
8117: my %currdirsrch;
8118: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8119: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
8120: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
8121: }
8122: }
8123: my %title = ( available => 'Directory search available',
1.24 raeburn 8124: localonly => 'Other domains can search',
1.23 raeburn 8125: searchby => 'Search types',
8126: searchtypes => 'Search latitude');
8127: my @offon = ('off','on');
1.24 raeburn 8128: my @otherdoms = ('Yes','No');
1.23 raeburn 8129:
1.25 raeburn 8130: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 8131: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
8132: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
8133:
1.44 raeburn 8134: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 8135: if (keys(%{$usertypes}) == 0) {
8136: @cansearch = ('default');
8137: } else {
8138: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
8139: foreach my $type (@{$currdirsrch{'cansearch'}}) {
8140: if (!grep(/^\Q$type\E$/,@cansearch)) {
8141: push(@{$changes{'cansearch'}},$type);
8142: }
1.23 raeburn 8143: }
1.26 raeburn 8144: foreach my $type (@cansearch) {
8145: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
8146: push(@{$changes{'cansearch'}},$type);
8147: }
1.23 raeburn 8148: }
1.26 raeburn 8149: } else {
8150: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 8151: }
8152: }
8153:
8154: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
8155: foreach my $by (@{$currdirsrch{'searchby'}}) {
8156: if (!grep(/^\Q$by\E$/,@searchby)) {
8157: push(@{$changes{'searchby'}},$by);
8158: }
8159: }
8160: foreach my $by (@searchby) {
8161: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
8162: push(@{$changes{'searchby'}},$by);
8163: }
8164: }
8165: } else {
8166: push(@{$changes{'searchby'}},@searchby);
8167: }
1.25 raeburn 8168:
8169: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
8170: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
8171: if (!grep(/^\Q$type\E$/,@searchtypes)) {
8172: push(@{$changes{'searchtypes'}},$type);
8173: }
8174: }
8175: foreach my $type (@searchtypes) {
8176: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
8177: push(@{$changes{'searchtypes'}},$type);
8178: }
8179: }
8180: } else {
8181: if (exists($currdirsrch{'searchtypes'})) {
8182: foreach my $type (@searchtypes) {
8183: if ($type ne $currdirsrch{'searchtypes'}) {
8184: push(@{$changes{'searchtypes'}},$type);
8185: }
8186: }
8187: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
8188: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
8189: }
8190: } else {
8191: push(@{$changes{'searchtypes'}},@searchtypes);
8192: }
8193: }
8194:
1.23 raeburn 8195: my %dirsrch_hash = (
8196: directorysrch => { available => $env{'form.dirsrch_available'},
8197: cansearch => \@cansearch,
1.24 raeburn 8198: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 8199: searchby => \@searchby,
1.25 raeburn 8200: searchtypes => \@searchtypes,
1.23 raeburn 8201: }
8202: );
8203: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
8204: $dom);
8205: if ($putresult eq 'ok') {
8206: if (exists($currdirsrch{'available'})) {
8207: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
8208: $changes{'available'} = 1;
8209: }
8210: } else {
8211: if ($env{'form.dirsrch_available'} eq '1') {
8212: $changes{'available'} = 1;
8213: }
8214: }
1.24 raeburn 8215: if (exists($currdirsrch{'localonly'})) {
8216: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
8217: $changes{'localonly'} = 1;
8218: }
8219: } else {
8220: if ($env{'form.dirsrch_localonly'} eq '1') {
8221: $changes{'localonly'} = 1;
8222: }
8223: }
1.23 raeburn 8224: if (keys(%changes) > 0) {
8225: $resulttext = &mt('Changes made:').'<ul>';
8226: if ($changes{'available'}) {
8227: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
8228: }
1.24 raeburn 8229: if ($changes{'localonly'}) {
8230: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
8231: }
8232:
1.23 raeburn 8233: if (ref($changes{'cansearch'}) eq 'ARRAY') {
8234: my $chgtext;
1.26 raeburn 8235: if (ref($usertypes) eq 'HASH') {
8236: if (keys(%{$usertypes}) > 0) {
8237: foreach my $type (@{$types}) {
8238: if (grep(/^\Q$type\E$/,@cansearch)) {
8239: $chgtext .= $usertypes->{$type}.'; ';
8240: }
8241: }
8242: if (grep(/^default$/,@cansearch)) {
8243: $chgtext .= $othertitle;
8244: } else {
8245: $chgtext =~ s/\; $//;
8246: }
1.160.6.13 raeburn 8247: $resulttext .=
8248: '<li>'.
8249: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
8250: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
8251: '</li>';
1.23 raeburn 8252: }
8253: }
8254: }
8255: if (ref($changes{'searchby'}) eq 'ARRAY') {
8256: my ($searchtitles,$titleorder) = &sorted_searchtitles();
8257: my $chgtext;
8258: foreach my $type (@{$titleorder}) {
8259: if (grep(/^\Q$type\E$/,@searchby)) {
8260: if (defined($searchtitles->{$type})) {
8261: $chgtext .= $searchtitles->{$type}.'; ';
8262: }
8263: }
8264: }
8265: $chgtext =~ s/\; $//;
8266: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8267: }
1.25 raeburn 8268: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8269: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8270: my $chgtext;
8271: foreach my $type (@{$srchtypeorder}) {
8272: if (grep(/^\Q$type\E$/,@searchtypes)) {
8273: if (defined($srchtypes_desc->{$type})) {
8274: $chgtext .= $srchtypes_desc->{$type}.'; ';
8275: }
8276: }
8277: }
8278: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 8279: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 8280: }
8281: $resulttext .= '</ul>';
8282: } else {
8283: $resulttext = &mt('No changes made to institution directory search settings');
8284: }
8285: } else {
8286: $resulttext = '<span class="LC_error">'.
1.27 raeburn 8287: &mt('An error occurred: [_1]',$putresult).'</span>';
8288: }
8289: return $resulttext;
8290: }
8291:
1.28 raeburn 8292: sub modify_contacts {
1.160.6.24 raeburn 8293: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 8294: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8295: if (ref($domconfig{'contacts'}) eq 'HASH') {
8296: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8297: $currsetting{$key} = $domconfig{'contacts'}{$key};
8298: }
8299: }
1.134 raeburn 8300: my (%others,%to,%bcc);
1.28 raeburn 8301: my @contacts = ('supportemail','adminemail');
1.102 raeburn 8302: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23 raeburn 8303: 'requestsmail','updatesmail','idconflictsmail');
8304: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 8305: foreach my $type (@mailings) {
8306: @{$newsetting{$type}} =
8307: &Apache::loncommon::get_env_multiple('form.'.$type);
8308: foreach my $item (@contacts) {
8309: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8310: $contacts_hash{contacts}{$type}{$item} = 1;
8311: } else {
8312: $contacts_hash{contacts}{$type}{$item} = 0;
8313: }
8314: }
8315: $others{$type} = $env{'form.'.$type.'_others'};
8316: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 8317: if ($type eq 'helpdeskmail') {
8318: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8319: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8320: }
1.28 raeburn 8321: }
8322: foreach my $item (@contacts) {
8323: $to{$item} = $env{'form.'.$item};
8324: $contacts_hash{'contacts'}{$item} = $to{$item};
8325: }
1.160.6.23 raeburn 8326: foreach my $item (@toggles) {
8327: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8328: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8329: }
8330: }
1.28 raeburn 8331: if (keys(%currsetting) > 0) {
8332: foreach my $item (@contacts) {
8333: if ($to{$item} ne $currsetting{$item}) {
8334: $changes{$item} = 1;
8335: }
8336: }
8337: foreach my $type (@mailings) {
8338: foreach my $item (@contacts) {
8339: if (ref($currsetting{$type}) eq 'HASH') {
8340: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8341: push(@{$changes{$type}},$item);
8342: }
8343: } else {
8344: push(@{$changes{$type}},@{$newsetting{$type}});
8345: }
8346: }
8347: if ($others{$type} ne $currsetting{$type}{'others'}) {
8348: push(@{$changes{$type}},'others');
8349: }
1.134 raeburn 8350: if ($type eq 'helpdeskmail') {
8351: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8352: push(@{$changes{$type}},'bcc');
8353: }
8354: }
1.28 raeburn 8355: }
8356: } else {
8357: my %default;
8358: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8359: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8360: $default{'errormail'} = 'adminemail';
8361: $default{'packagesmail'} = 'adminemail';
8362: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8363: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8364: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 8365: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8366: foreach my $item (@contacts) {
8367: if ($to{$item} ne $default{$item}) {
8368: $changes{$item} = 1;
1.160.6.23 raeburn 8369: }
1.28 raeburn 8370: }
8371: foreach my $type (@mailings) {
8372: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8373:
8374: push(@{$changes{$type}},@{$newsetting{$type}});
8375: }
8376: if ($others{$type} ne '') {
8377: push(@{$changes{$type}},'others');
1.134 raeburn 8378: }
8379: if ($type eq 'helpdeskmail') {
8380: if ($bcc{$type} ne '') {
8381: push(@{$changes{$type}},'bcc');
8382: }
8383: }
1.28 raeburn 8384: }
8385: }
1.160.6.23 raeburn 8386: foreach my $item (@toggles) {
8387: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8388: $changes{$item} = 1;
8389: } elsif ((!$env{'form.'.$item}) &&
8390: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8391: $changes{$item} = 1;
8392: }
8393: }
1.28 raeburn 8394: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8395: $dom);
8396: if ($putresult eq 'ok') {
8397: if (keys(%changes) > 0) {
1.160.6.24 raeburn 8398: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8399: if (ref($lastactref) eq 'HASH') {
8400: $lastactref->{'domainconfig'} = 1;
8401: }
1.28 raeburn 8402: my ($titles,$short_titles) = &contact_titles();
8403: $resulttext = &mt('Changes made:').'<ul>';
8404: foreach my $item (@contacts) {
8405: if ($changes{$item}) {
8406: $resulttext .= '<li>'.$titles->{$item}.
8407: &mt(' set to: ').
8408: '<span class="LC_cusr_emph">'.
8409: $to{$item}.'</span></li>';
8410: }
8411: }
8412: foreach my $type (@mailings) {
8413: if (ref($changes{$type}) eq 'ARRAY') {
8414: $resulttext .= '<li>'.$titles->{$type}.': ';
8415: my @text;
8416: foreach my $item (@{$newsetting{$type}}) {
8417: push(@text,$short_titles->{$item});
8418: }
8419: if ($others{$type} ne '') {
8420: push(@text,$others{$type});
8421: }
8422: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8423: join(', ',@text).'</span>';
8424: if ($type eq 'helpdeskmail') {
8425: if ($bcc{$type} ne '') {
8426: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8427: }
8428: }
8429: $resulttext .= '</li>';
1.28 raeburn 8430: }
8431: }
1.160.6.23 raeburn 8432: my @offon = ('off','on');
8433: if ($changes{'reporterrors'}) {
8434: $resulttext .= '<li>'.
8435: &mt('E-mail error reports to [_1] set to "'.
8436: $offon[$env{'form.reporterrors'}].'".',
8437: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8438: &mt('LON-CAPA core group - MSU'),600,500)).
8439: '</li>';
8440: }
8441: if ($changes{'reportupdates'}) {
8442: $resulttext .= '<li>'.
8443: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8444: $offon[$env{'form.reportupdates'}].'".',
8445: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8446: &mt('LON-CAPA core group - MSU'),600,500)).
8447: '</li>';
8448: }
1.28 raeburn 8449: $resulttext .= '</ul>';
8450: } else {
1.34 raeburn 8451: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8452: }
8453: } else {
8454: $resulttext = '<span class="LC_error">'.
8455: &mt('An error occurred: [_1].',$putresult).'</span>';
8456: }
8457: return $resulttext;
8458: }
8459:
8460: sub modify_usercreation {
1.27 raeburn 8461: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 8462: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8463: my $warningmsg;
1.27 raeburn 8464: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8465: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 8466: if ($key eq 'cancreate') {
8467: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8468: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8469: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8470: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8471: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8472: } else {
8473: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8474: }
1.50 raeburn 8475: }
1.43 raeburn 8476: }
1.160.6.34 raeburn 8477: } elsif ($key eq 'email_rule') {
8478: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8479: } else {
8480: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 8481: }
8482: }
1.34 raeburn 8483: }
1.160.6.34 raeburn 8484: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
8485: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
8486: my @contexts = ('author','course','requestcrs');
8487: foreach my $item(@contexts) {
8488: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8489: }
1.34 raeburn 8490: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8491: foreach my $item (@contexts) {
1.160.6.34 raeburn 8492: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8493: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8494: }
1.27 raeburn 8495: }
1.34 raeburn 8496: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8497: foreach my $item (@contexts) {
1.43 raeburn 8498: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8499: if ($cancreate{$item} ne 'any') {
8500: push(@{$changes{'cancreate'}},$item);
8501: }
8502: } else {
8503: if ($cancreate{$item} ne 'none') {
8504: push(@{$changes{'cancreate'}},$item);
8505: }
1.27 raeburn 8506: }
8507: }
8508: } else {
1.43 raeburn 8509: foreach my $item (@contexts) {
1.34 raeburn 8510: push(@{$changes{'cancreate'}},$item);
8511: }
1.27 raeburn 8512: }
1.34 raeburn 8513:
1.27 raeburn 8514: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8515: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8516: if (!grep(/^\Q$type\E$/,@username_rule)) {
8517: push(@{$changes{'username_rule'}},$type);
8518: }
8519: }
8520: foreach my $type (@username_rule) {
8521: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8522: push(@{$changes{'username_rule'}},$type);
8523: }
8524: }
8525: } else {
8526: push(@{$changes{'username_rule'}},@username_rule);
8527: }
8528:
1.32 raeburn 8529: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8530: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8531: if (!grep(/^\Q$type\E$/,@id_rule)) {
8532: push(@{$changes{'id_rule'}},$type);
8533: }
8534: }
8535: foreach my $type (@id_rule) {
8536: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8537: push(@{$changes{'id_rule'}},$type);
8538: }
8539: }
8540: } else {
8541: push(@{$changes{'id_rule'}},@id_rule);
8542: }
8543:
1.43 raeburn 8544: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8545: my @authtypes = ('int','krb4','krb5','loc');
8546: my %authhash;
1.43 raeburn 8547: foreach my $item (@authen_contexts) {
1.28 raeburn 8548: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8549: foreach my $auth (@authtypes) {
8550: if (grep(/^\Q$auth\E$/,@authallowed)) {
8551: $authhash{$item}{$auth} = 1;
8552: } else {
8553: $authhash{$item}{$auth} = 0;
8554: }
8555: }
8556: }
8557: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8558: foreach my $item (@authen_contexts) {
1.28 raeburn 8559: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8560: foreach my $auth (@authtypes) {
8561: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8562: push(@{$changes{'authtypes'}},$item);
8563: last;
8564: }
8565: }
8566: }
8567: }
8568: } else {
1.43 raeburn 8569: foreach my $item (@authen_contexts) {
1.28 raeburn 8570: push(@{$changes{'authtypes'}},$item);
8571: }
8572: }
8573:
1.160.6.34 raeburn 8574: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8575: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8576: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8577: $save_usercreate{'id_rule'} = \@id_rule;
8578: $save_usercreate{'username_rule'} = \@username_rule,
8579: $save_usercreate{'authtypes'} = \%authhash;
8580:
1.27 raeburn 8581: my %usercreation_hash = (
1.160.6.34 raeburn 8582: usercreation => \%save_usercreate,
8583: );
1.27 raeburn 8584:
8585: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8586: $dom);
1.50 raeburn 8587:
1.160.6.34 raeburn 8588: if ($putresult eq 'ok') {
8589: if (keys(%changes) > 0) {
8590: $resulttext = &mt('Changes made:').'<ul>';
8591: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8592: my %lt = &usercreation_types();
8593: foreach my $type (@{$changes{'cancreate'}}) {
8594: my $chgtext = $lt{$type}.', ';
8595: if ($cancreate{$type} eq 'none') {
8596: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8597: } elsif ($cancreate{$type} eq 'any') {
8598: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8599: } elsif ($cancreate{$type} eq 'official') {
8600: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8601: } elsif ($cancreate{$type} eq 'unofficial') {
8602: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8603: }
8604: $resulttext .= '<li>'.$chgtext.'</li>';
8605: }
8606: }
8607: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8608: my ($rules,$ruleorder) =
8609: &Apache::lonnet::inst_userrules($dom,'username');
8610: my $chgtext = '<ul>';
8611: foreach my $type (@username_rule) {
8612: if (ref($rules->{$type}) eq 'HASH') {
8613: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8614: }
8615: }
8616: $chgtext .= '</ul>';
8617: if (@username_rule > 0) {
8618: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8619: } else {
8620: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8621: }
8622: }
8623: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8624: my ($idrules,$idruleorder) =
8625: &Apache::lonnet::inst_userrules($dom,'id');
8626: my $chgtext = '<ul>';
8627: foreach my $type (@id_rule) {
8628: if (ref($idrules->{$type}) eq 'HASH') {
8629: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8630: }
8631: }
8632: $chgtext .= '</ul>';
8633: if (@id_rule > 0) {
8634: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8635: } else {
8636: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8637: }
8638: }
8639: my %authname = &authtype_names();
8640: my %context_title = &context_names();
8641: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8642: my $chgtext = '<ul>';
8643: foreach my $type (@{$changes{'authtypes'}}) {
8644: my @allowed;
8645: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8646: foreach my $auth (@authtypes) {
8647: if ($authhash{$type}{$auth}) {
8648: push(@allowed,$authname{$auth});
8649: }
8650: }
8651: if (@allowed > 0) {
8652: $chgtext .= join(', ',@allowed).'</li>';
8653: } else {
8654: $chgtext .= &mt('none').'</li>';
8655: }
8656: }
8657: $chgtext .= '</ul>';
8658: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8659: $resulttext .= '</li>';
8660: }
8661: $resulttext .= '</ul>';
8662: } else {
8663: $resulttext = &mt('No changes made to user creation settings');
8664: }
8665: } else {
8666: $resulttext = '<span class="LC_error">'.
8667: &mt('An error occurred: [_1]',$putresult).'</span>';
8668: }
8669: if ($warningmsg ne '') {
8670: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8671: }
8672: return $resulttext;
8673: }
8674:
8675: sub modify_selfcreation {
8676: my ($dom,%domconfig) = @_;
8677: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8678: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 8679: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8680: if (ref($types) eq 'ARRAY') {
8681: $usertypes->{'default'} = $othertitle;
8682: push(@{$types},'default');
8683: }
1.160.6.34 raeburn 8684: #
8685: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8686: #
8687: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8688: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8689: if ($key eq 'cancreate') {
8690: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8691: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8692: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8693: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.40 raeburn 8694: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 8695: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 8696: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8697: } else {
8698: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8699: }
8700: }
8701: }
8702: } elsif ($key eq 'email_rule') {
8703: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8704: } else {
8705: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8706: }
8707: }
8708: }
8709: #
8710: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8711: #
8712: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8713: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8714: if ($key eq 'selfcreate') {
8715: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8716: } else {
8717: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8718: }
8719: }
8720: }
8721:
8722: my @contexts = ('selfcreate');
8723: @{$cancreate{'selfcreate'}} = ();
8724: %{$cancreate{'emailusername'}} = ();
8725: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 8726: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 8727: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 8728: my %selfcreatetypes = (
8729: sso => 'users authenticated by institutional single sign on',
8730: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 8731: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 8732: );
1.160.6.34 raeburn 8733: #
8734: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8735: # is permitted.
8736: #
1.160.6.40 raeburn 8737:
8738: my @statuses;
8739: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8740: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8741: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8742: }
8743: }
8744: push(@statuses,'default');
8745:
1.160.6.35 raeburn 8746: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 8747: if ($item eq 'email') {
1.160.6.40 raeburn 8748: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 8749: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 8750: push(@contexts,'selfcreateprocessing');
8751: foreach my $type (@statuses) {
8752: if ($type eq 'default') {
8753: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8754: } else {
8755: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8756: }
8757: }
1.160.6.34 raeburn 8758: }
8759: } else {
8760: if ($env{'form.cancreate_'.$item}) {
8761: push(@{$cancreate{'selfcreate'}},$item);
8762: }
8763: }
8764: }
8765: my (@email_rule,%userinfo,%savecaptcha);
8766: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8767: #
1.160.6.35 raeburn 8768: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8769: # 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 8770: #
1.160.6.40 raeburn 8771:
1.160.6.48 raeburn 8772: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 8773: push(@contexts,'emailusername');
1.160.6.35 raeburn 8774: if (ref($types) eq 'ARRAY') {
8775: foreach my $type (@{$types}) {
8776: if (ref($infofields) eq 'ARRAY') {
8777: foreach my $field (@{$infofields}) {
8778: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8779: $cancreate{'emailusername'}{$type}{$field} = $1;
8780: }
8781: }
1.160.6.34 raeburn 8782: }
8783: }
8784: }
8785: #
8786: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8787: # queued requests for self-creation of account using e-mail address as username
8788: #
8789:
8790: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8791: @approvalnotify = sort(@approvalnotify);
8792: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8793: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8794: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8795: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8796: push(@{$changes{'cancreate'}},'notify');
8797: }
8798: } else {
8799: if ($cancreate{'notify'}{'approval'}) {
8800: push(@{$changes{'cancreate'}},'notify');
8801: }
8802: }
8803: } elsif ($cancreate{'notify'}{'approval'}) {
8804: push(@{$changes{'cancreate'}},'notify');
8805: }
8806:
8807: #
8808: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8809: #
8810: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8811: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8812: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8813: if (@{$curr_usercreation{'email_rule'}} > 0) {
8814: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8815: if (!grep(/^\Q$type\E$/,@email_rule)) {
8816: push(@{$changes{'email_rule'}},$type);
8817: }
8818: }
8819: }
8820: if (@email_rule > 0) {
8821: foreach my $type (@email_rule) {
8822: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8823: push(@{$changes{'email_rule'}},$type);
8824: }
8825: }
8826: }
8827: } elsif (@email_rule > 0) {
8828: push(@{$changes{'email_rule'}},@email_rule);
8829: }
8830: }
8831: #
1.160.6.40 raeburn 8832: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 8833: # institutional log-in.
8834: #
8835: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8836: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8837: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8838: ($domdefaults{'auth_def'} eq 'localauth'))) {
8839: $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.').' '.
8840: &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.');
8841: }
8842: }
8843: my @fields = ('lastname','firstname','middlename','generation',
8844: 'permanentemail','id');
1.160.6.44 raeburn 8845: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 8846: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8847: #
8848: # Where usernames may created for institutional log-in and/or institutional single sign on:
8849: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8850: # may self-create accounts
8851: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8852: # which the user may supply, if institutional data is unavailable.
8853: #
8854: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8855: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 8856: if (@{$types} > 1) {
1.160.6.34 raeburn 8857: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8858: push(@contexts,'statustocreate');
8859: } else {
8860: undef($cancreate{'statustocreate'});
8861: }
8862: foreach my $type (@{$types}) {
8863: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8864: foreach my $field (@fields) {
8865: if (grep(/^\Q$field\E$/,@modifiable)) {
8866: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8867: } else {
8868: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8869: }
8870: }
8871: }
8872: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8873: foreach my $type (@{$types}) {
8874: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8875: foreach my $field (@fields) {
8876: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8877: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8878: push(@{$changes{'selfcreate'}},$type);
8879: last;
8880: }
8881: }
8882: }
8883: }
8884: } else {
8885: foreach my $type (@{$types}) {
8886: push(@{$changes{'selfcreate'}},$type);
8887: }
8888: }
8889: }
1.160.6.44 raeburn 8890: foreach my $field (@shibfields) {
8891: if ($env{'form.shibenv_'.$field} ne '') {
8892: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
8893: }
8894: }
8895: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8896: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
8897: foreach my $field (@shibfields) {
8898: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
8899: push(@{$changes{'cancreate'}},'shibenv');
8900: }
8901: }
8902: } else {
8903: foreach my $field (@shibfields) {
8904: if ($env{'form.shibenv_'.$field}) {
8905: push(@{$changes{'cancreate'}},'shibenv');
8906: last;
8907: }
8908: }
8909: }
8910: }
1.160.6.34 raeburn 8911: }
8912: foreach my $item (@contexts) {
8913: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8914: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8915: if (ref($cancreate{$item}) eq 'ARRAY') {
8916: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8917: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8918: push(@{$changes{'cancreate'}},$item);
8919: }
8920: }
8921: }
8922: }
8923: if (ref($cancreate{$item}) eq 'ARRAY') {
8924: foreach my $type (@{$cancreate{$item}}) {
8925: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8926: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8927: push(@{$changes{'cancreate'}},$item);
8928: }
8929: }
8930: }
8931: }
8932: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8933: if (ref($cancreate{$item}) eq 'HASH') {
8934: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 8935: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8936: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8937: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8938: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8939: push(@{$changes{'cancreate'}},$item);
8940: }
8941: }
8942: }
1.160.6.40 raeburn 8943: } elsif ($item eq 'selfcreateprocessing') {
8944: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
8945: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8946: push(@{$changes{'cancreate'}},$item);
8947: }
8948: }
1.160.6.35 raeburn 8949: } else {
8950: if (!$cancreate{$item}{$curr}) {
8951: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8952: push(@{$changes{'cancreate'}},$item);
8953: }
1.160.6.34 raeburn 8954: }
8955: }
8956: }
8957: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 8958: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8959: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8960: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8961: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8962: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8963: push(@{$changes{'cancreate'}},$item);
8964: }
8965: }
8966: } else {
8967: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8968: push(@{$changes{'cancreate'}},$item);
8969: }
8970: }
8971: }
1.160.6.40 raeburn 8972: } elsif ($item eq 'selfcreateprocessing') {
8973: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
8974: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8975: push(@{$changes{'cancreate'}},$item);
8976: }
8977: }
1.160.6.35 raeburn 8978: } else {
8979: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8980: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8981: push(@{$changes{'cancreate'}},$item);
8982: }
1.160.6.34 raeburn 8983: }
8984: }
8985: }
8986: }
8987: } elsif ($curr_usercreation{'cancreate'}{$item}) {
8988: if (ref($cancreate{$item}) eq 'ARRAY') {
8989: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
8990: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8991: push(@{$changes{'cancreate'}},$item);
8992: }
8993: }
8994: } elsif (ref($cancreate{$item}) eq 'HASH') {
8995: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
8996: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8997: push(@{$changes{'cancreate'}},$item);
8998: }
8999: }
9000: }
9001: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 9002: if (ref($cancreate{$item}) eq 'HASH') {
9003: foreach my $type (keys(%{$cancreate{$item}})) {
9004: if (ref($cancreate{$item}{$type}) eq 'HASH') {
9005: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
9006: if ($cancreate{$item}{$type}{$field}) {
9007: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9008: push(@{$changes{'cancreate'}},$item);
9009: }
9010: last;
9011: }
9012: }
9013: }
9014: }
1.160.6.34 raeburn 9015: }
9016: }
9017: }
9018: #
9019: # Populate %save_usercreate hash with updates to self-creation configuration.
9020: #
9021: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
9022: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
9023: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
9024: if (ref($cancreate{'notify'}) eq 'HASH') {
9025: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
9026: }
1.160.6.40 raeburn 9027: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
9028: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
9029: }
1.160.6.34 raeburn 9030: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9031: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
9032: }
1.160.6.44 raeburn 9033: if (ref($cancreate{'shibenv'}) eq 'HASH') {
9034: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
9035: }
1.160.6.34 raeburn 9036: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
9037: $save_usercreate{'emailrule'} = \@email_rule;
9038:
9039: my %userconfig_hash = (
9040: usercreation => \%save_usercreate,
9041: usermodification => \%save_usermodify,
9042: );
9043: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
9044: $dom);
9045: #
9046: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
9047: #
1.27 raeburn 9048: if ($putresult eq 'ok') {
9049: if (keys(%changes) > 0) {
9050: $resulttext = &mt('Changes made:').'<ul>';
9051: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 9052: my %lt = &selfcreation_types();
1.34 raeburn 9053: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 9054: my $chgtext;
1.45 raeburn 9055: if ($type eq 'selfcreate') {
1.50 raeburn 9056: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 9057: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 9058: } else {
1.160.6.34 raeburn 9059: $chgtext .= &mt('Self-creation of a new account is permitted for:').
9060: '<ul>';
1.50 raeburn 9061: foreach my $case (@{$cancreate{$type}}) {
9062: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
9063: }
9064: $chgtext .= '</ul>';
1.100 raeburn 9065: if (ref($cancreate{$type}) eq 'ARRAY') {
9066: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
9067: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9068: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 9069: $chgtext .= '<br />'.
9070: '<span class="LC_warning">'.
9071: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9072: '</span>';
1.100 raeburn 9073: }
9074: }
9075: }
9076: }
1.43 raeburn 9077: }
1.160.6.44 raeburn 9078: } elsif ($type eq 'shibenv') {
9079: if (keys(%{$cancreate{$type}}) == 0) {
9080: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
9081: } else {
9082: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
9083: '<ul>';
9084: foreach my $field (@shibfields) {
9085: next if ($cancreate{$type}{$field} eq '');
9086: if ($field eq 'inststatus') {
9087: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
9088: } else {
9089: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
9090: }
9091: }
9092: $chgtext .= '</ul>';
9093: }
1.93 raeburn 9094: } elsif ($type eq 'statustocreate') {
1.96 raeburn 9095: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
9096: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
9097: if (@{$cancreate{'selfcreate'}} > 0) {
9098: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 9099: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 9100: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 9101: $chgtext .= '<br />'.
9102: '<span class="LC_warning">'.
9103: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9104: '</span>';
9105: }
1.96 raeburn 9106: } elsif (ref($usertypes) eq 'HASH') {
9107: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 9108: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
9109: } else {
9110: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
9111: }
9112: $chgtext .= '<ul>';
9113: foreach my $case (@{$cancreate{$type}}) {
9114: if ($case eq 'default') {
9115: $chgtext .= '<li>'.$othertitle.'</li>';
9116: } else {
9117: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 9118: }
9119: }
1.100 raeburn 9120: $chgtext .= '</ul>';
9121: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 9122: $chgtext .= '<br /><span class="LC_warning">'.
9123: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
9124: '</span>';
1.100 raeburn 9125: }
9126: }
9127: } else {
9128: if (@{$cancreate{$type}} == 0) {
9129: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
9130: } else {
9131: $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 9132: }
9133: }
9134: }
1.160.6.40 raeburn 9135: } elsif ($type eq 'selfcreateprocessing') {
9136: my %choices = &Apache::lonlocal::texthash (
9137: automatic => 'Automatic approval',
9138: approval => 'Queued for approval',
9139: );
9140: if (@statuses > 1) {
9141: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
9142: '<ul>';
9143: foreach my $type (@statuses) {
9144: if ($type eq 'default') {
9145: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9146: } else {
9147: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9148: }
9149: }
9150: $chgtext .= '</ul>';
9151: } else {
9152: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
9153: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
9154: }
1.160.6.5 raeburn 9155: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 9156: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 9157: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
9158: } else {
9159: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 9160: if ($captchas{$savecaptcha{$type}}) {
9161: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 9162: } else {
9163: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
9164: }
9165: }
9166: } elsif ($type eq 'recaptchakeys') {
9167: my ($privkey,$pubkey);
1.160.6.34 raeburn 9168: if (ref($savecaptcha{$type}) eq 'HASH') {
9169: $pubkey = $savecaptcha{$type}{'public'};
9170: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 9171: }
9172: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
9173: if (!$pubkey) {
9174: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
9175: } else {
9176: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9177: }
9178: if (!$privkey) {
9179: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
9180: } else {
9181: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
9182: }
9183: $chgtext .= '</ul>';
1.160.6.34 raeburn 9184: } elsif ($type eq 'emailusername') {
9185: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 9186: if (ref($types) eq 'ARRAY') {
9187: foreach my $type (@{$types}) {
9188: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
9189: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50 raeburn 9190: $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 9191: '<ul>';
9192: foreach my $field (@{$infofields}) {
9193: if ($cancreate{'emailusername'}{$type}{$field}) {
9194: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
9195: }
9196: }
1.160.6.50 raeburn 9197: $chgtext .= '</ul>';
9198: } else {
9199: $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 9200: }
9201: } else {
1.160.6.50 raeburn 9202: $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 9203: }
9204: }
9205: }
9206: }
9207: } elsif ($type eq 'notify') {
9208: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
9209: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9210: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
9211: if ($cancreate{'notify'}{'approval'}) {
9212: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
9213: }
9214: }
1.43 raeburn 9215: }
1.34 raeburn 9216: }
1.160.6.34 raeburn 9217: if ($chgtext) {
9218: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 9219: }
9220: }
9221: }
1.43 raeburn 9222: if (ref($changes{'email_rule'}) eq 'ARRAY') {
9223: my ($emailrules,$emailruleorder) =
9224: &Apache::lonnet::inst_userrules($dom,'email');
9225: my $chgtext = '<ul>';
9226: foreach my $type (@email_rule) {
9227: if (ref($emailrules->{$type}) eq 'HASH') {
9228: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
9229: }
9230: }
9231: $chgtext .= '</ul>';
9232: if (@email_rule > 0) {
1.160.6.34 raeburn 9233: $resulttext .= '<li>'.
9234: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
9235: $chgtext.
9236: '</li>';
1.43 raeburn 9237: } else {
1.160.6.34 raeburn 9238: $resulttext .= '<li>'.
9239: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
9240: '</li>';
1.43 raeburn 9241: }
9242: }
1.160.6.34 raeburn 9243: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
9244: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
9245: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9246: foreach my $type (@{$changes{'selfcreate'}}) {
9247: my $typename = $type;
9248: if (ref($usertypes) eq 'HASH') {
9249: if ($usertypes->{$type} ne '') {
9250: $typename = $usertypes->{$type};
1.28 raeburn 9251: }
9252: }
1.160.6.34 raeburn 9253: my @modifiable;
9254: $resulttext .= '<li>'.
9255: &mt('Self-creation of account by users with status: [_1]',
9256: '<span class="LC_cusr_emph">'.$typename.'</span>').
9257: ' - '.&mt('modifiable fields (if institutional data blank): ');
9258: foreach my $field (@fields) {
9259: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9260: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
9261: }
9262: }
9263: if (@modifiable > 0) {
9264: $resulttext .= join(', ',@modifiable);
1.43 raeburn 9265: } else {
1.160.6.34 raeburn 9266: $resulttext .= &mt('none');
1.43 raeburn 9267: }
1.160.6.34 raeburn 9268: $resulttext .= '</li>';
1.28 raeburn 9269: }
1.160.6.34 raeburn 9270: $resulttext .= '</ul></li>';
1.28 raeburn 9271: }
1.27 raeburn 9272: $resulttext .= '</ul>';
9273: } else {
1.160.6.34 raeburn 9274: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 9275: }
9276: } else {
9277: $resulttext = '<span class="LC_error">'.
1.23 raeburn 9278: &mt('An error occurred: [_1]',$putresult).'</span>';
9279: }
1.43 raeburn 9280: if ($warningmsg ne '') {
9281: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9282: }
1.23 raeburn 9283: return $resulttext;
9284: }
9285:
1.160.6.5 raeburn 9286: sub process_captcha {
9287: my ($container,$changes,$newsettings,$current) = @_;
9288: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9289: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9290: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9291: $newsettings->{'captcha'} = 'original';
9292: }
9293: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
9294: if ($container eq 'cancreate') {
9295: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9296: push(@{$changes->{'cancreate'}},'captcha');
9297: } elsif (!defined($changes->{'cancreate'})) {
9298: $changes->{'cancreate'} = ['captcha'];
9299: }
9300: } else {
9301: $changes->{'captcha'} = 1;
9302: }
9303: }
9304: my ($newpub,$newpriv,$currpub,$currpriv);
9305: if ($newsettings->{'captcha'} eq 'recaptcha') {
9306: $newpub = $env{'form.'.$container.'_recaptchapub'};
9307: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 9308: $newpub =~ s/[^\w\-]//g;
9309: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 9310: $newsettings->{'recaptchakeys'} = {
9311: public => $newpub,
9312: private => $newpriv,
9313: };
9314: }
9315: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9316: $currpub = $current->{'recaptchakeys'}{'public'};
9317: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 9318: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9319: $newsettings->{'recaptchakeys'} = {
9320: public => '',
9321: private => '',
9322: }
9323: }
1.160.6.5 raeburn 9324: }
9325: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
9326: if ($container eq 'cancreate') {
9327: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9328: push(@{$changes->{'cancreate'}},'recaptchakeys');
9329: } elsif (!defined($changes->{'cancreate'})) {
9330: $changes->{'cancreate'} = ['recaptchakeys'];
9331: }
9332: } else {
9333: $changes->{'recaptchakeys'} = 1;
9334: }
9335: }
9336: return;
9337: }
9338:
1.33 raeburn 9339: sub modify_usermodification {
9340: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9341: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 9342: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9343: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 9344: if ($key eq 'selfcreate') {
9345: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9346: } else {
9347: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9348: }
1.33 raeburn 9349: }
9350: }
1.160.6.34 raeburn 9351: my @contexts = ('author','course');
1.33 raeburn 9352: my %context_title = (
9353: author => 'In author context',
9354: course => 'In course context',
9355: );
9356: my @fields = ('lastname','firstname','middlename','generation',
9357: 'permanentemail','id');
9358: my %roles = (
9359: author => ['ca','aa'],
9360: course => ['st','ep','ta','in','cr'],
9361: );
9362: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9363: foreach my $context (@contexts) {
9364: foreach my $role (@{$roles{$context}}) {
9365: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9366: foreach my $item (@fields) {
9367: if (grep(/^\Q$item\E$/,@modifiable)) {
9368: $modifyhash{$context}{$role}{$item} = 1;
9369: } else {
9370: $modifyhash{$context}{$role}{$item} = 0;
9371: }
9372: }
9373: }
9374: if (ref($curr_usermodification{$context}) eq 'HASH') {
9375: foreach my $role (@{$roles{$context}}) {
9376: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9377: foreach my $field (@fields) {
9378: if ($modifyhash{$context}{$role}{$field} ne
9379: $curr_usermodification{$context}{$role}{$field}) {
9380: push(@{$changes{$context}},$role);
9381: last;
9382: }
9383: }
9384: }
9385: }
9386: } else {
9387: foreach my $context (@contexts) {
9388: foreach my $role (@{$roles{$context}}) {
9389: push(@{$changes{$context}},$role);
9390: }
9391: }
9392: }
9393: }
9394: my %usermodification_hash = (
9395: usermodification => \%modifyhash,
9396: );
9397: my $putresult = &Apache::lonnet::put_dom('configuration',
9398: \%usermodification_hash,$dom);
9399: if ($putresult eq 'ok') {
9400: if (keys(%changes) > 0) {
9401: $resulttext = &mt('Changes made: ').'<ul>';
9402: foreach my $context (@contexts) {
9403: if (ref($changes{$context}) eq 'ARRAY') {
9404: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9405: if (ref($changes{$context}) eq 'ARRAY') {
9406: foreach my $role (@{$changes{$context}}) {
9407: my $rolename;
1.160.6.34 raeburn 9408: if ($role eq 'cr') {
9409: $rolename = &mt('Custom');
1.33 raeburn 9410: } else {
1.160.6.34 raeburn 9411: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9412: }
9413: my @modifiable;
1.160.6.34 raeburn 9414: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9415: foreach my $field (@fields) {
9416: if ($modifyhash{$context}{$role}{$field}) {
9417: push(@modifiable,$fieldtitles{$field});
9418: }
9419: }
9420: if (@modifiable > 0) {
9421: $resulttext .= join(', ',@modifiable);
9422: } else {
9423: $resulttext .= &mt('none');
9424: }
9425: $resulttext .= '</li>';
9426: }
9427: $resulttext .= '</ul></li>';
9428: }
9429: }
9430: }
9431: $resulttext .= '</ul>';
9432: } else {
9433: $resulttext = &mt('No changes made to user modification settings');
9434: }
9435: } else {
9436: $resulttext = '<span class="LC_error">'.
9437: &mt('An error occurred: [_1]',$putresult).'</span>';
9438: }
9439: return $resulttext;
9440: }
9441:
1.43 raeburn 9442: sub modify_defaults {
1.160.6.27 raeburn 9443: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9444: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 9445: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9446: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9447: my @authtypes = ('internal','krb4','krb5','localauth');
9448: foreach my $item (@items) {
9449: $newvalues{$item} = $env{'form.'.$item};
9450: if ($item eq 'auth_def') {
9451: if ($newvalues{$item} ne '') {
9452: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9453: push(@errors,$item);
9454: }
9455: }
9456: } elsif ($item eq 'lang_def') {
9457: if ($newvalues{$item} ne '') {
9458: if ($newvalues{$item} =~ /^(\w+)/) {
9459: my $langcode = $1;
1.103 raeburn 9460: if ($langcode ne 'x_chef') {
9461: if (code2language($langcode) eq '') {
9462: push(@errors,$item);
9463: }
1.43 raeburn 9464: }
9465: } else {
9466: push(@errors,$item);
9467: }
9468: }
1.54 raeburn 9469: } elsif ($item eq 'timezone_def') {
9470: if ($newvalues{$item} ne '') {
1.62 raeburn 9471: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9472: push(@errors,$item);
9473: }
9474: }
1.68 raeburn 9475: } elsif ($item eq 'datelocale_def') {
9476: if ($newvalues{$item} ne '') {
9477: my @datelocale_ids = DateTime::Locale->ids();
9478: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9479: push(@errors,$item);
9480: }
9481: }
1.141 raeburn 9482: } elsif ($item eq 'portal_def') {
9483: if ($newvalues{$item} ne '') {
9484: 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])\/?$/) {
9485: push(@errors,$item);
9486: }
9487: }
1.43 raeburn 9488: }
9489: if (grep(/^\Q$item\E$/,@errors)) {
9490: $newvalues{$item} = $domdefaults{$item};
9491: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9492: $changes{$item} = 1;
9493: }
1.72 raeburn 9494: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9495: }
9496: my %defaults_hash = (
1.72 raeburn 9497: defaults => \%newvalues,
9498: );
1.43 raeburn 9499: my $title = &defaults_titles();
1.160.6.40 raeburn 9500:
9501: my $currinststatus;
9502: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9503: $currinststatus = $domconfig{'inststatus'};
9504: } else {
9505: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9506: $currinststatus = {
9507: inststatustypes => $usertypes,
9508: inststatusorder => $types,
9509: inststatusguest => [],
9510: };
9511: }
9512: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9513: my @allpos;
9514: my %guests;
9515: my %alltypes;
9516: my ($currtitles,$currguests,$currorder);
9517: if (ref($currinststatus) eq 'HASH') {
9518: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9519: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9520: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9521: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9522: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9523: }
9524: }
9525: unless (grep(/^\Q$type\E$/,@todelete)) {
9526: my $position = $env{'form.inststatus_pos_'.$type};
9527: $position =~ s/\D+//g;
9528: $allpos[$position] = $type;
9529: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9530: $alltypes{$type} =~ s/`//g;
9531: if ($env{'form.inststatus_guest_'.$type}) {
9532: $guests{$type} = 1;
9533: }
9534: }
9535: }
9536: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9537: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9538: }
9539: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9540: $currtitles =~ s/,$//;
9541: }
9542: }
9543: if ($env{'form.addinststatus'}) {
9544: my $newtype = $env{'form.addinststatus'};
9545: $newtype =~ s/\W//g;
9546: unless (exists($alltypes{$newtype})) {
9547: if ($env{'form.addinststatus_guest'}) {
9548: $guests{$newtype} = 1;
9549: }
9550: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9551: $alltypes{$newtype} =~ s/`//g;
9552: my $position = $env{'form.addinststatus_pos'};
9553: $position =~ s/\D+//g;
9554: if ($position ne '') {
9555: $allpos[$position] = $newtype;
9556: }
9557: }
9558: }
9559: my (@orderedstatus,@orderedguests);
9560: foreach my $type (@allpos) {
9561: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9562: push(@orderedstatus,$type);
9563: if ($guests{$type}) {
9564: push(@orderedguests,$type);
9565: }
9566: }
9567: }
9568: foreach my $type (keys(%alltypes)) {
9569: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9570: delete($alltypes{$type});
9571: }
9572: }
9573: $defaults_hash{'inststatus'} = {
9574: inststatustypes => \%alltypes,
9575: inststatusorder => \@orderedstatus,
9576: inststatusguest => \@orderedguests,
9577: };
9578: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9579: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9580: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9581: }
9582: }
9583: if ($currorder ne join(',',@orderedstatus)) {
9584: $changes{'inststatus'}{'inststatusorder'} = 1;
9585: }
9586: if ($currguests ne join(',',@orderedguests)) {
9587: $changes{'inststatus'}{'inststatusguest'} = 1;
9588: }
9589: my $newtitles;
9590: foreach my $item (@orderedstatus) {
9591: $newtitles .= $alltypes{$item}.',';
9592: }
9593: $newtitles =~ s/,$//;
9594: if ($currtitles ne $newtitles) {
9595: $changes{'inststatus'}{'inststatustypes'} = 1;
9596: }
1.43 raeburn 9597: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9598: $dom);
9599: if ($putresult eq 'ok') {
9600: if (keys(%changes) > 0) {
9601: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 9602: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9603: 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";
9604: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 9605: if ($item eq 'inststatus') {
9606: if (ref($changes{'inststatus'}) eq 'HASH') {
9607: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9608: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9609: foreach my $type (@orderedstatus) {
9610: $resulttext .= $alltypes{$type}.', ';
9611: }
9612: $resulttext =~ s/, $//;
9613: $resulttext .= '</li>';
9614: }
9615: if ($changes{'inststatus'}{'inststatusguest'}) {
9616: $resulttext .= '<li>';
9617: if (@orderedguests) {
9618: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9619: foreach my $type (@orderedguests) {
9620: $resulttext .= $alltypes{$type}.', ';
9621: }
9622: $resulttext =~ s/, $//;
9623: } else {
9624: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9625: }
9626: $resulttext .= '</li>';
9627: }
9628: }
9629: } else {
9630: my $value = $env{'form.'.$item};
9631: if ($value eq '') {
9632: $value = &mt('none');
9633: } elsif ($item eq 'auth_def') {
9634: my %authnames = &authtype_names();
9635: my %shortauth = (
9636: internal => 'int',
9637: krb4 => 'krb4',
9638: krb5 => 'krb5',
9639: localauth => 'loc',
9640: );
9641: $value = $authnames{$shortauth{$value}};
9642: }
9643: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9644: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 9645: }
9646: }
9647: $resulttext .= '</ul>';
9648: $mailmsgtext .= "\n";
9649: my $cachetime = 24*60*60;
1.72 raeburn 9650: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9651: if (ref($lastactref) eq 'HASH') {
9652: $lastactref->{'domdefaults'} = 1;
9653: }
1.68 raeburn 9654: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 9655: my $notify = 1;
9656: if (ref($domconfig{'contacts'}) eq 'HASH') {
9657: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9658: $notify = 0;
9659: }
9660: }
9661: if ($notify) {
9662: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9663: "LON-CAPA Domain Settings Change - $dom",
9664: $mailmsgtext);
9665: }
1.54 raeburn 9666: }
1.43 raeburn 9667: } else {
1.54 raeburn 9668: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 9669: }
9670: } else {
9671: $resulttext = '<span class="LC_error">'.
9672: &mt('An error occurred: [_1]',$putresult).'</span>';
9673: }
9674: if (@errors > 0) {
9675: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9676: foreach my $item (@errors) {
9677: $resulttext .= ' "'.$title->{$item}.'",';
9678: }
9679: $resulttext =~ s/,$//;
9680: }
9681: return $resulttext;
9682: }
9683:
1.46 raeburn 9684: sub modify_scantron {
1.160.6.24 raeburn 9685: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 9686: my ($resulttext,%confhash,%changes,$errors);
9687: my $custom = 'custom.tab';
9688: my $default = 'default.tab';
9689: my $servadm = $r->dir_config('lonAdmEMail');
9690: my ($configuserok,$author_ok,$switchserver) =
9691: &config_check($dom,$confname,$servadm);
9692: if ($env{'form.scantronformat.filename'} ne '') {
9693: my $error;
9694: if ($configuserok eq 'ok') {
9695: if ($switchserver) {
1.130 raeburn 9696: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 9697: } else {
9698: if ($author_ok eq 'ok') {
9699: my ($result,$scantronurl) =
9700: &publishlogo($r,'upload','scantronformat',$dom,
9701: $confname,'scantron','','',$custom);
9702: if ($result eq 'ok') {
9703: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 9704: $changes{'scantronformat'} = 1;
1.46 raeburn 9705: } else {
9706: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9707: }
9708: } else {
9709: $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);
9710: }
9711: }
9712: } else {
9713: $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);
9714: }
9715: if ($error) {
9716: &Apache::lonnet::logthis($error);
9717: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9718: }
9719: }
1.48 raeburn 9720: if (ref($domconfig{'scantron'}) eq 'HASH') {
9721: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9722: if ($env{'form.scantronformat_del'}) {
9723: $confhash{'scantron'}{'scantronformat'} = '';
9724: $changes{'scantronformat'} = 1;
1.46 raeburn 9725: }
9726: }
9727: }
9728: if (keys(%confhash) > 0) {
9729: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9730: $dom);
9731: if ($putresult eq 'ok') {
9732: if (keys(%changes) > 0) {
1.48 raeburn 9733: if (ref($confhash{'scantron'}) eq 'HASH') {
9734: $resulttext = &mt('Changes made:').'<ul>';
9735: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 9736: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 9737: } else {
1.130 raeburn 9738: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 9739: }
1.48 raeburn 9740: $resulttext .= '</ul>';
9741: } else {
1.130 raeburn 9742: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 9743: }
9744: $resulttext .= '</ul>';
9745: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9746: if (ref($lastactref) eq 'HASH') {
9747: $lastactref->{'domainconfig'} = 1;
9748: }
1.46 raeburn 9749: } else {
1.130 raeburn 9750: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9751: }
9752: } else {
9753: $resulttext = '<span class="LC_error">'.
9754: &mt('An error occurred: [_1]',$putresult).'</span>';
9755: }
9756: } else {
1.130 raeburn 9757: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9758: }
9759: if ($errors) {
9760: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9761: $errors.'</ul>';
9762: }
9763: return $resulttext;
9764: }
9765:
1.48 raeburn 9766: sub modify_coursecategories {
1.160.6.43 raeburn 9767: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 9768: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9769: $cathash);
1.48 raeburn 9770: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 9771: my @catitems = ('unauth','auth');
9772: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 9773: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 9774: $cathash = $domconfig{'coursecategories'}{'cats'};
9775: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9776: $changes{'togglecats'} = 1;
9777: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9778: }
9779: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9780: $changes{'categorize'} = 1;
9781: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9782: }
1.120 raeburn 9783: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9784: $changes{'togglecatscomm'} = 1;
9785: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9786: }
9787: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9788: $changes{'categorizecomm'} = 1;
9789: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9790: }
1.160.6.42 raeburn 9791: foreach my $item (@catitems) {
9792: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9793: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
9794: $changes{$item} = 1;
9795: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9796: }
9797: }
9798: }
1.57 raeburn 9799: } else {
9800: $changes{'togglecats'} = 1;
9801: $changes{'categorize'} = 1;
1.124 raeburn 9802: $changes{'togglecatscomm'} = 1;
9803: $changes{'categorizecomm'} = 1;
1.87 raeburn 9804: $domconfig{'coursecategories'} = {
9805: togglecats => $env{'form.togglecats'},
9806: categorize => $env{'form.categorize'},
1.124 raeburn 9807: togglecatscomm => $env{'form.togglecatscomm'},
9808: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 9809: };
1.160.6.42 raeburn 9810: foreach my $item (@catitems) {
9811: if ($env{'form.coursecat_'.$item} ne 'std') {
9812: $changes{$item} = 1;
9813: }
9814: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9815: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9816: }
9817: }
1.57 raeburn 9818: }
9819: if (ref($cathash) eq 'HASH') {
9820: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 9821: push (@deletecategory,'instcode::0');
9822: }
1.120 raeburn 9823: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9824: push(@deletecategory,'communities::0');
9825: }
1.48 raeburn 9826: }
1.57 raeburn 9827: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9828: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9829: if (@deletecategory > 0) {
9830: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 9831: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 9832: foreach my $item (@deletecategory) {
1.57 raeburn 9833: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9834: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 9835: $deletions{$item} = 1;
1.57 raeburn 9836: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 9837: }
9838: }
9839: }
1.57 raeburn 9840: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 9841: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 9842: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 9843: $reorderings{$item} = 1;
1.57 raeburn 9844: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 9845: }
9846: if ($env{'form.addcategory_name_'.$item} ne '') {
9847: my $newcat = $env{'form.addcategory_name_'.$item};
9848: my $newdepth = $depth+1;
9849: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9850: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 9851: $adds{$newitem} = 1;
9852: }
9853: if ($env{'form.subcat_'.$item} ne '') {
9854: my $newcat = $env{'form.subcat_'.$item};
9855: my $newdepth = $depth+1;
9856: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9857: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 9858: $adds{$newitem} = 1;
9859: }
9860: }
9861: }
9862: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 9863: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9864: my $newitem = 'instcode::0';
1.57 raeburn 9865: if ($cathash->{$newitem} eq '') {
9866: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9867: $adds{$newitem} = 1;
9868: }
9869: } else {
9870: my $newitem = 'instcode::0';
1.57 raeburn 9871: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9872: $adds{$newitem} = 1;
9873: }
9874: }
1.120 raeburn 9875: if ($env{'form.communities'} eq '1') {
9876: if (ref($cathash) eq 'HASH') {
9877: my $newitem = 'communities::0';
9878: if ($cathash->{$newitem} eq '') {
9879: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9880: $adds{$newitem} = 1;
9881: }
9882: } else {
9883: my $newitem = 'communities::0';
9884: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9885: $adds{$newitem} = 1;
9886: }
9887: }
1.48 raeburn 9888: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 9889: if (($env{'form.addcategory_name'} ne 'instcode') &&
9890: ($env{'form.addcategory_name'} ne 'communities')) {
9891: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9892: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9893: $adds{$newitem} = 1;
9894: }
1.48 raeburn 9895: }
1.57 raeburn 9896: my $putresult;
1.48 raeburn 9897: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9898: if (keys(%deletions) > 0) {
9899: foreach my $key (keys(%deletions)) {
9900: if ($predelallitems{$key} ne '') {
9901: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9902: }
9903: }
9904: }
9905: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 9906: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 9907: if (ref($chkcats[0]) eq 'ARRAY') {
9908: my $depth = 0;
9909: my $chg = 0;
9910: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9911: my $name = $chkcats[0][$i];
9912: my $item;
9913: if ($name eq '') {
9914: $chg ++;
9915: } else {
9916: $item = &escape($name).'::0';
9917: if ($chg) {
1.57 raeburn 9918: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 9919: }
9920: $depth ++;
1.57 raeburn 9921: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 9922: $depth --;
9923: }
9924: }
9925: }
1.57 raeburn 9926: }
9927: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9928: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 9929: if ($putresult eq 'ok') {
1.57 raeburn 9930: my %title = (
1.120 raeburn 9931: togglecats => 'Show/Hide a course in catalog',
9932: categorize => 'Assign a category to a course',
9933: togglecatscomm => 'Show/Hide a community in catalog',
9934: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9935: );
9936: my %level = (
1.120 raeburn 9937: dom => 'set in Domain ("Modify Course/Community")',
9938: crs => 'set in Course ("Course Configuration")',
9939: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 9940: none => 'No catalog',
9941: std => 'Standard catalog',
9942: domonly => 'Domain-only catalog',
9943: codesrch => 'Code search form',
1.57 raeburn 9944: );
1.48 raeburn 9945: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 9946: if ($changes{'togglecats'}) {
9947: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9948: }
9949: if ($changes{'categorize'}) {
9950: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 9951: }
1.120 raeburn 9952: if ($changes{'togglecatscomm'}) {
9953: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9954: }
9955: if ($changes{'categorizecomm'}) {
9956: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9957: }
1.160.6.42 raeburn 9958: if ($changes{'unauth'}) {
9959: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
9960: }
9961: if ($changes{'auth'}) {
9962: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
9963: }
1.57 raeburn 9964: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9965: my $cathash;
9966: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9967: $cathash = $domconfig{'coursecategories'}{'cats'};
9968: } else {
9969: $cathash = {};
9970: }
9971: my (@cats,@trails,%allitems);
9972: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
9973: if (keys(%deletions) > 0) {
9974: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
9975: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
9976: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
9977: }
9978: $resulttext .= '</ul></li>';
9979: }
9980: if (keys(%reorderings) > 0) {
9981: my %sort_by_trail;
9982: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
9983: foreach my $key (keys(%reorderings)) {
9984: if ($allitems{$key} ne '') {
9985: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9986: }
1.48 raeburn 9987: }
1.57 raeburn 9988: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9989: $resulttext .= '<li>'.$trails[$trail].'</li>';
9990: }
9991: $resulttext .= '</ul></li>';
1.48 raeburn 9992: }
1.57 raeburn 9993: if (keys(%adds) > 0) {
9994: my %sort_by_trail;
9995: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
9996: foreach my $key (keys(%adds)) {
9997: if ($allitems{$key} ne '') {
9998: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9999: }
10000: }
10001: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10002: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 10003: }
1.57 raeburn 10004: $resulttext .= '</ul></li>';
1.48 raeburn 10005: }
10006: }
10007: $resulttext .= '</ul>';
1.160.6.43 raeburn 10008: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 10009: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10010: if ($changes{'auth'}) {
10011: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
10012: }
10013: if ($changes{'unauth'}) {
10014: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
10015: }
10016: my $cachetime = 24*60*60;
10017: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 10018: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 10019: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 10020: }
10021: }
1.48 raeburn 10022: } else {
10023: $resulttext = '<span class="LC_error">'.
1.57 raeburn 10024: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 10025: }
10026: } else {
1.120 raeburn 10027: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 10028: }
10029: return $resulttext;
10030: }
10031:
1.69 raeburn 10032: sub modify_serverstatuses {
10033: my ($dom,%domconfig) = @_;
10034: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
10035: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
10036: %currserverstatus = %{$domconfig{'serverstatuses'}};
10037: }
10038: my @pages = &serverstatus_pages();
10039: foreach my $type (@pages) {
10040: $newserverstatus{$type}{'namedusers'} = '';
10041: $newserverstatus{$type}{'machines'} = '';
10042: if (defined($env{'form.'.$type.'_namedusers'})) {
10043: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
10044: my @okusers;
10045: foreach my $user (@users) {
10046: my ($uname,$udom) = split(/:/,$user);
10047: if (($udom =~ /^$match_domain$/) &&
10048: (&Apache::lonnet::domain($udom)) &&
10049: ($uname =~ /^$match_username$/)) {
10050: if (!grep(/^\Q$user\E/,@okusers)) {
10051: push(@okusers,$user);
10052: }
10053: }
10054: }
10055: if (@okusers > 0) {
10056: @okusers = sort(@okusers);
10057: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
10058: }
10059: }
10060: if (defined($env{'form.'.$type.'_machines'})) {
10061: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
10062: my @okmachines;
10063: foreach my $ip (@machines) {
10064: my @parts = split(/\./,$ip);
10065: next if (@parts < 4);
10066: my $badip = 0;
10067: for (my $i=0; $i<4; $i++) {
10068: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
10069: $badip = 1;
10070: last;
10071: }
10072: }
10073: if (!$badip) {
10074: push(@okmachines,$ip);
10075: }
10076: }
10077: @okmachines = sort(@okmachines);
10078: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
10079: }
10080: }
10081: my %serverstatushash = (
10082: serverstatuses => \%newserverstatus,
10083: );
10084: foreach my $type (@pages) {
1.83 raeburn 10085: foreach my $setting ('namedusers','machines') {
1.84 raeburn 10086: my (@current,@new);
1.83 raeburn 10087: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 10088: if ($currserverstatus{$type}{$setting} ne '') {
10089: @current = split(/,/,$currserverstatus{$type}{$setting});
10090: }
10091: }
10092: if ($newserverstatus{$type}{$setting} ne '') {
10093: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 10094: }
10095: if (@current > 0) {
10096: if (@new > 0) {
10097: foreach my $item (@current) {
10098: if (!grep(/^\Q$item\E$/,@new)) {
10099: $changes{$type}{$setting} = 1;
1.82 raeburn 10100: last;
10101: }
10102: }
1.84 raeburn 10103: foreach my $item (@new) {
10104: if (!grep(/^\Q$item\E$/,@current)) {
10105: $changes{$type}{$setting} = 1;
10106: last;
1.82 raeburn 10107: }
10108: }
10109: } else {
1.83 raeburn 10110: $changes{$type}{$setting} = 1;
1.69 raeburn 10111: }
1.83 raeburn 10112: } elsif (@new > 0) {
10113: $changes{$type}{$setting} = 1;
1.69 raeburn 10114: }
10115: }
10116: }
10117: if (keys(%changes) > 0) {
1.81 raeburn 10118: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10119: my $putresult = &Apache::lonnet::put_dom('configuration',
10120: \%serverstatushash,$dom);
10121: if ($putresult eq 'ok') {
10122: $resulttext .= &mt('Changes made:').'<ul>';
10123: foreach my $type (@pages) {
1.84 raeburn 10124: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 10125: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 10126: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 10127: if ($newserverstatus{$type}{'namedusers'} eq '') {
10128: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
10129: } else {
10130: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
10131: }
1.84 raeburn 10132: }
10133: if ($changes{$type}{'machines'}) {
1.69 raeburn 10134: if ($newserverstatus{$type}{'machines'} eq '') {
10135: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
10136: } else {
10137: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
10138: }
10139:
10140: }
10141: $resulttext .= '</ul></li>';
10142: }
10143: }
10144: $resulttext .= '</ul>';
10145: } else {
10146: $resulttext = '<span class="LC_error">'.
10147: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
10148:
10149: }
10150: } else {
10151: $resulttext = &mt('No changes made to access to server status pages');
10152: }
10153: return $resulttext;
10154: }
10155:
1.118 jms 10156: sub modify_helpsettings {
1.122 jms 10157: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 10158: my ($resulttext,$errors,%changes,%helphash);
10159: my %defaultchecked = ('submitbugs' => 'on');
10160: my @offon = ('off','on');
1.118 jms 10161: my @toggles = ('submitbugs');
10162: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
10163: foreach my $item (@toggles) {
1.160.6.5 raeburn 10164: if ($defaultchecked{$item} eq 'on') {
10165: if ($domconfig{'helpsettings'}{$item} eq '') {
10166: if ($env{'form.'.$item} eq '0') {
10167: $changes{$item} = 1;
10168: }
10169: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10170: $changes{$item} = 1;
10171: }
10172: } elsif ($defaultchecked{$item} eq 'off') {
10173: if ($domconfig{'helpsettings'}{$item} eq '') {
10174: if ($env{'form.'.$item} eq '1') {
10175: $changes{$item} = 1;
10176: }
10177: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10178: $changes{$item} = 1;
10179: }
1.160.6.26 raeburn 10180: }
1.160.6.5 raeburn 10181: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
10182: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 10183: }
10184: }
1.118 jms 10185: }
1.123 jms 10186: my $putresult;
10187: if (keys(%changes) > 0) {
1.160.6.5 raeburn 10188: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
10189: if ($putresult eq 'ok') {
10190: $resulttext = &mt('Changes made:').'<ul>';
10191: foreach my $item (sort(keys(%changes))) {
10192: if ($item eq 'submitbugs') {
10193: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
10194: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
10195: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
10196: }
10197: }
10198: $resulttext .= '</ul>';
10199: } else {
10200: $resulttext = &mt('No changes made to help settings');
10201: $errors .= '<li><span class="LC_error">'.
10202: &mt('An error occurred storing the settings: [_1]',
10203: $putresult).'</span></li>';
10204: }
1.118 jms 10205: }
10206: if ($errors) {
1.160.6.5 raeburn 10207: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 10208: $errors.'</ul>';
10209: }
10210: return $resulttext;
10211: }
10212:
1.121 raeburn 10213: sub modify_coursedefaults {
1.160.6.27 raeburn 10214: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 10215: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 10216: my %defaultchecked = (
10217: 'uselcmath' => 'on',
10218: 'usejsme' => 'on'
10219: );
10220: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 10221: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.30 raeburn 10222: 'uploadquota_community','uploadquota_textbook');
10223: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 10224: my %staticdefaults = (
10225: anonsurvey_threshold => 10,
10226: uploadquota => 500,
1.160.6.57 raeburn 10227: postsubmit => 60,
1.160.6.21 raeburn 10228: );
1.121 raeburn 10229:
10230: $defaultshash{'coursedefaults'} = {};
10231:
10232: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
10233: if ($domconfig{'coursedefaults'} eq '') {
10234: $domconfig{'coursedefaults'} = {};
10235: }
10236: }
10237:
10238: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
10239: foreach my $item (@toggles) {
10240: if ($defaultchecked{$item} eq 'on') {
10241: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10242: ($env{'form.'.$item} eq '0')) {
10243: $changes{$item} = 1;
1.160.6.16 raeburn 10244: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 10245: $changes{$item} = 1;
10246: }
10247: } elsif ($defaultchecked{$item} eq 'off') {
10248: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10249: ($env{'form.'.$item} eq '1')) {
10250: $changes{$item} = 1;
10251: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10252: $changes{$item} = 1;
10253: }
10254: }
10255: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
10256: }
1.160.6.21 raeburn 10257: foreach my $item (@numbers) {
10258: my ($currdef,$newdef);
1.160.6.26 raeburn 10259: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 10260: if ($item eq 'anonsurvey_threshold') {
10261: $currdef = $domconfig{'coursedefaults'}{$item};
10262: $newdef =~ s/\D//g;
10263: if ($newdef eq '' || $newdef < 1) {
10264: $newdef = 1;
10265: }
10266: $defaultshash{'coursedefaults'}{$item} = $newdef;
10267: } else {
10268: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
10269: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10270: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
10271: }
10272: $newdef =~ s/[^\w.\-]//g;
10273: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
10274: }
10275: if ($currdef ne $newdef) {
10276: my $staticdef;
10277: if ($item eq 'anonsurvey_threshold') {
10278: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10279: $changes{$item} = 1;
10280: }
10281: } else {
10282: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
10283: $changes{'uploadquota'} = 1;
10284: }
10285: }
1.139 raeburn 10286: }
10287: }
1.160.6.37 raeburn 10288:
1.160.6.57 raeburn 10289: my %credits;
10290: foreach my $type (@types) {
10291: unless ($type eq 'community') {
10292: $credits{$type} = $env{'form.'.$type.'_credits'};
10293: $credits{$type} =~ s/[^\d.]+//g;
10294: }
10295: }
10296: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
10297: ($env{'form.coursecredits'} eq '1')) {
10298: $changes{'coursecredits'} = 1;
10299: foreach my $type (keys(%credits)) {
10300: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10301: }
10302: } else {
10303: if ($env{'form.coursecredits'} eq '1') {
10304: foreach my $type (@types) {
10305: unless ($type eq 'community') {
10306: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
10307: $changes{'coursecredits'} = 1;
10308: }
10309: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10310: }
10311: }
10312: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10313: foreach my $type (@types) {
10314: unless ($type eq 'community') {
10315: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
10316: $changes{'coursecredits'} = 1;
10317: last;
10318: }
10319: }
10320: }
10321: }
10322: }
10323: if ($env{'form.postsubmit'} eq '1') {
10324: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
10325: my %currtimeout;
10326: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10327: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
10328: $changes{'postsubmit'} = 1;
10329: }
10330: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10331: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
10332: }
10333: } else {
10334: $changes{'postsubmit'} = 1;
10335: }
10336: foreach my $type (@types) {
10337: my $timeout = $env{'form.'.$type.'_timeout'};
10338: $timeout =~ s/\D//g;
10339: if ($timeout == $staticdefaults{'postsubmit'}) {
10340: $timeout = '';
10341: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
10342: $timeout = '0';
10343: }
10344: unless ($timeout eq '') {
10345: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
10346: }
10347: if (exists($currtimeout{$type})) {
10348: if ($timeout ne $currtimeout{$type}) {
10349: $changes{'postsubmit'} = 1;
10350: }
10351: } elsif ($timeout ne '') {
10352: $changes{'postsubmit'} = 1;
10353: }
10354: }
10355: } else {
10356: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
10357: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10358: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
10359: $changes{'postsubmit'} = 1;
10360: }
10361: } else {
10362: $changes{'postsubmit'} = 1;
10363: }
1.160.6.16 raeburn 10364: }
1.121 raeburn 10365: }
10366: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10367: $dom);
10368: if ($putresult eq 'ok') {
10369: if (keys(%changes) > 0) {
1.160.6.27 raeburn 10370: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 10371: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
10372: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'})) {
10373: foreach my $item ('uselcmath','usejsme') {
10374: if ($changes{$item}) {
10375: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
10376: }
1.160.6.16 raeburn 10377: }
10378: if ($changes{'coursecredits'}) {
10379: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 10380: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
10381: $domdefaults{$type.'credits'} =
10382: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
10383: }
10384: }
10385: }
10386: if ($changes{'postsubmit'}) {
10387: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10388: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
10389: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10390: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
10391: $domdefaults{$type.'postsubtimeout'} =
10392: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10393: }
10394: }
1.160.6.16 raeburn 10395: }
10396: }
1.160.6.21 raeburn 10397: if ($changes{'uploadquota'}) {
10398: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10399: foreach my $type (@types) {
10400: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10401: }
10402: }
10403: }
1.121 raeburn 10404: my $cachetime = 24*60*60;
10405: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10406: if (ref($lastactref) eq 'HASH') {
10407: $lastactref->{'domdefaults'} = 1;
10408: }
1.121 raeburn 10409: }
10410: $resulttext = &mt('Changes made:').'<ul>';
10411: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 10412: if ($item eq 'uselcmath') {
1.121 raeburn 10413: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 10414: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 10415: } else {
1.160.6.57 raeburn 10416: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
10417: }
10418: } elsif ($item eq 'usejsme') {
10419: if ($env{'form.'.$item} eq '1') {
10420: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
10421: } else {
10422: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 10423: }
1.139 raeburn 10424: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 10425: $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 10426: } elsif ($item eq 'uploadquota') {
10427: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10428: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10429: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10430: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 10431: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10432:
1.160.6.21 raeburn 10433: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10434: '</ul>'.
10435: '</li>';
10436: } else {
10437: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10438: }
1.160.6.57 raeburn 10439: } elsif ($item eq 'postsubmit') {
10440: if ($domdefaults{'postsubmit'} eq 'off') {
10441: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
10442: } else {
10443: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
10444: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10445: $resulttext .= &mt('durations:').'<ul>';
10446: foreach my $type (@types) {
10447: $resulttext .= '<li>';
10448: my $timeout;
10449: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10450: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10451: }
10452: my $display;
10453: if ($timeout eq '0') {
10454: $display = &mt('unlimited');
10455: } elsif ($timeout eq '') {
10456: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
10457: } else {
10458: $display = &mt('[quant,_1,second]',$timeout);
10459: }
10460: if ($type eq 'community') {
10461: $resulttext .= &mt('Communities');
10462: } elsif ($type eq 'official') {
10463: $resulttext .= &mt('Official courses');
10464: } elsif ($type eq 'unofficial') {
10465: $resulttext .= &mt('Unofficial courses');
10466: } elsif ($type eq 'textbook') {
10467: $resulttext .= &mt('Textbook courses');
10468: }
10469: $resulttext .= ' -- '.$display.'</li>';
10470: }
10471: $resulttext .= '</ul>';
10472: }
10473: $resulttext .= '</li>';
10474: }
1.160.6.16 raeburn 10475: } elsif ($item eq 'coursecredits') {
10476: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10477: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 10478: ($domdefaults{'unofficialcredits'} eq '') &&
10479: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 10480: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10481: } else {
10482: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10483: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10484: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 10485: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 10486: '</ul>'.
10487: '</li>';
10488: }
10489: } else {
10490: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10491: }
1.140 raeburn 10492: }
1.121 raeburn 10493: }
10494: $resulttext .= '</ul>';
10495: } else {
10496: $resulttext = &mt('No changes made to course defaults');
10497: }
10498: } else {
10499: $resulttext = '<span class="LC_error">'.
10500: &mt('An error occurred: [_1]',$putresult).'</span>';
10501: }
10502: return $resulttext;
10503: }
10504:
1.160.6.37 raeburn 10505: sub modify_selfenrollment {
10506: my ($dom,$lastactref,%domconfig) = @_;
10507: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10508: my @types = ('official','unofficial','community','textbook');
10509: my %titles = &tool_titles();
10510: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10511: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
10512: $ordered{'default'} = ['types','registered','approval','limit'];
10513:
10514: my (%roles,%shown,%toplevel);
10515: $roles{'0'} = &Apache::lonnet::plaintext('dc');
10516:
10517: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10518: if ($domconfig{'selfenrollment'} eq '') {
10519: $domconfig{'selfenrollment'} = {};
10520: }
10521: }
10522: %toplevel = (
10523: admin => 'Configuration Rights',
10524: default => 'Default settings',
10525: validation => 'Validation of self-enrollment requests',
10526: );
10527: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
10528:
10529: if (ref($ordered{'admin'}) eq 'ARRAY') {
10530: foreach my $item (@{$ordered{'admin'}}) {
10531: foreach my $type (@types) {
10532: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10533: $selfenrollhash{'admin'}{$type}{$item} = 1;
10534: } else {
10535: $selfenrollhash{'admin'}{$type}{$item} = 0;
10536: }
10537: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10538: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10539: if ($selfenrollhash{'admin'}{$type}{$item} ne
10540: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10541: push(@{$changes{'admin'}{$type}},$item);
10542: }
10543: } else {
10544: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10545: push(@{$changes{'admin'}{$type}},$item);
10546: }
10547: }
10548: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10549: push(@{$changes{'admin'}{$type}},$item);
10550: }
10551: }
10552: }
10553: }
10554:
10555: foreach my $item (@{$ordered{'default'}}) {
10556: foreach my $type (@types) {
10557: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10558: if ($item eq 'types') {
10559: unless (($value eq 'all') || ($value eq 'dom')) {
10560: $value = '';
10561: }
10562: } elsif ($item eq 'registered') {
10563: unless ($value eq '1') {
10564: $value = 0;
10565: }
10566: } elsif ($item eq 'approval') {
10567: unless ($value =~ /^[012]$/) {
10568: $value = 0;
10569: }
10570: } else {
10571: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10572: $value = 'none';
10573: }
10574: }
10575: $selfenrollhash{'default'}{$type}{$item} = $value;
10576: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10577: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10578: if ($selfenrollhash{'default'}{$type}{$item} ne
10579: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10580: push(@{$changes{'default'}{$type}},$item);
10581: }
10582: } else {
10583: push(@{$changes{'default'}{$type}},$item);
10584: }
10585: } else {
10586: push(@{$changes{'default'}{$type}},$item);
10587: }
10588: if ($item eq 'limit') {
10589: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10590: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10591: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10592: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10593: }
10594: } else {
10595: $selfenrollhash{'default'}{$type}{'cap'} = '';
10596: }
10597: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10598: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10599: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10600: push(@{$changes{'default'}{$type}},'cap');
10601: }
10602: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10603: push(@{$changes{'default'}{$type}},'cap');
10604: }
10605: }
10606: }
10607: }
10608:
10609: foreach my $item (@{$itemsref}) {
10610: if ($item eq 'fields') {
10611: my @changed;
10612: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10613: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10614: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10615: }
10616: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10617: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10618: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10619: $domconfig{'selfenrollment'}{'validation'}{$item});
10620: } else {
10621: @changed = @{$selfenrollhash{'validation'}{$item}};
10622: }
10623: } else {
10624: @changed = @{$selfenrollhash{'validation'}{$item}};
10625: }
10626: if (@changed) {
10627: if ($selfenrollhash{'validation'}{$item}) {
10628: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10629: } else {
10630: $changes{'validation'}{$item} = &mt('None');
10631: }
10632: }
10633: } else {
10634: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10635: if ($item eq 'markup') {
10636: if ($env{'form.selfenroll_validation_'.$item}) {
10637: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10638: }
10639: }
10640: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10641: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10642: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10643: }
10644: }
10645: }
10646: }
10647:
10648: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10649: $dom);
10650: if ($putresult eq 'ok') {
10651: if (keys(%changes) > 0) {
10652: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10653: $resulttext = &mt('Changes made:').'<ul>';
10654: foreach my $key ('admin','default','validation') {
10655: if (ref($changes{$key}) eq 'HASH') {
10656: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10657: if ($key eq 'validation') {
10658: foreach my $item (@{$itemsref}) {
10659: if (exists($changes{$key}{$item})) {
10660: if ($item eq 'markup') {
10661: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10662: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10663: } else {
10664: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10665: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10666: }
10667: }
10668: }
10669: } else {
10670: foreach my $type (@types) {
10671: if ($type eq 'community') {
10672: $roles{'1'} = &mt('Community personnel');
10673: } else {
10674: $roles{'1'} = &mt('Course personnel');
10675: }
10676: if (ref($changes{$key}{$type}) eq 'ARRAY') {
10677: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10678: if ($key eq 'admin') {
10679: my @mgrdc = ();
10680: if (ref($ordered{$key}) eq 'ARRAY') {
10681: foreach my $item (@{$ordered{'admin'}}) {
10682: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10683: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10684: push(@mgrdc,$item);
10685: }
10686: }
10687: }
10688: if (@mgrdc) {
10689: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10690: } else {
10691: delete($domdefaults{$type.'selfenrolladmdc'});
10692: }
10693: }
10694: } else {
10695: if (ref($ordered{$key}) eq 'ARRAY') {
10696: foreach my $item (@{$ordered{$key}}) {
10697: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10698: $domdefaults{$type.'selfenroll'.$item} =
10699: $selfenrollhash{$key}{$type}{$item};
10700: }
10701: }
10702: }
10703: }
10704: }
10705: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10706: foreach my $item (@{$ordered{$key}}) {
10707: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10708: $resulttext .= '<li>';
10709: if ($key eq 'admin') {
10710: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10711: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10712: } else {
10713: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10714: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10715: }
10716: $resulttext .= '</li>';
10717: }
10718: }
10719: $resulttext .= '</ul></li>';
10720: }
10721: }
10722: $resulttext .= '</ul></li>';
10723: }
10724: }
10725: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10726: my $cachetime = 24*60*60;
10727: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10728: if (ref($lastactref) eq 'HASH') {
10729: $lastactref->{'domdefaults'} = 1;
10730: }
10731: }
10732: }
10733: $resulttext .= '</ul>';
10734: } else {
10735: $resulttext = &mt('No changes made to self-enrollment settings');
10736: }
10737: } else {
10738: $resulttext = '<span class="LC_error">'.
10739: &mt('An error occurred: [_1]',$putresult).'</span>';
10740: }
10741: return $resulttext;
10742: }
10743:
1.137 raeburn 10744: sub modify_usersessions {
1.160.6.27 raeburn 10745: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 10746: my @hostingtypes = ('version','excludedomain','includedomain');
10747: my @offloadtypes = ('primary','default');
10748: my %types = (
10749: remote => \@hostingtypes,
10750: hosted => \@hostingtypes,
10751: spares => \@offloadtypes,
10752: );
10753: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 10754: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 10755: my (%by_ip,%by_location,@intdoms);
10756: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10757: my @locations = sort(keys(%by_location));
1.137 raeburn 10758: my (%defaultshash,%changes);
10759: foreach my $prefix (@prefixes) {
10760: $defaultshash{'usersessions'}{$prefix} = {};
10761: }
1.160.6.27 raeburn 10762: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 10763: my $resulttext;
1.138 raeburn 10764: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 10765: foreach my $prefix (@prefixes) {
1.145 raeburn 10766: next if ($prefix eq 'spares');
10767: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 10768: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10769: if ($type eq 'version') {
10770: my $value = $env{'form.'.$prefix.'_'.$type};
10771: my $okvalue;
10772: if ($value ne '') {
10773: if (grep(/^\Q$value\E$/,@lcversions)) {
10774: $okvalue = $value;
10775: }
10776: }
10777: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10778: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10779: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10780: if ($inuse == 0) {
10781: $changes{$prefix}{$type} = 1;
10782: } else {
10783: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10784: $changes{$prefix}{$type} = 1;
10785: }
10786: if ($okvalue ne '') {
10787: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10788: }
10789: }
10790: } else {
10791: if (($inuse == 1) && ($okvalue ne '')) {
10792: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10793: $changes{$prefix}{$type} = 1;
10794: }
10795: }
10796: } else {
10797: if (($inuse == 1) && ($okvalue ne '')) {
10798: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10799: $changes{$prefix}{$type} = 1;
10800: }
10801: }
10802: } else {
10803: if (($inuse == 1) && ($okvalue ne '')) {
10804: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10805: $changes{$prefix}{$type} = 1;
10806: }
10807: }
10808: } else {
10809: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10810: my @okvals;
10811: foreach my $val (@vals) {
1.138 raeburn 10812: if ($val =~ /:/) {
10813: my @items = split(/:/,$val);
10814: foreach my $item (@items) {
10815: if (ref($by_location{$item}) eq 'ARRAY') {
10816: push(@okvals,$item);
10817: }
10818: }
10819: } else {
10820: if (ref($by_location{$val}) eq 'ARRAY') {
10821: push(@okvals,$val);
10822: }
1.137 raeburn 10823: }
10824: }
10825: @okvals = sort(@okvals);
10826: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10827: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10828: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10829: if ($inuse == 0) {
10830: $changes{$prefix}{$type} = 1;
10831: } else {
10832: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10833: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10834: if (@changed > 0) {
10835: $changes{$prefix}{$type} = 1;
10836: }
10837: }
10838: } else {
10839: if ($inuse == 1) {
10840: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10841: $changes{$prefix}{$type} = 1;
10842: }
10843: }
10844: } else {
10845: if ($inuse == 1) {
10846: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10847: $changes{$prefix}{$type} = 1;
10848: }
10849: }
10850: } else {
10851: if ($inuse == 1) {
10852: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10853: $changes{$prefix}{$type} = 1;
10854: }
10855: }
10856: }
10857: }
10858: }
1.145 raeburn 10859:
10860: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 10861: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 10862: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10863: my $savespares;
10864:
10865: foreach my $lonhost (sort(keys(%servers))) {
10866: my $serverhomeID =
10867: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 10868: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 10869: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10870: my %spareschg;
10871: foreach my $type (@{$types{'spares'}}) {
10872: my @okspares;
10873: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10874: foreach my $server (@checked) {
1.152 raeburn 10875: if (&Apache::lonnet::hostname($server) ne '') {
10876: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10877: unless (grep(/^\Q$server\E$/,@okspares)) {
10878: push(@okspares,$server);
10879: }
1.145 raeburn 10880: }
10881: }
10882: }
10883: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10884: my $newspare;
1.152 raeburn 10885: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10886: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 10887: $newspare = $new;
10888: }
10889: }
1.152 raeburn 10890: my @spares;
10891: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10892: @spares = sort(@okspares,$newspare);
10893: } else {
10894: @spares = sort(@okspares);
10895: }
10896: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 10897: if (ref($spareid{$lonhost}) eq 'HASH') {
10898: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 10899: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 10900: if (@diffs > 0) {
10901: $spareschg{$type} = 1;
10902: }
10903: }
10904: }
10905: }
10906: if (keys(%spareschg) > 0) {
10907: $changes{'spares'}{$lonhost} = \%spareschg;
10908: }
10909: }
10910:
10911: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10912: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10913: if (ref($changes{'spares'}) eq 'HASH') {
10914: if (keys(%{$changes{'spares'}}) > 0) {
10915: $savespares = 1;
10916: }
10917: }
10918: } else {
10919: $savespares = 1;
10920: }
10921: }
10922:
1.147 raeburn 10923: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10924: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 10925: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10926: $dom);
10927: if ($putresult eq 'ok') {
10928: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10929: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
10930: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
10931: }
10932: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
10933: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
10934: }
10935: }
10936: my $cachetime = 24*60*60;
10937: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10938: if (ref($lastactref) eq 'HASH') {
10939: $lastactref->{'domdefaults'} = 1;
10940: }
1.147 raeburn 10941: if (keys(%changes) > 0) {
10942: my %lt = &usersession_titles();
10943: $resulttext = &mt('Changes made:').'<ul>';
10944: foreach my $prefix (@prefixes) {
10945: if (ref($changes{$prefix}) eq 'HASH') {
10946: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
10947: if ($prefix eq 'spares') {
10948: if (ref($changes{$prefix}) eq 'HASH') {
10949: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
10950: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 10951: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 10952: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
10953: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 10954: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
10955: foreach my $type (@{$types{$prefix}}) {
10956: if ($changes{$prefix}{$lonhost}{$type}) {
10957: my $offloadto = &mt('None');
10958: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
10959: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
10960: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
10961: }
1.145 raeburn 10962: }
1.147 raeburn 10963: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 10964: }
1.137 raeburn 10965: }
10966: }
1.147 raeburn 10967: $resulttext .= '</li>';
1.137 raeburn 10968: }
10969: }
1.147 raeburn 10970: } else {
10971: foreach my $type (@{$types{$prefix}}) {
10972: if (defined($changes{$prefix}{$type})) {
10973: my $newvalue;
10974: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10975: if (ref($defaultshash{'usersessions'}{$prefix})) {
10976: if ($type eq 'version') {
10977: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
10978: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10979: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
10980: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
10981: }
1.145 raeburn 10982: }
10983: }
10984: }
1.147 raeburn 10985: if ($newvalue eq '') {
10986: if ($type eq 'version') {
10987: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
10988: } else {
10989: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
10990: }
1.145 raeburn 10991: } else {
1.147 raeburn 10992: if ($type eq 'version') {
10993: $newvalue .= ' '.&mt('(or later)');
10994: }
10995: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 10996: }
1.137 raeburn 10997: }
10998: }
10999: }
1.147 raeburn 11000: $resulttext .= '</ul>';
1.137 raeburn 11001: }
11002: }
1.147 raeburn 11003: $resulttext .= '</ul>';
11004: } else {
11005: $resulttext = $nochgmsg;
1.137 raeburn 11006: }
11007: } else {
11008: $resulttext = '<span class="LC_error">'.
11009: &mt('An error occurred: [_1]',$putresult).'</span>';
11010: }
11011: } else {
1.147 raeburn 11012: $resulttext = $nochgmsg;
1.137 raeburn 11013: }
11014: return $resulttext;
11015: }
11016:
1.150 raeburn 11017: sub modify_loadbalancing {
11018: my ($dom,%domconfig) = @_;
11019: my $primary_id = &Apache::lonnet::domain($dom,'primary');
11020: my $intdom = &Apache::lonnet::internet_dom($primary_id);
11021: my ($othertitle,$usertypes,$types) =
11022: &Apache::loncommon::sorted_inst_types($dom);
11023: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 11024: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 11025: my @sparestypes = ('primary','default');
11026: my %typetitles = &sparestype_titles();
11027: my $resulttext;
1.160.6.7 raeburn 11028: my (%currbalancer,%currtargets,%currrules,%existing);
11029: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11030: %existing = %{$domconfig{'loadbalancing'}};
11031: }
11032: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
11033: \%currtargets,\%currrules);
11034: my ($saveloadbalancing,%defaultshash,%changes);
11035: my ($alltypes,$othertypes,$titles) =
11036: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
11037: my %ruletitles = &offloadtype_text();
11038: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
11039: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
11040: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
11041: if ($balancer eq '') {
11042: next;
11043: }
11044: if (!exists($servers{$balancer})) {
11045: if (exists($currbalancer{$balancer})) {
11046: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 11047: }
1.160.6.7 raeburn 11048: next;
11049: }
11050: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
11051: push(@{$changes{'delete'}},$balancer);
11052: next;
11053: }
11054: if (!exists($currbalancer{$balancer})) {
11055: push(@{$changes{'add'}},$balancer);
11056: }
11057: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
11058: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
11059: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
11060: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11061: $saveloadbalancing = 1;
11062: }
11063: foreach my $sparetype (@sparestypes) {
11064: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
11065: my @offloadto;
11066: foreach my $target (@targets) {
11067: if (($servers{$target}) && ($target ne $balancer)) {
11068: if ($sparetype eq 'default') {
11069: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
11070: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 11071: }
11072: }
1.160.6.7 raeburn 11073: unless(grep(/^\Q$target\E$/,@offloadto)) {
11074: push(@offloadto,$target);
11075: }
1.150 raeburn 11076: }
1.160.6.7 raeburn 11077: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 11078: }
11079: }
1.160.6.7 raeburn 11080: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 11081: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 11082: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
11083: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 11084: if (@targetdiffs > 0) {
1.160.6.7 raeburn 11085: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11086: }
1.160.6.7 raeburn 11087: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11088: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11089: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11090: }
11091: }
11092: }
11093: } else {
1.160.6.7 raeburn 11094: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
11095: foreach my $sparetype (@sparestypes) {
11096: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11097: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11098: $changes{'curr'}{$balancer}{'targets'} = 1;
11099: }
1.150 raeburn 11100: }
11101: }
1.160.6.7 raeburn 11102: }
1.150 raeburn 11103: }
11104: my $ishomedom;
1.160.6.7 raeburn 11105: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
11106: $ishomedom = 1;
1.150 raeburn 11107: }
11108: if (ref($alltypes) eq 'ARRAY') {
11109: foreach my $type (@{$alltypes}) {
11110: my $rule;
1.160.6.7 raeburn 11111: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 11112: (!$ishomedom)) {
1.160.6.7 raeburn 11113: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
11114: }
11115: if ($rule eq 'specific') {
1.160.6.55 raeburn 11116: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
11117: if (exists($servers{$specifiedhost})) {
11118: $rule = $specifiedhost;
11119: }
1.150 raeburn 11120: }
1.160.6.7 raeburn 11121: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
11122: if (ref($currrules{$balancer}) eq 'HASH') {
11123: if ($rule ne $currrules{$balancer}{$type}) {
11124: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11125: }
11126: } elsif ($rule ne '') {
1.160.6.7 raeburn 11127: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11128: }
11129: }
11130: }
1.160.6.7 raeburn 11131: }
11132: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
11133: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
11134: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
11135: $defaultshash{'loadbalancing'} = {};
11136: }
11137: my $putresult = &Apache::lonnet::put_dom('configuration',
11138: \%defaultshash,$dom);
11139: if ($putresult eq 'ok') {
11140: if (keys(%changes) > 0) {
1.160.6.54 raeburn 11141: my %toupdate;
1.160.6.7 raeburn 11142: if (ref($changes{'delete'}) eq 'ARRAY') {
11143: foreach my $balancer (sort(@{$changes{'delete'}})) {
11144: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 11145: $toupdate{$balancer} = 1;
1.150 raeburn 11146: }
1.160.6.7 raeburn 11147: }
11148: if (ref($changes{'add'}) eq 'ARRAY') {
11149: foreach my $balancer (sort(@{$changes{'add'}})) {
11150: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 11151: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 11152: }
11153: }
11154: if (ref($changes{'curr'}) eq 'HASH') {
11155: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 11156: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 11157: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
11158: if ($changes{'curr'}{$balancer}{'targets'}) {
11159: my %offloadstr;
11160: foreach my $sparetype (@sparestypes) {
11161: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11162: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11163: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11164: }
11165: }
1.150 raeburn 11166: }
1.160.6.7 raeburn 11167: if (keys(%offloadstr) == 0) {
11168: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 11169: } else {
1.160.6.7 raeburn 11170: my $showoffload;
11171: foreach my $sparetype (@sparestypes) {
11172: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
11173: if (defined($offloadstr{$sparetype})) {
11174: $showoffload .= $offloadstr{$sparetype};
11175: } else {
11176: $showoffload .= &mt('None');
11177: }
11178: $showoffload .= (' 'x3);
11179: }
11180: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 11181: }
11182: }
11183: }
1.160.6.7 raeburn 11184: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
11185: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
11186: foreach my $type (@{$alltypes}) {
11187: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
11188: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11189: my $balancetext;
11190: if ($rule eq '') {
11191: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 11192: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 11193: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
11194: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 11195: foreach my $sparetype (@sparestypes) {
11196: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11197: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11198: }
11199: }
1.160.6.55 raeburn 11200: foreach my $item (@{$alltypes}) {
11201: next if ($item =~ /^_LC_ipchange/);
11202: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
11203: if ($hasrule eq 'homeserver') {
11204: map { $toupdate{$_} = 1; } (keys(%libraryservers));
11205: } else {
11206: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
11207: if ($servers{$hasrule}) {
11208: $toupdate{$hasrule} = 1;
11209: }
11210: }
11211: }
11212: }
11213: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
11214: $balancetext = $ruletitles{$rule};
11215: } else {
11216: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11217: $balancetext = $ruletitles{'particular'}.' '.$receiver;
11218: if ($receiver) {
11219: $toupdate{$receiver};
11220: }
11221: }
11222: } else {
11223: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 11224: }
1.160.6.7 raeburn 11225: } else {
11226: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
11227: }
1.160.6.26 raeburn 11228: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 11229: }
11230: }
11231: }
11232: }
1.160.6.54 raeburn 11233: if (keys(%toupdate)) {
11234: my %thismachine;
11235: my $updatedhere;
11236: my $cachetime = 60*60*24;
11237: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
11238: foreach my $lonhost (keys(%toupdate)) {
11239: if ($thismachine{$lonhost}) {
11240: unless ($updatedhere) {
11241: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
11242: $defaultshash{'loadbalancing'},
11243: $cachetime);
11244: $updatedhere = 1;
11245: }
11246: } else {
11247: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
11248: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
11249: }
11250: }
11251: }
1.150 raeburn 11252: }
1.160.6.7 raeburn 11253: }
11254: if ($resulttext ne '') {
11255: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 11256: } else {
11257: $resulttext = $nochgmsg;
11258: }
11259: } else {
1.160.6.7 raeburn 11260: $resulttext = $nochgmsg;
1.150 raeburn 11261: }
11262: } else {
1.160.6.7 raeburn 11263: $resulttext = '<span class="LC_error">'.
11264: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 11265: }
11266: } else {
1.160.6.7 raeburn 11267: $resulttext = $nochgmsg;
1.150 raeburn 11268: }
11269: return $resulttext;
11270: }
11271:
1.48 raeburn 11272: sub recurse_check {
11273: my ($chkcats,$categories,$depth,$name) = @_;
11274: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
11275: my $chg = 0;
11276: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
11277: my $category = $chkcats->[$depth]{$name}[$j];
11278: my $item;
11279: if ($category eq '') {
11280: $chg ++;
11281: } else {
11282: my $deeper = $depth + 1;
11283: $item = &escape($category).':'.&escape($name).':'.$depth;
11284: if ($chg) {
11285: $categories->{$item} -= $chg;
11286: }
11287: &recurse_check($chkcats,$categories,$deeper,$category);
11288: $deeper --;
11289: }
11290: }
11291: }
11292: return;
11293: }
11294:
11295: sub recurse_cat_deletes {
11296: my ($item,$coursecategories,$deletions) = @_;
11297: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
11298: my $subdepth = $depth + 1;
11299: if (ref($coursecategories) eq 'HASH') {
11300: foreach my $subitem (keys(%{$coursecategories})) {
11301: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
11302: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
11303: delete($coursecategories->{$subitem});
11304: $deletions->{$subitem} = 1;
11305: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 11306: }
1.48 raeburn 11307: }
11308: }
11309: return;
11310: }
11311:
1.125 raeburn 11312: sub get_active_dcs {
11313: my ($dom) = @_;
1.160.6.16 raeburn 11314: my $now = time;
11315: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 11316: my %domcoords;
11317: my $numdcs = 0;
11318: foreach my $server (keys(%dompersonnel)) {
11319: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
11320: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 11321: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 11322: }
11323: }
11324: return %domcoords;
11325: }
11326:
11327: sub active_dc_picker {
1.160.6.16 raeburn 11328: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.39 raeburn 11329: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 11330: my @domcoord = keys(%domcoords);
11331: if (keys(%currhash)) {
11332: foreach my $dc (keys(%currhash)) {
11333: unless (exists($domcoords{$dc})) {
11334: push(@domcoord,$dc);
11335: }
11336: }
11337: }
11338: @domcoord = sort(@domcoord);
11339: my $numdcs = scalar(@domcoord);
11340: my $rows = 0;
11341: my $table;
1.125 raeburn 11342: if ($numdcs > 1) {
1.160.6.16 raeburn 11343: $table = '<table>';
11344: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 11345: my $rem = $i%($numinrow);
11346: if ($rem == 0) {
11347: if ($i > 0) {
1.160.6.16 raeburn 11348: $table .= '</tr>';
1.125 raeburn 11349: }
1.160.6.16 raeburn 11350: $table .= '<tr>';
11351: $rows ++;
1.125 raeburn 11352: }
1.160.6.16 raeburn 11353: my $check = '';
11354: if ($inputtype eq 'radio') {
11355: if (keys(%currhash) == 0) {
11356: if (!$i) {
11357: $check = ' checked="checked"';
11358: }
11359: } elsif (exists($currhash{$domcoord[$i]})) {
11360: $check = ' checked="checked"';
11361: }
11362: } else {
11363: if (exists($currhash{$domcoord[$i]})) {
11364: $check = ' checked="checked"';
1.125 raeburn 11365: }
11366: }
1.160.6.16 raeburn 11367: if ($i == @domcoord - 1) {
1.125 raeburn 11368: my $colsleft = $numinrow - $rem;
11369: if ($colsleft > 1) {
1.160.6.16 raeburn 11370: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 11371: } else {
1.160.6.16 raeburn 11372: $table .= '<td class="LC_left_item">';
1.125 raeburn 11373: }
11374: } else {
1.160.6.16 raeburn 11375: $table .= '<td class="LC_left_item">';
11376: }
11377: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
11378: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11379: $table .= '<span class="LC_nobreak"><label>'.
11380: '<input type="'.$inputtype.'" name="'.$name.'"'.
11381: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
11382: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 11383: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 11384: }
1.160.6.33 raeburn 11385: $table .= '</label></span></td>';
1.125 raeburn 11386: }
1.160.6.16 raeburn 11387: $table .= '</tr></table>';
11388: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 11389: my ($dcname,$dcdom) = split(':',$domcoord[0]);
11390: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 11391: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 11392: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 11393: if ($user ne $dcname.':'.$dcdom) {
11394: $table .= ' ('.$dcname.':'.$dcdom.')';
11395: }
1.160.6.16 raeburn 11396: } else {
11397: my $check;
11398: if (exists($currhash{$domcoord[0]})) {
11399: $check = ' checked="checked"';
11400: }
1.160.6.50 raeburn 11401: $table = '<span class="LC_nobreak"><label>'.
11402: '<input type="checkbox" name="'.$name.'" '.
11403: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 11404: if ($user ne $dcname.':'.$dcdom) {
11405: $table .= ' ('.$dcname.':'.$dcdom.')';
11406: }
11407: $table .= '</label></span>';
1.160.6.16 raeburn 11408: $rows ++;
11409: }
1.125 raeburn 11410: }
1.160.6.16 raeburn 11411: return ($numdcs,$table,$rows);
1.125 raeburn 11412: }
11413:
1.137 raeburn 11414: sub usersession_titles {
11415: return &Apache::lonlocal::texthash(
11416: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
11417: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 11418: spares => 'Servers offloaded to, when busy',
1.137 raeburn 11419: version => 'LON-CAPA version requirement',
1.138 raeburn 11420: excludedomain => 'Allow all, but exclude specific domains',
11421: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 11422: primary => 'Primary (checked first)',
1.154 raeburn 11423: default => 'Default',
1.137 raeburn 11424: );
11425: }
11426:
1.152 raeburn 11427: sub id_for_thisdom {
11428: my (%servers) = @_;
11429: my %altids;
11430: foreach my $server (keys(%servers)) {
11431: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11432: if ($serverhome ne $server) {
11433: $altids{$serverhome} = $server;
11434: }
11435: }
11436: return %altids;
11437: }
11438:
1.150 raeburn 11439: sub count_servers {
11440: my ($currbalancer,%servers) = @_;
11441: my (@spares,$numspares);
11442: foreach my $lonhost (sort(keys(%servers))) {
11443: next if ($currbalancer eq $lonhost);
11444: push(@spares,$lonhost);
11445: }
11446: if ($currbalancer) {
11447: $numspares = scalar(@spares);
11448: } else {
11449: $numspares = scalar(@spares) - 1;
11450: }
11451: return ($numspares,@spares);
11452: }
11453:
11454: sub lonbalance_targets_js {
1.160.6.7 raeburn 11455: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 11456: my $select = &mt('Select');
11457: my ($alltargets,$allishome,$allinsttypes,@alltypes);
11458: if (ref($servers) eq 'HASH') {
11459: $alltargets = join("','",sort(keys(%{$servers})));
11460: my @homedoms;
11461: foreach my $server (sort(keys(%{$servers}))) {
11462: if (&Apache::lonnet::host_domain($server) eq $dom) {
11463: push(@homedoms,'1');
11464: } else {
11465: push(@homedoms,'0');
11466: }
11467: }
11468: $allishome = join("','",@homedoms);
11469: }
11470: if (ref($types) eq 'ARRAY') {
11471: if (@{$types} > 0) {
11472: @alltypes = @{$types};
11473: }
11474: }
11475: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11476: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 11477: my (%currbalancer,%currtargets,%currrules,%existing);
11478: if (ref($settings) eq 'HASH') {
11479: %existing = %{$settings};
11480: }
11481: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11482: \%currtargets,\%currrules);
11483: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 11484: return <<"END";
11485:
11486: <script type="text/javascript">
11487: // <![CDATA[
11488:
1.160.6.7 raeburn 11489: currBalancers = new Array('$balancers');
11490:
11491: function toggleTargets(balnum) {
11492: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11493: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11494: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11495: var prevbalancer = prevhostitem.value;
11496: var baltotal = document.getElementById('loadbalancing_total').value;
11497: prevhostitem.value = balancer;
11498: if (prevbalancer != '') {
11499: var prevIdx = currBalancers.indexOf(prevbalancer);
11500: if (prevIdx != -1) {
11501: currBalancers.splice(prevIdx,1);
11502: }
11503: }
1.150 raeburn 11504: if (balancer == '') {
1.160.6.7 raeburn 11505: hideSpares(balnum);
1.150 raeburn 11506: } else {
1.160.6.7 raeburn 11507: var currIdx = currBalancers.indexOf(balancer);
11508: if (currIdx == -1) {
11509: currBalancers.push(balancer);
11510: }
1.150 raeburn 11511: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 11512: var ishomedom = homedoms[lonhostitem.selectedIndex];
11513: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 11514: }
1.160.6.7 raeburn 11515: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 11516: return;
11517: }
11518:
1.160.6.7 raeburn 11519: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 11520: var alltargets = new Array('$alltargets');
11521: var insttypes = new Array('$allinsttypes');
1.151 raeburn 11522: var offloadtypes = new Array('primary','default');
11523:
1.160.6.7 raeburn 11524: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11525: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 11526:
1.151 raeburn 11527: for (var i=0; i<offloadtypes.length; i++) {
11528: var count = 0;
11529: for (var j=0; j<alltargets.length; j++) {
11530: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 11531: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11532: item.value = alltargets[j];
11533: item.style.textAlign='left';
11534: item.style.textFace='normal';
11535: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11536: if (currBalancers.indexOf(alltargets[j]) == -1) {
11537: item.disabled = '';
11538: } else {
11539: item.disabled = 'disabled';
11540: item.checked = false;
11541: }
1.151 raeburn 11542: count ++;
11543: }
1.150 raeburn 11544: }
11545: }
1.151 raeburn 11546: for (var k=0; k<insttypes.length; k++) {
11547: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 11548: if (ishomedom == 1) {
1.160.6.7 raeburn 11549: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11550: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11551: } else {
1.160.6.7 raeburn 11552: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11553: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 11554: }
11555: } else {
1.160.6.7 raeburn 11556: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11557: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11558: }
1.151 raeburn 11559: if ((insttypes[k] != '_LC_external') &&
11560: ((insttypes[k] != '_LC_internetdom') ||
11561: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 11562: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11563: item.options.length = 0;
11564: item.options[0] = new Option("","",true,true);
11565: var idx = 0;
1.151 raeburn 11566: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 11567: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11568: idx ++;
11569: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 11570: }
11571: }
11572: }
11573: }
11574: return;
11575: }
11576:
1.160.6.7 raeburn 11577: function hideSpares(balnum) {
1.150 raeburn 11578: var alltargets = new Array('$alltargets');
11579: var insttypes = new Array('$allinsttypes');
11580: var offloadtypes = new Array('primary','default');
11581:
1.160.6.7 raeburn 11582: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11583: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 11584:
11585: var total = alltargets.length - 1;
11586: for (var i=0; i<offloadtypes; i++) {
11587: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 11588: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11589: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11590: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 11591: }
1.150 raeburn 11592: }
11593: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 11594: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11595: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 11596: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 11597: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11598: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 11599: }
11600: }
11601: return;
11602: }
11603:
1.160.6.7 raeburn 11604: function checkOffloads(item,balnum,type) {
1.150 raeburn 11605: var alltargets = new Array('$alltargets');
11606: var offloadtypes = new Array('primary','default');
11607: if (item.checked) {
11608: var total = alltargets.length - 1;
11609: var other;
11610: if (type == offloadtypes[0]) {
1.151 raeburn 11611: other = offloadtypes[1];
1.150 raeburn 11612: } else {
1.151 raeburn 11613: other = offloadtypes[0];
1.150 raeburn 11614: }
11615: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 11616: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 11617: if (server == item.value) {
1.160.6.7 raeburn 11618: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11619: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 11620: }
11621: }
11622: }
11623: }
11624: return;
11625: }
11626:
1.160.6.7 raeburn 11627: function singleServerToggle(balnum,type) {
11628: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 11629: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 11630: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11631: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11632:
11633: } else {
1.160.6.7 raeburn 11634: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11635: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 11636: }
11637: return;
11638: }
11639:
1.160.6.7 raeburn 11640: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 11641: if (type == '_LC_external') {
1.160.6.26 raeburn 11642: return;
1.150 raeburn 11643: }
1.160.6.7 raeburn 11644: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 11645: for (var i=0; i<typesRules.length; i++) {
11646: if (formname.elements[typesRules[i]].checked) {
11647: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 11648: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11649: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11650: } else {
1.160.6.7 raeburn 11651: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11652: }
11653: }
11654: }
11655: return;
11656: }
11657:
11658: function balancerDeleteChange(balnum) {
11659: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11660: var baltotal = document.getElementById('loadbalancing_total').value;
11661: var addtarget;
11662: var removetarget;
11663: var action = 'delete';
11664: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11665: var lonhost = hostitem.value;
11666: var currIdx = currBalancers.indexOf(lonhost);
11667: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11668: if (currIdx != -1) {
11669: currBalancers.splice(currIdx,1);
11670: }
11671: addtarget = lonhost;
11672: } else {
11673: if (currIdx == -1) {
11674: currBalancers.push(lonhost);
11675: }
11676: removetarget = lonhost;
11677: action = 'undelete';
11678: }
11679: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11680: }
11681: return;
11682: }
11683:
11684: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11685: if (baltotal > 1) {
11686: var offloadtypes = new Array('primary','default');
11687: var alltargets = new Array('$alltargets');
11688: var insttypes = new Array('$allinsttypes');
11689: for (var i=0; i<baltotal; i++) {
11690: if (i != balnum) {
11691: for (var j=0; j<offloadtypes.length; j++) {
11692: var total = alltargets.length - 1;
11693: for (var k=0; k<total; k++) {
11694: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11695: var server = serveritem.value;
11696: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11697: if (server == addtarget) {
11698: serveritem.disabled = '';
11699: }
11700: }
11701: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11702: if (server == removetarget) {
11703: serveritem.disabled = 'disabled';
11704: serveritem.checked = false;
11705: }
11706: }
11707: }
11708: }
11709: for (var j=0; j<insttypes.length; j++) {
11710: if (insttypes[j] != '_LC_external') {
11711: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11712: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11713: var currSel = singleserver.selectedIndex;
11714: var currVal = singleserver.options[currSel].value;
11715: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11716: var numoptions = singleserver.options.length;
11717: var needsnew = 1;
11718: for (var k=0; k<numoptions; k++) {
11719: if (singleserver.options[k] == addtarget) {
11720: needsnew = 0;
11721: break;
11722: }
11723: }
11724: if (needsnew == 1) {
11725: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11726: }
11727: }
11728: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11729: singleserver.options.length = 0;
11730: if ((currVal) && (currVal != removetarget)) {
11731: singleserver.options[0] = new Option("","",false,false);
11732: } else {
11733: singleserver.options[0] = new Option("","",true,true);
11734: }
11735: var idx = 0;
11736: for (var m=0; m<alltargets.length; m++) {
11737: if (currBalancers.indexOf(alltargets[m]) == -1) {
11738: idx ++;
11739: if (currVal == alltargets[m]) {
11740: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11741: } else {
11742: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11743: }
11744: }
11745: }
11746: }
11747: }
11748: }
11749: }
1.150 raeburn 11750: }
11751: }
11752: }
11753: return;
11754: }
11755:
1.152 raeburn 11756: // ]]>
11757: </script>
11758:
11759: END
11760: }
11761:
11762: sub new_spares_js {
11763: my @sparestypes = ('primary','default');
11764: my $types = join("','",@sparestypes);
11765: my $select = &mt('Select');
11766: return <<"END";
11767:
11768: <script type="text/javascript">
11769: // <![CDATA[
11770:
11771: function updateNewSpares(formname,lonhost) {
11772: var types = new Array('$types');
11773: var include = new Array();
11774: var exclude = new Array();
11775: for (var i=0; i<types.length; i++) {
11776: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11777: for (var j=0; j<spareboxes.length; j++) {
11778: if (formname.elements[spareboxes[j]].checked) {
11779: exclude.push(formname.elements[spareboxes[j]].value);
11780: } else {
11781: include.push(formname.elements[spareboxes[j]].value);
11782: }
11783: }
11784: }
11785: for (var i=0; i<types.length; i++) {
11786: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11787: var selIdx = newSpare.selectedIndex;
11788: var currnew = newSpare.options[selIdx].value;
11789: var okSpares = new Array();
11790: for (var j=0; j<newSpare.options.length; j++) {
11791: var possible = newSpare.options[j].value;
11792: if (possible != '') {
11793: if (exclude.indexOf(possible) == -1) {
11794: okSpares.push(possible);
11795: } else {
11796: if (currnew == possible) {
11797: selIdx = 0;
11798: }
11799: }
11800: }
11801: }
11802: for (var k=0; k<include.length; k++) {
11803: if (okSpares.indexOf(include[k]) == -1) {
11804: okSpares.push(include[k]);
11805: }
11806: }
11807: okSpares.sort();
11808: newSpare.options.length = 0;
11809: if (selIdx == 0) {
11810: newSpare.options[0] = new Option("$select","",true,true);
11811: } else {
11812: newSpare.options[0] = new Option("$select","",false,false);
11813: }
11814: for (var m=0; m<okSpares.length; m++) {
11815: var idx = m+1;
11816: var selThis = 0;
11817: if (selIdx != 0) {
11818: if (okSpares[m] == currnew) {
11819: selThis = 1;
11820: }
11821: }
11822: if (selThis == 1) {
11823: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11824: } else {
11825: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11826: }
11827: }
11828: }
11829: return;
11830: }
11831:
11832: function checkNewSpares(lonhost,type) {
11833: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11834: var chosen = newSpare.options[newSpare.selectedIndex].value;
11835: if (chosen != '') {
11836: var othertype;
11837: var othernewSpare;
11838: if (type == 'primary') {
11839: othernewSpare = document.getElementById('newspare_default_'+lonhost);
11840: }
11841: if (type == 'default') {
11842: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11843: }
11844: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11845: othernewSpare.selectedIndex = 0;
11846: }
11847: }
11848: return;
11849: }
11850:
11851: // ]]>
11852: </script>
11853:
11854: END
11855:
11856: }
11857:
11858: sub common_domprefs_js {
11859: return <<"END";
11860:
11861: <script type="text/javascript">
11862: // <![CDATA[
11863:
1.150 raeburn 11864: function getIndicesByName(formname,item) {
1.152 raeburn 11865: var group = new Array();
1.150 raeburn 11866: for (var i=0;i<formname.elements.length;i++) {
11867: if (formname.elements[i].name == item) {
1.152 raeburn 11868: group.push(formname.elements[i].id);
1.150 raeburn 11869: }
11870: }
1.152 raeburn 11871: return group;
1.150 raeburn 11872: }
11873:
11874: // ]]>
11875: </script>
11876:
11877: END
1.152 raeburn 11878:
1.150 raeburn 11879: }
11880:
1.160.6.5 raeburn 11881: sub recaptcha_js {
11882: my %lt = &captcha_phrases();
11883: return <<"END";
11884:
11885: <script type="text/javascript">
11886: // <![CDATA[
11887:
11888: function updateCaptcha(caller,context) {
11889: var privitem;
11890: var pubitem;
11891: var privtext;
11892: var pubtext;
11893: if (document.getElementById(context+'_recaptchapub')) {
11894: pubitem = document.getElementById(context+'_recaptchapub');
11895: } else {
11896: return;
11897: }
11898: if (document.getElementById(context+'_recaptchapriv')) {
11899: privitem = document.getElementById(context+'_recaptchapriv');
11900: } else {
11901: return;
11902: }
11903: if (document.getElementById(context+'_recaptchapubtxt')) {
11904: pubtext = document.getElementById(context+'_recaptchapubtxt');
11905: } else {
11906: return;
11907: }
11908: if (document.getElementById(context+'_recaptchaprivtxt')) {
11909: privtext = document.getElementById(context+'_recaptchaprivtxt');
11910: } else {
11911: return;
11912: }
11913: if (caller.checked) {
11914: if (caller.value == 'recaptcha') {
11915: pubitem.type = 'text';
11916: privitem.type = 'text';
11917: pubitem.size = '40';
11918: privitem.size = '40';
11919: pubtext.innerHTML = "$lt{'pub'}";
11920: privtext.innerHTML = "$lt{'priv'}";
11921: } else {
11922: pubitem.type = 'hidden';
11923: privitem.type = 'hidden';
11924: pubtext.innerHTML = '';
11925: privtext.innerHTML = '';
11926: }
11927: }
11928: return;
11929: }
11930:
11931: // ]]>
11932: </script>
11933:
11934: END
11935:
11936: }
11937:
1.160.6.40 raeburn 11938: sub toggle_display_js {
1.160.6.16 raeburn 11939: return <<"END";
11940:
11941: <script type="text/javascript">
11942: // <![CDATA[
11943:
1.160.6.40 raeburn 11944: function toggleDisplay(domForm,caller) {
11945: if (document.getElementById(caller)) {
11946: var divitem = document.getElementById(caller);
11947: var optionsElement = domForm.coursecredits;
11948: if (caller == 'emailoptions') {
11949: optionsElement = domForm.cancreate_email;
11950: }
1.160.6.57 raeburn 11951: if (caller == 'studentsubmission') {
11952: optionsElement = domForm.postsubmit;
11953: }
1.160.6.40 raeburn 11954: if (optionsElement.length) {
1.160.6.16 raeburn 11955: var currval;
1.160.6.40 raeburn 11956: for (var i=0; i<optionsElement.length; i++) {
11957: if (optionsElement[i].checked) {
11958: currval = optionsElement[i].value;
1.160.6.16 raeburn 11959: }
11960: }
11961: if (currval == 1) {
1.160.6.40 raeburn 11962: divitem.style.display = 'block';
1.160.6.16 raeburn 11963: } else {
1.160.6.40 raeburn 11964: divitem.style.display = 'none';
1.160.6.16 raeburn 11965: }
11966: }
11967: }
11968: return;
11969: }
11970:
11971: // ]]>
11972: </script>
11973:
11974: END
11975:
11976: }
11977:
1.160.6.5 raeburn 11978: sub captcha_phrases {
11979: return &Apache::lonlocal::texthash (
11980: priv => 'Private key',
11981: pub => 'Public key',
11982: original => 'original (CAPTCHA)',
11983: recaptcha => 'successor (ReCAPTCHA)',
11984: notused => 'unused',
11985: );
11986: }
11987:
1.160.6.24 raeburn 11988: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 11989: my ($dom,$cachekeys) = @_;
11990: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 11991: my %servers = &Apache::lonnet::internet_dom_servers($dom);
11992: my %thismachine;
11993: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.27 raeburn 11994: my @posscached = ('domainconfig','domdefaults');
1.160.6.24 raeburn 11995: if (keys(%servers) > 1) {
11996: foreach my $server (keys(%servers)) {
11997: next if ($thismachine{$server});
1.160.6.27 raeburn 11998: my @cached;
11999: foreach my $name (@posscached) {
12000: if ($cachekeys->{$name}) {
12001: push(@cached,&escape($name).':'.&escape($dom));
12002: }
12003: }
12004: if (@cached) {
12005: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
12006: }
1.160.6.24 raeburn 12007: }
12008: }
12009: return;
12010: }
12011:
1.3 raeburn 12012: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>