Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.59
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.59! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.58 2015/03/13 13:53:07 raeburn Exp $
1.160.6.40 raeburn 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
1.160.6.13 raeburn 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
1.160.6.27 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 raeburn 90: requestcourses or requestauthor).
1.101 raeburn 91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20 raeburn 97: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 98: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 99:
1.101 raeburn 100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.160.6.30 raeburn 106: (official, unofficial, community, and textbook). In each case the radio buttons
107: allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.160.6.37 raeburn 167: use Apache::lonuserutils();
1.160.6.39 raeburn 168: use Apache::loncoursequeueadmin();
1.69 raeburn 169: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 170: use LONCAPA::Enrollment;
1.81 raeburn 171: use LONCAPA::lonauthcgi();
1.9 raeburn 172: use File::Copy;
1.43 raeburn 173: use Locale::Language;
1.62 raeburn 174: use DateTime::TimeZone;
1.68 raeburn 175: use DateTime::Locale;
1.1 raeburn 176:
1.155 raeburn 177: my $registered_cleanup;
178: my $modified_urls;
179:
1.1 raeburn 180: sub handler {
181: my $r=shift;
182: if ($r->header_only) {
183: &Apache::loncommon::content_type($r,'text/html');
184: $r->send_http_header;
185: return OK;
186: }
187:
1.91 raeburn 188: my $context = 'domain';
1.1 raeburn 189: my $dom = $env{'request.role.domain'};
1.5 albertel 190: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 191: if (&Apache::lonnet::allowed('mau',$dom)) {
192: &Apache::loncommon::content_type($r,'text/html');
193: $r->send_http_header;
194: } else {
195: $env{'user.error.msg'}=
196: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
197: return HTTP_NOT_ACCEPTABLE;
198: }
1.155 raeburn 199:
200: $registered_cleanup=0;
201: @{$modified_urls}=();
202:
1.1 raeburn 203: &Apache::lonhtmlcommon::clear_breadcrumbs();
204: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 205: ['phase','actions']);
1.30 raeburn 206: my $phase = 'pickactions';
1.3 raeburn 207: if ( exists($env{'form.phase'}) ) {
208: $phase = $env{'form.phase'};
209: }
1.150 raeburn 210: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 211: my %domconfig =
1.6 raeburn 212: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 213: 'quotas','autoenroll','autoupdate','autocreate',
214: 'directorysrch','usercreation','usermodification',
215: 'contacts','defaults','scantron','coursecategories',
1.160.6.16 raeburn 216: 'serverstatuses','requestcourses','coursedefaults',
1.160.6.38 raeburn 217: 'usersessions','loadbalancing','requestauthor',
1.160.6.40 raeburn 218: 'selfenrollment','inststatus'],$dom);
1.43 raeburn 219: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 220: 'autoupdate','autocreate','directorysrch','contacts',
1.160.6.34 raeburn 221: 'usercreation','selfcreation','usermodification','scantron',
1.160.6.5 raeburn 222: 'requestcourses','requestauthor','coursecategories',
1.160.6.41 raeburn 223: 'serverstatuses','coursedefaults','selfenrollment',
1.160.6.37 raeburn 224: 'usersessions');
1.160.6.7 raeburn 225: my %existing;
226: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
227: %existing = %{$domconfig{'loadbalancing'}};
228: }
229: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 230: push(@prefs_order,'loadbalancing');
231: }
1.30 raeburn 232: my %prefs = (
233: 'rolecolors' =>
234: { text => 'Default color schemes',
1.67 raeburn 235: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 236: header => [{col1 => 'Student Settings',
237: col2 => '',},
238: {col1 => 'Coordinator Settings',
239: col2 => '',},
240: {col1 => 'Author Settings',
241: col2 => '',},
242: {col1 => 'Administrator Settings',
243: col2 => '',}],
1.160.6.37 raeburn 244: print => \&print_rolecolors,
245: modify => \&modify_rolecolors,
1.30 raeburn 246: },
1.110 raeburn 247: 'login' =>
1.30 raeburn 248: { text => 'Log-in page options',
1.67 raeburn 249: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 250: header => [{col1 => 'Log-in Page Items',
251: col2 => '',},
252: {col1 => 'Log-in Help',
1.160.6.56 raeburn 253: col2 => 'Value'},
254: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 255: col2 => 'Value'}],
1.160.6.37 raeburn 256: print => \&print_login,
257: modify => \&modify_login,
1.30 raeburn 258: },
1.43 raeburn 259: 'defaults' =>
1.160.6.40 raeburn 260: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 261: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 262: header => [{col1 => 'Setting',
1.160.6.40 raeburn 263: col2 => 'Value'},
264: {col1 => 'Institutional user types',
265: col2 => 'Assignable to e-mail usernames'}],
1.160.6.37 raeburn 266: print => \&print_defaults,
267: modify => \&modify_defaults,
1.43 raeburn 268: },
1.30 raeburn 269: 'quotas' =>
1.160.6.20 raeburn 270: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 271: help => 'Domain_Configuration_Quotas',
1.77 raeburn 272: header => [{col1 => 'User affiliation',
1.72 raeburn 273: col2 => 'Available tools',
1.160.6.28 raeburn 274: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 275: print => \&print_quotas,
276: modify => \&modify_quotas,
1.30 raeburn 277: },
278: 'autoenroll' =>
279: { text => 'Auto-enrollment settings',
1.67 raeburn 280: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 281: header => [{col1 => 'Configuration setting',
282: col2 => 'Value(s)'}],
1.160.6.37 raeburn 283: print => \&print_autoenroll,
284: modify => \&modify_autoenroll,
1.30 raeburn 285: },
286: 'autoupdate' =>
287: { text => 'Auto-update settings',
1.67 raeburn 288: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 289: header => [{col1 => 'Setting',
290: col2 => 'Value',},
1.131 raeburn 291: {col1 => 'Setting',
292: col2 => 'Affiliation'},
1.43 raeburn 293: {col1 => 'User population',
1.160.6.35 raeburn 294: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 295: print => \&print_autoupdate,
296: modify => \&modify_autoupdate,
1.30 raeburn 297: },
1.125 raeburn 298: 'autocreate' =>
299: { text => 'Auto-course creation settings',
300: help => 'Domain_Configuration_Auto_Creation',
301: header => [{col1 => 'Configuration Setting',
302: col2 => 'Value',}],
1.160.6.37 raeburn 303: print => \&print_autocreate,
304: modify => \&modify_autocreate,
1.125 raeburn 305: },
1.30 raeburn 306: 'directorysrch' =>
307: { text => 'Institutional directory searches',
1.67 raeburn 308: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 309: header => [{col1 => 'Setting',
310: col2 => 'Value',}],
1.160.6.37 raeburn 311: print => \&print_directorysrch,
312: modify => \&modify_directorysrch,
1.30 raeburn 313: },
314: 'contacts' =>
315: { text => 'Contact Information',
1.67 raeburn 316: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 317: header => [{col1 => 'Setting',
318: col2 => 'Value',}],
1.160.6.37 raeburn 319: print => \&print_contacts,
320: modify => \&modify_contacts,
1.30 raeburn 321: },
322: 'usercreation' =>
323: { text => 'User creation',
1.67 raeburn 324: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 325: header => [{col1 => 'Format rule type',
326: col2 => 'Format rules in force'},
1.34 raeburn 327: {col1 => 'User account creation',
328: col2 => 'Usernames which may be created',},
1.30 raeburn 329: {col1 => 'Context',
1.43 raeburn 330: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 331: print => \&print_usercreation,
332: modify => \&modify_usercreation,
1.30 raeburn 333: },
1.160.6.34 raeburn 334: 'selfcreation' =>
335: { text => 'Users self-creating accounts',
336: help => 'Domain_Configuration_Self_Creation',
337: header => [{col1 => 'Self-creation with institutional username',
338: col2 => 'Enabled?'},
339: {col1 => 'Institutional user type (login/SSO self-creation)',
340: col2 => 'Information user can enter'},
341: {col1 => 'Self-creation with e-mail as username',
342: col2 => 'Settings'}],
1.160.6.37 raeburn 343: print => \&print_selfcreation,
344: modify => \&modify_selfcreation,
1.160.6.34 raeburn 345: },
1.69 raeburn 346: 'usermodification' =>
1.33 raeburn 347: { text => 'User modification',
1.67 raeburn 348: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 349: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 350: col2 => 'User information updatable in author context'},
1.33 raeburn 351: {col1 => 'Target user has role',
1.160.6.35 raeburn 352: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 353: print => \&print_usermodification,
354: modify => \&modify_usermodification,
1.33 raeburn 355: },
1.69 raeburn 356: 'scantron' =>
1.95 www 357: { text => 'Bubblesheet format file',
1.67 raeburn 358: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 359: header => [ {col1 => 'Item',
360: col2 => '',
361: }],
1.160.6.37 raeburn 362: print => \&print_scantron,
363: modify => \&modify_scantron,
1.46 raeburn 364: },
1.86 raeburn 365: 'requestcourses' =>
366: {text => 'Request creation of courses',
367: help => 'Domain_Configuration_Request_Courses',
368: header => [{col1 => 'User affiliation',
1.102 raeburn 369: col2 => 'Availability/Processing of requests',},
370: {col1 => 'Setting',
1.160.6.30 raeburn 371: col2 => 'Value'},
372: {col1 => 'Available textbooks',
1.160.6.39 raeburn 373: col2 => ''},
1.160.6.46 raeburn 374: {col1 => 'Available templates',
375: col2 => ''},
1.160.6.39 raeburn 376: {col1 => 'Validation (not official courses)',
377: col2 => 'Value'},],
1.160.6.37 raeburn 378: print => \&print_quotas,
379: modify => \&modify_quotas,
1.86 raeburn 380: },
1.160.6.5 raeburn 381: 'requestauthor' =>
1.160.6.34 raeburn 382: {text => 'Request Authoring Space',
1.160.6.5 raeburn 383: help => 'Domain_Configuration_Request_Author',
384: header => [{col1 => 'User affiliation',
385: col2 => 'Availability/Processing of requests',},
386: {col1 => 'Setting',
387: col2 => 'Value'}],
1.160.6.37 raeburn 388: print => \&print_quotas,
389: modify => \&modify_quotas,
1.160.6.5 raeburn 390: },
1.69 raeburn 391: 'coursecategories' =>
1.120 raeburn 392: { text => 'Cataloging of courses/communities',
1.67 raeburn 393: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 394: header => [{col1 => 'Catalog type/availability',
395: col2 => '',},
396: {col1 => 'Category settings for standard catalog',
1.57 raeburn 397: col2 => '',},
398: {col1 => 'Categories',
399: col2 => '',
400: }],
1.160.6.37 raeburn 401: print => \&print_coursecategories,
402: modify => \&modify_coursecategories,
1.69 raeburn 403: },
404: 'serverstatuses' =>
1.77 raeburn 405: {text => 'Access to server status pages',
1.69 raeburn 406: help => 'Domain_Configuration_Server_Status',
407: header => [{col1 => 'Status Page',
408: col2 => 'Other named users',
409: col3 => 'Specific IPs',
410: }],
1.160.6.37 raeburn 411: print => \&print_serverstatuses,
412: modify => \&modify_serverstatuses,
1.69 raeburn 413: },
1.160.6.39 raeburn 414: 'coursedefaults' =>
1.160.6.16 raeburn 415: {text => 'Course/Community defaults',
416: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 417: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
418: col2 => 'Value',},
419: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 420: col2 => 'Value',},],
1.160.6.37 raeburn 421: print => \&print_coursedefaults,
422: modify => \&modify_coursedefaults,
423: },
1.160.6.39 raeburn 424: 'selfenrollment' =>
1.160.6.37 raeburn 425: {text => 'Self-enrollment in Course/Community',
426: help => 'Domain_Configuration_Selfenrollment',
427: header => [{col1 => 'Configuration Rights',
428: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
429: {col1 => 'Defaults',
430: col2 => 'Value'},
431: {col1 => 'Self-enrollment validation (optional)',
432: col2 => 'Value'},],
433: print => \&print_selfenrollment,
434: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 435: },
1.141 raeburn 436: 'usersessions' =>
1.145 raeburn 437: {text => 'User session hosting/offloading',
1.137 raeburn 438: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 439: header => [{col1 => 'Domain server',
440: col2 => 'Servers to offload sessions to when busy'},
441: {col1 => 'Hosting of users from other domains',
1.137 raeburn 442: col2 => 'Rules'},
443: {col1 => "Hosting domain's own users elsewhere",
444: col2 => 'Rules'}],
1.160.6.37 raeburn 445: print => \&print_usersessions,
446: modify => \&modify_usersessions,
1.137 raeburn 447: },
1.150 raeburn 448: 'loadbalancing' =>
1.160.6.7 raeburn 449: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 450: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 451: header => [{col1 => 'Balancers',
1.150 raeburn 452: col2 => 'Default destinations',
1.160.6.13 raeburn 453: col3 => 'User affiliation',
1.150 raeburn 454: col4 => 'Overrides'},
455: ],
1.160.6.37 raeburn 456: print => \&print_loadbalancing,
457: modify => \&modify_loadbalancing,
1.150 raeburn 458: },
1.3 raeburn 459: );
1.110 raeburn 460: if (keys(%servers) > 1) {
461: $prefs{'login'} = { text => 'Log-in page options',
462: help => 'Domain_Configuration_Login_Page',
463: header => [{col1 => 'Log-in Service',
464: col2 => 'Server Setting',},
465: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 466: col2 => ''},
467: {col1 => 'Log-in Help',
1.160.6.56 raeburn 468: col2 => 'Value'},
469: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 470: col2 => 'Value'}],
1.160.6.37 raeburn 471: print => \&print_login,
472: modify => \&modify_login,
1.110 raeburn 473: };
474: }
1.160.6.13 raeburn 475:
1.6 raeburn 476: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 477: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 478: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 479: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 480: text=>"Settings to display/modify"});
1.9 raeburn 481: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 482:
1.3 raeburn 483: if ($phase eq 'process') {
1.160.6.27 raeburn 484: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
485: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 486: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 487: $r->rflush();
1.160.6.27 raeburn 488: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 489: }
1.30 raeburn 490: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 491: my $js = &recaptcha_js().
1.160.6.40 raeburn 492: &toggle_display_js();
1.160.6.7 raeburn 493: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 494: my ($othertitle,$usertypes,$types) =
495: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 496: $js .= &lonbalance_targets_js($dom,$types,\%servers,
497: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 498: &new_spares_js().
499: &common_domprefs_js().
500: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 501: }
1.160.6.30 raeburn 502: if (grep(/^requestcourses$/,@actions)) {
503: my $javascript_validations;
504: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
505: $js .= <<END;
506: <script type="text/javascript">
507: $javascript_validations
508: </script>
509: $coursebrowserjs
510: END
511: }
1.150 raeburn 512: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 513: } else {
1.160.6.11 raeburn 514: # check if domconfig user exists for the domain.
515: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 516: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 517: &config_check($dom,$confname,$servadm);
518: unless ($configuserok eq 'ok') {
519: &Apache::lonconfigsettings::print_header($r,$phase,$context);
520: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
521: $confname).
522: '<br />'
523: );
524: if ($switchserver) {
525: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
526: '<br />'.
527: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
528: '<br />'.
529: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
530: '<br />'.
531: &mt('To do that now, use the following link: [_1]',$switchserver)
532: );
533: } else {
534: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
535: '<br />'.
536: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
537: );
538: }
539: $r->print(&Apache::loncommon::end_page());
540: return OK;
541: }
1.21 raeburn 542: if (keys(%domconfig) == 0) {
543: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 544: my @ids=&Apache::lonnet::current_machine_ids();
545: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 546: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 547: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 548: my $custom_img_count = 0;
549: foreach my $img (@loginimages) {
550: if ($designhash{$dom.'.login.'.$img} ne '') {
551: $custom_img_count ++;
552: }
553: }
554: foreach my $role (@roles) {
555: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
556: $custom_img_count ++;
557: }
558: }
559: if ($custom_img_count > 0) {
1.94 raeburn 560: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 561: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 562: $r->print(
563: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
564: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
565: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
566: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
567: if ($switch_server) {
1.30 raeburn 568: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 569: }
1.91 raeburn 570: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 571: return OK;
572: }
573: }
574: }
1.91 raeburn 575: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 576: }
577: return OK;
578: }
579:
580: sub process_changes {
1.160.6.24 raeburn 581: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 582: my %domconfig;
583: if (ref($values) eq 'HASH') {
584: %domconfig = %{$values};
585: }
1.3 raeburn 586: my $output;
587: if ($action eq 'login') {
1.160.6.24 raeburn 588: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 589: } elsif ($action eq 'rolecolors') {
1.9 raeburn 590: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 591: $lastactref,%domconfig);
1.3 raeburn 592: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 593: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 594: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 595: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 596: } elsif ($action eq 'autoupdate') {
597: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 598: } elsif ($action eq 'autocreate') {
599: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 600: } elsif ($action eq 'directorysrch') {
601: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 602: } elsif ($action eq 'usercreation') {
1.28 raeburn 603: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 604: } elsif ($action eq 'selfcreation') {
605: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 606: } elsif ($action eq 'usermodification') {
607: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 608: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 609: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 610: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 611: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 612: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 613: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 614: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 615: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 616: } elsif ($action eq 'serverstatuses') {
617: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 618: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 619: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 620: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 621: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.16 raeburn 622: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 623: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 624: } elsif ($action eq 'selfenrollment') {
625: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 626: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 627: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 628: } elsif ($action eq 'loadbalancing') {
629: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 630: }
631: return $output;
632: }
633:
634: sub print_config_box {
1.9 raeburn 635: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 636: my $rowtotal = 0;
1.49 raeburn 637: my $output;
638: if ($action eq 'coursecategories') {
639: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 640: } elsif ($action eq 'defaults') {
641: $output = &defaults_javascript($settings);
1.91 raeburn 642: }
1.160.6.40 raeburn 643: $output .=
1.30 raeburn 644: '<table class="LC_nested_outer">
1.3 raeburn 645: <tr>
1.66 raeburn 646: <th align="left" valign="middle"><span class="LC_nobreak">'.
647: &mt($item->{text}).' '.
648: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
649: '</tr>';
1.30 raeburn 650: $rowtotal ++;
1.110 raeburn 651: my $numheaders = 1;
652: if (ref($item->{'header'}) eq 'ARRAY') {
653: $numheaders = scalar(@{$item->{'header'}});
654: }
655: if ($numheaders > 1) {
1.64 raeburn 656: my $colspan = '';
1.145 raeburn 657: my $rightcolspan = '';
1.160.6.42 raeburn 658: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.56 raeburn 659: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 660: $colspan = ' colspan="2"';
661: }
1.145 raeburn 662: if ($action eq 'usersessions') {
663: $rightcolspan = ' colspan="3"';
664: }
1.30 raeburn 665: $output .= '
1.3 raeburn 666: <tr>
667: <td>
668: <table class="LC_nested">
669: <tr class="LC_info_row">
1.59 bisitz 670: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 671: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 672: </tr>';
1.69 raeburn 673: $rowtotal ++;
1.160.6.37 raeburn 674: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 675: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.40 raeburn 676: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
1.160.6.37 raeburn 677: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 678: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 679: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 680: } elsif ($action eq 'login') {
1.160.6.56 raeburn 681: if ($numheaders == 4) {
1.160.6.5 raeburn 682: $colspan = ' colspan="2"';
683: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
684: } else {
685: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
686: }
1.160.6.37 raeburn 687: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 688: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 689: } elsif ($action eq 'rolecolors') {
1.30 raeburn 690: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 691: }
1.30 raeburn 692: $output .= '
1.6 raeburn 693: </table>
694: </td>
695: </tr>
696: <tr>
697: <td>
698: <table class="LC_nested">
699: <tr class="LC_info_row">
1.160.6.37 raeburn 700: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 701: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 702: </tr>';
703: $rowtotal ++;
1.160.6.37 raeburn 704: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
705: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.42 raeburn 706: ($action eq 'usersessions') || ($action eq 'coursecategories')) {
707: if ($action eq 'coursecategories') {
708: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
709: $colspan = ' colspan="2"';
710: } else {
711: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
712: }
713: $output .= '
1.63 raeburn 714: </table>
715: </td>
716: </tr>
717: <tr>
718: <td>
719: <table class="LC_nested">
720: <tr class="LC_info_row">
721: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 722: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 723: </tr>'."\n";
724: if ($action eq 'coursecategories') {
725: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
726: } else {
727: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
728: }
1.63 raeburn 729: $rowtotal ++;
1.160.6.57 raeburn 730: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
731: ($action eq 'defaults')) {
1.160.6.37 raeburn 732: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 733: } elsif ($action eq 'login') {
1.160.6.56 raeburn 734: if ($numheaders == 4) {
1.160.6.5 raeburn 735: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
736: </table>
737: </td>
738: </tr>
739: <tr>
740: <td>
741: <table class="LC_nested">
742: <tr class="LC_info_row">
743: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 744: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 745: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
746: $rowtotal ++;
747: } else {
748: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
749: }
1.160.6.56 raeburn 750: $output .= '
751: </table>
752: </td>
753: </tr>
754: <tr>
755: <td>
756: <table class="LC_nested">
757: <tr class="LC_info_row">';
758: if ($numheaders == 4) {
759: $output .= '
760: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
761: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
762: </tr>';
763: } else {
764: $output .= '
765: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
766: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
767: </tr>';
768: }
769: $rowtotal ++;
770: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 771: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 772: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
773: $rowtotal ++;
774: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 775: </table>
776: </td>
777: </tr>
778: <tr>
779: <td>
780: <table class="LC_nested">
781: <tr class="LC_info_row">
782: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
783: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 784: &textbookcourses_javascript($settings).
785: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
786: </table>
787: </td>
788: </tr>
789: <tr>
790: <td>
791: <table class="LC_nested">
792: <tr class="LC_info_row">
793: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
794: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
795: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 796: </table>
797: </td>
798: </tr>
799: <tr>
800: <td>
801: <table class="LC_nested">
802: <tr class="LC_info_row">
1.160.6.46 raeburn 803: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
804: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 805: </tr>'.
806: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 807: } elsif ($action eq 'requestauthor') {
808: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 809: $rowtotal ++;
1.122 jms 810: } elsif ($action eq 'rolecolors') {
1.30 raeburn 811: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 812: </table>
813: </td>
814: </tr>
815: <tr>
816: <td>
817: <table class="LC_nested">
818: <tr class="LC_info_row">
1.69 raeburn 819: <td class="LC_left_item"'.$colspan.' valign="top">'.
820: &mt($item->{'header'}->[2]->{'col1'}).'</td>
821: <td class="LC_right_item" valign="top">'.
822: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 823: </tr>'.
1.30 raeburn 824: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 825: </table>
826: </td>
827: </tr>
828: <tr>
829: <td>
830: <table class="LC_nested">
831: <tr class="LC_info_row">
1.59 bisitz 832: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
833: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 834: </tr>'.
1.30 raeburn 835: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
836: $rowtotal += 2;
1.6 raeburn 837: }
1.3 raeburn 838: } else {
1.30 raeburn 839: $output .= '
1.3 raeburn 840: <tr>
841: <td>
842: <table class="LC_nested">
1.30 raeburn 843: <tr class="LC_info_row">';
1.24 raeburn 844: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 845: $output .= '
1.59 bisitz 846: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 847: } elsif ($action eq 'serverstatuses') {
848: $output .= '
849: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
850: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
851:
1.6 raeburn 852: } else {
1.30 raeburn 853: $output .= '
1.69 raeburn 854: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
855: }
1.72 raeburn 856: if (defined($item->{'header'}->[0]->{'col3'})) {
857: $output .= '<td class="LC_left_item" valign="top">'.
858: &mt($item->{'header'}->[0]->{'col2'});
859: if ($action eq 'serverstatuses') {
860: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
861: }
1.69 raeburn 862: } else {
863: $output .= '<td class="LC_right_item" valign="top">'.
864: &mt($item->{'header'}->[0]->{'col2'});
865: }
866: $output .= '</td>';
867: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 868: if (defined($item->{'header'}->[0]->{'col4'})) {
869: $output .= '<td class="LC_left_item" valign="top">'.
870: &mt($item->{'header'}->[0]->{'col3'});
871: } else {
872: $output .= '<td class="LC_right_item" valign="top">'.
873: &mt($item->{'header'}->[0]->{'col3'});
874: }
1.69 raeburn 875: if ($action eq 'serverstatuses') {
876: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
877: }
878: $output .= '</td>';
1.6 raeburn 879: }
1.150 raeburn 880: if ($item->{'header'}->[0]->{'col4'}) {
881: $output .= '<td class="LC_right_item" valign="top">'.
882: &mt($item->{'header'}->[0]->{'col4'});
883: }
1.69 raeburn 884: $output .= '</tr>';
1.48 raeburn 885: $rowtotal ++;
1.160.6.5 raeburn 886: if ($action eq 'quotas') {
1.86 raeburn 887: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.37 raeburn 888: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
1.160.6.40 raeburn 889: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.160.6.37 raeburn 890: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 891: } elsif ($action eq 'scantron') {
892: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 893: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 894: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.160.6.49 raeburn 895: } elsif ($action eq 'coursedefaults') {
896: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.121 raeburn 897: }
1.3 raeburn 898: }
1.30 raeburn 899: $output .= '
1.3 raeburn 900: </table>
901: </td>
902: </tr>
1.30 raeburn 903: </table><br />';
904: return ($output,$rowtotal);
1.1 raeburn 905: }
906:
1.3 raeburn 907: sub print_login {
1.160.6.5 raeburn 908: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 909: my ($css_class,$datatable);
1.6 raeburn 910: my %choices = &login_choices();
1.110 raeburn 911:
1.160.6.5 raeburn 912: if ($caller eq 'service') {
1.149 raeburn 913: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 914: my $choice = $choices{'disallowlogin'};
915: $css_class = ' class="LC_odd_row"';
1.128 raeburn 916: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 917: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 918: '<th>'.$choices{'server'}.'</th>'.
919: '<th>'.$choices{'serverpath'}.'</th>'.
920: '<th>'.$choices{'custompath'}.'</th>'.
921: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 922: my %disallowed;
923: if (ref($settings) eq 'HASH') {
924: if (ref($settings->{'loginvia'}) eq 'HASH') {
925: %disallowed = %{$settings->{'loginvia'}};
926: }
927: }
928: foreach my $lonhost (sort(keys(%servers))) {
929: my $direct = 'selected="selected"';
1.128 raeburn 930: if (ref($disallowed{$lonhost}) eq 'HASH') {
931: if ($disallowed{$lonhost}{'server'} ne '') {
932: $direct = '';
933: }
1.110 raeburn 934: }
1.115 raeburn 935: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 936: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 937: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
938: '</option>';
1.160.6.13 raeburn 939: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 940: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 941: my $selected = '';
1.128 raeburn 942: if (ref($disallowed{$lonhost}) eq 'HASH') {
943: if ($hostid eq $disallowed{$lonhost}{'server'}) {
944: $selected = 'selected="selected"';
945: }
1.110 raeburn 946: }
947: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
948: $servers{$hostid}.'</option>';
949: }
1.128 raeburn 950: $datatable .= '</select></td>'.
951: '<td><select name="'.$lonhost.'_serverpath">';
952: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
953: my $pathname = $path;
954: if ($path eq 'custom') {
955: $pathname = &mt('Custom Path').' ->';
956: }
957: my $selected = '';
958: if (ref($disallowed{$lonhost}) eq 'HASH') {
959: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
960: $selected = 'selected="selected"';
961: }
962: } elsif ($path eq '') {
963: $selected = 'selected="selected"';
964: }
965: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
966: }
967: $datatable .= '</select></td>';
968: my ($custom,$exempt);
969: if (ref($disallowed{$lonhost}) eq 'HASH') {
970: $custom = $disallowed{$lonhost}{'custompath'};
971: $exempt = $disallowed{$lonhost}{'exempt'};
972: }
973: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
974: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
975: '</tr>';
1.110 raeburn 976: }
977: $datatable .= '</table></td></tr>';
978: return $datatable;
1.160.6.5 raeburn 979: } elsif ($caller eq 'page') {
980: my %defaultchecked = (
981: 'coursecatalog' => 'on',
1.160.6.14 raeburn 982: 'helpdesk' => 'on',
1.160.6.5 raeburn 983: 'adminmail' => 'off',
984: 'newuser' => 'off',
985: );
1.160.6.14 raeburn 986: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 987: my (%checkedon,%checkedoff);
1.42 raeburn 988: foreach my $item (@toggles) {
1.160.6.5 raeburn 989: if ($defaultchecked{$item} eq 'on') {
990: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 991: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 992: } elsif ($defaultchecked{$item} eq 'off') {
993: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 994: $checkedon{$item} = ' ';
995: }
1.1 raeburn 996: }
1.160.6.5 raeburn 997: my @images = ('img','logo','domlogo','login');
998: my @logintext = ('textcol','bgcol');
999: my @bgs = ('pgbg','mainbg','sidebg');
1000: my @links = ('link','alink','vlink');
1001: my %designhash = &Apache::loncommon::get_domainconf($dom);
1002: my %defaultdesign = %Apache::loncommon::defaultdesign;
1003: my (%is_custom,%designs);
1004: my %defaults = (
1005: font => $defaultdesign{'login.font'},
1006: );
1.6 raeburn 1007: foreach my $item (@images) {
1.160.6.5 raeburn 1008: $defaults{$item} = $defaultdesign{'login.'.$item};
1009: $defaults{'showlogo'}{$item} = 1;
1010: }
1011: foreach my $item (@bgs) {
1012: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1013: }
1.41 raeburn 1014: foreach my $item (@logintext) {
1.160.6.5 raeburn 1015: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1016: }
1.160.6.5 raeburn 1017: foreach my $item (@links) {
1018: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1019: }
1.160.6.5 raeburn 1020: if (ref($settings) eq 'HASH') {
1021: foreach my $item (@toggles) {
1022: if ($settings->{$item} eq '1') {
1023: $checkedon{$item} = ' checked="checked" ';
1024: $checkedoff{$item} = ' ';
1025: } elsif ($settings->{$item} eq '0') {
1026: $checkedoff{$item} = ' checked="checked" ';
1027: $checkedon{$item} = ' ';
1028: }
1.6 raeburn 1029: }
1.160.6.5 raeburn 1030: foreach my $item (@images) {
1031: if (defined($settings->{$item})) {
1032: $designs{$item} = $settings->{$item};
1033: $is_custom{$item} = 1;
1034: }
1035: if (defined($settings->{'showlogo'}{$item})) {
1036: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1037: }
1038: }
1039: foreach my $item (@logintext) {
1040: if ($settings->{$item} ne '') {
1041: $designs{'logintext'}{$item} = $settings->{$item};
1042: $is_custom{$item} = 1;
1043: }
1044: }
1045: if ($settings->{'font'} ne '') {
1046: $designs{'font'} = $settings->{'font'};
1047: $is_custom{'font'} = 1;
1048: }
1049: foreach my $item (@bgs) {
1050: if ($settings->{$item} ne '') {
1051: $designs{'bgs'}{$item} = $settings->{$item};
1052: $is_custom{$item} = 1;
1053: }
1054: }
1055: foreach my $item (@links) {
1056: if ($settings->{$item} ne '') {
1057: $designs{'links'}{$item} = $settings->{$item};
1058: $is_custom{$item} = 1;
1059: }
1060: }
1061: } else {
1062: if ($designhash{$dom.'.login.font'} ne '') {
1063: $designs{'font'} = $designhash{$dom.'.login.font'};
1064: $is_custom{'font'} = 1;
1065: }
1066: foreach my $item (@images) {
1067: if ($designhash{$dom.'.login.'.$item} ne '') {
1068: $designs{$item} = $designhash{$dom.'.login.'.$item};
1069: $is_custom{$item} = 1;
1070: }
1071: }
1072: foreach my $item (@bgs) {
1073: if ($designhash{$dom.'.login.'.$item} ne '') {
1074: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1075: $is_custom{$item} = 1;
1076: }
1077: }
1078: foreach my $item (@links) {
1079: if ($designhash{$dom.'.login.'.$item} ne '') {
1080: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1081: $is_custom{$item} = 1;
1082: }
1.6 raeburn 1083: }
1084: }
1.160.6.5 raeburn 1085: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1086: logo => 'Institution Logo',
1087: domlogo => 'Domain Logo',
1088: login => 'Login box');
1089: my $itemcount = 1;
1090: foreach my $item (@toggles) {
1091: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1092: $datatable .=
1093: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1094: '</td><td>'.
1095: '<span class="LC_nobreak"><label><input type="radio" name="'.
1096: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1097: '</label> <label><input type="radio" name="'.$item.'"'.
1098: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1099: '</tr>';
1100: $itemcount ++;
1.6 raeburn 1101: }
1.160.6.5 raeburn 1102: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1103: $datatable .= '</tr></table></td></tr>';
1104: } elsif ($caller eq 'help') {
1105: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1106: my $switchserver = &check_switchserver($dom,$confname);
1107: my $itemcount = 1;
1108: $defaulturl = '/adm/loginproblems.html';
1109: $defaulttype = 'default';
1110: %lt = &Apache::lonlocal::texthash (
1111: del => 'Delete?',
1112: rep => 'Replace:',
1113: upl => 'Upload:',
1114: default => 'Default',
1115: custom => 'Custom',
1116: );
1117: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1118: my @currlangs;
1119: if (ref($settings) eq 'HASH') {
1120: if (ref($settings->{'helpurl'}) eq 'HASH') {
1121: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1122: next if ($settings->{'helpurl'}{$key} eq '');
1123: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1124: $type{$key} = 'custom';
1125: unless ($key eq 'nolang') {
1126: push(@currlangs,$key);
1127: }
1128: }
1129: } elsif ($settings->{'helpurl'} ne '') {
1130: $type{'nolang'} = 'custom';
1131: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1132: }
1133: }
1.160.6.5 raeburn 1134: foreach my $lang ('nolang',sort(@currlangs)) {
1135: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1136: $datatable .= '<tr'.$css_class.'>';
1137: if ($url{$lang} eq '') {
1138: $url{$lang} = $defaulturl;
1139: }
1140: if ($type{$lang} eq '') {
1141: $type{$lang} = $defaulttype;
1142: }
1143: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1144: if ($lang eq 'nolang') {
1145: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1146: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1147: } else {
1148: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1149: $langchoices{$lang},
1150: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1151: }
1152: $datatable .= '</span></td>'."\n".
1153: '<td class="LC_left_item">';
1154: if ($type{$lang} eq 'custom') {
1155: $datatable .= '<span class="LC_nobreak"><label>'.
1156: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1157: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1158: } else {
1159: $datatable .= $lt{'upl'};
1160: }
1161: $datatable .='<br />';
1162: if ($switchserver) {
1163: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1164: } else {
1165: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1166: }
1.160.6.5 raeburn 1167: $datatable .= '</td></tr>';
1168: $itemcount ++;
1.6 raeburn 1169: }
1.160.6.5 raeburn 1170: my @addlangs;
1171: foreach my $lang (sort(keys(%langchoices))) {
1172: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1173: push(@addlangs,$lang);
1174: }
1175: if (@addlangs > 0) {
1176: my %toadd;
1177: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1178: $toadd{''} = &mt('Select');
1179: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1180: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1181: &mt('Add log-in help page for a specific language:').' '.
1182: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1183: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1184: if ($switchserver) {
1185: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1186: } else {
1187: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1188: }
1.160.6.5 raeburn 1189: $datatable .= '</td></tr>';
1190: $itemcount ++;
1.6 raeburn 1191: }
1.160.6.5 raeburn 1192: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1193: } elsif ($caller eq 'headtag') {
1194: my %domservers = &Apache::lonnet::get_servers($dom);
1195: my $choice = $choices{'headtag'};
1196: $css_class = ' class="LC_odd_row"';
1197: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1198: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1199: '<th>'.$choices{'current'}.'</th>'.
1200: '<th>'.$choices{'action'}.'</th>'.
1201: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1202: my (%currurls,%currexempt);
1203: if (ref($settings) eq 'HASH') {
1204: if (ref($settings->{'headtag'}) eq 'HASH') {
1205: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1206: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1207: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1208: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1209: }
1210: }
1211: }
1212: }
1213: my %lt = &Apache::lonlocal::texthash(
1214: del => 'Delete?',
1215: rep => 'Replace:',
1216: upl => 'Upload:',
1217: curr => 'View contents',
1218: none => 'None',
1219: );
1220: my $switchserver = &check_switchserver($dom,$confname);
1221: foreach my $lonhost (sort(keys(%domservers))) {
1222: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1223: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1224: if ($currurls{$lonhost}) {
1225: $datatable .= '<td class="LC_right_item"><a href="'.
1226: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1227: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1228: '">'.$lt{'curr'}.'</a></td>'.
1229: '<td><span class="LC_nobreak"><label>'.
1230: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1231: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1232: } else {
1233: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1234: }
1235: $datatable .='<br />';
1236: if ($switchserver) {
1237: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1238: } else {
1239: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1240: }
1241: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1242: }
1243: $datatable .= '</table></td></tr>';
1.1 raeburn 1244: }
1.6 raeburn 1245: return $datatable;
1246: }
1247:
1248: sub login_choices {
1249: my %choices =
1250: &Apache::lonlocal::texthash (
1.116 bisitz 1251: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1252: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1253: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1254: disallowlogin => "Login page requests redirected",
1255: hostid => "Server",
1.128 raeburn 1256: server => "Redirect to:",
1257: serverpath => "Path",
1258: custompath => "Custom",
1259: exempt => "Exempt IP(s)",
1.110 raeburn 1260: directlogin => "No redirect",
1261: newuser => "Link to create a user account",
1262: img => "Header",
1263: logo => "Main Logo",
1264: domlogo => "Domain Logo",
1265: login => "Log-in Header",
1266: textcol => "Text color",
1267: bgcol => "Box color",
1268: bgs => "Background colors",
1269: links => "Link colors",
1270: font => "Font color",
1271: pgbg => "Header",
1272: mainbg => "Page",
1273: sidebg => "Login box",
1274: link => "Link",
1275: alink => "Active link",
1276: vlink => "Visited link",
1.160.6.56 raeburn 1277: headtag => "Custom markup",
1278: action => "Action",
1279: current => "Current",
1.6 raeburn 1280: );
1281: return %choices;
1282: }
1283:
1284: sub print_rolecolors {
1.30 raeburn 1285: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1286: my %choices = &color_font_choices();
1287: my @bgs = ('pgbg','tabbg','sidebg');
1288: my @links = ('link','alink','vlink');
1289: my @images = ('img');
1290: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1291: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1292: my %defaultdesign = %Apache::loncommon::defaultdesign;
1293: my (%is_custom,%designs);
1.160.6.22 raeburn 1294: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1295: if (ref($settings) eq 'HASH') {
1296: if (ref($settings->{$role}) eq 'HASH') {
1297: if ($settings->{$role}->{'img'} ne '') {
1298: $designs{'img'} = $settings->{$role}->{'img'};
1299: $is_custom{'img'} = 1;
1300: }
1301: if ($settings->{$role}->{'font'} ne '') {
1302: $designs{'font'} = $settings->{$role}->{'font'};
1303: $is_custom{'font'} = 1;
1304: }
1.97 tempelho 1305: if ($settings->{$role}->{'fontmenu'} ne '') {
1306: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1307: $is_custom{'fontmenu'} = 1;
1308: }
1.6 raeburn 1309: foreach my $item (@bgs) {
1310: if ($settings->{$role}->{$item} ne '') {
1311: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1312: $is_custom{$item} = 1;
1313: }
1314: }
1315: foreach my $item (@links) {
1316: if ($settings->{$role}->{$item} ne '') {
1317: $designs{'links'}{$item} = $settings->{$role}->{$item};
1318: $is_custom{$item} = 1;
1319: }
1320: }
1321: }
1322: } else {
1323: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1324: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1325: $is_custom{'img'} = 1;
1326: }
1.97 tempelho 1327: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1328: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1329: $is_custom{'fontmenu'} = 1;
1330: }
1.6 raeburn 1331: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1332: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1333: $is_custom{'font'} = 1;
1334: }
1335: foreach my $item (@bgs) {
1336: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1337: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1338: $is_custom{$item} = 1;
1339:
1340: }
1341: }
1342: foreach my $item (@links) {
1343: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1344: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1345: $is_custom{$item} = 1;
1346: }
1347: }
1348: }
1349: my $itemcount = 1;
1.30 raeburn 1350: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1351: $datatable .= '</tr></table></td></tr>';
1352: return $datatable;
1353: }
1354:
1.160.6.22 raeburn 1355: sub role_defaults {
1356: my ($role,$bgs,$links,$images,$logintext) = @_;
1357: my %defaults;
1358: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1359: return %defaults;
1360: }
1361: my %defaultdesign = %Apache::loncommon::defaultdesign;
1362: if ($role eq 'login') {
1363: %defaults = (
1364: font => $defaultdesign{$role.'.font'},
1365: );
1366: if (ref($logintext) eq 'ARRAY') {
1367: foreach my $item (@{$logintext}) {
1368: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1369: }
1370: }
1371: foreach my $item (@{$images}) {
1372: $defaults{'showlogo'}{$item} = 1;
1373: }
1374: } else {
1375: %defaults = (
1376: img => $defaultdesign{$role.'.img'},
1377: font => $defaultdesign{$role.'.font'},
1378: fontmenu => $defaultdesign{$role.'.fontmenu'},
1379: );
1380: }
1381: foreach my $item (@{$bgs}) {
1382: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1383: }
1384: foreach my $item (@{$links}) {
1385: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1386: }
1387: foreach my $item (@{$images}) {
1388: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1389: }
1390: return %defaults;
1391: }
1392:
1.6 raeburn 1393: sub display_color_options {
1.9 raeburn 1394: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1395: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1396: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1397: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1398: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1399: '<td>'.$choices->{'font'}.'</td>';
1400: if (!$is_custom->{'font'}) {
1.30 raeburn 1401: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1402: } else {
1403: $datatable .= '<td> </td>';
1404: }
1.160.6.9 raeburn 1405: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1406:
1.8 raeburn 1407: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1408: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1409: ' value="'.$current_color.'" /> '.
1410: ' </td></tr>';
1.107 raeburn 1411: unless ($role eq 'login') {
1412: $datatable .= '<tr'.$css_class.'>'.
1413: '<td>'.$choices->{'fontmenu'}.'</td>';
1414: if (!$is_custom->{'fontmenu'}) {
1415: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1416: } else {
1417: $datatable .= '<td> </td>';
1418: }
1.160.6.22 raeburn 1419: $current_color = $designs->{'fontmenu'} ?
1420: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1421: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1422: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1423: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1424: ' value="'.$current_color.'" /> '.
1425: ' </td></tr>';
1.97 tempelho 1426: }
1.9 raeburn 1427: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1428: foreach my $img (@{$images}) {
1.18 albertel 1429: $itemcount ++;
1.6 raeburn 1430: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1431: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1432: '<td>'.$choices->{$img};
1.41 raeburn 1433: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1434: if ($role eq 'login') {
1435: if ($img eq 'login') {
1436: $login_hdr_pick =
1.135 bisitz 1437: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1438: $logincolors =
1439: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1440: $designs,$defaults);
1.70 raeburn 1441: } elsif ($img ne 'domlogo') {
1442: $datatable.= &logo_display_options($img,$defaults,$designs);
1443: }
1444: }
1445: $datatable .= '</td>';
1.6 raeburn 1446: if ($designs->{$img} ne '') {
1447: $imgfile = $designs->{$img};
1.18 albertel 1448: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1449: } else {
1450: $imgfile = $defaults->{$img};
1451: }
1452: if ($imgfile) {
1.9 raeburn 1453: my ($showfile,$fullsize);
1454: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1455: my $urldir = $1;
1456: my $filename = $2;
1457: my @info = &Apache::lonnet::stat_file($designs->{$img});
1458: if (@info) {
1459: my $thumbfile = 'tn-'.$filename;
1460: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1461: if (@thumb) {
1462: $showfile = $urldir.'/'.$thumbfile;
1463: } else {
1464: $showfile = $imgfile;
1465: }
1466: } else {
1467: $showfile = '';
1468: }
1469: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1470: $showfile = $imgfile;
1.6 raeburn 1471: my $imgdir = $1;
1472: my $filename = $2;
1.159 raeburn 1473: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1474: $showfile = "/$imgdir/tn-".$filename;
1475: } else {
1.159 raeburn 1476: my $input = $londocroot.$imgfile;
1477: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1478: if (!-e $output) {
1.9 raeburn 1479: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1480: my ($fullwidth,$fullheight) = &check_dimensions($input);
1481: if ($fullwidth ne '' && $fullheight ne '') {
1482: if ($fullwidth > $width && $fullheight > $height) {
1483: my $size = $width.'x'.$height;
1484: system("convert -sample $size $input $output");
1.159 raeburn 1485: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1486: }
1487: }
1.6 raeburn 1488: }
1489: }
1.16 raeburn 1490: }
1.6 raeburn 1491: if ($showfile) {
1.40 raeburn 1492: if ($showfile =~ m{^/(adm|res)/}) {
1493: if ($showfile =~ m{^/res/}) {
1494: my $local_showfile =
1495: &Apache::lonnet::filelocation('',$showfile);
1496: &Apache::lonnet::repcopy($local_showfile);
1497: }
1498: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1499: }
1500: if ($imgfile) {
1501: if ($imgfile =~ m{^/(adm|res)/}) {
1502: if ($imgfile =~ m{^/res/}) {
1503: my $local_imgfile =
1504: &Apache::lonnet::filelocation('',$imgfile);
1505: &Apache::lonnet::repcopy($local_imgfile);
1506: }
1507: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1508: } else {
1509: $fullsize = $imgfile;
1510: }
1511: }
1.41 raeburn 1512: $datatable .= '<td>';
1513: if ($img eq 'login') {
1.135 bisitz 1514: $datatable .= $login_hdr_pick;
1515: }
1.41 raeburn 1516: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1517: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1518: } else {
1.160.6.22 raeburn 1519: $datatable .= '<td> </td><td class="LC_left_item">'.
1520: &mt('Upload:').'<br />';
1.6 raeburn 1521: }
1522: } else {
1.160.6.22 raeburn 1523: $datatable .= '<td> </td><td class="LC_left_item">'.
1524: &mt('Upload:').'<br />';
1.6 raeburn 1525: }
1.9 raeburn 1526: if ($switchserver) {
1527: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1528: } else {
1.135 bisitz 1529: if ($img ne 'login') { # suppress file selection for Log-in header
1530: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1531: }
1.9 raeburn 1532: }
1533: $datatable .= '</td></tr>';
1.6 raeburn 1534: }
1535: $itemcount ++;
1536: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1537: $datatable .= '<tr'.$css_class.'>'.
1538: '<td>'.$choices->{'bgs'}.'</td>';
1539: my $bgs_def;
1540: foreach my $item (@{$bgs}) {
1541: if (!$is_custom->{$item}) {
1.70 raeburn 1542: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1543: }
1544: }
1545: if ($bgs_def) {
1.8 raeburn 1546: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1547: } else {
1548: $datatable .= '<td> </td>';
1549: }
1550: $datatable .= '<td class="LC_right_item">'.
1551: '<table border="0"><tr>';
1.160.6.13 raeburn 1552:
1.6 raeburn 1553: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1554: $datatable .= '<td align="center">'.$choices->{$item};
1555: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1556: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1557: $datatable .= ' ';
1.6 raeburn 1558: }
1.160.6.9 raeburn 1559: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1560: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1561: }
1562: $datatable .= '</tr></table></td></tr>';
1563: $itemcount ++;
1564: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1565: $datatable .= '<tr'.$css_class.'>'.
1566: '<td>'.$choices->{'links'}.'</td>';
1567: my $links_def;
1568: foreach my $item (@{$links}) {
1569: if (!$is_custom->{$item}) {
1.30 raeburn 1570: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1571: }
1572: }
1573: if ($links_def) {
1.8 raeburn 1574: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1575: } else {
1576: $datatable .= '<td> </td>';
1577: }
1578: $datatable .= '<td class="LC_right_item">'.
1579: '<table border="0"><tr>';
1580: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1581: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1582: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1583: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1584: $datatable.=' ';
1.6 raeburn 1585: }
1.160.6.9 raeburn 1586: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1587: '" /></td>';
1588: }
1.30 raeburn 1589: $$rowtotal += $itemcount;
1.3 raeburn 1590: return $datatable;
1591: }
1592:
1.70 raeburn 1593: sub logo_display_options {
1594: my ($img,$defaults,$designs) = @_;
1595: my $checkedon;
1596: if (ref($defaults) eq 'HASH') {
1597: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1598: if ($defaults->{'showlogo'}{$img}) {
1599: $checkedon = 'checked="checked" ';
1600: }
1601: }
1602: }
1603: if (ref($designs) eq 'HASH') {
1604: if (ref($designs->{'showlogo'}) eq 'HASH') {
1605: if (defined($designs->{'showlogo'}{$img})) {
1606: if ($designs->{'showlogo'}{$img} == 0) {
1607: $checkedon = '';
1608: } elsif ($designs->{'showlogo'}{$img} == 1) {
1609: $checkedon = 'checked="checked" ';
1610: }
1611: }
1612: }
1613: }
1614: return '<br /><label> <input type="checkbox" name="'.
1615: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1616: &mt('show').'</label>'."\n";
1617: }
1618:
1.41 raeburn 1619: sub login_header_options {
1.135 bisitz 1620: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1621: my $output = '';
1.41 raeburn 1622: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1623: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1624: if (!$is_custom->{'textcol'}) {
1625: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1626: ' ';
1627: }
1628: if (!$is_custom->{'bgcol'}) {
1629: $output .= $choices->{'bgcol'}.': '.
1630: '<span id="css_'.$role.'_font" style="background-color: '.
1631: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1632: }
1633: $output .= '<br />';
1634: }
1635: $output .='<br />';
1636: return $output;
1637: }
1638:
1639: sub login_text_colors {
1.160.6.22 raeburn 1640: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1641: my $color_menu = '<table border="0"><tr>';
1642: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1643: $color_menu .= '<td align="center">'.$choices->{$item};
1644: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1645: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1646: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1647: }
1648: $color_menu .= '</tr></table><br />';
1649: return $color_menu;
1650: }
1651:
1652: sub image_changes {
1653: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1654: my $output;
1.135 bisitz 1655: if ($img eq 'login') {
1656: # suppress image for Log-in header
1657: } elsif (!$is_custom) {
1.70 raeburn 1658: if ($img ne 'domlogo') {
1.41 raeburn 1659: $output .= &mt('Default image:').'<br />';
1660: } else {
1661: $output .= &mt('Default in use:').'<br />';
1662: }
1663: }
1.135 bisitz 1664: if ($img eq 'login') { # suppress image for Log-in header
1665: $output .= '<td>'.$logincolors;
1.41 raeburn 1666: } else {
1.135 bisitz 1667: if ($img_import) {
1668: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1669: }
1670: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1671: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1672: if ($is_custom) {
1673: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1674: '<input type="checkbox" name="'.
1675: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1676: '</label> '.&mt('Replace:').'</span><br />';
1677: } else {
1.160.6.22 raeburn 1678: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1679: }
1.41 raeburn 1680: }
1681: return $output;
1682: }
1683:
1.3 raeburn 1684: sub print_quotas {
1.86 raeburn 1685: my ($dom,$settings,$rowtotal,$action) = @_;
1686: my $context;
1687: if ($action eq 'quotas') {
1688: $context = 'tools';
1689: } else {
1690: $context = $action;
1691: }
1.160.6.20 raeburn 1692: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1693: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1694: my $typecount = 0;
1.101 raeburn 1695: my ($css_class,%titles);
1.86 raeburn 1696: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1697: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1698: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1699: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1700: %titles = &courserequest_titles();
1.160.6.5 raeburn 1701: } elsif ($context eq 'requestauthor') {
1702: @usertools = ('author');
1703: @options = ('norequest','approval','automatic');
1704: %titles = &authorrequest_titles();
1.86 raeburn 1705: } else {
1.160.6.4 raeburn 1706: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1707: %titles = &tool_titles();
1.86 raeburn 1708: }
1.26 raeburn 1709: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1710: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1711: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1712: unless (($context eq 'requestcourses') ||
1713: ($context eq 'requestauthor')) {
1.86 raeburn 1714: if (ref($settings) eq 'HASH') {
1715: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1716: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1717: } else {
1718: $currdefquota = $settings->{$type};
1719: }
1.160.6.20 raeburn 1720: if (ref($settings->{authorquota}) eq 'HASH') {
1721: $currauthorquota = $settings->{authorquota}->{$type};
1722: }
1.78 raeburn 1723: }
1.72 raeburn 1724: }
1.3 raeburn 1725: if (defined($usertypes->{$type})) {
1726: $typecount ++;
1727: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1728: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1729: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1730: '<td class="LC_left_item">';
1.101 raeburn 1731: if ($context eq 'requestcourses') {
1732: $datatable .= '<table><tr>';
1733: }
1734: my %cell;
1.72 raeburn 1735: foreach my $item (@usertools) {
1.101 raeburn 1736: if ($context eq 'requestcourses') {
1737: my ($curroption,$currlimit);
1738: if (ref($settings) eq 'HASH') {
1739: if (ref($settings->{$item}) eq 'HASH') {
1740: $curroption = $settings->{$item}->{$type};
1741: if ($curroption =~ /^autolimit=(\d*)$/) {
1742: $currlimit = $1;
1743: }
1744: }
1745: }
1746: if (!$curroption) {
1747: $curroption = 'norequest';
1748: }
1749: $datatable .= '<th>'.$titles{$item}.'</th>';
1750: foreach my $option (@options) {
1751: my $val = $option;
1752: if ($option eq 'norequest') {
1753: $val = 0;
1754: }
1755: if ($option eq 'validate') {
1756: my $canvalidate = 0;
1757: if (ref($validations{$item}) eq 'HASH') {
1758: if ($validations{$item}{$type}) {
1759: $canvalidate = 1;
1760: }
1761: }
1762: next if (!$canvalidate);
1763: }
1764: my $checked = '';
1765: if ($option eq $curroption) {
1766: $checked = ' checked="checked"';
1767: } elsif ($option eq 'autolimit') {
1768: if ($curroption =~ /^autolimit/) {
1769: $checked = ' checked="checked"';
1770: }
1771: }
1772: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1773: '<input type="radio" name="crsreq_'.$item.
1774: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1775: $titles{$option}.'</label>';
1.101 raeburn 1776: if ($option eq 'autolimit') {
1.127 raeburn 1777: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1778: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1779: 'value="'.$currlimit.'" />';
1.101 raeburn 1780: }
1.127 raeburn 1781: $cell{$item} .= '</span> ';
1.103 raeburn 1782: if ($option eq 'autolimit') {
1.127 raeburn 1783: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1784: }
1.101 raeburn 1785: }
1.160.6.5 raeburn 1786: } elsif ($context eq 'requestauthor') {
1787: my $curroption;
1788: if (ref($settings) eq 'HASH') {
1789: $curroption = $settings->{$type};
1790: }
1791: if (!$curroption) {
1792: $curroption = 'norequest';
1793: }
1794: foreach my $option (@options) {
1795: my $val = $option;
1796: if ($option eq 'norequest') {
1797: $val = 0;
1798: }
1799: my $checked = '';
1800: if ($option eq $curroption) {
1801: $checked = ' checked="checked"';
1802: }
1803: $datatable .= '<span class="LC_nobreak"><label>'.
1804: '<input type="radio" name="authorreq_'.$type.
1805: '" value="'.$val.'"'.$checked.' />'.
1806: $titles{$option}.'</label></span> ';
1807: }
1.101 raeburn 1808: } else {
1809: my $checked = 'checked="checked" ';
1810: if (ref($settings) eq 'HASH') {
1811: if (ref($settings->{$item}) eq 'HASH') {
1812: if ($settings->{$item}->{$type} == 0) {
1813: $checked = '';
1814: } elsif ($settings->{$item}->{$type} == 1) {
1815: $checked = 'checked="checked" ';
1816: }
1.78 raeburn 1817: }
1.72 raeburn 1818: }
1.101 raeburn 1819: $datatable .= '<span class="LC_nobreak"><label>'.
1820: '<input type="checkbox" name="'.$context.'_'.$item.
1821: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1822: '</label></span> ';
1.72 raeburn 1823: }
1.101 raeburn 1824: }
1825: if ($context eq 'requestcourses') {
1826: $datatable .= '</tr><tr>';
1827: foreach my $item (@usertools) {
1.106 raeburn 1828: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1829: }
1830: $datatable .= '</tr></table>';
1.72 raeburn 1831: }
1.86 raeburn 1832: $datatable .= '</td>';
1.160.6.5 raeburn 1833: unless (($context eq 'requestcourses') ||
1834: ($context eq 'requestauthor')) {
1.86 raeburn 1835: $datatable .=
1.160.6.20 raeburn 1836: '<td class="LC_right_item">'.
1837: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1838: '<input type="text" name="quota_'.$type.
1.72 raeburn 1839: '" value="'.$currdefquota.
1.160.6.20 raeburn 1840: '" size="5" /></span>'.(' ' x 2).
1841: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1842: '<input type="text" name="authorquota_'.$type.
1843: '" value="'.$currauthorquota.
1844: '" size="5" /></span></td>';
1.86 raeburn 1845: }
1846: $datatable .= '</tr>';
1.3 raeburn 1847: }
1848: }
1849: }
1.160.6.5 raeburn 1850: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1851: $defaultquota = '20';
1.160.6.20 raeburn 1852: $authorquota = '500';
1.86 raeburn 1853: if (ref($settings) eq 'HASH') {
1854: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1855: $defaultquota = $settings->{'defaultquota'}->{'default'};
1856: } elsif (defined($settings->{'default'})) {
1857: $defaultquota = $settings->{'default'};
1858: }
1.160.6.20 raeburn 1859: if (ref($settings->{'authorquota'}) eq 'HASH') {
1860: $authorquota = $settings->{'authorquota'}->{'default'};
1861: }
1.3 raeburn 1862: }
1863: }
1864: $typecount ++;
1865: $css_class = $typecount%2?' class="LC_odd_row"':'';
1866: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1867: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1868: '<td class="LC_left_item">';
1.101 raeburn 1869: if ($context eq 'requestcourses') {
1870: $datatable .= '<table><tr>';
1871: }
1872: my %defcell;
1.72 raeburn 1873: foreach my $item (@usertools) {
1.101 raeburn 1874: if ($context eq 'requestcourses') {
1875: my ($curroption,$currlimit);
1876: if (ref($settings) eq 'HASH') {
1877: if (ref($settings->{$item}) eq 'HASH') {
1878: $curroption = $settings->{$item}->{'default'};
1879: if ($curroption =~ /^autolimit=(\d*)$/) {
1880: $currlimit = $1;
1881: }
1882: }
1883: }
1884: if (!$curroption) {
1885: $curroption = 'norequest';
1886: }
1887: $datatable .= '<th>'.$titles{$item}.'</th>';
1888: foreach my $option (@options) {
1889: my $val = $option;
1890: if ($option eq 'norequest') {
1891: $val = 0;
1892: }
1893: if ($option eq 'validate') {
1894: my $canvalidate = 0;
1895: if (ref($validations{$item}) eq 'HASH') {
1896: if ($validations{$item}{'default'}) {
1897: $canvalidate = 1;
1898: }
1899: }
1900: next if (!$canvalidate);
1901: }
1902: my $checked = '';
1903: if ($option eq $curroption) {
1904: $checked = ' checked="checked"';
1905: } elsif ($option eq 'autolimit') {
1906: if ($curroption =~ /^autolimit/) {
1907: $checked = ' checked="checked"';
1908: }
1909: }
1910: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1911: '<input type="radio" name="crsreq_'.$item.
1912: '_default" value="'.$val.'"'.$checked.' />'.
1913: $titles{$option}.'</label>';
1914: if ($option eq 'autolimit') {
1.127 raeburn 1915: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1916: $item.'_limit_default" size="1" '.
1917: 'value="'.$currlimit.'" />';
1918: }
1.127 raeburn 1919: $defcell{$item} .= '</span> ';
1.104 raeburn 1920: if ($option eq 'autolimit') {
1.127 raeburn 1921: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1922: }
1.101 raeburn 1923: }
1.160.6.5 raeburn 1924: } elsif ($context eq 'requestauthor') {
1925: my $curroption;
1926: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1927: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1928: }
1929: if (!$curroption) {
1930: $curroption = 'norequest';
1931: }
1932: foreach my $option (@options) {
1933: my $val = $option;
1934: if ($option eq 'norequest') {
1935: $val = 0;
1936: }
1937: my $checked = '';
1938: if ($option eq $curroption) {
1939: $checked = ' checked="checked"';
1940: }
1941: $datatable .= '<span class="LC_nobreak"><label>'.
1942: '<input type="radio" name="authorreq_default"'.
1943: ' value="'.$val.'"'.$checked.' />'.
1944: $titles{$option}.'</label></span> ';
1945: }
1.101 raeburn 1946: } else {
1947: my $checked = 'checked="checked" ';
1948: if (ref($settings) eq 'HASH') {
1949: if (ref($settings->{$item}) eq 'HASH') {
1950: if ($settings->{$item}->{'default'} == 0) {
1951: $checked = '';
1952: } elsif ($settings->{$item}->{'default'} == 1) {
1953: $checked = 'checked="checked" ';
1954: }
1.78 raeburn 1955: }
1.72 raeburn 1956: }
1.101 raeburn 1957: $datatable .= '<span class="LC_nobreak"><label>'.
1958: '<input type="checkbox" name="'.$context.'_'.$item.
1959: '" value="default" '.$checked.'/>'.$titles{$item}.
1960: '</label></span> ';
1961: }
1962: }
1963: if ($context eq 'requestcourses') {
1964: $datatable .= '</tr><tr>';
1965: foreach my $item (@usertools) {
1.106 raeburn 1966: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1967: }
1.101 raeburn 1968: $datatable .= '</tr></table>';
1.72 raeburn 1969: }
1.86 raeburn 1970: $datatable .= '</td>';
1.160.6.5 raeburn 1971: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 1972: $datatable .= '<td class="LC_right_item">'.
1973: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1974: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 1975: $defaultquota.'" size="5" /></span>'.(' ' x2).
1976: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1977: '<input type="text" name="authorquota" value="'.
1978: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1979: }
1980: $datatable .= '</tr>';
1.72 raeburn 1981: $typecount ++;
1982: $css_class = $typecount%2?' class="LC_odd_row"':'';
1983: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 1984: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1985: if ($context eq 'requestcourses') {
1.109 raeburn 1986: $datatable .= &mt('(overrides affiliation, if set)').
1987: '</td>'.
1988: '<td class="LC_left_item">'.
1989: '<table><tr>';
1.101 raeburn 1990: } else {
1.109 raeburn 1991: $datatable .= &mt('(overrides affiliation, if checked)').
1992: '</td>'.
1993: '<td class="LC_left_item" colspan="2">'.
1994: '<br />';
1.101 raeburn 1995: }
1996: my %advcell;
1.72 raeburn 1997: foreach my $item (@usertools) {
1.101 raeburn 1998: if ($context eq 'requestcourses') {
1999: my ($curroption,$currlimit);
2000: if (ref($settings) eq 'HASH') {
2001: if (ref($settings->{$item}) eq 'HASH') {
2002: $curroption = $settings->{$item}->{'_LC_adv'};
2003: if ($curroption =~ /^autolimit=(\d*)$/) {
2004: $currlimit = $1;
2005: }
2006: }
2007: }
2008: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2009: my $checked = '';
2010: if ($curroption eq '') {
2011: $checked = ' checked="checked"';
2012: }
2013: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2014: '<input type="radio" name="crsreq_'.$item.
2015: '__LC_adv" value=""'.$checked.' />'.
2016: &mt('No override set').'</label></span> ';
1.101 raeburn 2017: foreach my $option (@options) {
2018: my $val = $option;
2019: if ($option eq 'norequest') {
2020: $val = 0;
2021: }
2022: if ($option eq 'validate') {
2023: my $canvalidate = 0;
2024: if (ref($validations{$item}) eq 'HASH') {
2025: if ($validations{$item}{'_LC_adv'}) {
2026: $canvalidate = 1;
2027: }
2028: }
2029: next if (!$canvalidate);
2030: }
2031: my $checked = '';
1.104 raeburn 2032: if ($val eq $curroption) {
1.101 raeburn 2033: $checked = ' checked="checked"';
2034: } elsif ($option eq 'autolimit') {
2035: if ($curroption =~ /^autolimit/) {
2036: $checked = ' checked="checked"';
2037: }
2038: }
2039: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2040: '<input type="radio" name="crsreq_'.$item.
2041: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2042: $titles{$option}.'</label>';
2043: if ($option eq 'autolimit') {
1.127 raeburn 2044: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2045: $item.'_limit__LC_adv" size="1" '.
2046: 'value="'.$currlimit.'" />';
2047: }
1.127 raeburn 2048: $advcell{$item} .= '</span> ';
1.104 raeburn 2049: if ($option eq 'autolimit') {
1.127 raeburn 2050: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2051: }
1.101 raeburn 2052: }
1.160.6.5 raeburn 2053: } elsif ($context eq 'requestauthor') {
2054: my $curroption;
2055: if (ref($settings) eq 'HASH') {
2056: $curroption = $settings->{'_LC_adv'};
2057: }
2058: my $checked = '';
2059: if ($curroption eq '') {
2060: $checked = ' checked="checked"';
2061: }
2062: $datatable .= '<span class="LC_nobreak"><label>'.
2063: '<input type="radio" name="authorreq__LC_adv"'.
2064: ' value=""'.$checked.' />'.
2065: &mt('No override set').'</label></span> ';
2066: foreach my $option (@options) {
2067: my $val = $option;
2068: if ($option eq 'norequest') {
2069: $val = 0;
2070: }
2071: my $checked = '';
2072: if ($val eq $curroption) {
2073: $checked = ' checked="checked"';
2074: }
2075: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2076: '<input type="radio" name="authorreq__LC_adv"'.
2077: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2078: $titles{$option}.'</label></span> ';
2079: }
1.101 raeburn 2080: } else {
2081: my $checked = 'checked="checked" ';
2082: if (ref($settings) eq 'HASH') {
2083: if (ref($settings->{$item}) eq 'HASH') {
2084: if ($settings->{$item}->{'_LC_adv'} == 0) {
2085: $checked = '';
2086: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2087: $checked = 'checked="checked" ';
2088: }
1.79 raeburn 2089: }
1.72 raeburn 2090: }
1.101 raeburn 2091: $datatable .= '<span class="LC_nobreak"><label>'.
2092: '<input type="checkbox" name="'.$context.'_'.$item.
2093: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2094: '</label></span> ';
2095: }
2096: }
2097: if ($context eq 'requestcourses') {
2098: $datatable .= '</tr><tr>';
2099: foreach my $item (@usertools) {
1.106 raeburn 2100: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2101: }
1.101 raeburn 2102: $datatable .= '</tr></table>';
1.72 raeburn 2103: }
1.98 raeburn 2104: $datatable .= '</td></tr>';
1.30 raeburn 2105: $$rowtotal += $typecount;
1.3 raeburn 2106: return $datatable;
2107: }
2108:
1.160.6.5 raeburn 2109: sub print_requestmail {
2110: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2111: my ($now,$datatable,%currapp);
1.102 raeburn 2112: $now = time;
2113: if (ref($settings) eq 'HASH') {
2114: if (ref($settings->{'notify'}) eq 'HASH') {
2115: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2116: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2117: }
2118: }
2119: }
1.160.6.16 raeburn 2120: my $numinrow = 2;
1.160.6.34 raeburn 2121: my $css_class;
2122: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2123: my $text;
2124: if ($action eq 'requestcourses') {
2125: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2126: } elsif ($action eq 'requestauthor') {
2127: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2128: } else {
1.160.6.34 raeburn 2129: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2130: }
1.160.6.34 raeburn 2131: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2132: ' <td>'.$text.'</td>'.
1.102 raeburn 2133: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2134: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2135: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2136: if ($numdc > 0) {
2137: $datatable .= $table;
1.102 raeburn 2138: } else {
2139: $datatable .= &mt('There are no active Domain Coordinators');
2140: }
2141: $datatable .='</td></tr>';
2142: return $datatable;
2143: }
2144:
1.160.6.30 raeburn 2145: sub print_studentcode {
2146: my ($settings,$rowtotal) = @_;
2147: my $rownum = 0;
2148: my ($output,%current);
2149: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2150: if (ref($settings) eq 'HASH') {
2151: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2152: foreach my $type (@crstypes) {
2153: $current{$type} = $settings->{'uniquecode'}{$type};
2154: }
1.160.6.30 raeburn 2155: }
2156: }
2157: $output .= '<tr>'.
2158: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2159: '<td class="LC_left_item">';
2160: foreach my $type (@crstypes) {
2161: my $check = ' ';
2162: if ($current{$type}) {
2163: $check = ' checked="checked" ';
2164: }
2165: $output .= '<span class="LC_nobreak"><label>'.
2166: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2167: &mt($type).'</label></span>'.(' 'x2).' ';
2168: }
2169: $output .= '</td></tr>';
2170: $$rowtotal ++;
2171: return $output;
2172: }
2173:
2174: sub print_textbookcourses {
1.160.6.46 raeburn 2175: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2176: my $rownum = 0;
2177: my $css_class;
2178: my $itemcount = 1;
2179: my $maxnum = 0;
2180: my $bookshash;
2181: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2182: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2183: }
2184: my %ordered;
2185: if (ref($bookshash) eq 'HASH') {
2186: foreach my $item (keys(%{$bookshash})) {
2187: if (ref($bookshash->{$item}) eq 'HASH') {
2188: my $num = $bookshash->{$item}{'order'};
2189: $ordered{$num} = $item;
2190: }
2191: }
2192: }
2193: my $confname = $dom.'-domainconfig';
2194: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2195: my $maxnum = scalar(keys(%ordered));
2196: my $datatable;
1.160.6.30 raeburn 2197: if (keys(%ordered)) {
2198: my @items = sort { $a <=> $b } keys(%ordered);
2199: for (my $i=0; $i<@items; $i++) {
2200: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2201: my $key = $ordered{$items[$i]};
2202: my %coursehash=&Apache::lonnet::coursedescription($key);
2203: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2204: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2205: if (ref($bookshash->{$key}) eq 'HASH') {
2206: $subject = $bookshash->{$key}->{'subject'};
2207: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2208: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2209: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2210: $author = $bookshash->{$key}->{'author'};
2211: $image = $bookshash->{$key}->{'image'};
2212: if ($image ne '') {
2213: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2214: my $imagethumb = "$path/tn-".$imagefile;
2215: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2216: }
1.160.6.30 raeburn 2217: }
2218: }
1.160.6.46 raeburn 2219: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2220: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2221: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2222: for (my $k=0; $k<=$maxnum; $k++) {
2223: my $vpos = $k+1;
2224: my $selstr;
2225: if ($k == $i) {
2226: $selstr = ' selected="selected" ';
2227: }
2228: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2229: }
2230: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2231: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2232: &mt('Delete?').'</label></span></td>'.
2233: '<td colspan="2">'.
1.160.6.46 raeburn 2234: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2235: (' 'x2).
1.160.6.46 raeburn 2236: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2237: if ($type eq 'textbooks') {
2238: $datatable .= (' 'x2).
1.160.6.47 raeburn 2239: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2240: (' 'x2).
1.160.6.46 raeburn 2241: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2242: (' 'x2).
2243: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2244: if ($image) {
2245: $datatable .= '<span class="LC_nobreak">'.
2246: $imgsrc.
2247: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2248: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2249: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2250: }
2251: if ($switchserver) {
2252: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2253: } else {
2254: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2255: }
1.160.6.30 raeburn 2256: }
1.160.6.46 raeburn 2257: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2258: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2259: $coursetitle.'</span></td></tr>'."\n";
2260: $itemcount ++;
2261: }
2262: }
2263: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2264: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2265: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2266: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2267: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2268: for (my $k=0; $k<$maxnum+1; $k++) {
2269: my $vpos = $k+1;
2270: my $selstr;
2271: if ($k == $maxnum) {
2272: $selstr = ' selected="selected" ';
2273: }
2274: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2275: }
2276: $datatable .= '</select> '."\n".
1.160.6.46 raeburn 2277: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.160.6.30 raeburn 2278: '<td colspan="2">'.
1.160.6.46 raeburn 2279: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2280: (' 'x2).
1.160.6.46 raeburn 2281: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2282: (' 'x2);
2283: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2284: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2285: (' 'x2).
2286: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2287: (' 'x2).
2288: '<span class="LC_nobreak">'.&mt('Image:').' ';
2289: if ($switchserver) {
2290: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2291: } else {
2292: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2293: }
1.160.6.30 raeburn 2294: }
2295: $datatable .= '</span>'."\n".
2296: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2297: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2298: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2299: &Apache::loncommon::selectcourse_link
1.160.6.46 raeburn 2300: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.160.6.30 raeburn 2301: '</span></td>'."\n".
2302: '</tr>'."\n";
2303: $itemcount ++;
2304: return $datatable;
2305: }
2306:
2307: sub textbookcourses_javascript {
1.160.6.46 raeburn 2308: my ($settings) = @_;
2309: return unless(ref($settings) eq 'HASH');
2310: my (%ordered,%total,%jstext);
2311: foreach my $type ('textbooks','templates') {
2312: $total{$type} = 0;
2313: if (ref($settings->{$type}) eq 'HASH') {
2314: foreach my $item (keys(%{$settings->{$type}})) {
2315: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2316: my $num = $settings->{$type}->{$item}{'order'};
2317: $ordered{$type}{$num} = $item;
2318: }
2319: }
2320: $total{$type} = scalar(keys(%{$settings->{$type}}));
2321: }
2322: my @jsarray = ();
2323: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2324: push(@jsarray,$ordered{$type}{$item});
2325: }
2326: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2327: }
2328: return <<"ENDSCRIPT";
2329: <script type="text/javascript">
2330: // <![CDATA[
1.160.6.46 raeburn 2331: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2332: var changedVal;
1.160.6.46 raeburn 2333: $jstext{'textbooks'};
2334: $jstext{'templates'};
2335: var newpos;
2336: var maxh;
2337: if (caller == 'textbooks') {
2338: newpos = 'textbooks_addbook_pos';
2339: maxh = 1 + $total{'textbooks'};
2340: } else {
2341: newpos = 'templates_addbook_pos';
2342: maxh = 1 + $total{'templates'};
2343: }
1.160.6.30 raeburn 2344: var current = new Array;
2345: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2346: if (item == newpos) {
2347: changedVal = newitemVal;
2348: } else {
2349: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2350: current[newitemVal] = newpos;
2351: }
1.160.6.46 raeburn 2352: if (caller == 'textbooks') {
2353: for (var i=0; i<textbooks.length; i++) {
2354: var elementName = 'textbooks_'+textbooks[i];
2355: if (elementName != item) {
2356: if (form.elements[elementName]) {
2357: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2358: current[currVal] = elementName;
2359: }
2360: }
2361: }
2362: }
2363: if (caller == 'templates') {
2364: for (var i=0; i<templates.length; i++) {
2365: var elementName = 'templates_'+templates[i];
2366: if (elementName != item) {
2367: if (form.elements[elementName]) {
2368: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2369: current[currVal] = elementName;
2370: }
1.160.6.30 raeburn 2371: }
2372: }
2373: }
2374: var oldVal;
2375: for (var j=0; j<maxh; j++) {
2376: if (current[j] == undefined) {
2377: oldVal = j;
2378: }
2379: }
2380: if (oldVal < changedVal) {
2381: for (var k=oldVal+1; k<=changedVal ; k++) {
2382: var elementName = current[k];
2383: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2384: }
2385: } else {
2386: for (var k=changedVal; k<oldVal; k++) {
2387: var elementName = current[k];
2388: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2389: }
2390: }
2391: return;
2392: }
2393:
2394: // ]]>
2395: </script>
2396:
2397: ENDSCRIPT
2398: }
2399:
1.3 raeburn 2400: sub print_autoenroll {
1.30 raeburn 2401: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2402: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2403: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2404: if (ref($settings) eq 'HASH') {
2405: if (exists($settings->{'run'})) {
2406: if ($settings->{'run'} eq '0') {
2407: $runoff = ' checked="checked" ';
2408: $runon = ' ';
2409: } else {
2410: $runon = ' checked="checked" ';
2411: $runoff = ' ';
2412: }
2413: } else {
2414: if ($autorun) {
2415: $runon = ' checked="checked" ';
2416: $runoff = ' ';
2417: } else {
2418: $runoff = ' checked="checked" ';
2419: $runon = ' ';
2420: }
2421: }
1.129 raeburn 2422: if (exists($settings->{'co-owners'})) {
2423: if ($settings->{'co-owners'} eq '0') {
2424: $coownersoff = ' checked="checked" ';
2425: $coownerson = ' ';
2426: } else {
2427: $coownerson = ' checked="checked" ';
2428: $coownersoff = ' ';
2429: }
2430: } else {
2431: $coownersoff = ' checked="checked" ';
2432: $coownerson = ' ';
2433: }
1.3 raeburn 2434: if (exists($settings->{'sender_domain'})) {
2435: $defdom = $settings->{'sender_domain'};
2436: }
1.14 raeburn 2437: } else {
2438: if ($autorun) {
2439: $runon = ' checked="checked" ';
2440: $runoff = ' ';
2441: } else {
2442: $runoff = ' checked="checked" ';
2443: $runon = ' ';
2444: }
1.3 raeburn 2445: }
2446: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2447: my $notif_sender;
2448: if (ref($settings) eq 'HASH') {
2449: $notif_sender = $settings->{'sender_uname'};
2450: }
1.3 raeburn 2451: my $datatable='<tr class="LC_odd_row">'.
2452: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2453: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2454: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2455: $runon.' value="1" />'.&mt('Yes').'</label> '.
2456: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2457: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2458: '</tr><tr>'.
2459: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2460: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2461: &mt('username').': '.
2462: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2463: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2464: ': '.$domform.'</span></td></tr>'.
2465: '<tr class="LC_odd_row">'.
2466: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2467: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2468: '<input type="radio" name="autoassign_coowners"'.
2469: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2470: '<label><input type="radio" name="autoassign_coowners"'.
2471: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2472: '</tr>';
2473: $$rowtotal += 3;
1.3 raeburn 2474: return $datatable;
2475: }
2476:
2477: sub print_autoupdate {
1.30 raeburn 2478: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2479: my $datatable;
2480: if ($position eq 'top') {
2481: my $updateon = ' ';
2482: my $updateoff = ' checked="checked" ';
2483: my $classlistson = ' ';
2484: my $classlistsoff = ' checked="checked" ';
2485: if (ref($settings) eq 'HASH') {
2486: if ($settings->{'run'} eq '1') {
2487: $updateon = $updateoff;
2488: $updateoff = ' ';
2489: }
2490: if ($settings->{'classlists'} eq '1') {
2491: $classlistson = $classlistsoff;
2492: $classlistsoff = ' ';
2493: }
2494: }
2495: my %title = (
2496: run => 'Auto-update active?',
2497: classlists => 'Update information in classlists?',
2498: );
2499: $datatable = '<tr class="LC_odd_row">'.
2500: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2501: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2502: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2503: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2504: '<label><input type="radio" name="autoupdate_run"'.
2505: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2506: '</tr><tr>'.
2507: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2508: '<td class="LC_right_item"><span class="LC_nobreak">'.
2509: '<label><input type="radio" name="classlists"'.
2510: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2511: '<label><input type="radio" name="classlists"'.
2512: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2513: '</tr>';
1.30 raeburn 2514: $$rowtotal += 2;
1.131 raeburn 2515: } elsif ($position eq 'middle') {
2516: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2517: my $numinrow = 3;
2518: my $locknamesettings;
2519: $datatable .= &insttypes_row($settings,$types,$usertypes,
2520: $dom,$numinrow,$othertitle,
2521: 'lockablenames');
2522: $$rowtotal ++;
1.3 raeburn 2523: } else {
1.44 raeburn 2524: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2525: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2526: 'permanentemail','id');
1.33 raeburn 2527: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2528: my $numrows = 0;
1.26 raeburn 2529: if (ref($types) eq 'ARRAY') {
2530: if (@{$types} > 0) {
2531: $datatable =
2532: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2533: \@fields,$types,\$numrows);
1.30 raeburn 2534: $$rowtotal += @{$types};
1.26 raeburn 2535: }
1.3 raeburn 2536: }
2537: $datatable .=
2538: &usertype_update_row($settings,{'default' => $othertitle},
2539: \%fieldtitles,\@fields,['default'],
2540: \$numrows);
1.30 raeburn 2541: $$rowtotal ++;
1.3 raeburn 2542: }
2543: return $datatable;
2544: }
2545:
1.125 raeburn 2546: sub print_autocreate {
2547: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2548: my (%createon,%createoff,%currhash);
1.125 raeburn 2549: my @types = ('xml','req');
2550: if (ref($settings) eq 'HASH') {
2551: foreach my $item (@types) {
2552: $createoff{$item} = ' checked="checked" ';
2553: $createon{$item} = ' ';
2554: if (exists($settings->{$item})) {
2555: if ($settings->{$item}) {
2556: $createon{$item} = ' checked="checked" ';
2557: $createoff{$item} = ' ';
2558: }
2559: }
2560: }
1.160.6.16 raeburn 2561: if ($settings->{'xmldc'} ne '') {
2562: $currhash{$settings->{'xmldc'}} = 1;
2563: }
1.125 raeburn 2564: } else {
2565: foreach my $item (@types) {
2566: $createoff{$item} = ' checked="checked" ';
2567: $createon{$item} = ' ';
2568: }
2569: }
2570: $$rowtotal += 2;
1.160.6.16 raeburn 2571: my $numinrow = 2;
1.125 raeburn 2572: my $datatable='<tr class="LC_odd_row">'.
2573: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2574: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2575: '<input type="radio" name="autocreate_xml"'.
2576: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2577: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2578: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2579: '</td></tr><tr>'.
2580: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2581: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2582: '<input type="radio" name="autocreate_req"'.
2583: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2584: '<label><input type="radio" name="autocreate_req"'.
2585: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2586: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2587: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2588: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2589: if ($numdc > 1) {
1.160.6.50 raeburn 2590: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2591: '</td><td class="LC_left_item">';
1.125 raeburn 2592: } else {
1.160.6.50 raeburn 2593: $datatable .= &mt('Course creation processed as:').
2594: '</td><td class="LC_right_item">';
1.125 raeburn 2595: }
1.160.6.50 raeburn 2596: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2597: $$rowtotal += $rows;
1.125 raeburn 2598: return $datatable;
2599: }
2600:
1.23 raeburn 2601: sub print_directorysrch {
1.30 raeburn 2602: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2603: my $srchon = ' ';
2604: my $srchoff = ' checked="checked" ';
1.25 raeburn 2605: my ($exacton,$containson,$beginson);
1.24 raeburn 2606: my $localon = ' ';
2607: my $localoff = ' checked="checked" ';
1.23 raeburn 2608: if (ref($settings) eq 'HASH') {
2609: if ($settings->{'available'} eq '1') {
2610: $srchon = $srchoff;
2611: $srchoff = ' ';
2612: }
1.24 raeburn 2613: if ($settings->{'localonly'} eq '1') {
2614: $localon = $localoff;
2615: $localoff = ' ';
2616: }
1.25 raeburn 2617: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2618: foreach my $type (@{$settings->{'searchtypes'}}) {
2619: if ($type eq 'exact') {
2620: $exacton = ' checked="checked" ';
2621: } elsif ($type eq 'contains') {
2622: $containson = ' checked="checked" ';
2623: } elsif ($type eq 'begins') {
2624: $beginson = ' checked="checked" ';
2625: }
2626: }
2627: } else {
2628: if ($settings->{'searchtypes'} eq 'exact') {
2629: $exacton = ' checked="checked" ';
2630: } elsif ($settings->{'searchtypes'} eq 'contains') {
2631: $containson = ' checked="checked" ';
2632: } elsif ($settings->{'searchtypes'} eq 'specify') {
2633: $exacton = ' checked="checked" ';
2634: $containson = ' checked="checked" ';
2635: }
1.23 raeburn 2636: }
2637: }
2638: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2639: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2640:
2641: my $numinrow = 4;
1.26 raeburn 2642: my $cansrchrow = 0;
1.23 raeburn 2643: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2644: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2645: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2646: '<input type="radio" name="dirsrch_available"'.
2647: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2648: '<label><input type="radio" name="dirsrch_available"'.
2649: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2650: '</tr><tr>'.
1.30 raeburn 2651: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2652: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2653: '<input type="radio" name="dirsrch_localonly"'.
2654: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2655: '<label><input type="radio" name="dirsrch_localonly"'.
2656: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2657: '</tr>';
1.30 raeburn 2658: $$rowtotal += 2;
1.26 raeburn 2659: if (ref($usertypes) eq 'HASH') {
2660: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2661: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2662: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2663: $cansrchrow = 1;
2664: }
2665: }
2666: if ($cansrchrow) {
1.30 raeburn 2667: $$rowtotal ++;
1.26 raeburn 2668: $datatable .= '<tr>';
2669: } else {
2670: $datatable .= '<tr class="LC_odd_row">';
2671: }
1.30 raeburn 2672: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2673: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2674: foreach my $title (@{$titleorder}) {
2675: if (defined($searchtitles->{$title})) {
2676: my $check = ' ';
1.93 raeburn 2677: if (ref($settings) eq 'HASH') {
1.39 raeburn 2678: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2679: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2680: $check = ' checked="checked" ';
2681: }
1.25 raeburn 2682: }
2683: }
2684: $datatable .= '<td class="LC_left_item">'.
2685: '<span class="LC_nobreak"><label>'.
2686: '<input type="checkbox" name="searchby" '.
2687: 'value="'.$title.'"'.$check.'/>'.
2688: $searchtitles->{$title}.'</label></span></td>';
2689: }
2690: }
1.26 raeburn 2691: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2692: $$rowtotal ++;
1.26 raeburn 2693: if ($cansrchrow) {
2694: $datatable .= '<tr class="LC_odd_row">';
2695: } else {
2696: $datatable .= '<tr>';
2697: }
1.30 raeburn 2698: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2699: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2700: '<span class="LC_nobreak"><label>'.
2701: '<input type="checkbox" name="searchtypes" '.
2702: $exacton.' value="exact" />'.&mt('Exact match').
2703: '</label> '.
2704: '<label><input type="checkbox" name="searchtypes" '.
2705: $beginson.' value="begins" />'.&mt('Begins with').
2706: '</label> '.
2707: '<label><input type="checkbox" name="searchtypes" '.
2708: $containson.' value="contains" />'.&mt('Contains').
2709: '</label></span></td></tr>';
1.30 raeburn 2710: $$rowtotal ++;
1.25 raeburn 2711: return $datatable;
2712: }
2713:
1.28 raeburn 2714: sub print_contacts {
1.30 raeburn 2715: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2716: my $datatable;
2717: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2718: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2719: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.23 raeburn 2720: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2721: foreach my $type (@mailings) {
2722: $otheremails{$type} = '';
2723: }
1.134 raeburn 2724: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2725: if (ref($settings) eq 'HASH') {
2726: foreach my $item (@contacts) {
2727: if (exists($settings->{$item})) {
2728: $to{$item} = $settings->{$item};
2729: }
2730: }
2731: foreach my $type (@mailings) {
2732: if (exists($settings->{$type})) {
2733: if (ref($settings->{$type}) eq 'HASH') {
2734: foreach my $item (@contacts) {
2735: if ($settings->{$type}{$item}) {
2736: $checked{$type}{$item} = ' checked="checked" ';
2737: }
2738: }
2739: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2740: if ($type eq 'helpdeskmail') {
2741: $bccemails{$type} = $settings->{$type}{'bcc'};
2742: }
1.28 raeburn 2743: }
1.89 raeburn 2744: } elsif ($type eq 'lonstatusmail') {
2745: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2746: }
2747: }
2748: } else {
2749: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2750: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2751: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2752: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2753: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2754: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2755: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.23 raeburn 2756: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2757: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2758: }
2759: my ($titles,$short_titles) = &contact_titles();
2760: my $rownum = 0;
2761: my $css_class;
2762: foreach my $item (@contacts) {
1.69 raeburn 2763: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2764: $datatable .= '<tr'.$css_class.'>'.
2765: '<td><span class="LC_nobreak">'.$titles->{$item}.
2766: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2767: '<input type="text" name="'.$item.'" value="'.
2768: $to{$item}.'" /></td></tr>';
1.160.6.23 raeburn 2769: $rownum ++;
1.28 raeburn 2770: }
2771: foreach my $type (@mailings) {
1.69 raeburn 2772: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2773: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2774: '<td><span class="LC_nobreak">'.
2775: $titles->{$type}.': </span></td>'.
1.28 raeburn 2776: '<td class="LC_left_item">'.
2777: '<span class="LC_nobreak">';
2778: foreach my $item (@contacts) {
2779: $datatable .= '<label>'.
2780: '<input type="checkbox" name="'.$type.'"'.
2781: $checked{$type}{$item}.
2782: ' value="'.$item.'" />'.$short_titles->{$item}.
2783: '</label> ';
2784: }
2785: $datatable .= '</span><br />'.&mt('Others').': '.
2786: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2787: 'value="'.$otheremails{$type}.'" />';
2788: if ($type eq 'helpdeskmail') {
1.136 raeburn 2789: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2790: '<input type="text" name="'.$type.'_bcc" '.
2791: 'value="'.$bccemails{$type}.'" />';
2792: }
2793: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 2794: $rownum ++;
1.28 raeburn 2795: }
1.160.6.23 raeburn 2796: my %choices;
2797: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2798: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2799: &mt('LON-CAPA core group - MSU'),600,500));
2800: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2801: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2802: &mt('LON-CAPA core group - MSU'),600,500));
2803: my @toggles = ('reporterrors','reportupdates');
2804: my %defaultchecked = ('reporterrors' => 'on',
2805: 'reportupdates' => 'on');
2806: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2807: \%choices,$rownum);
2808: $datatable .= $reports;
1.30 raeburn 2809: $$rowtotal += $rownum;
1.28 raeburn 2810: return $datatable;
2811: }
2812:
1.118 jms 2813: sub print_helpsettings {
1.160.6.5 raeburn 2814: my ($dom,$confname,$settings,$rowtotal) = @_;
2815: my ($datatable,$itemcount);
2816: $itemcount = 1;
2817: my (%choices,%defaultchecked,@toggles);
2818: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2819: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2820: &mt('LON-CAPA bug tracker'),600,500));
2821: %defaultchecked = ('submitbugs' => 'on');
2822: @toggles = ('submitbugs',);
1.122 jms 2823:
1.160.6.5 raeburn 2824: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2825: \%choices,$itemcount);
2826: return $datatable;
1.121 raeburn 2827: }
2828:
2829: sub radiobutton_prefs {
1.160.6.16 raeburn 2830: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 2831: $additional,$align) = @_;
1.121 raeburn 2832: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2833: (ref($choices) eq 'HASH'));
2834:
2835: my (%checkedon,%checkedoff,$datatable,$css_class);
2836:
2837: foreach my $item (@{$toggles}) {
2838: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2839: $checkedon{$item} = ' checked="checked" ';
2840: $checkedoff{$item} = ' ';
1.121 raeburn 2841: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2842: $checkedoff{$item} = ' checked="checked" ';
2843: $checkedon{$item} = ' ';
2844: }
2845: }
2846: if (ref($settings) eq 'HASH') {
1.121 raeburn 2847: foreach my $item (@{$toggles}) {
1.118 jms 2848: if ($settings->{$item} eq '1') {
2849: $checkedon{$item} = ' checked="checked" ';
2850: $checkedoff{$item} = ' ';
2851: } elsif ($settings->{$item} eq '0') {
2852: $checkedoff{$item} = ' checked="checked" ';
2853: $checkedon{$item} = ' ';
2854: }
2855: }
1.121 raeburn 2856: }
1.160.6.16 raeburn 2857: if ($onclick) {
2858: $onclick = ' onclick="'.$onclick.'"';
2859: }
1.121 raeburn 2860: foreach my $item (@{$toggles}) {
1.118 jms 2861: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2862: $datatable .=
1.160.6.16 raeburn 2863: '<tr'.$css_class.'><td valign="top">'.
2864: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 2865: '</span></td>';
2866: if ($align eq 'left') {
2867: $datatable .= '<td class="LC_left_item">';
2868: } else {
2869: $datatable .= '<td class="LC_right_item">';
2870: }
2871: $datatable .=
2872: '<span class="LC_nobreak">'.
1.118 jms 2873: '<label><input type="radio" name="'.
1.160.6.16 raeburn 2874: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2875: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 2876: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2877: '</span>'.$additional.
2878: '</td>'.
1.118 jms 2879: '</tr>';
2880: $itemcount ++;
1.121 raeburn 2881: }
2882: return ($datatable,$itemcount);
2883: }
2884:
2885: sub print_coursedefaults {
1.139 raeburn 2886: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2887: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2888: my $itemcount = 1;
1.160.6.16 raeburn 2889: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 2890: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 2891: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2892: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 2893: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
2894: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
2895: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.16 raeburn 2896: );
1.160.6.21 raeburn 2897: my %staticdefaults = (
2898: anonsurvey_threshold => 10,
2899: uploadquota => 500,
1.160.6.57 raeburn 2900: postsubmit => 60,
1.160.6.21 raeburn 2901: );
1.139 raeburn 2902: if ($position eq 'top') {
1.160.6.57 raeburn 2903: %defaultchecked = (
2904: 'uselcmath' => 'on',
2905: 'usejsme' => 'on',
2906: );
2907: @toggles = ('uselcmath','usejsme');
1.139 raeburn 2908: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 2909: \%choices,$itemcount);
1.139 raeburn 2910: } else {
2911: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.57 raeburn 2912: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout);
1.160.6.16 raeburn 2913: my $currusecredits = 0;
1.160.6.57 raeburn 2914: my $postsubmitclient = 1;
1.160.6.30 raeburn 2915: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2916: if (ref($settings) eq 'HASH') {
2917: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 2918: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2919: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2920: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2921: }
2922: }
1.160.6.16 raeburn 2923: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 2924: foreach my $type (@types) {
2925: next if ($type eq 'community');
2926: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
2927: if ($defcredits{$type} ne '') {
2928: $currusecredits = 1;
2929: }
2930: }
2931: }
2932: if (ref($settings->{'postsubmit'}) eq 'HASH') {
2933: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
2934: $postsubmitclient = 0;
2935: foreach my $type (@types) {
2936: $deftimeout{$type} = $staticdefaults{'postsubmit'};
2937: }
2938: } else {
2939: foreach my $type (@types) {
2940: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
2941: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
2942: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
2943: } else {
2944: $deftimeout{$type} = $staticdefaults{'postsubmit'};
2945: }
2946: } else {
2947: $deftimeout{$type} = $staticdefaults{'postsubmit'};
2948: }
2949: }
2950: }
2951: } else {
2952: foreach my $type (@types) {
2953: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 2954: }
2955: }
1.160.6.58 raeburn 2956: } else {
2957: foreach my $type (@types) {
2958: $deftimeout{$type} = $staticdefaults{'postsubmit'};
2959: }
1.139 raeburn 2960: }
2961: if (!$currdefresponder) {
1.160.6.21 raeburn 2962: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2963: } elsif ($currdefresponder < 1) {
2964: $currdefresponder = 1;
2965: }
1.160.6.21 raeburn 2966: foreach my $type (@types) {
2967: if ($curruploadquota{$type} eq '') {
2968: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2969: }
2970: }
1.139 raeburn 2971: $datatable .=
1.160.6.16 raeburn 2972: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2973: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2974: '</span></td>'.
2975: '<td class="LC_right_item"><span class="LC_nobreak">'.
2976: '<input type="text" name="anonsurvey_threshold"'.
2977: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 2978: '</td></tr>'."\n";
2979: $itemcount ++;
2980: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2981: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2982: $choices{'uploadquota'}.
2983: '</span></td>'.
2984: '<td align="right" class="LC_right_item">'.
2985: '<table><tr>';
1.160.6.21 raeburn 2986: foreach my $type (@types) {
2987: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2988: '<input type="text" name="uploadquota_'.$type.'"'.
2989: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2990: }
2991: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 2992: $itemcount ++;
1.160.6.40 raeburn 2993: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 2994: my $display = 'none';
2995: if ($currusecredits) {
2996: $display = 'block';
2997: }
2998: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 2999: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3000: foreach my $type (@types) {
3001: next if ($type eq 'community');
3002: $additional .= '<td align="center">'.&mt($type).'<br />'.
3003: '<input type="text" name="'.$type.'_credits"'.
3004: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3005: }
3006: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 3007: %defaultchecked = ('coursecredits' => 'off');
3008: @toggles = ('coursecredits');
3009: my $current = {
3010: 'coursecredits' => $currusecredits,
3011: };
3012: (my $table,$itemcount) =
3013: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3014: \%choices,$itemcount,$onclick,$additional,'left');
3015: $datatable .= $table;
3016: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3017: my $display = 'none';
3018: if ($postsubmitclient) {
3019: $display = 'block';
3020: }
3021: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59! raeburn 3022: &mt('Number of seconds submit is disabled').'<br />'.
! 3023: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
! 3024: '<table><tr>';
1.160.6.57 raeburn 3025: foreach my $type (@types) {
3026: $additional .= '<td align="center">'.&mt($type).'<br />'.
3027: '<input type="text" name="'.$type.'_timeout" value="'.
3028: $deftimeout{$type}.'" size="5" /></td>';
3029: }
3030: $additional .= '</tr></table></div>'."\n";
3031: %defaultchecked = ('postsubmit' => 'on');
3032: @toggles = ('postsubmit');
3033: my $current = {
3034: 'postsubmit' => $postsubmitclient,
3035: };
3036: ($table,$itemcount) =
3037: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3038: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 3039: $datatable .= $table;
1.160.6.37 raeburn 3040: }
3041: $$rowtotal += $itemcount;
3042: return $datatable;
3043: }
3044:
3045: sub print_selfenrollment {
3046: my ($position,$dom,$settings,$rowtotal) = @_;
3047: my ($css_class,$datatable);
3048: my $itemcount = 1;
3049: my @types = ('official','unofficial','community','textbook');
3050: if (($position eq 'top') || ($position eq 'middle')) {
3051: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3052: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3053: my @rows;
3054: my $key;
3055: if ($position eq 'top') {
3056: $key = 'admin';
3057: if (ref($rowsref) eq 'ARRAY') {
3058: @rows = @{$rowsref};
3059: }
3060: } elsif ($position eq 'middle') {
3061: $key = 'default';
3062: @rows = ('types','registered','approval','limit');
3063: }
3064: foreach my $row (@rows) {
3065: if (defined($titlesref->{$row})) {
3066: $itemcount ++;
3067: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3068: $datatable .= '<tr'.$css_class.'>'.
3069: '<td>'.$titlesref->{$row}.'</td>'.
3070: '<td class="LC_left_item">'.
3071: '<table><tr>';
3072: my (%current,%currentcap);
3073: if (ref($settings) eq 'HASH') {
3074: if (ref($settings->{$key}) eq 'HASH') {
3075: foreach my $type (@types) {
3076: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3077: $current{$type} = $settings->{$key}->{$type}->{$row};
3078: }
3079: if (($row eq 'limit') && ($key eq 'default')) {
3080: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3081: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3082: }
3083: }
3084: }
3085: }
3086: }
3087: my %roles = (
3088: '0' => &Apache::lonnet::plaintext('dc'),
3089: );
3090:
3091: foreach my $type (@types) {
3092: unless (($row eq 'registered') && ($key eq 'default')) {
3093: $datatable .= '<th>'.&mt($type).'</th>';
3094: }
3095: }
3096: unless (($row eq 'registered') && ($key eq 'default')) {
3097: $datatable .= '</tr><tr>';
3098: }
3099: foreach my $type (@types) {
3100: if ($type eq 'community') {
3101: $roles{'1'} = &mt('Community personnel');
3102: } else {
3103: $roles{'1'} = &mt('Course personnel');
3104: }
3105: $datatable .= '<td style="vertical-align: top">';
3106: if ($position eq 'top') {
3107: my %checked;
3108: if ($current{$type} eq '0') {
3109: $checked{'0'} = ' checked="checked"';
3110: } else {
3111: $checked{'1'} = ' checked="checked"';
3112: }
3113: foreach my $role ('1','0') {
3114: $datatable .= '<span class="LC_nobreak"><label>'.
3115: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3116: 'value="'.$role.'"'.$checked{$role}.' />'.
3117: $roles{$role}.'</label></span> ';
3118: }
3119: } else {
3120: if ($row eq 'types') {
3121: my %checked;
3122: if ($current{$type} =~ /^(all|dom)$/) {
3123: $checked{$1} = ' checked="checked"';
3124: } else {
3125: $checked{''} = ' checked="checked"';
3126: }
3127: foreach my $val ('','dom','all') {
3128: $datatable .= '<span class="LC_nobreak"><label>'.
3129: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3130: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3131: }
3132: } elsif ($row eq 'registered') {
3133: my %checked;
3134: if ($current{$type} eq '1') {
3135: $checked{'1'} = ' checked="checked"';
3136: } else {
3137: $checked{'0'} = ' checked="checked"';
3138: }
3139: foreach my $val ('0','1') {
3140: $datatable .= '<span class="LC_nobreak"><label>'.
3141: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3142: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3143: }
3144: } elsif ($row eq 'approval') {
3145: my %checked;
3146: if ($current{$type} =~ /^([12])$/) {
3147: $checked{$1} = ' checked="checked"';
3148: } else {
3149: $checked{'0'} = ' checked="checked"';
3150: }
3151: for my $val (0..2) {
3152: $datatable .= '<span class="LC_nobreak"><label>'.
3153: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3154: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3155: }
3156: } elsif ($row eq 'limit') {
3157: my %checked;
3158: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3159: $checked{$1} = ' checked="checked"';
3160: } else {
3161: $checked{'none'} = ' checked="checked"';
3162: }
3163: my $cap;
3164: if ($currentcap{$type} =~ /^\d+$/) {
3165: $cap = $currentcap{$type};
3166: }
3167: foreach my $val ('none','allstudents','selfenrolled') {
3168: $datatable .= '<span class="LC_nobreak"><label>'.
3169: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3170: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3171: }
3172: $datatable .= '<br />'.
3173: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3174: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3175: '</span>';
3176: }
3177: }
3178: $datatable .= '</td>';
3179: }
3180: $datatable .= '</tr>';
3181: }
3182: $datatable .= '</table></td></tr>';
3183: }
3184: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3185: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3186: }
3187: $$rowtotal += $itemcount;
3188: return $datatable;
3189: }
3190:
3191: sub print_validation_rows {
3192: my ($caller,$dom,$settings,$rowtotal) = @_;
3193: my ($itemsref,$namesref,$fieldsref);
3194: if ($caller eq 'selfenroll') {
3195: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3196: } elsif ($caller eq 'requestcourses') {
3197: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3198: }
3199: my %currvalidation;
3200: if (ref($settings) eq 'HASH') {
3201: if (ref($settings->{'validation'}) eq 'HASH') {
3202: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3203: }
1.160.6.39 raeburn 3204: }
3205: my $datatable;
3206: my $itemcount = 0;
3207: foreach my $item (@{$itemsref}) {
3208: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3209: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3210: $namesref->{$item}.
3211: '</span></td>'.
3212: '<td class="LC_left_item">';
3213: if (($item eq 'url') || ($item eq 'button')) {
3214: $datatable .= '<span class="LC_nobreak">'.
3215: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3216: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3217: } elsif ($item eq 'fields') {
3218: my @currfields;
3219: if (ref($currvalidation{$item}) eq 'ARRAY') {
3220: @currfields = @{$currvalidation{$item}};
3221: }
3222: foreach my $field (@{$fieldsref}) {
3223: my $check = '';
3224: if (grep(/^\Q$field\E$/,@currfields)) {
3225: $check = ' checked="checked"';
3226: }
3227: $datatable .= '<span class="LC_nobreak"><label>'.
3228: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3229: ' value="'.$field.'"'.$check.' />'.$field.
3230: '</label></span> ';
3231: }
3232: } elsif ($item eq 'markup') {
3233: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3234: $currvalidation{$item}.
1.160.6.37 raeburn 3235: '</textarea>';
1.160.6.39 raeburn 3236: }
3237: $datatable .= '</td></tr>'."\n";
3238: if (ref($rowtotal)) {
1.160.6.37 raeburn 3239: $itemcount ++;
3240: }
1.139 raeburn 3241: }
1.160.6.39 raeburn 3242: if ($caller eq 'requestcourses') {
3243: my %currhash;
1.160.6.51 raeburn 3244: if (ref($settings) eq 'HASH') {
3245: if (ref($settings->{'validation'}) eq 'HASH') {
3246: if ($settings->{'validation'}{'dc'} ne '') {
3247: $currhash{$settings->{'validation'}{'dc'}} = 1;
3248: }
1.160.6.39 raeburn 3249: }
3250: }
3251: my $numinrow = 2;
3252: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3253: 'validationdc',%currhash);
1.160.6.50 raeburn 3254: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3255: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.160.6.39 raeburn 3256: if ($numdc > 1) {
1.160.6.50 raeburn 3257: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 3258: } else {
1.160.6.50 raeburn 3259: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 3260: }
1.160.6.50 raeburn 3261: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 3262: $itemcount ++;
3263: }
3264: if (ref($rowtotal)) {
3265: $$rowtotal += $itemcount;
3266: }
1.121 raeburn 3267: return $datatable;
1.118 jms 3268: }
3269:
1.137 raeburn 3270: sub print_usersessions {
3271: my ($position,$dom,$settings,$rowtotal) = @_;
3272: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3273: my (%by_ip,%by_location,@intdoms);
3274: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3275:
3276: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3277: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3278: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3279: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3280: my $itemcount = 1;
3281: if ($position eq 'top') {
1.152 raeburn 3282: if (keys(%serverhomes) > 1) {
1.145 raeburn 3283: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 3284: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 3285: } else {
1.140 raeburn 3286: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3287: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3288: }
1.137 raeburn 3289: } else {
1.145 raeburn 3290: if (keys(%by_location) == 0) {
3291: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3292: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3293: } else {
3294: my %lt = &usersession_titles();
3295: my $numinrow = 5;
3296: my $prefix;
3297: my @types;
3298: if ($position eq 'bottom') {
3299: $prefix = 'remote';
3300: @types = ('version','excludedomain','includedomain');
3301: } else {
3302: $prefix = 'hosted';
3303: @types = ('excludedomain','includedomain');
3304: }
3305: my (%current,%checkedon,%checkedoff);
3306: my @lcversions = &Apache::lonnet::all_loncaparevs();
3307: my @locations = sort(keys(%by_location));
3308: foreach my $type (@types) {
3309: $checkedon{$type} = '';
3310: $checkedoff{$type} = ' checked="checked"';
3311: }
3312: if (ref($settings) eq 'HASH') {
3313: if (ref($settings->{$prefix}) eq 'HASH') {
3314: foreach my $key (keys(%{$settings->{$prefix}})) {
3315: $current{$key} = $settings->{$prefix}{$key};
3316: if ($key eq 'version') {
3317: if ($current{$key} ne '') {
3318: $checkedon{$key} = ' checked="checked"';
3319: $checkedoff{$key} = '';
3320: }
3321: } elsif (ref($current{$key}) eq 'ARRAY') {
3322: $checkedon{$key} = ' checked="checked"';
3323: $checkedoff{$key} = '';
3324: }
1.137 raeburn 3325: }
3326: }
3327: }
1.145 raeburn 3328: foreach my $type (@types) {
3329: next if ($type ne 'version' && !@locations);
3330: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3331: $datatable .= '<tr'.$css_class.'>
3332: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3333: <span class="LC_nobreak">
3334: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3335: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3336: if ($type eq 'version') {
3337: my $selector = '<select name="'.$prefix.'_version">';
3338: foreach my $version (@lcversions) {
3339: my $selected = '';
3340: if ($current{'version'} eq $version) {
3341: $selected = ' selected="selected"';
3342: }
3343: $selector .= ' <option value="'.$version.'"'.
3344: $selected.'>'.$version.'</option>';
3345: }
3346: $selector .= '</select> ';
3347: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3348: } else {
3349: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3350: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3351: ' />'.(' 'x2).
3352: '<input type="button" value="'.&mt('uncheck all').'" '.
3353: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3354: "\n".
3355: '</div><div><table>';
3356: my $rem;
3357: for (my $i=0; $i<@locations; $i++) {
3358: my ($showloc,$value,$checkedtype);
3359: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3360: my $ip = $by_location{$locations[$i]}->[0];
3361: if (ref($by_ip{$ip}) eq 'ARRAY') {
3362: $value = join(':',@{$by_ip{$ip}});
3363: $showloc = join(', ',@{$by_ip{$ip}});
3364: if (ref($current{$type}) eq 'ARRAY') {
3365: foreach my $loc (@{$by_ip{$ip}}) {
3366: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3367: $checkedtype = ' checked="checked"';
3368: last;
3369: }
3370: }
1.138 raeburn 3371: }
3372: }
3373: }
1.145 raeburn 3374: $rem = $i%($numinrow);
3375: if ($rem == 0) {
3376: if ($i > 0) {
3377: $datatable .= '</tr>';
3378: }
3379: $datatable .= '<tr>';
3380: }
3381: $datatable .= '<td class="LC_left_item">'.
3382: '<span class="LC_nobreak"><label>'.
3383: '<input type="checkbox" name="'.$prefix.'_'.$type.
3384: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3385: '</label></span></td>';
1.137 raeburn 3386: }
1.145 raeburn 3387: $rem = @locations%($numinrow);
3388: my $colsleft = $numinrow - $rem;
3389: if ($colsleft > 1 ) {
3390: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3391: ' </td>';
3392: } elsif ($colsleft == 1) {
3393: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3394: }
1.145 raeburn 3395: $datatable .= '</tr></table>';
1.137 raeburn 3396: }
1.145 raeburn 3397: $datatable .= '</td></tr>';
3398: $itemcount ++;
1.137 raeburn 3399: }
3400: }
3401: }
3402: $$rowtotal += $itemcount;
3403: return $datatable;
3404: }
3405:
1.138 raeburn 3406: sub build_location_hashes {
3407: my ($intdoms,$by_ip,$by_location) = @_;
3408: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3409: (ref($by_location) eq 'HASH'));
3410: my %iphost = &Apache::lonnet::get_iphost();
3411: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3412: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3413: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3414: foreach my $id (@{$iphost{$primary_ip}}) {
3415: my $intdom = &Apache::lonnet::internet_dom($id);
3416: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3417: push(@{$intdoms},$intdom);
3418: }
3419: }
3420: }
3421: foreach my $ip (keys(%iphost)) {
3422: if (ref($iphost{$ip}) eq 'ARRAY') {
3423: foreach my $id (@{$iphost{$ip}}) {
3424: my $location = &Apache::lonnet::internet_dom($id);
3425: if ($location) {
3426: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3427: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3428: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3429: push(@{$by_ip->{$ip}},$location);
3430: }
3431: } else {
3432: $by_ip->{$ip} = [$location];
3433: }
3434: }
3435: }
3436: }
3437: }
3438: foreach my $ip (sort(keys(%{$by_ip}))) {
3439: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3440: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3441: my $first = $by_ip->{$ip}->[0];
3442: if (ref($by_location->{$first}) eq 'ARRAY') {
3443: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3444: push(@{$by_location->{$first}},$ip);
3445: }
3446: } else {
3447: $by_location->{$first} = [$ip];
3448: }
3449: }
3450: }
3451: return;
3452: }
3453:
1.145 raeburn 3454: sub current_offloads_to {
3455: my ($dom,$settings,$servers) = @_;
3456: my (%spareid,%otherdomconfigs);
1.152 raeburn 3457: if (ref($servers) eq 'HASH') {
1.145 raeburn 3458: foreach my $lonhost (sort(keys(%{$servers}))) {
3459: my $gotspares;
1.152 raeburn 3460: if (ref($settings) eq 'HASH') {
3461: if (ref($settings->{'spares'}) eq 'HASH') {
3462: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3463: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3464: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3465: $gotspares = 1;
3466: }
1.145 raeburn 3467: }
3468: }
3469: unless ($gotspares) {
3470: my $gotspares;
3471: my $serverhomeID =
3472: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3473: my $serverhomedom =
3474: &Apache::lonnet::host_domain($serverhomeID);
3475: if ($serverhomedom ne $dom) {
3476: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3477: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3478: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3479: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3480: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3481: $gotspares = 1;
3482: }
3483: }
3484: } else {
3485: $otherdomconfigs{$serverhomedom} =
3486: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3487: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3488: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3489: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3490: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3491: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3492: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3493: $gotspares = 1;
3494: }
3495: }
3496: }
3497: }
3498: }
3499: }
3500: }
3501: unless ($gotspares) {
3502: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3503: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3504: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3505: } else {
3506: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3507: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3508: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3509: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3510: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3511: } else {
1.150 raeburn 3512: my %what = (
3513: spareid => 1,
3514: );
3515: my ($result,$returnhash) =
3516: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3517: if ($result eq 'ok') {
3518: if (ref($returnhash) eq 'HASH') {
3519: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3520: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3521: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3522: }
3523: }
1.145 raeburn 3524: }
3525: }
3526: }
3527: }
3528: }
3529: }
3530: return %spareid;
3531: }
3532:
3533: sub spares_row {
1.152 raeburn 3534: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3535: my $css_class;
3536: my $numinrow = 4;
3537: my $itemcount = 1;
3538: my $datatable;
1.152 raeburn 3539: my %typetitles = &sparestype_titles();
3540: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3541: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3542: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3543: my ($othercontrol,$serverdom);
3544: if ($serverhome ne $server) {
3545: $serverdom = &Apache::lonnet::host_domain($serverhome);
3546: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3547: } else {
3548: $serverdom = &Apache::lonnet::host_domain($server);
3549: if ($serverdom ne $dom) {
3550: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3551: }
3552: }
3553: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3554: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3555: $datatable .= '<tr'.$css_class.'>
3556: <td rowspan="2">
1.160.6.13 raeburn 3557: <span class="LC_nobreak">'.
3558: &mt('[_1] when busy, offloads to:'
3559: ,'<b>'.$server.'</b>').
3560: "\n";
1.145 raeburn 3561: my (%current,%canselect);
1.152 raeburn 3562: my @choices =
3563: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3564: foreach my $type ('primary','default') {
3565: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3566: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3567: my @spares = @{$spareid->{$server}{$type}};
3568: if (@spares > 0) {
1.152 raeburn 3569: if ($othercontrol) {
3570: $current{$type} = join(', ',@spares);
3571: } else {
3572: $current{$type} .= '<table>';
3573: my $numspares = scalar(@spares);
3574: for (my $i=0; $i<@spares; $i++) {
3575: my $rem = $i%($numinrow);
3576: if ($rem == 0) {
3577: if ($i > 0) {
3578: $current{$type} .= '</tr>';
3579: }
3580: $current{$type} .= '<tr>';
1.145 raeburn 3581: }
1.152 raeburn 3582: $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'".');" /> '.
3583: $spareid->{$server}{$type}[$i].
3584: '</label></td>'."\n";
3585: }
3586: my $rem = @spares%($numinrow);
3587: my $colsleft = $numinrow - $rem;
3588: if ($colsleft > 1 ) {
3589: $current{$type} .= '<td colspan="'.$colsleft.
3590: '" class="LC_left_item">'.
3591: ' </td>';
3592: } elsif ($colsleft == 1) {
3593: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3594: }
1.152 raeburn 3595: $current{$type} .= '</tr></table>';
1.150 raeburn 3596: }
1.145 raeburn 3597: }
3598: }
3599: if ($current{$type} eq '') {
3600: $current{$type} = &mt('None specified');
3601: }
1.152 raeburn 3602: if ($othercontrol) {
3603: if ($type eq 'primary') {
3604: $canselect{$type} = $othercontrol;
3605: }
3606: } else {
3607: $canselect{$type} =
3608: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3609: '<select name="newspare_'.$type.'_'.$server.'" '.
3610: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3611: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3612: if (@choices > 0) {
3613: foreach my $lonhost (@choices) {
3614: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3615: }
3616: }
3617: $canselect{$type} .= '</select>'."\n";
3618: }
3619: } else {
3620: $current{$type} = &mt('Could not be determined');
3621: if ($type eq 'primary') {
3622: $canselect{$type} = $othercontrol;
3623: }
1.145 raeburn 3624: }
1.152 raeburn 3625: if ($type eq 'default') {
3626: $datatable .= '<tr'.$css_class.'>';
3627: }
3628: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3629: '<td>'.$current{$type}.'</td>'."\n".
3630: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3631: }
3632: $itemcount ++;
3633: }
3634: }
3635: $$rowtotal += $itemcount;
3636: return $datatable;
3637: }
3638:
1.152 raeburn 3639: sub possible_newspares {
3640: my ($server,$currspares,$serverhomes,$altids) = @_;
3641: my $serverhostname = &Apache::lonnet::hostname($server);
3642: my %excluded;
3643: if ($serverhostname ne '') {
3644: %excluded = (
3645: $serverhostname => 1,
3646: );
3647: }
3648: if (ref($currspares) eq 'HASH') {
3649: foreach my $type (keys(%{$currspares})) {
3650: if (ref($currspares->{$type}) eq 'ARRAY') {
3651: if (@{$currspares->{$type}} > 0) {
3652: foreach my $curr (@{$currspares->{$type}}) {
3653: my $hostname = &Apache::lonnet::hostname($curr);
3654: $excluded{$hostname} = 1;
3655: }
3656: }
3657: }
3658: }
3659: }
3660: my @choices;
3661: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3662: if (keys(%{$serverhomes}) > 1) {
3663: foreach my $name (sort(keys(%{$serverhomes}))) {
3664: unless ($excluded{$name}) {
3665: if (exists($altids->{$serverhomes->{$name}})) {
3666: push(@choices,$altids->{$serverhomes->{$name}});
3667: } else {
3668: push(@choices,$serverhomes->{$name});
1.145 raeburn 3669: }
3670: }
3671: }
3672: }
3673: }
1.152 raeburn 3674: return sort(@choices);
1.145 raeburn 3675: }
3676:
1.150 raeburn 3677: sub print_loadbalancing {
3678: my ($dom,$settings,$rowtotal) = @_;
3679: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3680: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3681: my $numinrow = 1;
3682: my $datatable;
3683: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 3684: my (%currbalancer,%currtargets,%currrules,%existing);
3685: if (ref($settings) eq 'HASH') {
3686: %existing = %{$settings};
3687: }
3688: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3689: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3690: \%currtargets,\%currrules);
1.150 raeburn 3691: } else {
3692: return;
3693: }
3694: my ($othertitle,$usertypes,$types) =
3695: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 3696: my $rownum = 8;
1.150 raeburn 3697: if (ref($types) eq 'ARRAY') {
3698: $rownum += scalar(@{$types});
3699: }
1.160.6.7 raeburn 3700: my @css_class = ('LC_odd_row','LC_even_row');
3701: my $balnum = 0;
3702: my $islast;
3703: my (@toshow,$disabledtext);
3704: if (keys(%currbalancer) > 0) {
3705: @toshow = sort(keys(%currbalancer));
3706: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3707: push(@toshow,'');
3708: }
3709: } else {
3710: @toshow = ('');
3711: $disabledtext = &mt('No existing load balancer');
3712: }
3713: foreach my $lonhost (@toshow) {
3714: if ($balnum == scalar(@toshow)-1) {
3715: $islast = 1;
3716: } else {
3717: $islast = 0;
3718: }
3719: my $cssidx = $balnum%2;
3720: my $targets_div_style = 'display: none';
3721: my $disabled_div_style = 'display: block';
3722: my $homedom_div_style = 'display: none';
3723: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3724: '<td rowspan="'.$rownum.'" valign="top">'.
3725: '<p>';
3726: if ($lonhost eq '') {
3727: $datatable .= '<span class="LC_nobreak">';
3728: if (keys(%currbalancer) > 0) {
3729: $datatable .= &mt('Add balancer:');
3730: } else {
3731: $datatable .= &mt('Enable balancer:');
3732: }
3733: $datatable .= ' '.
3734: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3735: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3736: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3737: '<option value="" selected="selected">'.&mt('None').
3738: '</option>'."\n";
3739: foreach my $server (sort(keys(%servers))) {
3740: next if ($currbalancer{$server});
3741: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3742: }
3743: $datatable .=
3744: '</select>'."\n".
3745: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3746: } else {
3747: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3748: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3749: &mt('Stop balancing').'</label>'.
3750: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3751: $targets_div_style = 'display: block';
3752: $disabled_div_style = 'display: none';
3753: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3754: $homedom_div_style = 'display: block';
3755: }
3756: }
3757: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3758: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3759: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3760: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3761: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3762: my @sparestypes = ('primary','default');
3763: my %typetitles = &sparestype_titles();
3764: foreach my $sparetype (@sparestypes) {
3765: my $targettable;
3766: for (my $i=0; $i<$numspares; $i++) {
3767: my $checked;
3768: if (ref($currtargets{$lonhost}) eq 'HASH') {
3769: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3770: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3771: $checked = ' checked="checked"';
3772: }
3773: }
3774: }
3775: my ($chkboxval,$disabled);
3776: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3777: $chkboxval = $spares[$i];
3778: }
3779: if (exists($currbalancer{$spares[$i]})) {
3780: $disabled = ' disabled="disabled"';
3781: }
3782: $targettable .=
1.160.6.55 raeburn 3783: '<td><span class="LC_nobreak"><label>'.
3784: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 3785: $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 3786: '</span></label></span></td>';
1.160.6.7 raeburn 3787: my $rem = $i%($numinrow);
3788: if ($rem == 0) {
3789: if (($i > 0) && ($i < $numspares-1)) {
3790: $targettable .= '</tr>';
3791: }
3792: if ($i < $numspares-1) {
3793: $targettable .= '<tr>';
1.150 raeburn 3794: }
3795: }
3796: }
1.160.6.7 raeburn 3797: if ($targettable ne '') {
3798: my $rem = $numspares%($numinrow);
3799: my $colsleft = $numinrow - $rem;
3800: if ($colsleft > 1 ) {
3801: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3802: ' </td>';
3803: } elsif ($colsleft == 1) {
3804: $targettable .= '<td class="LC_left_item"> </td>';
3805: }
3806: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3807: '<table><tr>'.$targettable.'</tr></table><br />';
3808: }
3809: }
3810: $datatable .= '</div></td></tr>'.
3811: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3812: $othertitle,$usertypes,$types,\%servers,
3813: \%currbalancer,$lonhost,
3814: $targets_div_style,$homedom_div_style,
3815: $css_class[$cssidx],$balnum,$islast);
3816: $$rowtotal += $rownum;
3817: $balnum ++;
3818: }
3819: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3820: return $datatable;
3821: }
3822:
3823: sub get_loadbalancers_config {
3824: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3825: return unless ((ref($servers) eq 'HASH') &&
3826: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3827: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3828: if (keys(%{$existing}) > 0) {
3829: my $oldlonhost;
3830: foreach my $key (sort(keys(%{$existing}))) {
3831: if ($key eq 'lonhost') {
3832: $oldlonhost = $existing->{'lonhost'};
3833: $currbalancer->{$oldlonhost} = 1;
3834: } elsif ($key eq 'targets') {
3835: if ($oldlonhost) {
3836: $currtargets->{$oldlonhost} = $existing->{'targets'};
3837: }
3838: } elsif ($key eq 'rules') {
3839: if ($oldlonhost) {
3840: $currrules->{$oldlonhost} = $existing->{'rules'};
3841: }
3842: } elsif (ref($existing->{$key}) eq 'HASH') {
3843: $currbalancer->{$key} = 1;
3844: $currtargets->{$key} = $existing->{$key}{'targets'};
3845: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3846: }
3847: }
1.160.6.7 raeburn 3848: } else {
3849: my ($balancerref,$targetsref) =
3850: &Apache::lonnet::get_lonbalancer_config($servers);
3851: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3852: foreach my $server (sort(keys(%{$balancerref}))) {
3853: $currbalancer->{$server} = 1;
3854: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3855: }
3856: }
3857: }
1.160.6.7 raeburn 3858: return;
1.150 raeburn 3859: }
3860:
3861: sub loadbalancing_rules {
3862: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3863: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3864: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3865: my $output;
1.160.6.7 raeburn 3866: my $num = 0;
3867: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3868: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3869: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3870: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3871: $num ++;
1.150 raeburn 3872: my $current;
3873: if (ref($currrules) eq 'HASH') {
3874: $current = $currrules->{$type};
3875: }
1.160.6.55 raeburn 3876: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 3877: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3878: $current = '';
3879: }
3880: }
3881: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3882: $servers,$currbalancer,$lonhost,$dom,
3883: $targets_div_style,$homedom_div_style,
3884: $css_class,$balnum,$num,$islast);
1.150 raeburn 3885: }
3886: }
3887: return $output;
3888: }
3889:
3890: sub loadbalancing_titles {
3891: my ($dom,$intdom,$usertypes,$types) = @_;
3892: my %othertypes = (
3893: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3894: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3895: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3896: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 3897: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3898: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3899: );
1.160.6.26 raeburn 3900: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3901: if (ref($types) eq 'ARRAY') {
3902: unshift(@alltypes,@{$types},'default');
3903: }
3904: my %titles;
3905: foreach my $type (@alltypes) {
3906: if ($type =~ /^_LC_/) {
3907: $titles{$type} = $othertypes{$type};
3908: } elsif ($type eq 'default') {
3909: $titles{$type} = &mt('All users from [_1]',$dom);
3910: if (ref($types) eq 'ARRAY') {
3911: if (@{$types} > 0) {
3912: $titles{$type} = &mt('Other users from [_1]',$dom);
3913: }
3914: }
3915: } elsif (ref($usertypes) eq 'HASH') {
3916: $titles{$type} = $usertypes->{$type};
3917: }
3918: }
3919: return (\@alltypes,\%othertypes,\%titles);
3920: }
3921:
3922: sub loadbalance_rule_row {
1.160.6.7 raeburn 3923: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3924: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 3925: my @rulenames;
1.150 raeburn 3926: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 3927: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 3928: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 3929: } else {
1.160.6.26 raeburn 3930: @rulenames = ('default','homeserver');
3931: if ($type eq '_LC_external') {
3932: push(@rulenames,'externalbalancer');
3933: } else {
3934: push(@rulenames,'specific');
3935: }
3936: push(@rulenames,'none');
1.150 raeburn 3937: }
3938: my $style = $targets_div_style;
1.160.6.55 raeburn 3939: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 3940: $style = $homedom_div_style;
3941: }
1.160.6.7 raeburn 3942: my $space;
3943: if ($islast && $num == 1) {
3944: $space = '<div display="inline-block"> </div>';
3945: }
3946: my $output =
3947: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3948: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3949: '<td valaign="top">'.$space.
3950: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3951: for (my $i=0; $i<@rulenames; $i++) {
3952: my $rule = $rulenames[$i];
3953: my ($checked,$extra);
3954: if ($rulenames[$i] eq 'default') {
3955: $rule = '';
3956: }
3957: if ($rulenames[$i] eq 'specific') {
3958: if (ref($servers) eq 'HASH') {
3959: my $default;
3960: if (($current ne '') && (exists($servers->{$current}))) {
3961: $checked = ' checked="checked"';
3962: }
3963: unless ($checked) {
3964: $default = ' selected="selected"';
3965: }
1.160.6.7 raeburn 3966: $extra =
3967: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3968: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3969: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3970: '<option value=""'.$default.'></option>'."\n";
3971: foreach my $server (sort(keys(%{$servers}))) {
3972: if (ref($currbalancer) eq 'HASH') {
3973: next if (exists($currbalancer->{$server}));
3974: }
1.150 raeburn 3975: my $selected;
1.160.6.7 raeburn 3976: if ($server eq $current) {
1.150 raeburn 3977: $selected = ' selected="selected"';
3978: }
1.160.6.7 raeburn 3979: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3980: }
3981: $extra .= '</select>';
3982: }
3983: } elsif ($rule eq $current) {
3984: $checked = ' checked="checked"';
3985: }
3986: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3987: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3988: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3989: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 3990: ')"'.$checked.' /> ';
1.160.6.56 raeburn 3991: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 3992: $output .= $ruletitles{'particular'};
3993: } else {
3994: $output .= $ruletitles{$rulenames[$i]};
3995: }
3996: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 3997: }
3998: $output .= '</div></td></tr>'."\n";
3999: return $output;
4000: }
4001:
4002: sub offloadtype_text {
4003: my %ruletitles = &Apache::lonlocal::texthash (
4004: 'default' => 'Offloads to default destinations',
4005: 'homeserver' => "Offloads to user's home server",
4006: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4007: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 4008: 'none' => 'No offload',
1.160.6.26 raeburn 4009: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4010: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 4011: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4012: );
4013: return %ruletitles;
4014: }
4015:
4016: sub sparestype_titles {
4017: my %typestitles = &Apache::lonlocal::texthash (
4018: 'primary' => 'primary',
4019: 'default' => 'default',
4020: );
4021: return %typestitles;
4022: }
4023:
1.28 raeburn 4024: sub contact_titles {
4025: my %titles = &Apache::lonlocal::texthash (
4026: 'supportemail' => 'Support E-mail address',
1.69 raeburn 4027: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 4028: 'errormail' => 'Error reports to be e-mailed to',
4029: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 4030: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4031: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 4032: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 4033: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 4034: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4035: );
4036: my %short_titles = &Apache::lonlocal::texthash (
4037: adminemail => 'Admin E-mail address',
4038: supportemail => 'Support E-mail',
4039: );
4040: return (\%titles,\%short_titles);
4041: }
4042:
1.72 raeburn 4043: sub tool_titles {
4044: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 4045: aboutme => 'Personal web page',
1.86 raeburn 4046: blog => 'Blog',
1.160.6.4 raeburn 4047: webdav => 'WebDAV',
1.86 raeburn 4048: portfolio => 'Portfolio',
1.88 bisitz 4049: official => 'Official courses (with institutional codes)',
4050: unofficial => 'Unofficial courses',
1.98 raeburn 4051: community => 'Communities',
1.160.6.30 raeburn 4052: textbook => 'Textbook courses',
1.86 raeburn 4053: );
1.72 raeburn 4054: return %titles;
4055: }
4056:
1.101 raeburn 4057: sub courserequest_titles {
4058: my %titles = &Apache::lonlocal::texthash (
4059: official => 'Official',
4060: unofficial => 'Unofficial',
4061: community => 'Communities',
1.160.6.30 raeburn 4062: textbook => 'Textbook',
1.101 raeburn 4063: norequest => 'Not allowed',
1.104 raeburn 4064: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4065: validate => 'With validation',
4066: autolimit => 'Numerical limit',
1.103 raeburn 4067: unlimited => '(blank for unlimited)',
1.101 raeburn 4068: );
4069: return %titles;
4070: }
4071:
1.160.6.5 raeburn 4072: sub authorrequest_titles {
4073: my %titles = &Apache::lonlocal::texthash (
4074: norequest => 'Not allowed',
4075: approval => 'Approval by Dom. Coord.',
4076: automatic => 'Automatic approval',
4077: );
4078: return %titles;
4079: }
4080:
1.101 raeburn 4081: sub courserequest_conditions {
4082: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4083: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 4084: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4085: );
4086: return %conditions;
4087: }
4088:
4089:
1.27 raeburn 4090: sub print_usercreation {
1.30 raeburn 4091: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4092: my $numinrow = 4;
1.28 raeburn 4093: my $datatable;
4094: if ($position eq 'top') {
1.30 raeburn 4095: $$rowtotal ++;
1.34 raeburn 4096: my $rowcount = 0;
1.32 raeburn 4097: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4098: if (ref($rules) eq 'HASH') {
4099: if (keys(%{$rules}) > 0) {
1.32 raeburn 4100: $datatable .= &user_formats_row('username',$settings,$rules,
4101: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4102: $$rowtotal ++;
1.32 raeburn 4103: $rowcount ++;
4104: }
4105: }
4106: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4107: if (ref($idrules) eq 'HASH') {
4108: if (keys(%{$idrules}) > 0) {
4109: $datatable .= &user_formats_row('id',$settings,$idrules,
4110: $idruleorder,$numinrow,$rowcount);
4111: $$rowtotal ++;
4112: $rowcount ++;
1.28 raeburn 4113: }
4114: }
1.39 raeburn 4115: if ($rowcount == 0) {
4116: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4117: $$rowtotal ++;
4118: $rowcount ++;
4119: }
1.34 raeburn 4120: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 4121: my @creators = ('author','course','requestcrs');
1.37 raeburn 4122: my ($rules,$ruleorder) =
4123: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4124: my %lt = &usercreation_types();
4125: my %checked;
4126: if (ref($settings) eq 'HASH') {
4127: if (ref($settings->{'cancreate'}) eq 'HASH') {
4128: foreach my $item (@creators) {
4129: $checked{$item} = $settings->{'cancreate'}{$item};
4130: }
4131: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4132: foreach my $item (@creators) {
4133: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4134: $checked{$item} = 'none';
4135: }
4136: }
4137: }
4138: }
4139: my $rownum = 0;
4140: foreach my $item (@creators) {
4141: $rownum ++;
1.160.6.34 raeburn 4142: if ($checked{$item} eq '') {
4143: $checked{$item} = 'any';
1.34 raeburn 4144: }
4145: my $css_class;
4146: if ($rownum%2) {
4147: $css_class = '';
4148: } else {
4149: $css_class = ' class="LC_odd_row" ';
4150: }
4151: $datatable .= '<tr'.$css_class.'>'.
4152: '<td><span class="LC_nobreak">'.$lt{$item}.
4153: '</span></td><td align="right">';
1.160.6.34 raeburn 4154: my @options = ('any');
4155: if (ref($rules) eq 'HASH') {
4156: if (keys(%{$rules}) > 0) {
4157: push(@options,('official','unofficial'));
1.37 raeburn 4158: }
4159: }
1.160.6.34 raeburn 4160: push(@options,'none');
1.37 raeburn 4161: foreach my $option (@options) {
1.50 raeburn 4162: my $type = 'radio';
1.34 raeburn 4163: my $check = ' ';
1.160.6.34 raeburn 4164: if ($checked{$item} eq $option) {
4165: $check = ' checked="checked" ';
1.34 raeburn 4166: }
4167: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4168: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4169: $item.'" value="'.$option.'"'.$check.'/> '.
4170: $lt{$option}.'</label> </span>';
4171: }
4172: $datatable .= '</td></tr>';
4173: }
1.28 raeburn 4174: } else {
4175: my @contexts = ('author','course','domain');
4176: my @authtypes = ('int','krb4','krb5','loc');
4177: my %checked;
4178: if (ref($settings) eq 'HASH') {
4179: if (ref($settings->{'authtypes'}) eq 'HASH') {
4180: foreach my $item (@contexts) {
4181: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4182: foreach my $auth (@authtypes) {
4183: if ($settings->{'authtypes'}{$item}{$auth}) {
4184: $checked{$item}{$auth} = ' checked="checked" ';
4185: }
4186: }
4187: }
4188: }
1.27 raeburn 4189: }
1.35 raeburn 4190: } else {
4191: foreach my $item (@contexts) {
1.36 raeburn 4192: foreach my $auth (@authtypes) {
1.35 raeburn 4193: $checked{$item}{$auth} = ' checked="checked" ';
4194: }
4195: }
1.27 raeburn 4196: }
1.28 raeburn 4197: my %title = &context_names();
4198: my %authname = &authtype_names();
4199: my $rownum = 0;
4200: my $css_class;
4201: foreach my $item (@contexts) {
4202: if ($rownum%2) {
4203: $css_class = '';
4204: } else {
4205: $css_class = ' class="LC_odd_row" ';
4206: }
1.30 raeburn 4207: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4208: '<td>'.$title{$item}.
4209: '</td><td class="LC_left_item">'.
4210: '<span class="LC_nobreak">';
4211: foreach my $auth (@authtypes) {
4212: $datatable .= '<label>'.
4213: '<input type="checkbox" name="'.$item.'_auth" '.
4214: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4215: $authname{$auth}.'</label> ';
4216: }
4217: $datatable .= '</span></td></tr>';
4218: $rownum ++;
1.27 raeburn 4219: }
1.30 raeburn 4220: $$rowtotal += $rownum;
1.27 raeburn 4221: }
4222: return $datatable;
4223: }
4224:
1.160.6.34 raeburn 4225: sub print_selfcreation {
4226: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4227: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4228: if (ref($settings) eq 'HASH') {
4229: if (ref($settings->{'cancreate'}) eq 'HASH') {
4230: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4231: if (ref($createsettings) eq 'HASH') {
4232: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4233: @selfcreate = @{$createsettings->{'selfcreate'}};
4234: } elsif ($createsettings->{'selfcreate'} ne '') {
4235: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4236: @selfcreate = ('email','login','sso');
4237: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4238: @selfcreate = ($createsettings->{'selfcreate'});
4239: }
4240: }
4241: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4242: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 4243: }
4244: }
4245: }
4246: }
4247: my %radiohash;
4248: my $numinrow = 4;
4249: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4250: if ($position eq 'top') {
4251: my %choices = &Apache::lonlocal::texthash (
4252: cancreate_login => 'Institutional Login',
4253: cancreate_sso => 'Institutional Single Sign On',
4254: );
4255: my @toggles = sort(keys(%choices));
4256: my %defaultchecked = (
4257: 'cancreate_login' => 'off',
4258: 'cancreate_sso' => 'off',
4259: );
1.160.6.35 raeburn 4260: my ($onclick,$itemcount);
1.160.6.34 raeburn 4261: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4262: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 4263: $$rowtotal += $itemcount;
1.160.6.39 raeburn 4264:
1.160.6.34 raeburn 4265: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4266:
4267: if (ref($usertypes) eq 'HASH') {
4268: if (keys(%{$usertypes}) > 0) {
4269: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4270: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 4271: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 4272: $$rowtotal ++;
4273: }
4274: }
1.160.6.44 raeburn 4275: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4276: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4277: $fieldtitles{'inststatus'} = &mt('Institutional status');
4278: my $rem;
4279: my $numperrow = 2;
4280: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4281: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 4282: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 4283: '<td class="LC_left_item">'."\n".
4284: '<table><tr><td>'."\n";
4285: for (my $i=0; $i<@fields; $i++) {
4286: $rem = $i%($numperrow);
4287: if ($rem == 0) {
4288: if ($i > 0) {
4289: $datatable .= '</tr>';
4290: }
4291: $datatable .= '<tr>';
4292: }
4293: my $currval;
1.160.6.51 raeburn 4294: if (ref($createsettings) eq 'HASH') {
4295: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4296: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4297: }
1.160.6.44 raeburn 4298: }
4299: $datatable .= '<td class="LC_left_item">'.
4300: '<span class="LC_nobreak">'.
4301: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4302: 'value="'.$currval.'" size="10" /> '.
4303: $fieldtitles{$fields[$i]}.'</span></td>';
4304: }
4305: my $colsleft = $numperrow - $rem;
4306: if ($colsleft > 1 ) {
4307: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4308: ' </td>';
4309: } elsif ($colsleft == 1) {
4310: $datatable .= '<td class="LC_left_item"> </td>';
4311: }
4312: $datatable .= '</tr></table></td></tr>';
4313: $$rowtotal ++;
1.160.6.34 raeburn 4314: } elsif ($position eq 'middle') {
4315: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4316: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4317: $usertypes->{'default'} = $othertitle;
4318: if (ref($types) eq 'ARRAY') {
4319: push(@{$types},'default');
4320: $usertypes->{'default'} = $othertitle;
4321: foreach my $status (@{$types}) {
4322: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 4323: $numinrow,$$rowtotal,$usertypes);
1.160.6.44 raeburn 4324: $$rowtotal ++;
1.160.6.34 raeburn 4325: }
4326: }
4327: } else {
1.160.6.40 raeburn 4328: my %choices = &Apache::lonlocal::texthash (
4329: cancreate_email => 'E-mail address as username',
4330: );
4331: my @toggles = sort(keys(%choices));
4332: my %defaultchecked = (
4333: 'cancreate_email' => 'off',
4334: );
4335: my $itemcount = 0;
4336: my $display = 'none';
4337: if (grep(/^\Qemail\E$/,@selfcreate)) {
4338: $display = 'block';
4339: }
4340: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4341: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4342: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4343: my $usertypes = {};
4344: my $order = [];
4345: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4346: $usertypes = $domdefaults{'inststatustypes'};
4347: $order = $domdefaults{'inststatusguest'};
4348: }
4349: if (ref($order) eq 'ARRAY') {
4350: push(@{$order},'default');
4351: if (@{$order} > 1) {
4352: $usertypes->{'default'} = &mt('Other users');
4353: $additional .= '<table><tr>';
4354: foreach my $status (@{$order}) {
4355: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4356: }
4357: $additional .= '</tr><tr>';
4358: foreach my $status (@{$order}) {
4359: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 4360: }
1.160.6.40 raeburn 4361: $additional .= '</tr></table>';
1.160.6.34 raeburn 4362: } else {
1.160.6.40 raeburn 4363: $usertypes->{'default'} = &mt('All users');
4364: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 4365: }
4366: }
1.160.6.40 raeburn 4367: $additional .= '</div>'."\n";
4368:
4369: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 4370: \%choices,$$rowtotal,$onclick,$additional);
4371: $$rowtotal ++;
1.160.6.40 raeburn 4372: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 4373: $$rowtotal ++;
1.160.6.35 raeburn 4374: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4375: $numinrow = 1;
1.160.6.40 raeburn 4376: if (ref($order) eq 'ARRAY') {
4377: foreach my $status (@{$order}) {
1.160.6.35 raeburn 4378: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4379: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4380: $$rowtotal ++;
4381: }
4382: }
1.160.6.34 raeburn 4383: my ($emailrules,$emailruleorder) =
4384: &Apache::lonnet::inst_userrules($dom,'email');
4385: if (ref($emailrules) eq 'HASH') {
4386: if (keys(%{$emailrules}) > 0) {
4387: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 4388: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 4389: $$rowtotal ++;
4390: }
4391: }
1.160.6.35 raeburn 4392: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 4393: }
4394: return $datatable;
4395: }
4396:
1.160.6.40 raeburn 4397: sub email_as_username {
4398: my ($rowtotal,$processing,$type) = @_;
4399: my %choices =
4400: &Apache::lonlocal::texthash (
4401: automatic => 'Automatic approval',
4402: approval => 'Queued for approval',
4403: );
4404: my $output;
4405: foreach my $option ('automatic','approval') {
4406: my $checked;
4407: if (ref($processing) eq 'HASH') {
4408: if ($type eq '') {
4409: if (!exists($processing->{'default'})) {
4410: if ($option eq 'automatic') {
4411: $checked = ' checked="checked"';
4412: }
4413: } else {
4414: if ($processing->{'default'} eq $option) {
4415: $checked = ' checked="checked"';
4416: }
4417: }
4418: } else {
4419: if (!exists($processing->{$type})) {
4420: if ($option eq 'automatic') {
4421: $checked = ' checked="checked"';
4422: }
4423: } else {
4424: if ($processing->{$type} eq $option) {
4425: $checked = ' checked="checked"';
4426: }
4427: }
4428: }
4429: } elsif ($option eq 'automatic') {
4430: $checked = ' checked="checked"';
4431: }
4432: my $name = 'cancreate_emailprocess';
4433: if (($type ne '') && ($type ne 'default')) {
4434: $name .= '_'.$type;
4435: }
4436: $output .= '<span class="LC_nobreak"><label>'.
4437: '<input type="radio" name="'.$name.'"'.
4438: $checked.' value="'.$option.'" />'.
4439: $choices{$option}.'</label></span>';
4440: if ($type eq '') {
4441: $output .= ' ';
4442: } else {
4443: $output .= '<br />';
4444: }
4445: }
4446: $$rowtotal ++;
4447: return $output;
4448: }
4449:
1.160.6.5 raeburn 4450: sub captcha_choice {
4451: my ($context,$settings,$itemcount) = @_;
4452: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4453: my %lt = &captcha_phrases();
4454: $keyentry = 'hidden';
4455: if ($context eq 'cancreate') {
1.160.6.34 raeburn 4456: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 4457: } elsif ($context eq 'login') {
4458: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
4459: }
4460: if (ref($settings) eq 'HASH') {
4461: if ($settings->{'captcha'}) {
4462: $checked{$settings->{'captcha'}} = ' checked="checked"';
4463: } else {
4464: $checked{'original'} = ' checked="checked"';
4465: }
4466: if ($settings->{'captcha'} eq 'recaptcha') {
4467: $pubtext = $lt{'pub'};
4468: $privtext = $lt{'priv'};
4469: $keyentry = 'text';
4470: }
4471: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4472: $currpub = $settings->{'recaptchakeys'}{'public'};
4473: $currpriv = $settings->{'recaptchakeys'}{'private'};
4474: }
4475: } else {
4476: $checked{'original'} = ' checked="checked"';
4477: }
4478: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4479: my $output = '<tr'.$css_class.'>'.
4480: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
4481: '<table><tr><td>'."\n";
4482: foreach my $option ('original','recaptcha','notused') {
4483: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4484: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4485: $lt{$option}.'</label></span>';
4486: unless ($option eq 'notused') {
4487: $output .= (' 'x2)."\n";
4488: }
4489: }
4490: #
4491: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4492: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
4493: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
4494: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
4495: #
4496: $output .= '</td></tr>'."\n".
4497: '<tr><td>'."\n".
4498: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4499: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4500: $currpub.'" size="40" /></span><br />'."\n".
4501: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4502: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4503: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4504: '</td></tr>';
4505: return $output;
4506: }
4507:
1.32 raeburn 4508: sub user_formats_row {
4509: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4510: my $output;
4511: my %text = (
4512: 'username' => 'new usernames',
4513: 'id' => 'IDs',
1.45 raeburn 4514: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4515: );
4516: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4517: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4518: '<td><span class="LC_nobreak">';
4519: if ($type eq 'email') {
4520: $output .= &mt("Formats disallowed for $text{$type}: ");
4521: } else {
4522: $output .= &mt("Format rules to check for $text{$type}: ");
4523: }
4524: $output .= '</span></td>'.
4525: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4526: my $rem;
4527: if (ref($ruleorder) eq 'ARRAY') {
4528: for (my $i=0; $i<@{$ruleorder}; $i++) {
4529: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4530: my $rem = $i%($numinrow);
4531: if ($rem == 0) {
4532: if ($i > 0) {
4533: $output .= '</tr>';
4534: }
4535: $output .= '<tr>';
4536: }
4537: my $check = ' ';
1.39 raeburn 4538: if (ref($settings) eq 'HASH') {
4539: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4540: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4541: $check = ' checked="checked" ';
4542: }
1.27 raeburn 4543: }
4544: }
4545: $output .= '<td class="LC_left_item">'.
4546: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4547: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4548: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4549: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4550: }
4551: }
4552: $rem = @{$ruleorder}%($numinrow);
4553: }
4554: my $colsleft = $numinrow - $rem;
4555: if ($colsleft > 1 ) {
4556: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4557: ' </td>';
4558: } elsif ($colsleft == 1) {
4559: $output .= '<td class="LC_left_item"> </td>';
4560: }
4561: $output .= '</tr></table></td></tr>';
4562: return $output;
4563: }
4564:
1.34 raeburn 4565: sub usercreation_types {
4566: my %lt = &Apache::lonlocal::texthash (
4567: author => 'When adding a co-author',
4568: course => 'When adding a user to a course',
1.100 raeburn 4569: requestcrs => 'When requesting a course',
1.34 raeburn 4570: any => 'Any',
4571: official => 'Institutional only ',
4572: unofficial => 'Non-institutional only',
4573: none => 'None',
4574: );
4575: return %lt;
1.48 raeburn 4576: }
1.34 raeburn 4577:
1.160.6.34 raeburn 4578: sub selfcreation_types {
4579: my %lt = &Apache::lonlocal::texthash (
4580: selfcreate => 'User creates own account',
4581: any => 'Any',
4582: official => 'Institutional only ',
4583: unofficial => 'Non-institutional only',
4584: email => 'E-mail address',
4585: login => 'Institutional Login',
4586: sso => 'SSO',
4587: );
4588: }
4589:
1.28 raeburn 4590: sub authtype_names {
4591: my %lt = &Apache::lonlocal::texthash(
4592: int => 'Internal',
4593: krb4 => 'Kerberos 4',
4594: krb5 => 'Kerberos 5',
4595: loc => 'Local',
4596: );
4597: return %lt;
4598: }
4599:
4600: sub context_names {
4601: my %context_title = &Apache::lonlocal::texthash(
4602: author => 'Creating users when an Author',
4603: course => 'Creating users when in a course',
4604: domain => 'Creating users when a Domain Coordinator',
4605: );
4606: return %context_title;
4607: }
4608:
1.33 raeburn 4609: sub print_usermodification {
4610: my ($position,$dom,$settings,$rowtotal) = @_;
4611: my $numinrow = 4;
4612: my ($context,$datatable,$rowcount);
4613: if ($position eq 'top') {
4614: $rowcount = 0;
4615: $context = 'author';
4616: foreach my $role ('ca','aa') {
4617: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4618: $numinrow,$rowcount);
4619: $$rowtotal ++;
4620: $rowcount ++;
4621: }
1.160.6.37 raeburn 4622: } elsif ($position eq 'bottom') {
1.33 raeburn 4623: $context = 'course';
4624: $rowcount = 0;
4625: foreach my $role ('st','ep','ta','in','cr') {
4626: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4627: $numinrow,$rowcount);
4628: $$rowtotal ++;
4629: $rowcount ++;
4630: }
4631: }
4632: return $datatable;
4633: }
4634:
1.43 raeburn 4635: sub print_defaults {
1.160.6.40 raeburn 4636: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4637: my $rownum = 0;
4638: my ($datatable,$css_class);
1.160.6.40 raeburn 4639: if ($position eq 'top') {
4640: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4641: 'datelocale_def','portal_def');
4642: my %defaults;
4643: if (ref($settings) eq 'HASH') {
4644: %defaults = %{$settings};
1.43 raeburn 4645: } else {
1.160.6.40 raeburn 4646: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4647: foreach my $item (@items) {
4648: $defaults{$item} = $domdefaults{$item};
4649: }
1.43 raeburn 4650: }
1.160.6.40 raeburn 4651: my $titles = &defaults_titles($dom);
4652: foreach my $item (@items) {
4653: if ($rownum%2) {
4654: $css_class = '';
4655: } else {
4656: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 4657: }
1.160.6.40 raeburn 4658: $datatable .= '<tr'.$css_class.'>'.
4659: '<td><span class="LC_nobreak">'.$titles->{$item}.
4660: '</span></td><td class="LC_right_item" colspan="3">';
4661: if ($item eq 'auth_def') {
4662: my @authtypes = ('internal','krb4','krb5','localauth');
4663: my %shortauth = (
4664: internal => 'int',
4665: krb4 => 'krb4',
4666: krb5 => 'krb5',
4667: localauth => 'loc'
4668: );
4669: my %authnames = &authtype_names();
4670: foreach my $auth (@authtypes) {
4671: my $checked = ' ';
4672: if ($defaults{$item} eq $auth) {
4673: $checked = ' checked="checked" ';
4674: }
4675: $datatable .= '<label><input type="radio" name="'.$item.
4676: '" value="'.$auth.'"'.$checked.'/>'.
4677: $authnames{$shortauth{$auth}}.'</label> ';
4678: }
4679: } elsif ($item eq 'timezone_def') {
4680: my $includeempty = 1;
4681: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4682: } elsif ($item eq 'datelocale_def') {
4683: my $includeempty = 1;
4684: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4685: } elsif ($item eq 'lang_def') {
4686: my %langchoices = &get_languages_hash();
4687: $langchoices{''} = 'No language preference';
4688: %langchoices = &Apache::lonlocal::texthash(%langchoices);
4689: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
4690: \%langchoices);
4691: } else {
4692: my $size;
4693: if ($item eq 'portal_def') {
4694: $size = ' size="25"';
4695: }
4696: $datatable .= '<input type="text" name="'.$item.'" value="'.
4697: $defaults{$item}.'"'.$size.' />';
4698: }
4699: $datatable .= '</td></tr>';
4700: $rownum ++;
4701: }
4702: } else {
4703: my (%defaults);
4704: if (ref($settings) eq 'HASH') {
4705: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4706: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4707: my $maxnum = @{$settings->{'inststatusorder'}};
4708: for (my $i=0; $i<$maxnum; $i++) {
4709: $css_class = $rownum%2?' class="LC_odd_row"':'';
4710: my $item = $settings->{'inststatusorder'}->[$i];
4711: my $title = $settings->{'inststatustypes'}->{$item};
4712: my $guestok;
4713: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4714: $guestok = 1;
4715: }
4716: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4717: $datatable .= '<tr'.$css_class.'>'.
4718: '<td><span class="LC_nobreak">'.
4719: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4720: for (my $k=0; $k<=$maxnum; $k++) {
4721: my $vpos = $k+1;
4722: my $selstr;
4723: if ($k == $i) {
4724: $selstr = ' selected="selected" ';
4725: }
4726: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4727: }
4728: my ($checkedon,$checkedoff);
4729: $checkedoff = ' checked="checked"';
4730: if ($guestok) {
4731: $checkedon = $checkedoff;
4732: $checkedoff = '';
4733: }
4734: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4735: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4736: &mt('delete').'</span></td>'.
4737: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4738: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4739: '</span></td>'.
4740: '<td class="LC_right_item"><span class="LC_nobreak">'.
4741: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4742: &mt('Yes').'</label>'.(' 'x2).
4743: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4744: &mt('No').'</label></span></td></tr>';
4745: }
4746: $css_class = $rownum%2?' class="LC_odd_row"':'';
4747: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4748: $datatable .= '<tr '.$css_class.'>'.
4749: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4750: for (my $k=0; $k<=$maxnum; $k++) {
4751: my $vpos = $k+1;
4752: my $selstr;
4753: if ($k == $maxnum) {
4754: $selstr = ' selected="selected" ';
4755: }
4756: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4757: }
4758: $datatable .= '</select> '.&mt('Internal ID:').
4759: '<input type="text" size="10" name="addinststatus" value="" /></span>'.
4760: ' '.&mt('(new)').
4761: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4762: &mt('Name displayed:').
4763: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4764: '<td class="LC_right_item"><span class="LC_nobreak">'.
4765: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4766: &mt('Yes').'</label>'.(' 'x2).
4767: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4768: &mt('No').'</label></span></td></tr>';
4769: '</tr>'."\n";
4770: $rownum ++;
1.141 raeburn 4771: }
1.43 raeburn 4772: }
4773: }
4774: $$rowtotal += $rownum;
4775: return $datatable;
4776: }
4777:
1.160.6.5 raeburn 4778: sub get_languages_hash {
4779: my %langchoices;
4780: foreach my $id (&Apache::loncommon::languageids()) {
4781: my $code = &Apache::loncommon::supportedlanguagecode($id);
4782: if ($code ne '') {
4783: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4784: }
4785: }
4786: return %langchoices;
4787: }
4788:
1.43 raeburn 4789: sub defaults_titles {
1.141 raeburn 4790: my ($dom) = @_;
1.43 raeburn 4791: my %titles = &Apache::lonlocal::texthash (
4792: 'auth_def' => 'Default authentication type',
4793: 'auth_arg_def' => 'Default authentication argument',
4794: 'lang_def' => 'Default language',
1.54 raeburn 4795: 'timezone_def' => 'Default timezone',
1.68 raeburn 4796: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4797: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4798: );
1.141 raeburn 4799: if ($dom) {
4800: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4801: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4802: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4803: $protocol = 'http' if ($protocol ne 'https');
4804: if ($uint_dom) {
4805: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4806: $uint_dom);
4807: }
4808: }
1.43 raeburn 4809: return (\%titles);
4810: }
4811:
1.46 raeburn 4812: sub print_scantronformat {
4813: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4814: my $itemcount = 1;
1.60 raeburn 4815: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4816: %confhash);
1.46 raeburn 4817: my $switchserver = &check_switchserver($dom,$confname);
4818: my %lt = &Apache::lonlocal::texthash (
1.95 www 4819: default => 'Default bubblesheet format file error',
4820: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4821: );
4822: my %scantronfiles = (
4823: default => 'default.tab',
4824: custom => 'custom.tab',
4825: );
4826: foreach my $key (keys(%scantronfiles)) {
4827: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4828: .$scantronfiles{$key};
4829: }
4830: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4831: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4832: if (!$switchserver) {
4833: my $servadm = $r->dir_config('lonAdmEMail');
4834: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4835: if ($configuserok eq 'ok') {
4836: if ($author_ok eq 'ok') {
4837: my %legacyfile = (
4838: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4839: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4840: );
4841: my %md5chk;
4842: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4843: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4844: chomp($md5chk{$type});
1.46 raeburn 4845: }
4846: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4847: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4848: ($scantronurls{$type},my $error) =
1.46 raeburn 4849: &legacy_scantronformat($r,$dom,$confname,
4850: $type,$legacyfile{$type},
4851: $scantronurls{$type},
4852: $scantronfiles{$type});
1.60 raeburn 4853: if ($error ne '') {
4854: $error{$type} = $error;
4855: }
4856: }
4857: if (keys(%error) == 0) {
4858: $is_custom = 1;
4859: $confhash{'scantron'}{'scantronformat'} =
4860: $scantronurls{'custom'};
4861: my $putresult =
4862: &Apache::lonnet::put_dom('configuration',
4863: \%confhash,$dom);
4864: if ($putresult ne 'ok') {
4865: $error{'custom'} =
4866: '<span class="LC_error">'.
4867: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4868: }
1.46 raeburn 4869: }
4870: } else {
1.60 raeburn 4871: ($scantronurls{'default'},my $error) =
1.46 raeburn 4872: &legacy_scantronformat($r,$dom,$confname,
4873: 'default',$legacyfile{'default'},
4874: $scantronurls{'default'},
4875: $scantronfiles{'default'});
1.60 raeburn 4876: if ($error eq '') {
4877: $confhash{'scantron'}{'scantronformat'} = '';
4878: my $putresult =
4879: &Apache::lonnet::put_dom('configuration',
4880: \%confhash,$dom);
4881: if ($putresult ne 'ok') {
4882: $error{'default'} =
4883: '<span class="LC_error">'.
4884: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4885: }
4886: } else {
4887: $error{'default'} = $error;
4888: }
1.46 raeburn 4889: }
4890: }
4891: }
4892: } else {
1.95 www 4893: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4894: }
4895: }
4896: if (ref($settings) eq 'HASH') {
4897: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4898: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4899: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4900: $scantronurl = '';
4901: } else {
4902: $scantronurl = $settings->{'scantronformat'};
4903: }
4904: $is_custom = 1;
4905: } else {
4906: $scantronurl = $scantronurls{'default'};
4907: }
4908: } else {
1.60 raeburn 4909: if ($is_custom) {
4910: $scantronurl = $scantronurls{'custom'};
4911: } else {
4912: $scantronurl = $scantronurls{'default'};
4913: }
1.46 raeburn 4914: }
4915: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4916: $datatable .= '<tr'.$css_class.'>';
4917: if (!$is_custom) {
1.65 raeburn 4918: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4919: '<span class="LC_nobreak">';
1.46 raeburn 4920: if ($scantronurl) {
1.160.6.21 raeburn 4921: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4922: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4923: } else {
4924: $datatable = &mt('File unavailable for display');
4925: }
1.65 raeburn 4926: $datatable .= '</span></td>';
1.60 raeburn 4927: if (keys(%error) == 0) {
4928: $datatable .= '<td valign="bottom">';
4929: if (!$switchserver) {
4930: $datatable .= &mt('Upload:').'<br />';
4931: }
4932: } else {
4933: my $errorstr;
4934: foreach my $key (sort(keys(%error))) {
4935: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4936: }
4937: $datatable .= '<td>'.$errorstr;
4938: }
1.46 raeburn 4939: } else {
4940: if (keys(%error) > 0) {
4941: my $errorstr;
4942: foreach my $key (sort(keys(%error))) {
4943: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4944: }
1.60 raeburn 4945: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4946: } elsif ($scantronurl) {
1.160.6.26 raeburn 4947: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 4948: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4949: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 4950: $link.
4951: '<label><input type="checkbox" name="scantronformat_del"'.
4952: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4953: '<td><span class="LC_nobreak"> '.
4954: &mt('Replace:').'</span><br />';
1.46 raeburn 4955: }
4956: }
4957: if (keys(%error) == 0) {
4958: if ($switchserver) {
4959: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4960: } else {
1.65 raeburn 4961: $datatable .='<span class="LC_nobreak"> '.
4962: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4963: }
4964: }
4965: $datatable .= '</td></tr>';
4966: $$rowtotal ++;
4967: return $datatable;
4968: }
4969:
4970: sub legacy_scantronformat {
4971: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4972: my ($url,$error);
4973: my @statinfo = &Apache::lonnet::stat_file($newurl);
4974: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4975: (my $result,$url) =
4976: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4977: '','',$newfile);
4978: if ($result ne 'ok') {
1.130 raeburn 4979: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4980: }
4981: }
4982: return ($url,$error);
4983: }
1.43 raeburn 4984:
1.49 raeburn 4985: sub print_coursecategories {
1.57 raeburn 4986: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4987: my $datatable;
4988: if ($position eq 'top') {
1.160.6.42 raeburn 4989: my (%checked);
4990: my @catitems = ('unauth','auth');
4991: my @cattypes = ('std','domonly','codesrch','none');
4992: $checked{'unauth'} = 'std';
4993: $checked{'auth'} = 'std';
4994: if (ref($settings) eq 'HASH') {
4995: foreach my $type (@cattypes) {
4996: if ($type eq $settings->{'unauth'}) {
4997: $checked{'unauth'} = $type;
4998: }
4999: if ($type eq $settings->{'auth'}) {
5000: $checked{'auth'} = $type;
5001: }
5002: }
5003: }
5004: my %lt = &Apache::lonlocal::texthash (
5005: unauth => 'Catalog type for unauthenticated users',
5006: auth => 'Catalog type for authenticated users',
5007: none => 'No catalog',
5008: std => 'Standard catalog',
5009: domonly => 'Domain-only catalog',
5010: codesrch => "Code search form",
5011: );
5012: my $itemcount = 0;
5013: foreach my $item (@catitems) {
5014: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5015: $datatable .= '<tr '.$css_class.'>'.
5016: '<td>'.$lt{$item}.'</td>'.
5017: '<td class="LC_right_item"><span class="LC_nobreak">';
5018: foreach my $type (@cattypes) {
5019: my $ischecked;
5020: if ($checked{$item} eq $type) {
5021: $ischecked=' checked="checked"';
5022: }
5023: $datatable .= '<label>'.
5024: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5025: ' />'.$lt{$type}.'</label> ';
5026: }
5027: $datatable .= '</td></tr>';
5028: $itemcount ++;
5029: }
5030: $$rowtotal += $itemcount;
5031: } elsif ($position eq 'middle') {
1.57 raeburn 5032: my $toggle_cats_crs = ' ';
5033: my $toggle_cats_dom = ' checked="checked" ';
5034: my $can_cat_crs = ' ';
5035: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5036: my $toggle_catscomm_comm = ' ';
5037: my $toggle_catscomm_dom = ' checked="checked" ';
5038: my $can_catcomm_comm = ' ';
5039: my $can_catcomm_dom = ' checked="checked" ';
5040:
1.57 raeburn 5041: if (ref($settings) eq 'HASH') {
5042: if ($settings->{'togglecats'} eq 'crs') {
5043: $toggle_cats_crs = $toggle_cats_dom;
5044: $toggle_cats_dom = ' ';
5045: }
5046: if ($settings->{'categorize'} eq 'crs') {
5047: $can_cat_crs = $can_cat_dom;
5048: $can_cat_dom = ' ';
5049: }
1.120 raeburn 5050: if ($settings->{'togglecatscomm'} eq 'comm') {
5051: $toggle_catscomm_comm = $toggle_catscomm_dom;
5052: $toggle_catscomm_dom = ' ';
5053: }
5054: if ($settings->{'categorizecomm'} eq 'comm') {
5055: $can_catcomm_comm = $can_catcomm_dom;
5056: $can_catcomm_dom = ' ';
5057: }
1.57 raeburn 5058: }
5059: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 5060: togglecats => 'Show/Hide a course in catalog',
5061: togglecatscomm => 'Show/Hide a community in catalog',
5062: categorize => 'Assign a category to a course',
5063: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5064: );
5065: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 5066: dom => 'Set in Domain',
5067: crs => 'Set in Course',
5068: comm => 'Set in Community',
1.57 raeburn 5069: );
5070: $datatable = '<tr class="LC_odd_row">'.
5071: '<td>'.$title{'togglecats'}.'</td>'.
5072: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5073: '<input type="radio" name="togglecats"'.
5074: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5075: '<label><input type="radio" name="togglecats"'.
5076: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5077: '</tr><tr>'.
5078: '<td>'.$title{'categorize'}.'</td>'.
5079: '<td class="LC_right_item"><span class="LC_nobreak">'.
5080: '<label><input type="radio" name="categorize"'.
5081: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5082: '<label><input type="radio" name="categorize"'.
5083: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5084: '</tr><tr class="LC_odd_row">'.
5085: '<td>'.$title{'togglecatscomm'}.'</td>'.
5086: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5087: '<input type="radio" name="togglecatscomm"'.
5088: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5089: '<label><input type="radio" name="togglecatscomm"'.
5090: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5091: '</tr><tr>'.
5092: '<td>'.$title{'categorizecomm'}.'</td>'.
5093: '<td class="LC_right_item"><span class="LC_nobreak">'.
5094: '<label><input type="radio" name="categorizecomm"'.
5095: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5096: '<label><input type="radio" name="categorizecomm"'.
5097: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 5098: '</tr>';
1.120 raeburn 5099: $$rowtotal += 4;
1.57 raeburn 5100: } else {
5101: my $css_class;
5102: my $itemcount = 1;
5103: my $cathash;
5104: if (ref($settings) eq 'HASH') {
5105: $cathash = $settings->{'cats'};
5106: }
5107: if (ref($cathash) eq 'HASH') {
5108: my (@cats,@trails,%allitems,%idx,@jsarray);
5109: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5110: \%allitems,\%idx,\@jsarray);
5111: my $maxdepth = scalar(@cats);
5112: my $colattrib = '';
5113: if ($maxdepth > 2) {
5114: $colattrib = ' colspan="2" ';
5115: }
5116: my @path;
5117: if (@cats > 0) {
5118: if (ref($cats[0]) eq 'ARRAY') {
5119: my $numtop = @{$cats[0]};
5120: my $maxnum = $numtop;
1.120 raeburn 5121: my %default_names = (
5122: instcode => &mt('Official courses'),
5123: communities => &mt('Communities'),
5124: );
5125:
5126: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5127: ($cathash->{'instcode::0'} eq '') ||
5128: (!grep(/^communities$/,@{$cats[0]})) ||
5129: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5130: $maxnum ++;
5131: }
5132: my $lastidx;
5133: for (my $i=0; $i<$numtop; $i++) {
5134: my $parent = $cats[0][$i];
5135: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5136: my $item = &escape($parent).'::0';
5137: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5138: $lastidx = $idx{$item};
5139: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5140: .'<select name="'.$item.'"'.$chgstr.'>';
5141: for (my $k=0; $k<=$maxnum; $k++) {
5142: my $vpos = $k+1;
5143: my $selstr;
5144: if ($k == $i) {
5145: $selstr = ' selected="selected" ';
5146: }
5147: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5148: }
1.160.6.29 raeburn 5149: $datatable .= '</select></span></td><td>';
1.120 raeburn 5150: if ($parent eq 'instcode' || $parent eq 'communities') {
5151: $datatable .= '<span class="LC_nobreak">'
5152: .$default_names{$parent}.'</span>';
5153: if ($parent eq 'instcode') {
5154: $datatable .= '<br /><span class="LC_nobreak">('
5155: .&mt('with institutional codes')
5156: .')</span></td><td'.$colattrib.'>';
5157: } else {
5158: $datatable .= '<table><tr><td>';
5159: }
5160: $datatable .= '<span class="LC_nobreak">'
5161: .'<label><input type="radio" name="'
5162: .$parent.'" value="1" checked="checked" />'
5163: .&mt('Display').'</label>';
5164: if ($parent eq 'instcode') {
5165: $datatable .= ' ';
5166: } else {
5167: $datatable .= '</span></td></tr><tr><td>'
5168: .'<span class="LC_nobreak">';
5169: }
5170: $datatable .= '<label><input type="radio" name="'
5171: .$parent.'" value="0" />'
5172: .&mt('Do not display').'</label></span>';
5173: if ($parent eq 'communities') {
5174: $datatable .= '</td></tr></table>';
5175: }
5176: $datatable .= '</td>';
1.57 raeburn 5177: } else {
5178: $datatable .= $parent
1.160.6.29 raeburn 5179: .' <span class="LC_nobreak"><label>'
5180: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5181: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5182: }
5183: my $depth = 1;
5184: push(@path,$parent);
5185: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5186: pop(@path);
5187: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5188: $itemcount ++;
5189: }
1.48 raeburn 5190: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5191: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5192: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5193: for (my $k=0; $k<=$maxnum; $k++) {
5194: my $vpos = $k+1;
5195: my $selstr;
1.57 raeburn 5196: if ($k == $numtop) {
1.48 raeburn 5197: $selstr = ' selected="selected" ';
5198: }
5199: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5200: }
1.59 bisitz 5201: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5202: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5203: .'</tr>'."\n";
1.48 raeburn 5204: $itemcount ++;
1.120 raeburn 5205: foreach my $default ('instcode','communities') {
5206: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5207: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5208: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5209: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5210: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5211: for (my $k=0; $k<=$maxnum; $k++) {
5212: my $vpos = $k+1;
5213: my $selstr;
5214: if ($k == $maxnum) {
5215: $selstr = ' selected="selected" ';
5216: }
5217: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5218: }
1.120 raeburn 5219: $datatable .= '</select></span></td>'.
5220: '<td><span class="LC_nobreak">'.
5221: $default_names{$default}.'</span>';
5222: if ($default eq 'instcode') {
5223: $datatable .= '<br /><span class="LC_nobreak">('
5224: .&mt('with institutional codes').')</span>';
5225: }
5226: $datatable .= '</td>'
5227: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5228: .&mt('Display').'</label> '
5229: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5230: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5231: }
5232: }
5233: }
1.57 raeburn 5234: } else {
5235: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5236: }
5237: } else {
1.160.6.42 raeburn 5238: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5239: .&initialize_categories($itemcount);
1.48 raeburn 5240: }
1.57 raeburn 5241: $$rowtotal += $itemcount;
1.48 raeburn 5242: }
5243: return $datatable;
5244: }
5245:
1.69 raeburn 5246: sub print_serverstatuses {
5247: my ($dom,$settings,$rowtotal) = @_;
5248: my $datatable;
5249: my @pages = &serverstatus_pages();
5250: my (%namedaccess,%machineaccess);
5251: foreach my $type (@pages) {
5252: $namedaccess{$type} = '';
5253: $machineaccess{$type}= '';
5254: }
5255: if (ref($settings) eq 'HASH') {
5256: foreach my $type (@pages) {
5257: if (exists($settings->{$type})) {
5258: if (ref($settings->{$type}) eq 'HASH') {
5259: foreach my $key (keys(%{$settings->{$type}})) {
5260: if ($key eq 'namedusers') {
5261: $namedaccess{$type} = $settings->{$type}->{$key};
5262: } elsif ($key eq 'machines') {
5263: $machineaccess{$type} = $settings->{$type}->{$key};
5264: }
5265: }
5266: }
5267: }
5268: }
5269: }
1.81 raeburn 5270: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5271: my $rownum = 0;
5272: my $css_class;
5273: foreach my $type (@pages) {
5274: $rownum ++;
5275: $css_class = $rownum%2?' class="LC_odd_row"':'';
5276: $datatable .= '<tr'.$css_class.'>'.
5277: '<td><span class="LC_nobreak">'.
5278: $titles->{$type}.'</span></td>'.
5279: '<td class="LC_left_item">'.
5280: '<input type="text" name="'.$type.'_namedusers" '.
5281: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5282: '<td class="LC_right_item">'.
5283: '<span class="LC_nobreak">'.
5284: '<input type="text" name="'.$type.'_machines" '.
5285: 'value="'.$machineaccess{$type}.'" size="10" />'.
5286: '</td></tr>'."\n";
5287: }
5288: $$rowtotal += $rownum;
5289: return $datatable;
5290: }
5291:
5292: sub serverstatus_pages {
5293: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 5294: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 5295: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.36 raeburn 5296: 'uniquecodes','diskusage');
1.69 raeburn 5297: }
5298:
1.160.6.40 raeburn 5299: sub defaults_javascript {
5300: my ($settings) = @_;
1.160.6.51 raeburn 5301: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 5302: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5303: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5304: if ($maxnum eq '') {
5305: $maxnum = 0;
5306: }
5307: $maxnum ++;
1.160.6.51 raeburn 5308: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 5309: return <<"ENDSCRIPT";
5310: <script type="text/javascript">
5311: // <![CDATA[
5312: function reorderTypes(form,caller) {
5313: var changedVal;
5314: $jstext
5315: var newpos = 'addinststatus_pos';
5316: var current = new Array;
5317: var maxh = $maxnum;
5318: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5319: var oldVal;
5320: if (caller == newpos) {
5321: changedVal = newitemVal;
5322: } else {
5323: var curritem = 'inststatus_pos_'+caller;
5324: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5325: current[newitemVal] = newpos;
5326: }
5327: for (var i=0; i<inststatuses.length; i++) {
5328: if (inststatuses[i] != caller) {
5329: var elementName = 'inststatus_pos_'+inststatuses[i];
5330: if (form.elements[elementName]) {
5331: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5332: current[currVal] = elementName;
5333: }
5334: }
5335: }
5336: for (var j=0; j<maxh; j++) {
5337: if (current[j] == undefined) {
5338: oldVal = j;
5339: }
5340: }
5341: if (oldVal < changedVal) {
5342: for (var k=oldVal+1; k<=changedVal ; k++) {
5343: var elementName = current[k];
5344: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5345: }
5346: } else {
5347: for (var k=changedVal; k<oldVal; k++) {
5348: var elementName = current[k];
5349: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5350: }
5351: }
5352: return;
5353: }
5354:
5355: // ]]>
5356: </script>
5357:
5358: ENDSCRIPT
5359: }
5360: }
5361:
1.49 raeburn 5362: sub coursecategories_javascript {
5363: my ($settings) = @_;
1.57 raeburn 5364: my ($output,$jstext,$cathash);
1.49 raeburn 5365: if (ref($settings) eq 'HASH') {
1.57 raeburn 5366: $cathash = $settings->{'cats'};
5367: }
5368: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5369: my (@cats,@jsarray,%idx);
1.57 raeburn 5370: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5371: if (@jsarray > 0) {
5372: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5373: for (my $i=0; $i<@jsarray; $i++) {
5374: if (ref($jsarray[$i]) eq 'ARRAY') {
5375: my $catstr = join('","',@{$jsarray[$i]});
5376: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5377: }
5378: }
5379: }
5380: } else {
5381: $jstext = ' var categories = Array(1);'."\n".
5382: ' categories[0] = Array("instcode_pos");'."\n";
5383: }
1.160.6.42 raeburn 5384: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5385: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
5386: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.');
1.49 raeburn 5387: $output = <<"ENDSCRIPT";
5388: <script type="text/javascript">
1.109 raeburn 5389: // <![CDATA[
1.49 raeburn 5390: function reorderCats(form,parent,item,idx) {
5391: var changedVal;
5392: $jstext
5393: var newpos = 'addcategory_pos';
5394: if (parent == '') {
5395: var has_instcode = 0;
5396: var maxtop = categories[idx].length;
5397: for (var j=0; j<maxtop; j++) {
5398: if (categories[idx][j] == 'instcode::0') {
5399: has_instcode == 1;
5400: }
5401: }
5402: if (has_instcode == 0) {
5403: categories[idx][maxtop] = 'instcode_pos';
5404: }
5405: } else {
5406: newpos += '_'+parent;
5407: }
5408: var maxh = 1 + categories[idx].length;
5409: var current = new Array;
5410: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5411: if (item == newpos) {
5412: changedVal = newitemVal;
5413: } else {
5414: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5415: current[newitemVal] = newpos;
5416: }
5417: for (var i=0; i<categories[idx].length; i++) {
5418: var elementName = categories[idx][i];
5419: if (elementName != item) {
5420: if (form.elements[elementName]) {
5421: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5422: current[currVal] = elementName;
5423: }
5424: }
5425: }
5426: var oldVal;
5427: for (var j=0; j<maxh; j++) {
5428: if (current[j] == undefined) {
5429: oldVal = j;
5430: }
5431: }
5432: if (oldVal < changedVal) {
5433: for (var k=oldVal+1; k<=changedVal ; k++) {
5434: var elementName = current[k];
5435: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5436: }
5437: } else {
5438: for (var k=changedVal; k<oldVal; k++) {
5439: var elementName = current[k];
5440: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5441: }
5442: }
5443: return;
5444: }
1.120 raeburn 5445:
5446: function categoryCheck(form) {
5447: if (form.elements['addcategory_name'].value == 'instcode') {
5448: alert('$instcode_reserved\\n$choose_again');
5449: return false;
5450: }
5451: if (form.elements['addcategory_name'].value == 'communities') {
5452: alert('$communities_reserved\\n$choose_again');
5453: return false;
5454: }
5455: return true;
5456: }
5457:
1.109 raeburn 5458: // ]]>
1.49 raeburn 5459: </script>
5460:
5461: ENDSCRIPT
5462: return $output;
5463: }
5464:
1.48 raeburn 5465: sub initialize_categories {
5466: my ($itemcount) = @_;
1.120 raeburn 5467: my ($datatable,$css_class,$chgstr);
5468: my %default_names = (
5469: instcode => 'Official courses (with institutional codes)',
5470: communities => 'Communities',
5471: );
5472: my $select0 = ' selected="selected"';
5473: my $select1 = '';
5474: foreach my $default ('instcode','communities') {
5475: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5476: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5477: if ($default eq 'communities') {
5478: $select1 = $select0;
5479: $select0 = '';
5480: }
5481: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5482: .'<select name="'.$default.'_pos">'
5483: .'<option value="0"'.$select0.'>1</option>'
5484: .'<option value="1"'.$select1.'>2</option>'
5485: .'<option value="2">3</option></select> '
5486: .$default_names{$default}
5487: .'</span></td><td><span class="LC_nobreak">'
5488: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5489: .&mt('Display').'</label> <label>'
5490: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5491: .'</label></span></td></tr>';
1.120 raeburn 5492: $itemcount ++;
5493: }
1.48 raeburn 5494: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5495: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5496: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5497: .'<select name="addcategory_pos"'.$chgstr.'>'
5498: .'<option value="0">1</option>'
5499: .'<option value="1">2</option>'
5500: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5501: .&mt('Add category').'</td><td>'.&mt('Name:')
5502: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5503: return $datatable;
5504: }
5505:
5506: sub build_category_rows {
1.49 raeburn 5507: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5508: my ($text,$name,$item,$chgstr);
1.48 raeburn 5509: if (ref($cats) eq 'ARRAY') {
5510: my $maxdepth = scalar(@{$cats});
5511: if (ref($cats->[$depth]) eq 'HASH') {
5512: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5513: my $numchildren = @{$cats->[$depth]{$parent}};
5514: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 5515: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5516: my ($idxnum,$parent_name,$parent_item);
5517: my $higher = $depth - 1;
5518: if ($higher == 0) {
5519: $parent_name = &escape($parent).'::'.$higher;
5520: } else {
5521: if (ref($path) eq 'ARRAY') {
5522: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5523: }
5524: }
5525: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5526: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5527: if ($j < $numchildren) {
1.48 raeburn 5528: $name = $cats->[$depth]{$parent}[$j];
5529: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5530: $idxnum = $idx->{$item};
5531: } else {
5532: $name = $parent_name;
5533: $item = $parent_item;
1.48 raeburn 5534: }
1.49 raeburn 5535: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5536: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5537: for (my $i=0; $i<=$numchildren; $i++) {
5538: my $vpos = $i+1;
5539: my $selstr;
5540: if ($j == $i) {
5541: $selstr = ' selected="selected" ';
5542: }
5543: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5544: }
5545: $text .= '</select> ';
5546: if ($j < $numchildren) {
5547: my $deeper = $depth+1;
5548: $text .= $name.' '
5549: .'<label><input type="checkbox" name="deletecategory" value="'
5550: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5551: if(ref($path) eq 'ARRAY') {
5552: push(@{$path},$name);
1.49 raeburn 5553: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5554: pop(@{$path});
5555: }
5556: } else {
1.59 bisitz 5557: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5558: if ($j == $numchildren) {
5559: $text .= $name;
5560: } else {
5561: $text .= $item;
5562: }
5563: $text .= '" value="" />';
5564: }
5565: $text .= '</td></tr>';
5566: }
5567: $text .= '</table></td>';
5568: } else {
5569: my $higher = $depth-1;
5570: if ($higher == 0) {
5571: $name = &escape($parent).'::'.$higher;
5572: } else {
5573: if (ref($path) eq 'ARRAY') {
5574: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5575: }
5576: }
5577: my $colspan;
5578: if ($parent ne 'instcode') {
5579: $colspan = $maxdepth - $depth - 1;
5580: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5581: }
5582: }
5583: }
5584: }
5585: return $text;
5586: }
5587:
1.33 raeburn 5588: sub modifiable_userdata_row {
1.160.6.35 raeburn 5589: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5590: my ($role,$rolename,$statustype);
5591: $role = $item;
1.160.6.34 raeburn 5592: if ($context eq 'cancreate') {
1.160.6.35 raeburn 5593: if ($item =~ /^emailusername_(.+)$/) {
5594: $statustype = $1;
5595: $role = 'emailusername';
5596: if (ref($usertypes) eq 'HASH') {
5597: if ($usertypes->{$statustype}) {
5598: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5599: } else {
5600: $rolename = &mt('Data provided by user');
5601: }
5602: }
1.160.6.34 raeburn 5603: }
5604: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5605: if (ref($usertypes) eq 'HASH') {
5606: $rolename = $usertypes->{$role};
5607: } else {
5608: $rolename = $role;
5609: }
1.33 raeburn 5610: } else {
1.63 raeburn 5611: if ($role eq 'cr') {
5612: $rolename = &mt('Custom role');
5613: } else {
5614: $rolename = &Apache::lonnet::plaintext($role);
5615: }
1.33 raeburn 5616: }
1.160.6.34 raeburn 5617: my (@fields,%fieldtitles);
5618: if (ref($fieldsref) eq 'ARRAY') {
5619: @fields = @{$fieldsref};
5620: } else {
5621: @fields = ('lastname','firstname','middlename','generation',
5622: 'permanentemail','id');
5623: }
5624: if ((ref($titlesref) eq 'HASH')) {
5625: %fieldtitles = %{$titlesref};
5626: } else {
5627: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5628: }
1.33 raeburn 5629: my $output;
5630: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5631: $output = '<tr '.$css_class.'>'.
5632: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5633: '<td class="LC_left_item" colspan="2"><table>';
5634: my $rem;
5635: my %checks;
5636: if (ref($settings) eq 'HASH') {
5637: if (ref($settings->{$context}) eq 'HASH') {
5638: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 5639: my $hashref = $settings->{$context}->{$role};
5640: if ($role eq 'emailusername') {
5641: if ($statustype) {
5642: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5643: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 5644: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 5645: foreach my $field (@fields) {
5646: if ($hashref->{$field}) {
5647: $checks{$field} = $hashref->{$field};
5648: }
5649: }
5650: }
5651: }
5652: }
5653: } else {
5654: if (ref($hashref) eq 'HASH') {
5655: foreach my $field (@fields) {
5656: if ($hashref->{$field}) {
5657: $checks{$field} = ' checked="checked" ';
5658: }
5659: }
1.33 raeburn 5660: }
5661: }
5662: }
5663: }
5664: }
1.160.6.39 raeburn 5665:
1.33 raeburn 5666: for (my $i=0; $i<@fields; $i++) {
5667: my $rem = $i%($numinrow);
5668: if ($rem == 0) {
5669: if ($i > 0) {
5670: $output .= '</tr>';
5671: }
5672: $output .= '<tr>';
5673: }
5674: my $check = ' ';
1.160.6.35 raeburn 5675: unless ($role eq 'emailusername') {
5676: if (exists($checks{$fields[$i]})) {
5677: $check = $checks{$fields[$i]}
5678: } else {
5679: if ($role eq 'st') {
5680: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 5681: $check = ' checked="checked" ';
1.160.6.35 raeburn 5682: }
1.33 raeburn 5683: }
5684: }
5685: }
5686: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 5687: '<span class="LC_nobreak">';
5688: if ($role eq 'emailusername') {
5689: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5690: $checks{$fields[$i]} = 'omit';
5691: }
5692: foreach my $option ('required','optional','omit') {
5693: my $checked='';
5694: if ($checks{$fields[$i]} eq $option) {
5695: $checked='checked="checked" ';
5696: }
5697: $output .= '<label>'.
5698: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5699: &mt($option).'</label>'.(' ' x2);
5700: }
5701: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5702: } else {
5703: $output .= '<label>'.
5704: '<input type="checkbox" name="canmodify_'.$role.'" '.
5705: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5706: '</label>';
5707: }
5708: $output .= '</span></td>';
1.33 raeburn 5709: $rem = @fields%($numinrow);
5710: }
5711: my $colsleft = $numinrow - $rem;
5712: if ($colsleft > 1 ) {
5713: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5714: ' </td>';
5715: } elsif ($colsleft == 1) {
5716: $output .= '<td class="LC_left_item"> </td>';
5717: }
5718: $output .= '</tr></table></td></tr>';
5719: return $output;
5720: }
1.28 raeburn 5721:
1.93 raeburn 5722: sub insttypes_row {
1.160.6.34 raeburn 5723: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5724: my %lt = &Apache::lonlocal::texthash (
5725: cansearch => 'Users allowed to search',
5726: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5727: lockablenames => 'User preference to lock name',
1.93 raeburn 5728: );
5729: my $showdom;
5730: if ($context eq 'cansearch') {
5731: $showdom = ' ('.$dom.')';
5732: }
1.160.6.5 raeburn 5733: my $class = 'LC_left_item';
5734: if ($context eq 'statustocreate') {
5735: $class = 'LC_right_item';
5736: }
1.160.6.34 raeburn 5737: my $css_class = ' class="LC_odd_row"';
5738: if ($rownum ne '') {
5739: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5740: }
5741: my $output = '<tr'.$css_class.'>'.
5742: '<td>'.$lt{$context}.$showdom.
5743: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5744: my $rem;
5745: if (ref($types) eq 'ARRAY') {
5746: for (my $i=0; $i<@{$types}; $i++) {
5747: if (defined($usertypes->{$types->[$i]})) {
5748: my $rem = $i%($numinrow);
5749: if ($rem == 0) {
5750: if ($i > 0) {
5751: $output .= '</tr>';
5752: }
5753: $output .= '<tr>';
1.23 raeburn 5754: }
1.26 raeburn 5755: my $check = ' ';
1.99 raeburn 5756: if (ref($settings) eq 'HASH') {
5757: if (ref($settings->{$context}) eq 'ARRAY') {
5758: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5759: $check = ' checked="checked" ';
5760: }
5761: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5762: $check = ' checked="checked" ';
5763: }
1.23 raeburn 5764: }
1.26 raeburn 5765: $output .= '<td class="LC_left_item">'.
5766: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5767: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5768: 'value="'.$types->[$i].'"'.$check.'/>'.
5769: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5770: }
5771: }
1.26 raeburn 5772: $rem = @{$types}%($numinrow);
1.23 raeburn 5773: }
5774: my $colsleft = $numinrow - $rem;
1.131 raeburn 5775: if (($rem == 0) && (@{$types} > 0)) {
5776: $output .= '<tr>';
5777: }
1.23 raeburn 5778: if ($colsleft > 1) {
1.25 raeburn 5779: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5780: } else {
1.25 raeburn 5781: $output .= '<td class="LC_left_item">';
1.23 raeburn 5782: }
5783: my $defcheck = ' ';
1.99 raeburn 5784: if (ref($settings) eq 'HASH') {
5785: if (ref($settings->{$context}) eq 'ARRAY') {
5786: if (grep(/^default$/,@{$settings->{$context}})) {
5787: $defcheck = ' checked="checked" ';
5788: }
5789: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5790: $defcheck = ' checked="checked" ';
5791: }
1.23 raeburn 5792: }
1.25 raeburn 5793: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5794: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5795: 'value="default"'.$defcheck.'/>'.
5796: $othertitle.'</label></span></td>'.
5797: '</tr></table></td></tr>';
5798: return $output;
1.23 raeburn 5799: }
5800:
5801: sub sorted_searchtitles {
5802: my %searchtitles = &Apache::lonlocal::texthash(
5803: 'uname' => 'username',
5804: 'lastname' => 'last name',
5805: 'lastfirst' => 'last name, first name',
5806: );
5807: my @titleorder = ('uname','lastname','lastfirst');
5808: return (\%searchtitles,\@titleorder);
5809: }
5810:
1.25 raeburn 5811: sub sorted_searchtypes {
5812: my %srchtypes_desc = (
5813: exact => 'is exact match',
5814: contains => 'contains ..',
5815: begins => 'begins with ..',
5816: );
5817: my @srchtypeorder = ('exact','begins','contains');
5818: return (\%srchtypes_desc,\@srchtypeorder);
5819: }
5820:
1.3 raeburn 5821: sub usertype_update_row {
5822: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5823: my $datatable;
5824: my $numinrow = 4;
5825: foreach my $type (@{$types}) {
5826: if (defined($usertypes->{$type})) {
5827: $$rownums ++;
5828: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5829: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5830: '</td><td class="LC_left_item"><table>';
5831: for (my $i=0; $i<@{$fields}; $i++) {
5832: my $rem = $i%($numinrow);
5833: if ($rem == 0) {
5834: if ($i > 0) {
5835: $datatable .= '</tr>';
5836: }
5837: $datatable .= '<tr>';
5838: }
5839: my $check = ' ';
1.39 raeburn 5840: if (ref($settings) eq 'HASH') {
5841: if (ref($settings->{'fields'}) eq 'HASH') {
5842: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5843: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5844: $check = ' checked="checked" ';
5845: }
1.3 raeburn 5846: }
5847: }
5848: }
5849:
5850: if ($i == @{$fields}-1) {
5851: my $colsleft = $numinrow - $rem;
5852: if ($colsleft > 1) {
5853: $datatable .= '<td colspan="'.$colsleft.'">';
5854: } else {
5855: $datatable .= '<td>';
5856: }
5857: } else {
5858: $datatable .= '<td>';
5859: }
1.8 raeburn 5860: $datatable .= '<span class="LC_nobreak"><label>'.
5861: '<input type="checkbox" name="updateable_'.$type.
5862: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5863: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5864: }
5865: $datatable .= '</tr></table></td></tr>';
5866: }
5867: }
5868: return $datatable;
1.1 raeburn 5869: }
5870:
5871: sub modify_login {
1.160.6.24 raeburn 5872: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 5873: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5874: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5875: %title = ( coursecatalog => 'Display course catalog',
5876: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 5877: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 5878: newuser => 'Link for visitors to create a user account',
5879: loginheader => 'Log-in box header');
5880: @offon = ('off','on');
1.112 raeburn 5881: if (ref($domconfig{login}) eq 'HASH') {
5882: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5883: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5884: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5885: }
5886: }
5887: }
1.9 raeburn 5888: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5889: \%domconfig,\%loginhash);
1.160.6.14 raeburn 5890: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5891: foreach my $item (@toggles) {
5892: $loginhash{login}{$item} = $env{'form.'.$item};
5893: }
1.41 raeburn 5894: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5895: if (ref($colchanges{'login'}) eq 'HASH') {
5896: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5897: \%loginhash);
5898: }
1.110 raeburn 5899:
1.149 raeburn 5900: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 5901: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 5902: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5903: if (keys(%servers) > 1) {
5904: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5905: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5906: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5907: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5908: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5909: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5910: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5911: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5912: $changes{'loginvia'}{$lonhost} = 1;
5913: } else {
5914: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5915: $changes{'loginvia'}{$lonhost} = 1;
5916: }
5917: } else {
5918: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5919: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5920: $changes{'loginvia'}{$lonhost} = 1;
5921: }
5922: }
5923: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5924: foreach my $item (@loginvia_attribs) {
5925: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5926: }
5927: } else {
5928: foreach my $item (@loginvia_attribs) {
5929: my $new = $env{'form.'.$lonhost.'_'.$item};
5930: if (($item eq 'serverpath') && ($new eq 'custom')) {
5931: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5932: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5933: $new = '/';
5934: }
5935: }
5936: if (($item eq 'custompath') &&
5937: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5938: $new = '';
5939: }
5940: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5941: $changes{'loginvia'}{$lonhost} = 1;
5942: }
5943: if ($item eq 'exempt') {
1.160.6.56 raeburn 5944: $new = &check_exempt_addresses($new);
1.128 raeburn 5945: }
5946: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5947: }
5948: }
1.112 raeburn 5949: } else {
1.128 raeburn 5950: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5951: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5952: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5953: foreach my $item (@loginvia_attribs) {
5954: my $new = $env{'form.'.$lonhost.'_'.$item};
5955: if (($item eq 'serverpath') && ($new eq 'custom')) {
5956: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5957: $new = '/';
5958: }
5959: }
5960: if (($item eq 'custompath') &&
5961: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5962: $new = '';
5963: }
5964: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5965: }
1.110 raeburn 5966: }
5967: }
5968: }
5969: }
1.119 raeburn 5970:
1.160.6.5 raeburn 5971: my $servadm = $r->dir_config('lonAdmEMail');
5972: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5973: if (ref($domconfig{'login'}) eq 'HASH') {
5974: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5975: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5976: if ($lang eq 'nolang') {
5977: push(@currlangs,$lang);
5978: } elsif (defined($langchoices{$lang})) {
5979: push(@currlangs,$lang);
5980: } else {
5981: next;
5982: }
5983: }
5984: }
5985: }
5986: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5987: if (@currlangs > 0) {
5988: foreach my $lang (@currlangs) {
5989: if (grep(/^\Q$lang\E$/,@delurls)) {
5990: $changes{'helpurl'}{$lang} = 1;
5991: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5992: $changes{'helpurl'}{$lang} = 1;
5993: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5994: push(@newlangs,$lang);
5995: } else {
5996: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5997: }
5998: }
5999: }
6000: unless (grep(/^nolang$/,@currlangs)) {
6001: if ($env{'form.loginhelpurl_nolang.filename'}) {
6002: $changes{'helpurl'}{'nolang'} = 1;
6003: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6004: push(@newlangs,'nolang');
6005: }
6006: }
6007: if ($env{'form.loginhelpurl_add_lang'}) {
6008: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6009: ($env{'form.loginhelpurl_add_file.filename'})) {
6010: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6011: $addedfile = $env{'form.loginhelpurl_add_lang'};
6012: }
6013: }
6014: if ((@newlangs > 0) || ($addedfile)) {
6015: my $error;
6016: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6017: if ($configuserok eq 'ok') {
6018: if ($switchserver) {
6019: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6020: } elsif ($author_ok eq 'ok') {
6021: my @allnew = @newlangs;
6022: if ($addedfile ne '') {
6023: push(@allnew,$addedfile);
6024: }
6025: foreach my $lang (@allnew) {
6026: my $formelem = 'loginhelpurl_'.$lang;
6027: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6028: $formelem = 'loginhelpurl_add_file';
6029: }
6030: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6031: "help/$lang",'','',$newfile{$lang});
6032: if ($result eq 'ok') {
6033: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6034: $changes{'helpurl'}{$lang} = 1;
6035: } else {
6036: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6037: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6038: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
6039: (!grep(/^\Q$lang\E$/,@delurls))) {
6040:
6041: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6042: }
6043: }
6044: }
6045: } else {
6046: $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);
6047: }
6048: } else {
6049: $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);
6050: }
6051: if ($error) {
6052: &Apache::lonnet::logthis($error);
6053: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6054: }
6055: }
1.160.6.56 raeburn 6056:
6057: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6058: if (ref($domconfig{'login'}) eq 'HASH') {
6059: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6060: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6061: if ($domservers{$lonhost}) {
6062: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6063: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
6064: $currexempt{$lonhost} = $domconfig{'login'}{'headtagexempt'}{$lonhost}{'exempt'}
6065: }
6066: }
6067: }
6068: }
6069: }
6070: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6071: foreach my $lonhost (sort(keys(%domservers))) {
6072: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6073: $changes{'headtag'}{$lonhost} = 1;
6074: } else {
6075: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6076: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6077: }
6078: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6079: push(@newhosts,$lonhost);
6080: } elsif ($currheadtagurls{$lonhost}) {
6081: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6082: if ($currexempt{$lonhost}) {
6083: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6084: $changes{'headtag'}{$lonhost} = 1;
6085: }
6086: } elsif ($possexempt{$lonhost}) {
6087: $changes{'headtag'}{$lonhost} = 1;
6088: }
6089: if ($possexempt{$lonhost}) {
6090: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6091: }
6092: }
6093: }
6094: }
6095: if (@newhosts) {
6096: my $error;
6097: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6098: if ($configuserok eq 'ok') {
6099: if ($switchserver) {
6100: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6101: } elsif ($author_ok eq 'ok') {
6102: foreach my $lonhost (@newhosts) {
6103: my $formelem = 'loginheadtag_'.$lonhost;
6104: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6105: "login/headtag/$lonhost",'','',
6106: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6107: if ($result eq 'ok') {
6108: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6109: $changes{'headtag'}{$lonhost} = 1;
6110: if ($possexempt{$lonhost}) {
6111: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6112: }
6113: } else {
6114: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6115: $newheadtagurls{$lonhost},$result);
6116: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6117: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
6118: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
6119: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
6120: }
6121: }
6122: }
6123: } else {
6124: $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);
6125: }
6126: } else {
6127: $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);
6128: }
6129: if ($error) {
6130: &Apache::lonnet::logthis($error);
6131: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6132: }
6133: }
6134:
1.160.6.5 raeburn 6135: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
6136:
6137: my $defaulthelpfile = '/adm/loginproblems.html';
6138: my $defaulttext = &mt('Default in use');
6139:
1.1 raeburn 6140: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
6141: $dom);
6142: if ($putresult eq 'ok') {
1.160.6.14 raeburn 6143: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6144: my %defaultchecked = (
6145: 'coursecatalog' => 'on',
1.160.6.14 raeburn 6146: 'helpdesk' => 'on',
1.42 raeburn 6147: 'adminmail' => 'off',
1.43 raeburn 6148: 'newuser' => 'off',
1.42 raeburn 6149: );
1.55 raeburn 6150: if (ref($domconfig{'login'}) eq 'HASH') {
6151: foreach my $item (@toggles) {
6152: if ($defaultchecked{$item} eq 'on') {
6153: if (($domconfig{'login'}{$item} eq '0') &&
6154: ($env{'form.'.$item} eq '1')) {
6155: $changes{$item} = 1;
6156: } elsif (($domconfig{'login'}{$item} eq '' ||
6157: $domconfig{'login'}{$item} eq '1') &&
6158: ($env{'form.'.$item} eq '0')) {
6159: $changes{$item} = 1;
6160: }
6161: } elsif ($defaultchecked{$item} eq 'off') {
6162: if (($domconfig{'login'}{$item} eq '1') &&
6163: ($env{'form.'.$item} eq '0')) {
6164: $changes{$item} = 1;
6165: } elsif (($domconfig{'login'}{$item} eq '' ||
6166: $domconfig{'login'}{$item} eq '0') &&
6167: ($env{'form.'.$item} eq '1')) {
6168: $changes{$item} = 1;
6169: }
1.42 raeburn 6170: }
6171: }
1.41 raeburn 6172: }
1.6 raeburn 6173: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 6174: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6175: if (ref($lastactref) eq 'HASH') {
6176: $lastactref->{'domainconfig'} = 1;
6177: }
1.1 raeburn 6178: $resulttext = &mt('Changes made:').'<ul>';
6179: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 6180: if ($item eq 'loginvia') {
1.112 raeburn 6181: if (ref($changes{$item}) eq 'HASH') {
6182: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
6183: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 6184: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
6185: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
6186: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
6187: $protocol = 'http' if ($protocol ne 'https');
6188: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
6189:
6190: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6191: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6192: } else {
6193: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6194: }
6195: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6196: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
6197: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
6198: }
6199: $resulttext .= '</li>';
6200: } else {
6201: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6202: }
1.112 raeburn 6203: } else {
1.128 raeburn 6204: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 6205: }
6206: }
1.128 raeburn 6207: $resulttext .= '</ul></li>';
1.112 raeburn 6208: }
1.160.6.5 raeburn 6209: } elsif ($item eq 'helpurl') {
6210: if (ref($changes{$item}) eq 'HASH') {
6211: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6212: if (grep(/^\Q$lang\E$/,@delurls)) {
6213: my ($chg,$link);
6214: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6215: if ($lang eq 'nolang') {
6216: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6217: } else {
6218: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6219: }
6220: $resulttext .= '<li>'.$chg.'</li>';
6221: } else {
6222: my $chg;
6223: if ($lang eq 'nolang') {
6224: $chg = &mt('custom log-in help file for no preferred language');
6225: } else {
6226: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6227: }
6228: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6229: $loginhash{'login'}{'helpurl'}{$lang}.
6230: '?inhibitmenu=yes',$chg,600,500).
6231: '</li>';
6232: }
6233: }
6234: }
1.160.6.56 raeburn 6235: } elsif ($item eq 'headtag') {
6236: if (ref($changes{$item}) eq 'HASH') {
6237: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
6238: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6239: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
6240: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6241: $resulttext .= '<li><a href="'.
6242: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
6243: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
6244: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
6245: if ($possexempt{$lonhost}) {
6246: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
6247: } else {
6248: $resulttext .= &mt('included for any client IP');
6249: }
6250: $resulttext .= '</li>';
6251: }
6252: }
6253: }
1.160.6.5 raeburn 6254: } elsif ($item eq 'captcha') {
6255: if (ref($loginhash{'login'}) eq 'HASH') {
6256: my $chgtxt;
6257: if ($loginhash{'login'}{$item} eq 'notused') {
6258: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6259: } else {
6260: my %captchas = &captcha_phrases();
6261: if ($captchas{$loginhash{'login'}{$item}}) {
6262: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6263: } else {
6264: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6265: }
6266: }
6267: $resulttext .= '<li>'.$chgtxt.'</li>';
6268: }
6269: } elsif ($item eq 'recaptchakeys') {
6270: if (ref($loginhash{'login'}) eq 'HASH') {
6271: my ($privkey,$pubkey);
6272: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6273: $pubkey = $loginhash{'login'}{$item}{'public'};
6274: $privkey = $loginhash{'login'}{$item}{'private'};
6275: }
6276: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6277: if (!$pubkey) {
6278: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6279: } else {
6280: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6281: }
6282: if (!$privkey) {
6283: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6284: } else {
1.160.6.53 raeburn 6285: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 6286: }
6287: $chgtxt .= '</ul>';
6288: $resulttext .= '<li>'.$chgtxt.'</li>';
6289: }
1.41 raeburn 6290: } else {
6291: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6292: }
1.1 raeburn 6293: }
1.6 raeburn 6294: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6295: } else {
6296: $resulttext = &mt('No changes made to log-in page settings');
6297: }
6298: } else {
1.11 albertel 6299: $resulttext = '<span class="LC_error">'.
6300: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6301: }
1.6 raeburn 6302: if ($errors) {
1.9 raeburn 6303: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6304: $errors.'</ul>';
6305: }
6306: return $resulttext;
6307: }
6308:
1.160.6.56 raeburn 6309: sub check_exempt_addresses {
6310: my ($iplist) = @_;
6311: $iplist =~ s/^\s+//;
6312: $iplist =~ s/\s+$//;
6313: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
6314: my (@okips,$new);
6315: foreach my $ip (@poss_ips) {
6316: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
6317: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
6318: push(@okips,$ip);
6319: }
6320: }
6321: }
6322: if (@okips > 0) {
6323: $new = join(',',@okips);
6324: } else {
6325: $new = '';
6326: }
6327: return $new;
6328: }
6329:
1.6 raeburn 6330: sub color_font_choices {
6331: my %choices =
6332: &Apache::lonlocal::texthash (
6333: img => "Header",
6334: bgs => "Background colors",
6335: links => "Link colors",
1.55 raeburn 6336: images => "Images",
1.6 raeburn 6337: font => "Font color",
1.160.6.22 raeburn 6338: fontmenu => "Font menu",
1.76 raeburn 6339: pgbg => "Page",
1.6 raeburn 6340: tabbg => "Header",
6341: sidebg => "Border",
6342: link => "Link",
6343: alink => "Active link",
6344: vlink => "Visited link",
6345: );
6346: return %choices;
6347: }
6348:
6349: sub modify_rolecolors {
1.160.6.24 raeburn 6350: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6351: my ($resulttext,%rolehash);
6352: $rolehash{'rolecolors'} = {};
1.55 raeburn 6353: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6354: if ($domconfig{'rolecolors'} eq '') {
6355: $domconfig{'rolecolors'} = {};
6356: }
6357: }
1.9 raeburn 6358: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6359: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6360: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6361: $dom);
6362: if ($putresult eq 'ok') {
6363: if (keys(%changes) > 0) {
1.41 raeburn 6364: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6365: if (ref($lastactref) eq 'HASH') {
6366: $lastactref->{'domainconfig'} = 1;
6367: }
1.6 raeburn 6368: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6369: $rolehash{'rolecolors'});
6370: } else {
6371: $resulttext = &mt('No changes made to default color schemes');
6372: }
6373: } else {
1.11 albertel 6374: $resulttext = '<span class="LC_error">'.
6375: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6376: }
6377: if ($errors) {
6378: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6379: $errors.'</ul>';
6380: }
6381: return $resulttext;
6382: }
6383:
6384: sub modify_colors {
1.9 raeburn 6385: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6386: my (%changes,%choices);
1.51 raeburn 6387: my @bgs;
1.6 raeburn 6388: my @links = ('link','alink','vlink');
1.41 raeburn 6389: my @logintext;
1.6 raeburn 6390: my @images;
6391: my $servadm = $r->dir_config('lonAdmEMail');
6392: my $errors;
1.160.6.22 raeburn 6393: my %defaults;
1.6 raeburn 6394: foreach my $role (@{$roles}) {
6395: if ($role eq 'login') {
1.12 raeburn 6396: %choices = &login_choices();
1.41 raeburn 6397: @logintext = ('textcol','bgcol');
1.12 raeburn 6398: } else {
6399: %choices = &color_font_choices();
6400: }
6401: if ($role eq 'login') {
1.41 raeburn 6402: @images = ('img','logo','domlogo','login');
1.51 raeburn 6403: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6404: } else {
6405: @images = ('img');
1.160.6.22 raeburn 6406: @bgs = ('pgbg','tabbg','sidebg');
6407: }
6408: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6409: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6410: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6411: }
6412: if ($role eq 'login') {
6413: foreach my $item (@logintext) {
1.160.6.39 raeburn 6414: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6415: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6416: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6417: }
6418: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 6419: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6420: }
6421: }
6422: } else {
1.160.6.39 raeburn 6423: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6424: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6425: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6426: }
6427: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 6428: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6429: }
1.6 raeburn 6430: }
1.160.6.22 raeburn 6431: foreach my $item (@bgs) {
1.160.6.39 raeburn 6432: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6433: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6434: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6435: }
6436: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 6437: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6438: }
6439: }
6440: foreach my $item (@links) {
1.160.6.39 raeburn 6441: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6442: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6443: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6444: }
6445: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 6446: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6447: }
1.6 raeburn 6448: }
1.46 raeburn 6449: my ($configuserok,$author_ok,$switchserver) =
6450: &config_check($dom,$confname,$servadm);
1.9 raeburn 6451: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6452: if (ref($domconfig->{$role}) ne 'HASH') {
6453: $domconfig->{$role} = {};
6454: }
1.8 raeburn 6455: foreach my $img (@images) {
1.70 raeburn 6456: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6457: if (defined($env{'form.login_showlogo_'.$img})) {
6458: $confhash->{$role}{'showlogo'}{$img} = 1;
6459: } else {
6460: $confhash->{$role}{'showlogo'}{$img} = 0;
6461: }
6462: }
1.18 albertel 6463: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6464: && !defined($domconfig->{$role}{$img})
6465: && !$env{'form.'.$role.'_del_'.$img}
6466: && $env{'form.'.$role.'_import_'.$img}) {
6467: # import the old configured image from the .tab setting
6468: # if they haven't provided a new one
6469: $domconfig->{$role}{$img} =
6470: $env{'form.'.$role.'_import_'.$img};
6471: }
1.6 raeburn 6472: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6473: my $error;
1.6 raeburn 6474: if ($configuserok eq 'ok') {
1.9 raeburn 6475: if ($switchserver) {
1.12 raeburn 6476: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6477: } else {
6478: if ($author_ok eq 'ok') {
6479: my ($result,$logourl) =
6480: &publishlogo($r,'upload',$role.'_'.$img,
6481: $dom,$confname,$img,$width,$height);
6482: if ($result eq 'ok') {
6483: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6484: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6485: } else {
1.12 raeburn 6486: $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 6487: }
6488: } else {
1.46 raeburn 6489: $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 6490: }
6491: }
6492: } else {
1.46 raeburn 6493: $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 6494: }
6495: if ($error) {
1.8 raeburn 6496: &Apache::lonnet::logthis($error);
1.11 albertel 6497: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6498: }
6499: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6500: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6501: my $error;
6502: if ($configuserok eq 'ok') {
6503: # is confname an author?
6504: if ($switchserver eq '') {
6505: if ($author_ok eq 'ok') {
6506: my ($result,$logourl) =
6507: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6508: $dom,$confname,$img,$width,$height);
6509: if ($result eq 'ok') {
6510: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6511: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6512: }
6513: }
6514: }
6515: }
1.6 raeburn 6516: }
6517: }
6518: }
6519: if (ref($domconfig) eq 'HASH') {
6520: if (ref($domconfig->{$role}) eq 'HASH') {
6521: foreach my $img (@images) {
6522: if ($domconfig->{$role}{$img} ne '') {
6523: if ($env{'form.'.$role.'_del_'.$img}) {
6524: $confhash->{$role}{$img} = '';
1.12 raeburn 6525: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6526: } else {
1.9 raeburn 6527: if ($confhash->{$role}{$img} eq '') {
6528: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6529: }
1.6 raeburn 6530: }
6531: } else {
6532: if ($env{'form.'.$role.'_del_'.$img}) {
6533: $confhash->{$role}{$img} = '';
1.12 raeburn 6534: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6535: }
6536: }
1.70 raeburn 6537: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6538: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6539: if ($confhash->{$role}{'showlogo'}{$img} ne
6540: $domconfig->{$role}{'showlogo'}{$img}) {
6541: $changes{$role}{'showlogo'}{$img} = 1;
6542: }
6543: } else {
6544: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6545: $changes{$role}{'showlogo'}{$img} = 1;
6546: }
6547: }
6548: }
6549: }
1.6 raeburn 6550: if ($domconfig->{$role}{'font'} ne '') {
6551: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6552: $changes{$role}{'font'} = 1;
6553: }
6554: } else {
6555: if ($confhash->{$role}{'font'}) {
6556: $changes{$role}{'font'} = 1;
6557: }
6558: }
1.107 raeburn 6559: if ($role ne 'login') {
6560: if ($domconfig->{$role}{'fontmenu'} ne '') {
6561: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6562: $changes{$role}{'fontmenu'} = 1;
6563: }
6564: } else {
6565: if ($confhash->{$role}{'fontmenu'}) {
6566: $changes{$role}{'fontmenu'} = 1;
6567: }
1.97 tempelho 6568: }
6569: }
1.6 raeburn 6570: foreach my $item (@bgs) {
6571: if ($domconfig->{$role}{$item} ne '') {
6572: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6573: $changes{$role}{'bgs'}{$item} = 1;
6574: }
6575: } else {
6576: if ($confhash->{$role}{$item}) {
6577: $changes{$role}{'bgs'}{$item} = 1;
6578: }
6579: }
6580: }
6581: foreach my $item (@links) {
6582: if ($domconfig->{$role}{$item} ne '') {
6583: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6584: $changes{$role}{'links'}{$item} = 1;
6585: }
6586: } else {
6587: if ($confhash->{$role}{$item}) {
6588: $changes{$role}{'links'}{$item} = 1;
6589: }
6590: }
6591: }
1.41 raeburn 6592: foreach my $item (@logintext) {
6593: if ($domconfig->{$role}{$item} ne '') {
6594: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6595: $changes{$role}{'logintext'}{$item} = 1;
6596: }
6597: } else {
6598: if ($confhash->{$role}{$item}) {
6599: $changes{$role}{'logintext'}{$item} = 1;
6600: }
6601: }
6602: }
1.6 raeburn 6603: } else {
6604: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6605: \@logintext,$confhash,\%changes);
1.6 raeburn 6606: }
6607: } else {
6608: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6609: \@logintext,$confhash,\%changes);
1.6 raeburn 6610: }
6611: }
6612: return ($errors,%changes);
6613: }
6614:
1.46 raeburn 6615: sub config_check {
6616: my ($dom,$confname,$servadm) = @_;
6617: my ($configuserok,$author_ok,$switchserver,%currroles);
6618: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6619: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6620: $confname,$servadm);
6621: if ($configuserok eq 'ok') {
6622: $switchserver = &check_switchserver($dom,$confname);
6623: if ($switchserver eq '') {
6624: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6625: }
6626: }
6627: return ($configuserok,$author_ok,$switchserver);
6628: }
6629:
1.6 raeburn 6630: sub default_change_checker {
1.41 raeburn 6631: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6632: foreach my $item (@{$links}) {
6633: if ($confhash->{$role}{$item}) {
6634: $changes->{$role}{'links'}{$item} = 1;
6635: }
6636: }
6637: foreach my $item (@{$bgs}) {
6638: if ($confhash->{$role}{$item}) {
6639: $changes->{$role}{'bgs'}{$item} = 1;
6640: }
6641: }
1.41 raeburn 6642: foreach my $item (@{$logintext}) {
6643: if ($confhash->{$role}{$item}) {
6644: $changes->{$role}{'logintext'}{$item} = 1;
6645: }
6646: }
1.6 raeburn 6647: foreach my $img (@{$images}) {
6648: if ($env{'form.'.$role.'_del_'.$img}) {
6649: $confhash->{$role}{$img} = '';
1.12 raeburn 6650: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6651: }
1.70 raeburn 6652: if ($role eq 'login') {
6653: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6654: $changes->{$role}{'showlogo'}{$img} = 1;
6655: }
6656: }
1.6 raeburn 6657: }
6658: if ($confhash->{$role}{'font'}) {
6659: $changes->{$role}{'font'} = 1;
6660: }
1.48 raeburn 6661: }
1.6 raeburn 6662:
6663: sub display_colorchgs {
6664: my ($dom,$changes,$roles,$confhash) = @_;
6665: my (%choices,$resulttext);
6666: if (!grep(/^login$/,@{$roles})) {
6667: $resulttext = &mt('Changes made:').'<br />';
6668: }
6669: foreach my $role (@{$roles}) {
6670: if ($role eq 'login') {
6671: %choices = &login_choices();
6672: } else {
6673: %choices = &color_font_choices();
6674: }
6675: if (ref($changes->{$role}) eq 'HASH') {
6676: if ($role ne 'login') {
6677: $resulttext .= '<h4>'.&mt($role).'</h4>';
6678: }
6679: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6680: if ($role ne 'login') {
6681: $resulttext .= '<ul>';
6682: }
6683: if (ref($changes->{$role}{$key}) eq 'HASH') {
6684: if ($role ne 'login') {
6685: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6686: }
6687: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6688: if (($role eq 'login') && ($key eq 'showlogo')) {
6689: if ($confhash->{$role}{$key}{$item}) {
6690: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6691: } else {
6692: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6693: }
6694: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6695: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6696: } else {
1.12 raeburn 6697: my $newitem = $confhash->{$role}{$item};
6698: if ($key eq 'images') {
6699: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6700: }
6701: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6702: }
6703: }
6704: if ($role ne 'login') {
6705: $resulttext .= '</ul></li>';
6706: }
6707: } else {
6708: if ($confhash->{$role}{$key} eq '') {
6709: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6710: } else {
6711: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6712: }
6713: }
6714: if ($role ne 'login') {
6715: $resulttext .= '</ul>';
6716: }
6717: }
6718: }
6719: }
1.3 raeburn 6720: return $resulttext;
1.1 raeburn 6721: }
6722:
1.9 raeburn 6723: sub thumb_dimensions {
6724: return ('200','50');
6725: }
6726:
1.16 raeburn 6727: sub check_dimensions {
6728: my ($inputfile) = @_;
6729: my ($fullwidth,$fullheight);
6730: if ($inputfile =~ m|^[/\w.\-]+$|) {
6731: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6732: my $imageinfo = <PIPE>;
6733: if (!close(PIPE)) {
6734: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6735: }
6736: chomp($imageinfo);
6737: my ($fullsize) =
1.21 raeburn 6738: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6739: if ($fullsize) {
6740: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6741: }
6742: }
6743: }
6744: return ($fullwidth,$fullheight);
6745: }
6746:
1.9 raeburn 6747: sub check_configuser {
6748: my ($uhome,$dom,$confname,$servadm) = @_;
6749: my ($configuserok,%currroles);
6750: if ($uhome eq 'no_host') {
6751: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6752: my $configpass = &LONCAPA::Enrollment::create_password();
6753: $configuserok =
6754: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6755: $configpass,'','','','','',undef,$servadm);
6756: } else {
6757: $configuserok = 'ok';
6758: %currroles =
6759: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6760: }
6761: return ($configuserok,%currroles);
6762: }
6763:
6764: sub check_authorstatus {
6765: my ($dom,$confname,%currroles) = @_;
6766: my $author_ok;
1.40 raeburn 6767: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6768: my $start = time;
6769: my $end = 0;
6770: $author_ok =
6771: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6772: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6773: } else {
6774: $author_ok = 'ok';
6775: }
6776: return $author_ok;
6777: }
6778:
6779: sub publishlogo {
1.46 raeburn 6780: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6781: my ($output,$fname,$logourl);
6782: if ($action eq 'upload') {
6783: $fname=$env{'form.'.$formname.'.filename'};
6784: chop($env{'form.'.$formname});
6785: } else {
6786: ($fname) = ($formname =~ /([^\/]+)$/);
6787: }
1.46 raeburn 6788: if ($savefileas ne '') {
6789: $fname = $savefileas;
6790: }
1.9 raeburn 6791: $fname=&Apache::lonnet::clean_filename($fname);
6792: # See if there is anything left
6793: unless ($fname) { return ('error: no uploaded file'); }
6794: $fname="$subdir/$fname";
1.160.6.5 raeburn 6795: my $docroot=$r->dir_config('lonDocRoot');
6796: my $filepath="$docroot/priv";
6797: my $relpath = "$dom/$confname";
1.9 raeburn 6798: my ($fnamepath,$file,$fetchthumb);
6799: $file=$fname;
6800: if ($fname=~m|/|) {
6801: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6802: }
1.160.6.26 raeburn 6803: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6804: my $count;
1.160.6.5 raeburn 6805: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6806: $filepath.="/$parts[$count]";
6807: if ((-e $filepath)!=1) {
6808: mkdir($filepath,02770);
6809: }
6810: }
6811: # Check for bad extension and disallow upload
6812: if ($file=~/\.(\w+)$/ &&
6813: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6814: $output =
1.160.6.25 raeburn 6815: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6816: } elsif ($file=~/\.(\w+)$/ &&
6817: !defined(&Apache::loncommon::fileembstyle($1))) {
6818: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6819: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 6820: $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 6821: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 6822: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6823: } else {
6824: my $source = $filepath.'/'.$file;
6825: my $logfile;
6826: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 6827: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6828: }
6829: print $logfile
6830: "\n================= Publish ".localtime()." ================\n".
6831: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6832: # Save the file
6833: if (!open(FH,'>'.$source)) {
6834: &Apache::lonnet::logthis('Failed to create '.$source);
6835: return (&mt('Failed to create file'));
6836: }
6837: if ($action eq 'upload') {
6838: if (!print FH ($env{'form.'.$formname})) {
6839: &Apache::lonnet::logthis('Failed to write to '.$source);
6840: return (&mt('Failed to write file'));
6841: }
6842: } else {
6843: my $original = &Apache::lonnet::filelocation('',$formname);
6844: if(!copy($original,$source)) {
6845: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6846: return (&mt('Failed to write file'));
6847: }
6848: }
6849: close(FH);
6850: chmod(0660, $source); # Permissions to rw-rw---.
6851:
6852: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6853: my $copyfile=$targetdir.'/'.$file;
6854:
6855: my @parts=split(/\//,$targetdir);
6856: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6857: for (my $count=5;$count<=$#parts;$count++) {
6858: $path.="/$parts[$count]";
6859: if (!-e $path) {
6860: print $logfile "\nCreating directory ".$path;
6861: mkdir($path,02770);
6862: }
6863: }
6864: my $versionresult;
6865: if (-e $copyfile) {
6866: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6867: } else {
6868: $versionresult = 'ok';
6869: }
6870: if ($versionresult eq 'ok') {
6871: if (copy($source,$copyfile)) {
6872: print $logfile "\nCopied original source to ".$copyfile."\n";
6873: $output = 'ok';
6874: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6875: push(@{$modified_urls},[$copyfile,$source]);
6876: my $metaoutput =
6877: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6878: unless ($registered_cleanup) {
6879: my $handlers = $r->get_handlers('PerlCleanupHandler');
6880: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6881: $registered_cleanup=1;
6882: }
1.9 raeburn 6883: } else {
6884: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6885: $output = &mt('Failed to copy file to RES space').", $!";
6886: }
6887: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6888: my $inputfile = $filepath.'/'.$file;
6889: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6890: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6891: if ($fullwidth ne '' && $fullheight ne '') {
6892: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6893: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6894: system("convert -sample $thumbsize $inputfile $outfile");
6895: chmod(0660, $filepath.'/tn-'.$file);
6896: if (-e $outfile) {
6897: my $copyfile=$targetdir.'/tn-'.$file;
6898: if (copy($outfile,$copyfile)) {
6899: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6900: my $thumb_metaoutput =
6901: &write_metadata($dom,$confname,$formname,
6902: $targetdir,'tn-'.$file,$logfile);
6903: push(@{$modified_urls},[$copyfile,$outfile]);
6904: unless ($registered_cleanup) {
6905: my $handlers = $r->get_handlers('PerlCleanupHandler');
6906: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6907: $registered_cleanup=1;
6908: }
1.16 raeburn 6909: } else {
6910: print $logfile "\nUnable to write ".$copyfile.
6911: ':'.$!."\n";
6912: }
6913: }
1.9 raeburn 6914: }
6915: }
6916: }
6917: } else {
6918: $output = $versionresult;
6919: }
6920: }
6921: return ($output,$logourl);
6922: }
6923:
6924: sub logo_versioning {
6925: my ($targetdir,$file,$logfile) = @_;
6926: my $target = $targetdir.'/'.$file;
6927: my ($maxversion,$fn,$extn,$output);
6928: $maxversion = 0;
6929: if ($file =~ /^(.+)\.(\w+)$/) {
6930: $fn=$1;
6931: $extn=$2;
6932: }
6933: opendir(DIR,$targetdir);
6934: while (my $filename=readdir(DIR)) {
6935: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6936: $maxversion=($1>$maxversion)?$1:$maxversion;
6937: }
6938: }
6939: $maxversion++;
6940: print $logfile "\nCreating old version ".$maxversion."\n";
6941: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6942: if (copy($target,$copyfile)) {
6943: print $logfile "Copied old target to ".$copyfile."\n";
6944: $copyfile=$copyfile.'.meta';
6945: if (copy($target.'.meta',$copyfile)) {
6946: print $logfile "Copied old target metadata to ".$copyfile."\n";
6947: $output = 'ok';
6948: } else {
6949: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6950: $output = &mt('Failed to copy old meta').", $!, ";
6951: }
6952: } else {
6953: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6954: $output = &mt('Failed to copy old target').", $!, ";
6955: }
6956: return $output;
6957: }
6958:
6959: sub write_metadata {
6960: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6961: my (%metadatafields,%metadatakeys,$output);
6962: $metadatafields{'title'}=$formname;
6963: $metadatafields{'creationdate'}=time;
6964: $metadatafields{'lastrevisiondate'}=time;
6965: $metadatafields{'copyright'}='public';
6966: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6967: $env{'user.domain'};
6968: $metadatafields{'authorspace'}=$confname.':'.$dom;
6969: $metadatafields{'domain'}=$dom;
6970: {
6971: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6972: my $mfh;
1.155 raeburn 6973: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 6974: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6975: unless ($_=~/\./) {
6976: my $unikey=$_;
6977: $unikey=~/^([A-Za-z]+)/;
6978: my $tag=$1;
6979: $tag=~tr/A-Z/a-z/;
6980: print $mfh "\n\<$tag";
6981: foreach (split(/\,/,$metadatakeys{$unikey})) {
6982: my $value=$metadatafields{$unikey.'.'.$_};
6983: $value=~s/\"/\'\'/g;
6984: print $mfh ' '.$_.'="'.$value.'"';
6985: }
6986: print $mfh '>'.
6987: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6988: .'</'.$tag.'>';
6989: }
6990: }
6991: $output = 'ok';
6992: print $logfile "\nWrote metadata";
6993: close($mfh);
6994: } else {
6995: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6996: $output = &mt('Could not write metadata');
6997: }
6998: }
1.155 raeburn 6999: return $output;
7000: }
7001:
7002: sub notifysubscribed {
7003: foreach my $targetsource (@{$modified_urls}){
7004: next unless (ref($targetsource) eq 'ARRAY');
7005: my ($target,$source)=@{$targetsource};
7006: if ($source ne '') {
7007: if (open(my $logfh,'>>'.$source.'.log')) {
7008: print $logfh "\nCleanup phase: Notifications\n";
7009: my @subscribed=&subscribed_hosts($target);
7010: foreach my $subhost (@subscribed) {
7011: print $logfh "\nNotifying host ".$subhost.':';
7012: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7013: print $logfh $reply;
7014: }
7015: my @subscribedmeta=&subscribed_hosts("$target.meta");
7016: foreach my $subhost (@subscribedmeta) {
7017: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7018: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7019: $subhost);
7020: print $logfh $reply;
7021: }
7022: print $logfh "\n============ Done ============\n";
1.160 raeburn 7023: close($logfh);
1.155 raeburn 7024: }
7025: }
7026: }
7027: return OK;
7028: }
7029:
7030: sub subscribed_hosts {
7031: my ($target) = @_;
7032: my @subscribed;
7033: if (open(my $fh,"<$target.subscription")) {
7034: while (my $subline=<$fh>) {
7035: if ($subline =~ /^($match_lonid):/) {
7036: my $host = $1;
7037: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7038: unless (grep(/^\Q$host\E$/,@subscribed)) {
7039: push(@subscribed,$host);
7040: }
7041: }
7042: }
7043: }
7044: }
7045: return @subscribed;
1.9 raeburn 7046: }
7047:
7048: sub check_switchserver {
7049: my ($dom,$confname) = @_;
7050: my ($allowed,$switchserver);
7051: my $home = &Apache::lonnet::homeserver($confname,$dom);
7052: if ($home eq 'no_host') {
7053: $home = &Apache::lonnet::domain($dom,'primary');
7054: }
7055: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7056: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7057: if (!$allowed) {
1.160.6.11 raeburn 7058: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7059: }
7060: return $switchserver;
7061: }
7062:
1.1 raeburn 7063: sub modify_quotas {
1.160.6.30 raeburn 7064: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7065: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 7066: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 7067: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7068: $validationfieldsref);
1.86 raeburn 7069: if ($action eq 'quotas') {
7070: $context = 'tools';
1.160.6.26 raeburn 7071: } else {
1.86 raeburn 7072: $context = $action;
7073: }
7074: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 7075: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 7076: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7077: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7078: %titles = &courserequest_titles();
7079: $toolregexp = join('|',@usertools);
7080: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 7081: $confname = $dom.'-domainconfig';
7082: my $servadm = $r->dir_config('lonAdmEMail');
7083: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 7084: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7085: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 7086: } elsif ($context eq 'requestauthor') {
7087: @usertools = ('author');
7088: %titles = &authorrequest_titles();
1.86 raeburn 7089: } else {
1.160.6.4 raeburn 7090: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7091: %titles = &tool_titles();
1.86 raeburn 7092: }
1.160.6.27 raeburn 7093: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7094: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7095: foreach my $key (keys(%env)) {
1.101 raeburn 7096: if ($context eq 'requestcourses') {
7097: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7098: my $item = $1;
7099: my $type = $2;
7100: if ($type =~ /^limit_(.+)/) {
7101: $limithash{$item}{$1} = $env{$key};
7102: } else {
7103: $confhash{$item}{$type} = $env{$key};
7104: }
7105: }
1.160.6.5 raeburn 7106: } elsif ($context eq 'requestauthor') {
7107: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7108: $confhash{$1} = $env{$key};
7109: }
1.101 raeburn 7110: } else {
1.86 raeburn 7111: if ($key =~ /^form\.quota_(.+)$/) {
7112: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 7113: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7114: $confhash{'authorquota'}{$1} = $env{$key};
7115: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 7116: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7117: }
1.72 raeburn 7118: }
7119: }
1.160.6.5 raeburn 7120: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 7121: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 7122: @approvalnotify = sort(@approvalnotify);
7123: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 7124: my @crstypes = ('official','unofficial','community','textbook');
7125: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
7126: foreach my $type (@hasuniquecode) {
7127: if (grep(/^\Q$type\E$/,@crstypes)) {
7128: $confhash{'uniquecode'}{$type} = 1;
7129: }
7130: }
1.160.6.46 raeburn 7131: my (%newbook,%allpos);
1.160.6.30 raeburn 7132: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7133: foreach my $type ('textbooks','templates') {
7134: @{$allpos{$type}} = ();
7135: my $invalid;
7136: if ($type eq 'textbooks') {
7137: $invalid = &mt('Invalid LON-CAPA course for textbook');
7138: } else {
7139: $invalid = &mt('Invalid LON-CAPA course for template');
7140: }
7141: if ($env{'form.'.$type.'_addbook'}) {
7142: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
7143: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
7144: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
7145: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
7146: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7147: } else {
7148: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
7149: my $position = $env{'form.'.$type.'_addbook_pos'};
7150: $position =~ s/\D+//g;
7151: if ($position ne '') {
7152: $allpos{$type}[$position] = $newbook{$type};
7153: }
1.160.6.30 raeburn 7154: }
1.160.6.46 raeburn 7155: } else {
7156: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 7157: }
7158: }
1.160.6.46 raeburn 7159: }
1.160.6.30 raeburn 7160: }
1.102 raeburn 7161: if (ref($domconfig{$action}) eq 'HASH') {
7162: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
7163: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
7164: $changes{'notify'}{'approval'} = 1;
7165: }
7166: } else {
1.144 raeburn 7167: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7168: $changes{'notify'}{'approval'} = 1;
7169: }
7170: }
1.160.6.30 raeburn 7171: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
7172: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7173: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
7174: unless ($confhash{'uniquecode'}{$crstype}) {
7175: $changes{'uniquecode'} = 1;
7176: }
7177: }
7178: unless ($changes{'uniquecode'}) {
7179: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
7180: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
7181: $changes{'uniquecode'} = 1;
7182: }
7183: }
7184: }
7185: } else {
7186: $changes{'uniquecode'} = 1;
7187: }
7188: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
7189: $changes{'uniquecode'} = 1;
7190: }
7191: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7192: foreach my $type ('textbooks','templates') {
7193: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7194: my %deletions;
7195: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
7196: if (@todelete) {
7197: map { $deletions{$_} = 1; } @todelete;
7198: }
7199: my %imgdeletions;
7200: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
7201: if (@todeleteimages) {
7202: map { $imgdeletions{$_} = 1; } @todeleteimages;
7203: }
7204: my $maxnum = $env{'form.'.$type.'_maxnum'};
7205: for (my $i=0; $i<=$maxnum; $i++) {
7206: my $itemid = $env{'form.'.$type.'_id_'.$i};
7207: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
7208: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
7209: if ($deletions{$key}) {
7210: if ($domconfig{$action}{$type}{$key}{'image'}) {
7211: #FIXME need to obsolete item in RES space
7212: }
7213: next;
7214: } else {
7215: my $newpos = $env{'form.'.$itemid};
7216: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 7217: foreach my $item ('subject','title','publisher','author') {
7218: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7219: ($type eq 'templates'));
1.160.6.46 raeburn 7220: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
7221: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
7222: $changes{$type}{$key} = 1;
7223: }
7224: }
7225: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 7226: }
1.160.6.46 raeburn 7227: if ($imgdeletions{$key}) {
7228: $changes{$type}{$key} = 1;
7229: #FIXME need to obsolete item in RES space
7230: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
7231: my ($cdom,$cnum) = split(/_/,$key);
7232: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
7233: $cdom,$cnum,$type,$configuserok,
7234: $switchserver,$author_ok);
7235: if ($imgurl) {
7236: $confhash{$type}{$key}{'image'} = $imgurl;
7237: $changes{$type}{$key} = 1;
1.160.6.30 raeburn 7238: }
1.160.6.46 raeburn 7239: if ($error) {
7240: &Apache::lonnet::logthis($error);
7241: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7242: }
7243: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7244: $confhash{$type}{$key}{'image'} =
7245: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 7246: }
7247: }
7248: }
7249: }
7250: }
7251: }
1.102 raeburn 7252: } else {
1.144 raeburn 7253: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7254: $changes{'notify'}{'approval'} = 1;
7255: }
1.160.6.30 raeburn 7256: if (ref($confhash{'uniquecode'} eq 'HASH')) {
7257: $changes{'uniquecode'} = 1;
7258: }
7259: }
7260: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7261: foreach my $type ('textbooks','templates') {
7262: if ($newbook{$type}) {
7263: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 7264: foreach my $item ('subject','title','publisher','author') {
7265: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7266: ($type eq 'template'));
1.160.6.46 raeburn 7267: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7268: if ($env{'form.'.$type.'_addbook_'.$item}) {
7269: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7270: }
7271: }
7272: if ($type eq 'textbooks') {
7273: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7274: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7275: my ($imageurl,$error) =
7276: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7277: $configuserok,$switchserver,$author_ok);
7278: if ($imageurl) {
7279: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7280: }
7281: if ($error) {
7282: &Apache::lonnet::logthis($error);
7283: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7284: }
7285: }
1.160.6.30 raeburn 7286: }
7287: }
1.160.6.46 raeburn 7288: if (@{$allpos{$type}} > 0) {
7289: my $idx = 0;
7290: foreach my $item (@{$allpos{$type}}) {
7291: if ($item ne '') {
7292: $confhash{$type}{$item}{'order'} = $idx;
7293: if (ref($domconfig{$action}) eq 'HASH') {
7294: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7295: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7296: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7297: $changes{$type}{$item} = 1;
7298: }
1.160.6.30 raeburn 7299: }
7300: }
7301: }
1.160.6.46 raeburn 7302: $idx ++;
1.160.6.30 raeburn 7303: }
7304: }
7305: }
7306: }
1.160.6.39 raeburn 7307: if (ref($validationitemsref) eq 'ARRAY') {
7308: foreach my $item (@{$validationitemsref}) {
7309: if ($item eq 'fields') {
7310: my @changed;
7311: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7312: if (@{$confhash{'validation'}{$item}} > 0) {
7313: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7314: }
7315: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7316: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7317: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7318: $domconfig{'requestcourses'}{'validation'}{$item});
7319: } else {
7320: @changed = @{$confhash{'validation'}{$item}};
7321: }
7322: } else {
7323: @changed = @{$confhash{'validation'}{$item}};
7324: }
7325: if (@changed) {
7326: if ($confhash{'validation'}{$item}) {
7327: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7328: } else {
7329: $changes{'validation'}{$item} = &mt('None');
7330: }
7331: }
7332: } else {
7333: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7334: if ($item eq 'markup') {
7335: if ($env{'form.requestcourses_validation_'.$item}) {
7336: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7337: }
7338: }
7339: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7340: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7341: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7342: }
7343: } else {
7344: if ($confhash{'validation'}{$item} ne '') {
7345: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7346: }
7347: }
7348: }
7349: }
7350: }
7351: if ($env{'form.validationdc'}) {
7352: my $newval = $env{'form.validationdc'};
7353: my %domcoords = &get_active_dcs($dom);
7354: if (exists($domcoords{$newval})) {
7355: $confhash{'validation'}{'dc'} = $newval;
7356: }
7357: }
7358: if (ref($confhash{'validation'}) eq 'HASH') {
7359: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7360: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7361: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7362: if ($confhash{'validation'}{'dc'} eq '') {
7363: $changes{'validation'}{'dc'} = &mt('None');
7364: } else {
7365: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7366: }
7367: }
7368: } elsif ($confhash{'validation'}{'dc'} ne '') {
7369: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7370: }
7371: } elsif ($confhash{'validation'}{'dc'} ne '') {
7372: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7373: }
7374: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7375: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7376: $changes{'validation'}{'dc'} = &mt('None');
7377: }
7378: }
1.102 raeburn 7379: }
7380: } else {
1.86 raeburn 7381: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 7382: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7383: }
1.72 raeburn 7384: foreach my $item (@usertools) {
7385: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7386: my $unset;
1.101 raeburn 7387: if ($context eq 'requestcourses') {
1.104 raeburn 7388: $unset = '0';
7389: if ($type eq '_LC_adv') {
7390: $unset = '';
7391: }
1.101 raeburn 7392: if ($confhash{$item}{$type} eq 'autolimit') {
7393: $confhash{$item}{$type} .= '=';
7394: unless ($limithash{$item}{$type} =~ /\D/) {
7395: $confhash{$item}{$type} .= $limithash{$item}{$type};
7396: }
7397: }
1.160.6.5 raeburn 7398: } elsif ($context eq 'requestauthor') {
7399: $unset = '0';
7400: if ($type eq '_LC_adv') {
7401: $unset = '';
7402: }
1.72 raeburn 7403: } else {
1.101 raeburn 7404: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7405: $confhash{$item}{$type} = 1;
7406: } else {
7407: $confhash{$item}{$type} = 0;
7408: }
1.72 raeburn 7409: }
1.86 raeburn 7410: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 7411: if ($action eq 'requestauthor') {
7412: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7413: $changes{$type} = 1;
7414: }
7415: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7416: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7417: $changes{$item}{$type} = 1;
7418: }
7419: } else {
7420: if ($context eq 'requestcourses') {
1.104 raeburn 7421: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7422: $changes{$item}{$type} = 1;
7423: }
7424: } else {
7425: if (!$confhash{$item}{$type}) {
7426: $changes{$item}{$type} = 1;
7427: }
7428: }
7429: }
7430: } else {
7431: if ($context eq 'requestcourses') {
1.104 raeburn 7432: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7433: $changes{$item}{$type} = 1;
7434: }
1.160.6.5 raeburn 7435: } elsif ($context eq 'requestauthor') {
7436: if ($confhash{$type} ne $unset) {
7437: $changes{$type} = 1;
7438: }
1.72 raeburn 7439: } else {
7440: if (!$confhash{$item}{$type}) {
7441: $changes{$item}{$type} = 1;
7442: }
7443: }
7444: }
1.1 raeburn 7445: }
7446: }
1.160.6.5 raeburn 7447: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7448: if (ref($domconfig{'quotas'}) eq 'HASH') {
7449: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7450: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7451: if (exists($confhash{'defaultquota'}{$key})) {
7452: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7453: $changes{'defaultquota'}{$key} = 1;
7454: }
7455: } else {
7456: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7457: }
7458: }
1.86 raeburn 7459: } else {
7460: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7461: if (exists($confhash{'defaultquota'}{$key})) {
7462: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7463: $changes{'defaultquota'}{$key} = 1;
7464: }
7465: } else {
7466: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7467: }
1.1 raeburn 7468: }
7469: }
1.160.6.20 raeburn 7470: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7471: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7472: if (exists($confhash{'authorquota'}{$key})) {
7473: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7474: $changes{'authorquota'}{$key} = 1;
7475: }
7476: } else {
7477: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7478: }
7479: }
7480: }
1.1 raeburn 7481: }
1.86 raeburn 7482: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7483: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7484: if (ref($domconfig{'quotas'}) eq 'HASH') {
7485: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7486: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7487: $changes{'defaultquota'}{$key} = 1;
7488: }
7489: } else {
7490: if (!exists($domconfig{'quotas'}{$key})) {
7491: $changes{'defaultquota'}{$key} = 1;
7492: }
1.72 raeburn 7493: }
7494: } else {
1.86 raeburn 7495: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7496: }
1.1 raeburn 7497: }
7498: }
1.160.6.20 raeburn 7499: if (ref($confhash{'authorquota'}) eq 'HASH') {
7500: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7501: if (ref($domconfig{'quotas'}) eq 'HASH') {
7502: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7503: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7504: $changes{'authorquota'}{$key} = 1;
7505: }
7506: } else {
7507: $changes{'authorquota'}{$key} = 1;
7508: }
7509: } else {
7510: $changes{'authorquota'}{$key} = 1;
7511: }
7512: }
7513: }
1.1 raeburn 7514: }
1.72 raeburn 7515:
1.160.6.5 raeburn 7516: if ($context eq 'requestauthor') {
7517: $domdefaults{'requestauthor'} = \%confhash;
7518: } else {
7519: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 7520: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 7521: $domdefaults{$key} = $confhash{$key};
7522: }
1.160.6.5 raeburn 7523: }
1.72 raeburn 7524: }
1.160.6.5 raeburn 7525:
1.1 raeburn 7526: my %quotahash = (
1.86 raeburn 7527: $action => { %confhash }
1.1 raeburn 7528: );
7529: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7530: $dom);
7531: if ($putresult eq 'ok') {
7532: if (keys(%changes) > 0) {
1.72 raeburn 7533: my $cachetime = 24*60*60;
7534: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 7535: if (ref($lastactref) eq 'HASH') {
7536: $lastactref->{'domdefaults'} = 1;
7537: }
1.1 raeburn 7538: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 7539: unless (($context eq 'requestcourses') ||
7540: ($context eq 'requestauthor')) {
1.86 raeburn 7541: if (ref($changes{'defaultquota'}) eq 'HASH') {
7542: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7543: foreach my $type (@{$types},'default') {
7544: if (defined($changes{'defaultquota'}{$type})) {
7545: my $typetitle = $usertypes->{$type};
7546: if ($type eq 'default') {
7547: $typetitle = $othertitle;
7548: }
1.160.6.28 raeburn 7549: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7550: }
7551: }
1.86 raeburn 7552: $resulttext .= '</ul></li>';
1.72 raeburn 7553: }
1.160.6.20 raeburn 7554: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 7555: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 7556: foreach my $type (@{$types},'default') {
7557: if (defined($changes{'authorquota'}{$type})) {
7558: my $typetitle = $usertypes->{$type};
7559: if ($type eq 'default') {
7560: $typetitle = $othertitle;
7561: }
1.160.6.28 raeburn 7562: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 7563: }
7564: }
7565: $resulttext .= '</ul></li>';
7566: }
1.72 raeburn 7567: }
1.80 raeburn 7568: my %newenv;
1.72 raeburn 7569: foreach my $item (@usertools) {
1.160.6.5 raeburn 7570: my (%haschgs,%inconf);
7571: if ($context eq 'requestauthor') {
7572: %haschgs = %changes;
7573: %inconf = %confhash;
7574: } else {
7575: if (ref($changes{$item}) eq 'HASH') {
7576: %haschgs = %{$changes{$item}};
7577: }
7578: if (ref($confhash{$item}) eq 'HASH') {
7579: %inconf = %{$confhash{$item}};
7580: }
7581: }
7582: if (keys(%haschgs) > 0) {
1.80 raeburn 7583: my $newacc =
7584: &Apache::lonnet::usertools_access($env{'user.name'},
7585: $env{'user.domain'},
1.86 raeburn 7586: $item,'reload',$context);
1.160.6.5 raeburn 7587: if (($context eq 'requestcourses') ||
7588: ($context eq 'requestauthor')) {
1.108 raeburn 7589: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7590: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7591: }
7592: } else {
7593: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7594: $newenv{'environment.availabletools.'.$item} = $newacc;
7595: }
1.80 raeburn 7596: }
1.160.6.5 raeburn 7597: unless ($context eq 'requestauthor') {
7598: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7599: }
1.72 raeburn 7600: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 7601: if ($haschgs{$type}) {
1.72 raeburn 7602: my $typetitle = $usertypes->{$type};
7603: if ($type eq 'default') {
7604: $typetitle = $othertitle;
7605: } elsif ($type eq '_LC_adv') {
7606: $typetitle = 'LON-CAPA Advanced Users';
7607: }
1.160.6.5 raeburn 7608: if ($inconf{$type}) {
1.101 raeburn 7609: if ($context eq 'requestcourses') {
7610: my $cond;
1.160.6.5 raeburn 7611: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7612: if ($1 eq '') {
7613: $cond = &mt('(Automatic processing of any request).');
7614: } else {
7615: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7616: }
7617: } else {
1.160.6.5 raeburn 7618: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7619: }
7620: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 7621: } elsif ($context eq 'requestauthor') {
7622: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7623: $titles{$inconf{$type}},$typetitle);
7624:
1.101 raeburn 7625: } else {
7626: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7627: }
1.72 raeburn 7628: } else {
1.104 raeburn 7629: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 7630: if ($inconf{$type} eq '0') {
1.104 raeburn 7631: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7632: } else {
7633: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7634: }
7635: } else {
7636: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7637: }
1.72 raeburn 7638: }
7639: }
1.26 raeburn 7640: }
1.160.6.5 raeburn 7641: unless ($context eq 'requestauthor') {
7642: $resulttext .= '</ul></li>';
7643: }
1.26 raeburn 7644: }
1.1 raeburn 7645: }
1.160.6.5 raeburn 7646: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7647: if (ref($changes{'notify'}) eq 'HASH') {
7648: if ($changes{'notify'}{'approval'}) {
7649: if (ref($confhash{'notify'}) eq 'HASH') {
7650: if ($confhash{'notify'}{'approval'}) {
7651: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7652: } else {
1.160.6.5 raeburn 7653: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7654: }
7655: }
7656: }
7657: }
7658: }
1.160.6.30 raeburn 7659: if ($action eq 'requestcourses') {
7660: my @offon = ('off','on');
7661: if ($changes{'uniquecode'}) {
7662: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7663: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7664: $resulttext .= '<li>'.
7665: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7666: '</li>';
7667: } else {
7668: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7669: '</li>';
7670: }
7671: }
1.160.6.46 raeburn 7672: foreach my $type ('textbooks','templates') {
7673: if (ref($changes{$type}) eq 'HASH') {
7674: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7675: foreach my $key (sort(keys(%{$changes{$type}}))) {
7676: my %coursehash = &Apache::lonnet::coursedescription($key);
7677: my $coursetitle = $coursehash{'description'};
7678: my $position = $confhash{$type}{$key}{'order'} + 1;
7679: $resulttext .= '<li>';
1.160.6.47 raeburn 7680: foreach my $item ('subject','title','publisher','author') {
7681: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7682: ($type eq 'templates'));
1.160.6.46 raeburn 7683: my $name = $item.':';
7684: $name =~ s/^(\w)/\U$1/;
7685: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7686: }
7687: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7688: if ($type eq 'textbooks') {
7689: if ($confhash{$type}{$key}{'image'}) {
7690: $resulttext .= ' '.&mt('Image: [_1]',
7691: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
7692: ' alt="Textbook cover" />').'<br />';
7693: }
7694: }
7695: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 7696: }
1.160.6.46 raeburn 7697: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 7698: }
7699: }
1.160.6.39 raeburn 7700: if (ref($changes{'validation'}) eq 'HASH') {
7701: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7702: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7703: foreach my $item (@{$validationitemsref}) {
7704: if (exists($changes{'validation'}{$item})) {
7705: if ($item eq 'markup') {
7706: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7707: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7708: } else {
7709: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7710: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7711: }
7712: }
7713: }
7714: if (exists($changes{'validation'}{'dc'})) {
7715: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7716: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7717: }
7718: }
7719: }
1.160.6.30 raeburn 7720: }
1.1 raeburn 7721: $resulttext .= '</ul>';
1.80 raeburn 7722: if (keys(%newenv)) {
7723: &Apache::lonnet::appenv(\%newenv);
7724: }
1.1 raeburn 7725: } else {
1.86 raeburn 7726: if ($context eq 'requestcourses') {
7727: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 7728: } elsif ($context eq 'requestauthor') {
7729: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7730: } else {
1.90 weissno 7731: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7732: }
1.1 raeburn 7733: }
7734: } else {
1.11 albertel 7735: $resulttext = '<span class="LC_error">'.
7736: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7737: }
1.160.6.30 raeburn 7738: if ($errors) {
7739: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7740: '<ul>'.$errors.'</ul></p>';
7741: }
1.3 raeburn 7742: return $resulttext;
1.1 raeburn 7743: }
7744:
1.160.6.30 raeburn 7745: sub process_textbook_image {
1.160.6.46 raeburn 7746: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 7747: my $filename = $env{'form.'.$caller.'.filename'};
7748: my ($error,$url);
7749: my ($width,$height) = (50,50);
7750: if ($configuserok eq 'ok') {
7751: if ($switchserver) {
7752: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7753: $switchserver);
7754: } elsif ($author_ok eq 'ok') {
7755: my ($result,$imageurl) =
7756: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.46 raeburn 7757: "$type/$dom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 7758: if ($result eq 'ok') {
7759: $url = $imageurl;
7760: } else {
7761: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7762: }
7763: } else {
7764: $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);
7765: }
7766: } else {
7767: $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);
7768: }
7769: return ($url,$error);
7770: }
7771:
1.3 raeburn 7772: sub modify_autoenroll {
1.160.6.24 raeburn 7773: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7774: my ($resulttext,%changes);
7775: my %currautoenroll;
7776: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7777: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7778: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7779: }
7780: }
7781: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7782: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7783: sender => 'Sender for notification messages',
7784: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 7785: my @offon = ('off','on');
1.17 raeburn 7786: my $sender_uname = $env{'form.sender_uname'};
7787: my $sender_domain = $env{'form.sender_domain'};
7788: if ($sender_domain eq '') {
7789: $sender_uname = '';
7790: } elsif ($sender_uname eq '') {
7791: $sender_domain = '';
7792: }
1.129 raeburn 7793: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 7794: my %autoenrollhash = (
1.129 raeburn 7795: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7796: 'sender_uname' => $sender_uname,
7797: 'sender_domain' => $sender_domain,
7798: 'co-owners' => $coowners,
1.1 raeburn 7799: }
7800: );
1.4 raeburn 7801: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7802: $dom);
1.1 raeburn 7803: if ($putresult eq 'ok') {
7804: if (exists($currautoenroll{'run'})) {
7805: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7806: $changes{'run'} = 1;
7807: }
7808: } elsif ($autorun) {
7809: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7810: $changes{'run'} = 1;
1.1 raeburn 7811: }
7812: }
1.17 raeburn 7813: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7814: $changes{'sender'} = 1;
7815: }
1.17 raeburn 7816: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7817: $changes{'sender'} = 1;
7818: }
1.129 raeburn 7819: if ($currautoenroll{'co-owners'} ne '') {
7820: if ($currautoenroll{'co-owners'} ne $coowners) {
7821: $changes{'coowners'} = 1;
7822: }
7823: } elsif ($coowners) {
7824: $changes{'coowners'} = 1;
7825: }
1.1 raeburn 7826: if (keys(%changes) > 0) {
7827: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7828: if ($changes{'run'}) {
1.1 raeburn 7829: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7830: }
7831: if ($changes{'sender'}) {
1.17 raeburn 7832: if ($sender_uname eq '' || $sender_domain eq '') {
7833: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7834: } else {
7835: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7836: }
1.1 raeburn 7837: }
1.129 raeburn 7838: if ($changes{'coowners'}) {
7839: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7840: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7841: if (ref($lastactref) eq 'HASH') {
7842: $lastactref->{'domainconfig'} = 1;
7843: }
1.129 raeburn 7844: }
1.1 raeburn 7845: $resulttext .= '</ul>';
7846: } else {
7847: $resulttext = &mt('No changes made to auto-enrollment settings');
7848: }
7849: } else {
1.11 albertel 7850: $resulttext = '<span class="LC_error">'.
7851: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7852: }
1.3 raeburn 7853: return $resulttext;
1.1 raeburn 7854: }
7855:
7856: sub modify_autoupdate {
1.3 raeburn 7857: my ($dom,%domconfig) = @_;
1.1 raeburn 7858: my ($resulttext,%currautoupdate,%fields,%changes);
7859: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7860: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7861: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7862: }
7863: }
7864: my @offon = ('off','on');
7865: my %title = &Apache::lonlocal::texthash (
7866: run => 'Auto-update:',
7867: classlists => 'Updates to user information in classlists?'
7868: );
1.44 raeburn 7869: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7870: my %fieldtitles = &Apache::lonlocal::texthash (
7871: id => 'Student/Employee ID',
1.20 raeburn 7872: permanentemail => 'E-mail address',
1.1 raeburn 7873: lastname => 'Last Name',
7874: firstname => 'First Name',
7875: middlename => 'Middle Name',
1.132 raeburn 7876: generation => 'Generation',
1.1 raeburn 7877: );
1.142 raeburn 7878: $othertitle = &mt('All users');
1.1 raeburn 7879: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 7880: $othertitle = &mt('Other users');
1.1 raeburn 7881: }
7882: foreach my $key (keys(%env)) {
7883: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 7884: my ($usertype,$item) = ($1,$2);
7885: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7886: if ($usertype eq 'default') {
7887: push(@{$fields{$1}},$2);
7888: } elsif (ref($types) eq 'ARRAY') {
7889: if (grep(/^\Q$usertype\E$/,@{$types})) {
7890: push(@{$fields{$1}},$2);
7891: }
7892: }
7893: }
1.1 raeburn 7894: }
7895: }
1.131 raeburn 7896: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7897: @lockablenames = sort(@lockablenames);
7898: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7899: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7900: if (@changed) {
7901: $changes{'lockablenames'} = 1;
7902: }
7903: } else {
7904: if (@lockablenames) {
7905: $changes{'lockablenames'} = 1;
7906: }
7907: }
1.1 raeburn 7908: my %updatehash = (
7909: autoupdate => { run => $env{'form.autoupdate_run'},
7910: classlists => $env{'form.classlists'},
7911: fields => {%fields},
1.131 raeburn 7912: lockablenames => \@lockablenames,
1.1 raeburn 7913: }
7914: );
7915: foreach my $key (keys(%currautoupdate)) {
7916: if (($key eq 'run') || ($key eq 'classlists')) {
7917: if (exists($updatehash{autoupdate}{$key})) {
7918: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7919: $changes{$key} = 1;
7920: }
7921: }
7922: } elsif ($key eq 'fields') {
7923: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 7924: foreach my $item (@{$types},'default') {
1.1 raeburn 7925: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7926: my $change = 0;
7927: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7928: if (!exists($fields{$item})) {
7929: $change = 1;
1.132 raeburn 7930: last;
1.1 raeburn 7931: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 7932: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 7933: $change = 1;
1.132 raeburn 7934: last;
1.1 raeburn 7935: }
7936: }
7937: }
7938: if ($change) {
7939: push(@{$changes{$key}},$item);
7940: }
1.26 raeburn 7941: }
1.1 raeburn 7942: }
7943: }
1.131 raeburn 7944: } elsif ($key eq 'lockablenames') {
7945: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7946: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7947: if (@changed) {
7948: $changes{'lockablenames'} = 1;
7949: }
7950: } else {
7951: if (@lockablenames) {
7952: $changes{'lockablenames'} = 1;
7953: }
7954: }
7955: }
7956: }
7957: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7958: if (@lockablenames) {
7959: $changes{'lockablenames'} = 1;
1.1 raeburn 7960: }
7961: }
1.26 raeburn 7962: foreach my $item (@{$types},'default') {
7963: if (defined($fields{$item})) {
7964: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 7965: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7966: my $change = 0;
7967: if (ref($fields{$item}) eq 'ARRAY') {
7968: foreach my $type (@{$fields{$item}}) {
7969: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7970: $change = 1;
7971: last;
7972: }
7973: }
7974: }
7975: if ($change) {
7976: push(@{$changes{'fields'}},$item);
7977: }
7978: } else {
1.26 raeburn 7979: push(@{$changes{'fields'}},$item);
7980: }
7981: } else {
7982: push(@{$changes{'fields'}},$item);
1.1 raeburn 7983: }
7984: }
7985: }
7986: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7987: $dom);
7988: if ($putresult eq 'ok') {
7989: if (keys(%changes) > 0) {
7990: $resulttext = &mt('Changes made:').'<ul>';
7991: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 7992: if ($key eq 'lockablenames') {
7993: $resulttext .= '<li>';
7994: if (@lockablenames) {
7995: $usertypes->{'default'} = $othertitle;
7996: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7997: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7998: } else {
7999: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
8000: }
8001: $resulttext .= '</li>';
8002: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 8003: foreach my $item (@{$changes{$key}}) {
8004: my @newvalues;
8005: foreach my $type (@{$fields{$item}}) {
8006: push(@newvalues,$fieldtitles{$type});
8007: }
1.3 raeburn 8008: my $newvaluestr;
8009: if (@newvalues > 0) {
8010: $newvaluestr = join(', ',@newvalues);
8011: } else {
8012: $newvaluestr = &mt('none');
1.6 raeburn 8013: }
1.1 raeburn 8014: if ($item eq 'default') {
1.26 raeburn 8015: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 8016: } else {
1.26 raeburn 8017: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 8018: }
8019: }
8020: } else {
8021: my $newvalue;
8022: if ($key eq 'run') {
8023: $newvalue = $offon[$env{'form.autoupdate_run'}];
8024: } else {
8025: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 8026: }
1.1 raeburn 8027: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
8028: }
8029: }
8030: $resulttext .= '</ul>';
8031: } else {
1.3 raeburn 8032: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 8033: }
8034: } else {
1.11 albertel 8035: $resulttext = '<span class="LC_error">'.
8036: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8037: }
1.3 raeburn 8038: return $resulttext;
1.1 raeburn 8039: }
8040:
1.125 raeburn 8041: sub modify_autocreate {
8042: my ($dom,%domconfig) = @_;
8043: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
8044: if (ref($domconfig{'autocreate'}) eq 'HASH') {
8045: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
8046: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
8047: }
8048: }
8049: my %title= ( xml => 'Auto-creation of courses in XML course description files',
8050: req => 'Auto-creation of validated requests for official courses',
8051: xmldc => 'Identity of course creator of courses from XML files',
8052: );
8053: my @types = ('xml','req');
8054: foreach my $item (@types) {
8055: $newvals{$item} = $env{'form.autocreate_'.$item};
8056: $newvals{$item} =~ s/\D//g;
8057: $newvals{$item} = 0 if ($newvals{$item} eq '');
8058: }
8059: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
8060: my %domcoords = &get_active_dcs($dom);
8061: unless (exists($domcoords{$newvals{'xmldc'}})) {
8062: $newvals{'xmldc'} = '';
8063: }
8064: %autocreatehash = (
8065: autocreate => { xml => $newvals{'xml'},
8066: req => $newvals{'req'},
8067: }
8068: );
8069: if ($newvals{'xmldc'} ne '') {
8070: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
8071: }
8072: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
8073: $dom);
8074: if ($putresult eq 'ok') {
8075: my @items = @types;
8076: if ($newvals{'xml'}) {
8077: push(@items,'xmldc');
8078: }
8079: foreach my $item (@items) {
8080: if (exists($currautocreate{$item})) {
8081: if ($currautocreate{$item} ne $newvals{$item}) {
8082: $changes{$item} = 1;
8083: }
8084: } elsif ($newvals{$item}) {
8085: $changes{$item} = 1;
8086: }
8087: }
8088: if (keys(%changes) > 0) {
8089: my @offon = ('off','on');
8090: $resulttext = &mt('Changes made:').'<ul>';
8091: foreach my $item (@types) {
8092: if ($changes{$item}) {
8093: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 8094: $resulttext .= '<li>'.
8095: &mt("$title{$item} set to [_1]$newtxt [_2]",
8096: '<b>','</b>').
8097: '</li>';
1.125 raeburn 8098: }
8099: }
8100: if ($changes{'xmldc'}) {
8101: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
8102: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 8103: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 8104: }
8105: $resulttext .= '</ul>';
8106: } else {
8107: $resulttext = &mt('No changes made to auto-creation settings');
8108: }
8109: } else {
8110: $resulttext = '<span class="LC_error">'.
8111: &mt('An error occurred: [_1]',$putresult).'</span>';
8112: }
8113: return $resulttext;
8114: }
8115:
1.23 raeburn 8116: sub modify_directorysrch {
8117: my ($dom,%domconfig) = @_;
8118: my ($resulttext,%changes);
8119: my %currdirsrch;
8120: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8121: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
8122: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
8123: }
8124: }
8125: my %title = ( available => 'Directory search available',
1.24 raeburn 8126: localonly => 'Other domains can search',
1.23 raeburn 8127: searchby => 'Search types',
8128: searchtypes => 'Search latitude');
8129: my @offon = ('off','on');
1.24 raeburn 8130: my @otherdoms = ('Yes','No');
1.23 raeburn 8131:
1.25 raeburn 8132: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 8133: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
8134: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
8135:
1.44 raeburn 8136: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 8137: if (keys(%{$usertypes}) == 0) {
8138: @cansearch = ('default');
8139: } else {
8140: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
8141: foreach my $type (@{$currdirsrch{'cansearch'}}) {
8142: if (!grep(/^\Q$type\E$/,@cansearch)) {
8143: push(@{$changes{'cansearch'}},$type);
8144: }
1.23 raeburn 8145: }
1.26 raeburn 8146: foreach my $type (@cansearch) {
8147: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
8148: push(@{$changes{'cansearch'}},$type);
8149: }
1.23 raeburn 8150: }
1.26 raeburn 8151: } else {
8152: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 8153: }
8154: }
8155:
8156: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
8157: foreach my $by (@{$currdirsrch{'searchby'}}) {
8158: if (!grep(/^\Q$by\E$/,@searchby)) {
8159: push(@{$changes{'searchby'}},$by);
8160: }
8161: }
8162: foreach my $by (@searchby) {
8163: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
8164: push(@{$changes{'searchby'}},$by);
8165: }
8166: }
8167: } else {
8168: push(@{$changes{'searchby'}},@searchby);
8169: }
1.25 raeburn 8170:
8171: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
8172: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
8173: if (!grep(/^\Q$type\E$/,@searchtypes)) {
8174: push(@{$changes{'searchtypes'}},$type);
8175: }
8176: }
8177: foreach my $type (@searchtypes) {
8178: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
8179: push(@{$changes{'searchtypes'}},$type);
8180: }
8181: }
8182: } else {
8183: if (exists($currdirsrch{'searchtypes'})) {
8184: foreach my $type (@searchtypes) {
8185: if ($type ne $currdirsrch{'searchtypes'}) {
8186: push(@{$changes{'searchtypes'}},$type);
8187: }
8188: }
8189: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
8190: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
8191: }
8192: } else {
8193: push(@{$changes{'searchtypes'}},@searchtypes);
8194: }
8195: }
8196:
1.23 raeburn 8197: my %dirsrch_hash = (
8198: directorysrch => { available => $env{'form.dirsrch_available'},
8199: cansearch => \@cansearch,
1.24 raeburn 8200: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 8201: searchby => \@searchby,
1.25 raeburn 8202: searchtypes => \@searchtypes,
1.23 raeburn 8203: }
8204: );
8205: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
8206: $dom);
8207: if ($putresult eq 'ok') {
8208: if (exists($currdirsrch{'available'})) {
8209: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
8210: $changes{'available'} = 1;
8211: }
8212: } else {
8213: if ($env{'form.dirsrch_available'} eq '1') {
8214: $changes{'available'} = 1;
8215: }
8216: }
1.24 raeburn 8217: if (exists($currdirsrch{'localonly'})) {
8218: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
8219: $changes{'localonly'} = 1;
8220: }
8221: } else {
8222: if ($env{'form.dirsrch_localonly'} eq '1') {
8223: $changes{'localonly'} = 1;
8224: }
8225: }
1.23 raeburn 8226: if (keys(%changes) > 0) {
8227: $resulttext = &mt('Changes made:').'<ul>';
8228: if ($changes{'available'}) {
8229: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
8230: }
1.24 raeburn 8231: if ($changes{'localonly'}) {
8232: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
8233: }
8234:
1.23 raeburn 8235: if (ref($changes{'cansearch'}) eq 'ARRAY') {
8236: my $chgtext;
1.26 raeburn 8237: if (ref($usertypes) eq 'HASH') {
8238: if (keys(%{$usertypes}) > 0) {
8239: foreach my $type (@{$types}) {
8240: if (grep(/^\Q$type\E$/,@cansearch)) {
8241: $chgtext .= $usertypes->{$type}.'; ';
8242: }
8243: }
8244: if (grep(/^default$/,@cansearch)) {
8245: $chgtext .= $othertitle;
8246: } else {
8247: $chgtext =~ s/\; $//;
8248: }
1.160.6.13 raeburn 8249: $resulttext .=
8250: '<li>'.
8251: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
8252: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
8253: '</li>';
1.23 raeburn 8254: }
8255: }
8256: }
8257: if (ref($changes{'searchby'}) eq 'ARRAY') {
8258: my ($searchtitles,$titleorder) = &sorted_searchtitles();
8259: my $chgtext;
8260: foreach my $type (@{$titleorder}) {
8261: if (grep(/^\Q$type\E$/,@searchby)) {
8262: if (defined($searchtitles->{$type})) {
8263: $chgtext .= $searchtitles->{$type}.'; ';
8264: }
8265: }
8266: }
8267: $chgtext =~ s/\; $//;
8268: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8269: }
1.25 raeburn 8270: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8271: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8272: my $chgtext;
8273: foreach my $type (@{$srchtypeorder}) {
8274: if (grep(/^\Q$type\E$/,@searchtypes)) {
8275: if (defined($srchtypes_desc->{$type})) {
8276: $chgtext .= $srchtypes_desc->{$type}.'; ';
8277: }
8278: }
8279: }
8280: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 8281: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 8282: }
8283: $resulttext .= '</ul>';
8284: } else {
8285: $resulttext = &mt('No changes made to institution directory search settings');
8286: }
8287: } else {
8288: $resulttext = '<span class="LC_error">'.
1.27 raeburn 8289: &mt('An error occurred: [_1]',$putresult).'</span>';
8290: }
8291: return $resulttext;
8292: }
8293:
1.28 raeburn 8294: sub modify_contacts {
1.160.6.24 raeburn 8295: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 8296: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8297: if (ref($domconfig{'contacts'}) eq 'HASH') {
8298: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8299: $currsetting{$key} = $domconfig{'contacts'}{$key};
8300: }
8301: }
1.134 raeburn 8302: my (%others,%to,%bcc);
1.28 raeburn 8303: my @contacts = ('supportemail','adminemail');
1.102 raeburn 8304: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23 raeburn 8305: 'requestsmail','updatesmail','idconflictsmail');
8306: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 8307: foreach my $type (@mailings) {
8308: @{$newsetting{$type}} =
8309: &Apache::loncommon::get_env_multiple('form.'.$type);
8310: foreach my $item (@contacts) {
8311: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8312: $contacts_hash{contacts}{$type}{$item} = 1;
8313: } else {
8314: $contacts_hash{contacts}{$type}{$item} = 0;
8315: }
8316: }
8317: $others{$type} = $env{'form.'.$type.'_others'};
8318: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 8319: if ($type eq 'helpdeskmail') {
8320: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8321: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8322: }
1.28 raeburn 8323: }
8324: foreach my $item (@contacts) {
8325: $to{$item} = $env{'form.'.$item};
8326: $contacts_hash{'contacts'}{$item} = $to{$item};
8327: }
1.160.6.23 raeburn 8328: foreach my $item (@toggles) {
8329: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8330: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8331: }
8332: }
1.28 raeburn 8333: if (keys(%currsetting) > 0) {
8334: foreach my $item (@contacts) {
8335: if ($to{$item} ne $currsetting{$item}) {
8336: $changes{$item} = 1;
8337: }
8338: }
8339: foreach my $type (@mailings) {
8340: foreach my $item (@contacts) {
8341: if (ref($currsetting{$type}) eq 'HASH') {
8342: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8343: push(@{$changes{$type}},$item);
8344: }
8345: } else {
8346: push(@{$changes{$type}},@{$newsetting{$type}});
8347: }
8348: }
8349: if ($others{$type} ne $currsetting{$type}{'others'}) {
8350: push(@{$changes{$type}},'others');
8351: }
1.134 raeburn 8352: if ($type eq 'helpdeskmail') {
8353: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8354: push(@{$changes{$type}},'bcc');
8355: }
8356: }
1.28 raeburn 8357: }
8358: } else {
8359: my %default;
8360: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8361: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8362: $default{'errormail'} = 'adminemail';
8363: $default{'packagesmail'} = 'adminemail';
8364: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8365: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8366: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 8367: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8368: foreach my $item (@contacts) {
8369: if ($to{$item} ne $default{$item}) {
8370: $changes{$item} = 1;
1.160.6.23 raeburn 8371: }
1.28 raeburn 8372: }
8373: foreach my $type (@mailings) {
8374: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8375:
8376: push(@{$changes{$type}},@{$newsetting{$type}});
8377: }
8378: if ($others{$type} ne '') {
8379: push(@{$changes{$type}},'others');
1.134 raeburn 8380: }
8381: if ($type eq 'helpdeskmail') {
8382: if ($bcc{$type} ne '') {
8383: push(@{$changes{$type}},'bcc');
8384: }
8385: }
1.28 raeburn 8386: }
8387: }
1.160.6.23 raeburn 8388: foreach my $item (@toggles) {
8389: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8390: $changes{$item} = 1;
8391: } elsif ((!$env{'form.'.$item}) &&
8392: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8393: $changes{$item} = 1;
8394: }
8395: }
1.28 raeburn 8396: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8397: $dom);
8398: if ($putresult eq 'ok') {
8399: if (keys(%changes) > 0) {
1.160.6.24 raeburn 8400: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8401: if (ref($lastactref) eq 'HASH') {
8402: $lastactref->{'domainconfig'} = 1;
8403: }
1.28 raeburn 8404: my ($titles,$short_titles) = &contact_titles();
8405: $resulttext = &mt('Changes made:').'<ul>';
8406: foreach my $item (@contacts) {
8407: if ($changes{$item}) {
8408: $resulttext .= '<li>'.$titles->{$item}.
8409: &mt(' set to: ').
8410: '<span class="LC_cusr_emph">'.
8411: $to{$item}.'</span></li>';
8412: }
8413: }
8414: foreach my $type (@mailings) {
8415: if (ref($changes{$type}) eq 'ARRAY') {
8416: $resulttext .= '<li>'.$titles->{$type}.': ';
8417: my @text;
8418: foreach my $item (@{$newsetting{$type}}) {
8419: push(@text,$short_titles->{$item});
8420: }
8421: if ($others{$type} ne '') {
8422: push(@text,$others{$type});
8423: }
8424: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8425: join(', ',@text).'</span>';
8426: if ($type eq 'helpdeskmail') {
8427: if ($bcc{$type} ne '') {
8428: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8429: }
8430: }
8431: $resulttext .= '</li>';
1.28 raeburn 8432: }
8433: }
1.160.6.23 raeburn 8434: my @offon = ('off','on');
8435: if ($changes{'reporterrors'}) {
8436: $resulttext .= '<li>'.
8437: &mt('E-mail error reports to [_1] set to "'.
8438: $offon[$env{'form.reporterrors'}].'".',
8439: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8440: &mt('LON-CAPA core group - MSU'),600,500)).
8441: '</li>';
8442: }
8443: if ($changes{'reportupdates'}) {
8444: $resulttext .= '<li>'.
8445: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8446: $offon[$env{'form.reportupdates'}].'".',
8447: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8448: &mt('LON-CAPA core group - MSU'),600,500)).
8449: '</li>';
8450: }
1.28 raeburn 8451: $resulttext .= '</ul>';
8452: } else {
1.34 raeburn 8453: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8454: }
8455: } else {
8456: $resulttext = '<span class="LC_error">'.
8457: &mt('An error occurred: [_1].',$putresult).'</span>';
8458: }
8459: return $resulttext;
8460: }
8461:
8462: sub modify_usercreation {
1.27 raeburn 8463: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 8464: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8465: my $warningmsg;
1.27 raeburn 8466: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8467: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 8468: if ($key eq 'cancreate') {
8469: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8470: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8471: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8472: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8473: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8474: } else {
8475: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8476: }
1.50 raeburn 8477: }
1.43 raeburn 8478: }
1.160.6.34 raeburn 8479: } elsif ($key eq 'email_rule') {
8480: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8481: } else {
8482: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 8483: }
8484: }
1.34 raeburn 8485: }
1.160.6.34 raeburn 8486: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
8487: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
8488: my @contexts = ('author','course','requestcrs');
8489: foreach my $item(@contexts) {
8490: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8491: }
1.34 raeburn 8492: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8493: foreach my $item (@contexts) {
1.160.6.34 raeburn 8494: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8495: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8496: }
1.27 raeburn 8497: }
1.34 raeburn 8498: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8499: foreach my $item (@contexts) {
1.43 raeburn 8500: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8501: if ($cancreate{$item} ne 'any') {
8502: push(@{$changes{'cancreate'}},$item);
8503: }
8504: } else {
8505: if ($cancreate{$item} ne 'none') {
8506: push(@{$changes{'cancreate'}},$item);
8507: }
1.27 raeburn 8508: }
8509: }
8510: } else {
1.43 raeburn 8511: foreach my $item (@contexts) {
1.34 raeburn 8512: push(@{$changes{'cancreate'}},$item);
8513: }
1.27 raeburn 8514: }
1.34 raeburn 8515:
1.27 raeburn 8516: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8517: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8518: if (!grep(/^\Q$type\E$/,@username_rule)) {
8519: push(@{$changes{'username_rule'}},$type);
8520: }
8521: }
8522: foreach my $type (@username_rule) {
8523: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8524: push(@{$changes{'username_rule'}},$type);
8525: }
8526: }
8527: } else {
8528: push(@{$changes{'username_rule'}},@username_rule);
8529: }
8530:
1.32 raeburn 8531: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8532: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8533: if (!grep(/^\Q$type\E$/,@id_rule)) {
8534: push(@{$changes{'id_rule'}},$type);
8535: }
8536: }
8537: foreach my $type (@id_rule) {
8538: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8539: push(@{$changes{'id_rule'}},$type);
8540: }
8541: }
8542: } else {
8543: push(@{$changes{'id_rule'}},@id_rule);
8544: }
8545:
1.43 raeburn 8546: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8547: my @authtypes = ('int','krb4','krb5','loc');
8548: my %authhash;
1.43 raeburn 8549: foreach my $item (@authen_contexts) {
1.28 raeburn 8550: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8551: foreach my $auth (@authtypes) {
8552: if (grep(/^\Q$auth\E$/,@authallowed)) {
8553: $authhash{$item}{$auth} = 1;
8554: } else {
8555: $authhash{$item}{$auth} = 0;
8556: }
8557: }
8558: }
8559: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8560: foreach my $item (@authen_contexts) {
1.28 raeburn 8561: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8562: foreach my $auth (@authtypes) {
8563: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8564: push(@{$changes{'authtypes'}},$item);
8565: last;
8566: }
8567: }
8568: }
8569: }
8570: } else {
1.43 raeburn 8571: foreach my $item (@authen_contexts) {
1.28 raeburn 8572: push(@{$changes{'authtypes'}},$item);
8573: }
8574: }
8575:
1.160.6.34 raeburn 8576: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8577: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8578: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8579: $save_usercreate{'id_rule'} = \@id_rule;
8580: $save_usercreate{'username_rule'} = \@username_rule,
8581: $save_usercreate{'authtypes'} = \%authhash;
8582:
1.27 raeburn 8583: my %usercreation_hash = (
1.160.6.34 raeburn 8584: usercreation => \%save_usercreate,
8585: );
1.27 raeburn 8586:
8587: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8588: $dom);
1.50 raeburn 8589:
1.160.6.34 raeburn 8590: if ($putresult eq 'ok') {
8591: if (keys(%changes) > 0) {
8592: $resulttext = &mt('Changes made:').'<ul>';
8593: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8594: my %lt = &usercreation_types();
8595: foreach my $type (@{$changes{'cancreate'}}) {
8596: my $chgtext = $lt{$type}.', ';
8597: if ($cancreate{$type} eq 'none') {
8598: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8599: } elsif ($cancreate{$type} eq 'any') {
8600: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8601: } elsif ($cancreate{$type} eq 'official') {
8602: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8603: } elsif ($cancreate{$type} eq 'unofficial') {
8604: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8605: }
8606: $resulttext .= '<li>'.$chgtext.'</li>';
8607: }
8608: }
8609: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8610: my ($rules,$ruleorder) =
8611: &Apache::lonnet::inst_userrules($dom,'username');
8612: my $chgtext = '<ul>';
8613: foreach my $type (@username_rule) {
8614: if (ref($rules->{$type}) eq 'HASH') {
8615: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8616: }
8617: }
8618: $chgtext .= '</ul>';
8619: if (@username_rule > 0) {
8620: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8621: } else {
8622: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8623: }
8624: }
8625: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8626: my ($idrules,$idruleorder) =
8627: &Apache::lonnet::inst_userrules($dom,'id');
8628: my $chgtext = '<ul>';
8629: foreach my $type (@id_rule) {
8630: if (ref($idrules->{$type}) eq 'HASH') {
8631: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8632: }
8633: }
8634: $chgtext .= '</ul>';
8635: if (@id_rule > 0) {
8636: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8637: } else {
8638: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8639: }
8640: }
8641: my %authname = &authtype_names();
8642: my %context_title = &context_names();
8643: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8644: my $chgtext = '<ul>';
8645: foreach my $type (@{$changes{'authtypes'}}) {
8646: my @allowed;
8647: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8648: foreach my $auth (@authtypes) {
8649: if ($authhash{$type}{$auth}) {
8650: push(@allowed,$authname{$auth});
8651: }
8652: }
8653: if (@allowed > 0) {
8654: $chgtext .= join(', ',@allowed).'</li>';
8655: } else {
8656: $chgtext .= &mt('none').'</li>';
8657: }
8658: }
8659: $chgtext .= '</ul>';
8660: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8661: $resulttext .= '</li>';
8662: }
8663: $resulttext .= '</ul>';
8664: } else {
8665: $resulttext = &mt('No changes made to user creation settings');
8666: }
8667: } else {
8668: $resulttext = '<span class="LC_error">'.
8669: &mt('An error occurred: [_1]',$putresult).'</span>';
8670: }
8671: if ($warningmsg ne '') {
8672: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8673: }
8674: return $resulttext;
8675: }
8676:
8677: sub modify_selfcreation {
8678: my ($dom,%domconfig) = @_;
8679: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8680: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 8681: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8682: if (ref($types) eq 'ARRAY') {
8683: $usertypes->{'default'} = $othertitle;
8684: push(@{$types},'default');
8685: }
1.160.6.34 raeburn 8686: #
8687: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8688: #
8689: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8690: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8691: if ($key eq 'cancreate') {
8692: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8693: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8694: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8695: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.40 raeburn 8696: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 8697: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 8698: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8699: } else {
8700: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8701: }
8702: }
8703: }
8704: } elsif ($key eq 'email_rule') {
8705: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8706: } else {
8707: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8708: }
8709: }
8710: }
8711: #
8712: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8713: #
8714: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8715: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8716: if ($key eq 'selfcreate') {
8717: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8718: } else {
8719: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8720: }
8721: }
8722: }
8723:
8724: my @contexts = ('selfcreate');
8725: @{$cancreate{'selfcreate'}} = ();
8726: %{$cancreate{'emailusername'}} = ();
8727: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 8728: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 8729: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 8730: my %selfcreatetypes = (
8731: sso => 'users authenticated by institutional single sign on',
8732: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 8733: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 8734: );
1.160.6.34 raeburn 8735: #
8736: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8737: # is permitted.
8738: #
1.160.6.40 raeburn 8739:
8740: my @statuses;
8741: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8742: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8743: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8744: }
8745: }
8746: push(@statuses,'default');
8747:
1.160.6.35 raeburn 8748: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 8749: if ($item eq 'email') {
1.160.6.40 raeburn 8750: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 8751: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 8752: push(@contexts,'selfcreateprocessing');
8753: foreach my $type (@statuses) {
8754: if ($type eq 'default') {
8755: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8756: } else {
8757: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8758: }
8759: }
1.160.6.34 raeburn 8760: }
8761: } else {
8762: if ($env{'form.cancreate_'.$item}) {
8763: push(@{$cancreate{'selfcreate'}},$item);
8764: }
8765: }
8766: }
8767: my (@email_rule,%userinfo,%savecaptcha);
8768: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8769: #
1.160.6.35 raeburn 8770: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8771: # 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 8772: #
1.160.6.40 raeburn 8773:
1.160.6.48 raeburn 8774: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 8775: push(@contexts,'emailusername');
1.160.6.35 raeburn 8776: if (ref($types) eq 'ARRAY') {
8777: foreach my $type (@{$types}) {
8778: if (ref($infofields) eq 'ARRAY') {
8779: foreach my $field (@{$infofields}) {
8780: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8781: $cancreate{'emailusername'}{$type}{$field} = $1;
8782: }
8783: }
1.160.6.34 raeburn 8784: }
8785: }
8786: }
8787: #
8788: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8789: # queued requests for self-creation of account using e-mail address as username
8790: #
8791:
8792: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8793: @approvalnotify = sort(@approvalnotify);
8794: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8795: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8796: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8797: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8798: push(@{$changes{'cancreate'}},'notify');
8799: }
8800: } else {
8801: if ($cancreate{'notify'}{'approval'}) {
8802: push(@{$changes{'cancreate'}},'notify');
8803: }
8804: }
8805: } elsif ($cancreate{'notify'}{'approval'}) {
8806: push(@{$changes{'cancreate'}},'notify');
8807: }
8808:
8809: #
8810: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8811: #
8812: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8813: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8814: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8815: if (@{$curr_usercreation{'email_rule'}} > 0) {
8816: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8817: if (!grep(/^\Q$type\E$/,@email_rule)) {
8818: push(@{$changes{'email_rule'}},$type);
8819: }
8820: }
8821: }
8822: if (@email_rule > 0) {
8823: foreach my $type (@email_rule) {
8824: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8825: push(@{$changes{'email_rule'}},$type);
8826: }
8827: }
8828: }
8829: } elsif (@email_rule > 0) {
8830: push(@{$changes{'email_rule'}},@email_rule);
8831: }
8832: }
8833: #
1.160.6.40 raeburn 8834: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 8835: # institutional log-in.
8836: #
8837: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8838: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8839: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8840: ($domdefaults{'auth_def'} eq 'localauth'))) {
8841: $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.').' '.
8842: &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.');
8843: }
8844: }
8845: my @fields = ('lastname','firstname','middlename','generation',
8846: 'permanentemail','id');
1.160.6.44 raeburn 8847: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 8848: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8849: #
8850: # Where usernames may created for institutional log-in and/or institutional single sign on:
8851: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8852: # may self-create accounts
8853: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8854: # which the user may supply, if institutional data is unavailable.
8855: #
8856: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8857: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 8858: if (@{$types} > 1) {
1.160.6.34 raeburn 8859: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8860: push(@contexts,'statustocreate');
8861: } else {
8862: undef($cancreate{'statustocreate'});
8863: }
8864: foreach my $type (@{$types}) {
8865: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8866: foreach my $field (@fields) {
8867: if (grep(/^\Q$field\E$/,@modifiable)) {
8868: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8869: } else {
8870: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8871: }
8872: }
8873: }
8874: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8875: foreach my $type (@{$types}) {
8876: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8877: foreach my $field (@fields) {
8878: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8879: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8880: push(@{$changes{'selfcreate'}},$type);
8881: last;
8882: }
8883: }
8884: }
8885: }
8886: } else {
8887: foreach my $type (@{$types}) {
8888: push(@{$changes{'selfcreate'}},$type);
8889: }
8890: }
8891: }
1.160.6.44 raeburn 8892: foreach my $field (@shibfields) {
8893: if ($env{'form.shibenv_'.$field} ne '') {
8894: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
8895: }
8896: }
8897: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8898: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
8899: foreach my $field (@shibfields) {
8900: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
8901: push(@{$changes{'cancreate'}},'shibenv');
8902: }
8903: }
8904: } else {
8905: foreach my $field (@shibfields) {
8906: if ($env{'form.shibenv_'.$field}) {
8907: push(@{$changes{'cancreate'}},'shibenv');
8908: last;
8909: }
8910: }
8911: }
8912: }
1.160.6.34 raeburn 8913: }
8914: foreach my $item (@contexts) {
8915: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8916: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8917: if (ref($cancreate{$item}) eq 'ARRAY') {
8918: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8919: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8920: push(@{$changes{'cancreate'}},$item);
8921: }
8922: }
8923: }
8924: }
8925: if (ref($cancreate{$item}) eq 'ARRAY') {
8926: foreach my $type (@{$cancreate{$item}}) {
8927: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8928: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8929: push(@{$changes{'cancreate'}},$item);
8930: }
8931: }
8932: }
8933: }
8934: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8935: if (ref($cancreate{$item}) eq 'HASH') {
8936: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 8937: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8938: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8939: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8940: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8941: push(@{$changes{'cancreate'}},$item);
8942: }
8943: }
8944: }
1.160.6.40 raeburn 8945: } elsif ($item eq 'selfcreateprocessing') {
8946: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
8947: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8948: push(@{$changes{'cancreate'}},$item);
8949: }
8950: }
1.160.6.35 raeburn 8951: } else {
8952: if (!$cancreate{$item}{$curr}) {
8953: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8954: push(@{$changes{'cancreate'}},$item);
8955: }
1.160.6.34 raeburn 8956: }
8957: }
8958: }
8959: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 8960: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8961: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8962: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8963: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8964: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8965: push(@{$changes{'cancreate'}},$item);
8966: }
8967: }
8968: } else {
8969: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8970: push(@{$changes{'cancreate'}},$item);
8971: }
8972: }
8973: }
1.160.6.40 raeburn 8974: } elsif ($item eq 'selfcreateprocessing') {
8975: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
8976: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8977: push(@{$changes{'cancreate'}},$item);
8978: }
8979: }
1.160.6.35 raeburn 8980: } else {
8981: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8982: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8983: push(@{$changes{'cancreate'}},$item);
8984: }
1.160.6.34 raeburn 8985: }
8986: }
8987: }
8988: }
8989: } elsif ($curr_usercreation{'cancreate'}{$item}) {
8990: if (ref($cancreate{$item}) eq 'ARRAY') {
8991: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
8992: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8993: push(@{$changes{'cancreate'}},$item);
8994: }
8995: }
8996: } elsif (ref($cancreate{$item}) eq 'HASH') {
8997: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
8998: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8999: push(@{$changes{'cancreate'}},$item);
9000: }
9001: }
9002: }
9003: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 9004: if (ref($cancreate{$item}) eq 'HASH') {
9005: foreach my $type (keys(%{$cancreate{$item}})) {
9006: if (ref($cancreate{$item}{$type}) eq 'HASH') {
9007: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
9008: if ($cancreate{$item}{$type}{$field}) {
9009: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9010: push(@{$changes{'cancreate'}},$item);
9011: }
9012: last;
9013: }
9014: }
9015: }
9016: }
1.160.6.34 raeburn 9017: }
9018: }
9019: }
9020: #
9021: # Populate %save_usercreate hash with updates to self-creation configuration.
9022: #
9023: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
9024: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
9025: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
9026: if (ref($cancreate{'notify'}) eq 'HASH') {
9027: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
9028: }
1.160.6.40 raeburn 9029: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
9030: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
9031: }
1.160.6.34 raeburn 9032: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9033: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
9034: }
1.160.6.44 raeburn 9035: if (ref($cancreate{'shibenv'}) eq 'HASH') {
9036: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
9037: }
1.160.6.34 raeburn 9038: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
9039: $save_usercreate{'emailrule'} = \@email_rule;
9040:
9041: my %userconfig_hash = (
9042: usercreation => \%save_usercreate,
9043: usermodification => \%save_usermodify,
9044: );
9045: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
9046: $dom);
9047: #
9048: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
9049: #
1.27 raeburn 9050: if ($putresult eq 'ok') {
9051: if (keys(%changes) > 0) {
9052: $resulttext = &mt('Changes made:').'<ul>';
9053: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 9054: my %lt = &selfcreation_types();
1.34 raeburn 9055: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 9056: my $chgtext;
1.45 raeburn 9057: if ($type eq 'selfcreate') {
1.50 raeburn 9058: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 9059: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 9060: } else {
1.160.6.34 raeburn 9061: $chgtext .= &mt('Self-creation of a new account is permitted for:').
9062: '<ul>';
1.50 raeburn 9063: foreach my $case (@{$cancreate{$type}}) {
9064: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
9065: }
9066: $chgtext .= '</ul>';
1.100 raeburn 9067: if (ref($cancreate{$type}) eq 'ARRAY') {
9068: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
9069: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9070: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 9071: $chgtext .= '<br />'.
9072: '<span class="LC_warning">'.
9073: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9074: '</span>';
1.100 raeburn 9075: }
9076: }
9077: }
9078: }
1.43 raeburn 9079: }
1.160.6.44 raeburn 9080: } elsif ($type eq 'shibenv') {
9081: if (keys(%{$cancreate{$type}}) == 0) {
9082: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
9083: } else {
9084: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
9085: '<ul>';
9086: foreach my $field (@shibfields) {
9087: next if ($cancreate{$type}{$field} eq '');
9088: if ($field eq 'inststatus') {
9089: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
9090: } else {
9091: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
9092: }
9093: }
9094: $chgtext .= '</ul>';
9095: }
1.93 raeburn 9096: } elsif ($type eq 'statustocreate') {
1.96 raeburn 9097: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
9098: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
9099: if (@{$cancreate{'selfcreate'}} > 0) {
9100: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 9101: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 9102: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 9103: $chgtext .= '<br />'.
9104: '<span class="LC_warning">'.
9105: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9106: '</span>';
9107: }
1.96 raeburn 9108: } elsif (ref($usertypes) eq 'HASH') {
9109: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 9110: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
9111: } else {
9112: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
9113: }
9114: $chgtext .= '<ul>';
9115: foreach my $case (@{$cancreate{$type}}) {
9116: if ($case eq 'default') {
9117: $chgtext .= '<li>'.$othertitle.'</li>';
9118: } else {
9119: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 9120: }
9121: }
1.100 raeburn 9122: $chgtext .= '</ul>';
9123: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 9124: $chgtext .= '<br /><span class="LC_warning">'.
9125: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
9126: '</span>';
1.100 raeburn 9127: }
9128: }
9129: } else {
9130: if (@{$cancreate{$type}} == 0) {
9131: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
9132: } else {
9133: $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 9134: }
9135: }
9136: }
1.160.6.40 raeburn 9137: } elsif ($type eq 'selfcreateprocessing') {
9138: my %choices = &Apache::lonlocal::texthash (
9139: automatic => 'Automatic approval',
9140: approval => 'Queued for approval',
9141: );
9142: if (@statuses > 1) {
9143: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
9144: '<ul>';
9145: foreach my $type (@statuses) {
9146: if ($type eq 'default') {
9147: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9148: } else {
9149: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9150: }
9151: }
9152: $chgtext .= '</ul>';
9153: } else {
9154: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
9155: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
9156: }
1.160.6.5 raeburn 9157: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 9158: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 9159: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
9160: } else {
9161: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 9162: if ($captchas{$savecaptcha{$type}}) {
9163: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 9164: } else {
9165: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
9166: }
9167: }
9168: } elsif ($type eq 'recaptchakeys') {
9169: my ($privkey,$pubkey);
1.160.6.34 raeburn 9170: if (ref($savecaptcha{$type}) eq 'HASH') {
9171: $pubkey = $savecaptcha{$type}{'public'};
9172: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 9173: }
9174: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
9175: if (!$pubkey) {
9176: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
9177: } else {
9178: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9179: }
9180: if (!$privkey) {
9181: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
9182: } else {
9183: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
9184: }
9185: $chgtext .= '</ul>';
1.160.6.34 raeburn 9186: } elsif ($type eq 'emailusername') {
9187: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 9188: if (ref($types) eq 'ARRAY') {
9189: foreach my $type (@{$types}) {
9190: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
9191: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50 raeburn 9192: $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 9193: '<ul>';
9194: foreach my $field (@{$infofields}) {
9195: if ($cancreate{'emailusername'}{$type}{$field}) {
9196: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
9197: }
9198: }
1.160.6.50 raeburn 9199: $chgtext .= '</ul>';
9200: } else {
9201: $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 9202: }
9203: } else {
1.160.6.50 raeburn 9204: $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 9205: }
9206: }
9207: }
9208: }
9209: } elsif ($type eq 'notify') {
9210: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
9211: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9212: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
9213: if ($cancreate{'notify'}{'approval'}) {
9214: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
9215: }
9216: }
1.43 raeburn 9217: }
1.34 raeburn 9218: }
1.160.6.34 raeburn 9219: if ($chgtext) {
9220: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 9221: }
9222: }
9223: }
1.43 raeburn 9224: if (ref($changes{'email_rule'}) eq 'ARRAY') {
9225: my ($emailrules,$emailruleorder) =
9226: &Apache::lonnet::inst_userrules($dom,'email');
9227: my $chgtext = '<ul>';
9228: foreach my $type (@email_rule) {
9229: if (ref($emailrules->{$type}) eq 'HASH') {
9230: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
9231: }
9232: }
9233: $chgtext .= '</ul>';
9234: if (@email_rule > 0) {
1.160.6.34 raeburn 9235: $resulttext .= '<li>'.
9236: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
9237: $chgtext.
9238: '</li>';
1.43 raeburn 9239: } else {
1.160.6.34 raeburn 9240: $resulttext .= '<li>'.
9241: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
9242: '</li>';
1.43 raeburn 9243: }
9244: }
1.160.6.34 raeburn 9245: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
9246: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
9247: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9248: foreach my $type (@{$changes{'selfcreate'}}) {
9249: my $typename = $type;
9250: if (ref($usertypes) eq 'HASH') {
9251: if ($usertypes->{$type} ne '') {
9252: $typename = $usertypes->{$type};
1.28 raeburn 9253: }
9254: }
1.160.6.34 raeburn 9255: my @modifiable;
9256: $resulttext .= '<li>'.
9257: &mt('Self-creation of account by users with status: [_1]',
9258: '<span class="LC_cusr_emph">'.$typename.'</span>').
9259: ' - '.&mt('modifiable fields (if institutional data blank): ');
9260: foreach my $field (@fields) {
9261: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9262: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
9263: }
9264: }
9265: if (@modifiable > 0) {
9266: $resulttext .= join(', ',@modifiable);
1.43 raeburn 9267: } else {
1.160.6.34 raeburn 9268: $resulttext .= &mt('none');
1.43 raeburn 9269: }
1.160.6.34 raeburn 9270: $resulttext .= '</li>';
1.28 raeburn 9271: }
1.160.6.34 raeburn 9272: $resulttext .= '</ul></li>';
1.28 raeburn 9273: }
1.27 raeburn 9274: $resulttext .= '</ul>';
9275: } else {
1.160.6.34 raeburn 9276: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 9277: }
9278: } else {
9279: $resulttext = '<span class="LC_error">'.
1.23 raeburn 9280: &mt('An error occurred: [_1]',$putresult).'</span>';
9281: }
1.43 raeburn 9282: if ($warningmsg ne '') {
9283: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9284: }
1.23 raeburn 9285: return $resulttext;
9286: }
9287:
1.160.6.5 raeburn 9288: sub process_captcha {
9289: my ($container,$changes,$newsettings,$current) = @_;
9290: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9291: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9292: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9293: $newsettings->{'captcha'} = 'original';
9294: }
9295: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
9296: if ($container eq 'cancreate') {
9297: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9298: push(@{$changes->{'cancreate'}},'captcha');
9299: } elsif (!defined($changes->{'cancreate'})) {
9300: $changes->{'cancreate'} = ['captcha'];
9301: }
9302: } else {
9303: $changes->{'captcha'} = 1;
9304: }
9305: }
9306: my ($newpub,$newpriv,$currpub,$currpriv);
9307: if ($newsettings->{'captcha'} eq 'recaptcha') {
9308: $newpub = $env{'form.'.$container.'_recaptchapub'};
9309: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 9310: $newpub =~ s/[^\w\-]//g;
9311: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 9312: $newsettings->{'recaptchakeys'} = {
9313: public => $newpub,
9314: private => $newpriv,
9315: };
9316: }
9317: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9318: $currpub = $current->{'recaptchakeys'}{'public'};
9319: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 9320: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9321: $newsettings->{'recaptchakeys'} = {
9322: public => '',
9323: private => '',
9324: }
9325: }
1.160.6.5 raeburn 9326: }
9327: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
9328: if ($container eq 'cancreate') {
9329: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9330: push(@{$changes->{'cancreate'}},'recaptchakeys');
9331: } elsif (!defined($changes->{'cancreate'})) {
9332: $changes->{'cancreate'} = ['recaptchakeys'];
9333: }
9334: } else {
9335: $changes->{'recaptchakeys'} = 1;
9336: }
9337: }
9338: return;
9339: }
9340:
1.33 raeburn 9341: sub modify_usermodification {
9342: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9343: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 9344: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9345: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 9346: if ($key eq 'selfcreate') {
9347: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9348: } else {
9349: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9350: }
1.33 raeburn 9351: }
9352: }
1.160.6.34 raeburn 9353: my @contexts = ('author','course');
1.33 raeburn 9354: my %context_title = (
9355: author => 'In author context',
9356: course => 'In course context',
9357: );
9358: my @fields = ('lastname','firstname','middlename','generation',
9359: 'permanentemail','id');
9360: my %roles = (
9361: author => ['ca','aa'],
9362: course => ['st','ep','ta','in','cr'],
9363: );
9364: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9365: foreach my $context (@contexts) {
9366: foreach my $role (@{$roles{$context}}) {
9367: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9368: foreach my $item (@fields) {
9369: if (grep(/^\Q$item\E$/,@modifiable)) {
9370: $modifyhash{$context}{$role}{$item} = 1;
9371: } else {
9372: $modifyhash{$context}{$role}{$item} = 0;
9373: }
9374: }
9375: }
9376: if (ref($curr_usermodification{$context}) eq 'HASH') {
9377: foreach my $role (@{$roles{$context}}) {
9378: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9379: foreach my $field (@fields) {
9380: if ($modifyhash{$context}{$role}{$field} ne
9381: $curr_usermodification{$context}{$role}{$field}) {
9382: push(@{$changes{$context}},$role);
9383: last;
9384: }
9385: }
9386: }
9387: }
9388: } else {
9389: foreach my $context (@contexts) {
9390: foreach my $role (@{$roles{$context}}) {
9391: push(@{$changes{$context}},$role);
9392: }
9393: }
9394: }
9395: }
9396: my %usermodification_hash = (
9397: usermodification => \%modifyhash,
9398: );
9399: my $putresult = &Apache::lonnet::put_dom('configuration',
9400: \%usermodification_hash,$dom);
9401: if ($putresult eq 'ok') {
9402: if (keys(%changes) > 0) {
9403: $resulttext = &mt('Changes made: ').'<ul>';
9404: foreach my $context (@contexts) {
9405: if (ref($changes{$context}) eq 'ARRAY') {
9406: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9407: if (ref($changes{$context}) eq 'ARRAY') {
9408: foreach my $role (@{$changes{$context}}) {
9409: my $rolename;
1.160.6.34 raeburn 9410: if ($role eq 'cr') {
9411: $rolename = &mt('Custom');
1.33 raeburn 9412: } else {
1.160.6.34 raeburn 9413: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9414: }
9415: my @modifiable;
1.160.6.34 raeburn 9416: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9417: foreach my $field (@fields) {
9418: if ($modifyhash{$context}{$role}{$field}) {
9419: push(@modifiable,$fieldtitles{$field});
9420: }
9421: }
9422: if (@modifiable > 0) {
9423: $resulttext .= join(', ',@modifiable);
9424: } else {
9425: $resulttext .= &mt('none');
9426: }
9427: $resulttext .= '</li>';
9428: }
9429: $resulttext .= '</ul></li>';
9430: }
9431: }
9432: }
9433: $resulttext .= '</ul>';
9434: } else {
9435: $resulttext = &mt('No changes made to user modification settings');
9436: }
9437: } else {
9438: $resulttext = '<span class="LC_error">'.
9439: &mt('An error occurred: [_1]',$putresult).'</span>';
9440: }
9441: return $resulttext;
9442: }
9443:
1.43 raeburn 9444: sub modify_defaults {
1.160.6.27 raeburn 9445: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9446: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 9447: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9448: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9449: my @authtypes = ('internal','krb4','krb5','localauth');
9450: foreach my $item (@items) {
9451: $newvalues{$item} = $env{'form.'.$item};
9452: if ($item eq 'auth_def') {
9453: if ($newvalues{$item} ne '') {
9454: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9455: push(@errors,$item);
9456: }
9457: }
9458: } elsif ($item eq 'lang_def') {
9459: if ($newvalues{$item} ne '') {
9460: if ($newvalues{$item} =~ /^(\w+)/) {
9461: my $langcode = $1;
1.103 raeburn 9462: if ($langcode ne 'x_chef') {
9463: if (code2language($langcode) eq '') {
9464: push(@errors,$item);
9465: }
1.43 raeburn 9466: }
9467: } else {
9468: push(@errors,$item);
9469: }
9470: }
1.54 raeburn 9471: } elsif ($item eq 'timezone_def') {
9472: if ($newvalues{$item} ne '') {
1.62 raeburn 9473: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9474: push(@errors,$item);
9475: }
9476: }
1.68 raeburn 9477: } elsif ($item eq 'datelocale_def') {
9478: if ($newvalues{$item} ne '') {
9479: my @datelocale_ids = DateTime::Locale->ids();
9480: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9481: push(@errors,$item);
9482: }
9483: }
1.141 raeburn 9484: } elsif ($item eq 'portal_def') {
9485: if ($newvalues{$item} ne '') {
9486: 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])\/?$/) {
9487: push(@errors,$item);
9488: }
9489: }
1.43 raeburn 9490: }
9491: if (grep(/^\Q$item\E$/,@errors)) {
9492: $newvalues{$item} = $domdefaults{$item};
9493: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9494: $changes{$item} = 1;
9495: }
1.72 raeburn 9496: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9497: }
9498: my %defaults_hash = (
1.72 raeburn 9499: defaults => \%newvalues,
9500: );
1.43 raeburn 9501: my $title = &defaults_titles();
1.160.6.40 raeburn 9502:
9503: my $currinststatus;
9504: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9505: $currinststatus = $domconfig{'inststatus'};
9506: } else {
9507: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9508: $currinststatus = {
9509: inststatustypes => $usertypes,
9510: inststatusorder => $types,
9511: inststatusguest => [],
9512: };
9513: }
9514: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9515: my @allpos;
9516: my %guests;
9517: my %alltypes;
9518: my ($currtitles,$currguests,$currorder);
9519: if (ref($currinststatus) eq 'HASH') {
9520: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9521: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9522: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9523: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9524: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9525: }
9526: }
9527: unless (grep(/^\Q$type\E$/,@todelete)) {
9528: my $position = $env{'form.inststatus_pos_'.$type};
9529: $position =~ s/\D+//g;
9530: $allpos[$position] = $type;
9531: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9532: $alltypes{$type} =~ s/`//g;
9533: if ($env{'form.inststatus_guest_'.$type}) {
9534: $guests{$type} = 1;
9535: }
9536: }
9537: }
9538: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9539: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9540: }
9541: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9542: $currtitles =~ s/,$//;
9543: }
9544: }
9545: if ($env{'form.addinststatus'}) {
9546: my $newtype = $env{'form.addinststatus'};
9547: $newtype =~ s/\W//g;
9548: unless (exists($alltypes{$newtype})) {
9549: if ($env{'form.addinststatus_guest'}) {
9550: $guests{$newtype} = 1;
9551: }
9552: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9553: $alltypes{$newtype} =~ s/`//g;
9554: my $position = $env{'form.addinststatus_pos'};
9555: $position =~ s/\D+//g;
9556: if ($position ne '') {
9557: $allpos[$position] = $newtype;
9558: }
9559: }
9560: }
9561: my (@orderedstatus,@orderedguests);
9562: foreach my $type (@allpos) {
9563: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9564: push(@orderedstatus,$type);
9565: if ($guests{$type}) {
9566: push(@orderedguests,$type);
9567: }
9568: }
9569: }
9570: foreach my $type (keys(%alltypes)) {
9571: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9572: delete($alltypes{$type});
9573: }
9574: }
9575: $defaults_hash{'inststatus'} = {
9576: inststatustypes => \%alltypes,
9577: inststatusorder => \@orderedstatus,
9578: inststatusguest => \@orderedguests,
9579: };
9580: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9581: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9582: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9583: }
9584: }
9585: if ($currorder ne join(',',@orderedstatus)) {
9586: $changes{'inststatus'}{'inststatusorder'} = 1;
9587: }
9588: if ($currguests ne join(',',@orderedguests)) {
9589: $changes{'inststatus'}{'inststatusguest'} = 1;
9590: }
9591: my $newtitles;
9592: foreach my $item (@orderedstatus) {
9593: $newtitles .= $alltypes{$item}.',';
9594: }
9595: $newtitles =~ s/,$//;
9596: if ($currtitles ne $newtitles) {
9597: $changes{'inststatus'}{'inststatustypes'} = 1;
9598: }
1.43 raeburn 9599: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9600: $dom);
9601: if ($putresult eq 'ok') {
9602: if (keys(%changes) > 0) {
9603: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 9604: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9605: 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";
9606: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 9607: if ($item eq 'inststatus') {
9608: if (ref($changes{'inststatus'}) eq 'HASH') {
9609: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9610: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9611: foreach my $type (@orderedstatus) {
9612: $resulttext .= $alltypes{$type}.', ';
9613: }
9614: $resulttext =~ s/, $//;
9615: $resulttext .= '</li>';
9616: }
9617: if ($changes{'inststatus'}{'inststatusguest'}) {
9618: $resulttext .= '<li>';
9619: if (@orderedguests) {
9620: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9621: foreach my $type (@orderedguests) {
9622: $resulttext .= $alltypes{$type}.', ';
9623: }
9624: $resulttext =~ s/, $//;
9625: } else {
9626: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9627: }
9628: $resulttext .= '</li>';
9629: }
9630: }
9631: } else {
9632: my $value = $env{'form.'.$item};
9633: if ($value eq '') {
9634: $value = &mt('none');
9635: } elsif ($item eq 'auth_def') {
9636: my %authnames = &authtype_names();
9637: my %shortauth = (
9638: internal => 'int',
9639: krb4 => 'krb4',
9640: krb5 => 'krb5',
9641: localauth => 'loc',
9642: );
9643: $value = $authnames{$shortauth{$value}};
9644: }
9645: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9646: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 9647: }
9648: }
9649: $resulttext .= '</ul>';
9650: $mailmsgtext .= "\n";
9651: my $cachetime = 24*60*60;
1.72 raeburn 9652: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9653: if (ref($lastactref) eq 'HASH') {
9654: $lastactref->{'domdefaults'} = 1;
9655: }
1.68 raeburn 9656: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 9657: my $notify = 1;
9658: if (ref($domconfig{'contacts'}) eq 'HASH') {
9659: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9660: $notify = 0;
9661: }
9662: }
9663: if ($notify) {
9664: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9665: "LON-CAPA Domain Settings Change - $dom",
9666: $mailmsgtext);
9667: }
1.54 raeburn 9668: }
1.43 raeburn 9669: } else {
1.54 raeburn 9670: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 9671: }
9672: } else {
9673: $resulttext = '<span class="LC_error">'.
9674: &mt('An error occurred: [_1]',$putresult).'</span>';
9675: }
9676: if (@errors > 0) {
9677: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9678: foreach my $item (@errors) {
9679: $resulttext .= ' "'.$title->{$item}.'",';
9680: }
9681: $resulttext =~ s/,$//;
9682: }
9683: return $resulttext;
9684: }
9685:
1.46 raeburn 9686: sub modify_scantron {
1.160.6.24 raeburn 9687: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 9688: my ($resulttext,%confhash,%changes,$errors);
9689: my $custom = 'custom.tab';
9690: my $default = 'default.tab';
9691: my $servadm = $r->dir_config('lonAdmEMail');
9692: my ($configuserok,$author_ok,$switchserver) =
9693: &config_check($dom,$confname,$servadm);
9694: if ($env{'form.scantronformat.filename'} ne '') {
9695: my $error;
9696: if ($configuserok eq 'ok') {
9697: if ($switchserver) {
1.130 raeburn 9698: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 9699: } else {
9700: if ($author_ok eq 'ok') {
9701: my ($result,$scantronurl) =
9702: &publishlogo($r,'upload','scantronformat',$dom,
9703: $confname,'scantron','','',$custom);
9704: if ($result eq 'ok') {
9705: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 9706: $changes{'scantronformat'} = 1;
1.46 raeburn 9707: } else {
9708: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9709: }
9710: } else {
9711: $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);
9712: }
9713: }
9714: } else {
9715: $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);
9716: }
9717: if ($error) {
9718: &Apache::lonnet::logthis($error);
9719: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9720: }
9721: }
1.48 raeburn 9722: if (ref($domconfig{'scantron'}) eq 'HASH') {
9723: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9724: if ($env{'form.scantronformat_del'}) {
9725: $confhash{'scantron'}{'scantronformat'} = '';
9726: $changes{'scantronformat'} = 1;
1.46 raeburn 9727: }
9728: }
9729: }
9730: if (keys(%confhash) > 0) {
9731: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9732: $dom);
9733: if ($putresult eq 'ok') {
9734: if (keys(%changes) > 0) {
1.48 raeburn 9735: if (ref($confhash{'scantron'}) eq 'HASH') {
9736: $resulttext = &mt('Changes made:').'<ul>';
9737: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 9738: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 9739: } else {
1.130 raeburn 9740: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 9741: }
1.48 raeburn 9742: $resulttext .= '</ul>';
9743: } else {
1.130 raeburn 9744: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 9745: }
9746: $resulttext .= '</ul>';
9747: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9748: if (ref($lastactref) eq 'HASH') {
9749: $lastactref->{'domainconfig'} = 1;
9750: }
1.46 raeburn 9751: } else {
1.130 raeburn 9752: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9753: }
9754: } else {
9755: $resulttext = '<span class="LC_error">'.
9756: &mt('An error occurred: [_1]',$putresult).'</span>';
9757: }
9758: } else {
1.130 raeburn 9759: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9760: }
9761: if ($errors) {
9762: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9763: $errors.'</ul>';
9764: }
9765: return $resulttext;
9766: }
9767:
1.48 raeburn 9768: sub modify_coursecategories {
1.160.6.43 raeburn 9769: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 9770: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9771: $cathash);
1.48 raeburn 9772: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 9773: my @catitems = ('unauth','auth');
9774: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 9775: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 9776: $cathash = $domconfig{'coursecategories'}{'cats'};
9777: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9778: $changes{'togglecats'} = 1;
9779: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9780: }
9781: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9782: $changes{'categorize'} = 1;
9783: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9784: }
1.120 raeburn 9785: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9786: $changes{'togglecatscomm'} = 1;
9787: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9788: }
9789: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9790: $changes{'categorizecomm'} = 1;
9791: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9792: }
1.160.6.42 raeburn 9793: foreach my $item (@catitems) {
9794: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9795: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
9796: $changes{$item} = 1;
9797: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9798: }
9799: }
9800: }
1.57 raeburn 9801: } else {
9802: $changes{'togglecats'} = 1;
9803: $changes{'categorize'} = 1;
1.124 raeburn 9804: $changes{'togglecatscomm'} = 1;
9805: $changes{'categorizecomm'} = 1;
1.87 raeburn 9806: $domconfig{'coursecategories'} = {
9807: togglecats => $env{'form.togglecats'},
9808: categorize => $env{'form.categorize'},
1.124 raeburn 9809: togglecatscomm => $env{'form.togglecatscomm'},
9810: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 9811: };
1.160.6.42 raeburn 9812: foreach my $item (@catitems) {
9813: if ($env{'form.coursecat_'.$item} ne 'std') {
9814: $changes{$item} = 1;
9815: }
9816: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9817: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9818: }
9819: }
1.57 raeburn 9820: }
9821: if (ref($cathash) eq 'HASH') {
9822: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 9823: push (@deletecategory,'instcode::0');
9824: }
1.120 raeburn 9825: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9826: push(@deletecategory,'communities::0');
9827: }
1.48 raeburn 9828: }
1.57 raeburn 9829: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9830: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9831: if (@deletecategory > 0) {
9832: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 9833: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 9834: foreach my $item (@deletecategory) {
1.57 raeburn 9835: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9836: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 9837: $deletions{$item} = 1;
1.57 raeburn 9838: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 9839: }
9840: }
9841: }
1.57 raeburn 9842: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 9843: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 9844: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 9845: $reorderings{$item} = 1;
1.57 raeburn 9846: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 9847: }
9848: if ($env{'form.addcategory_name_'.$item} ne '') {
9849: my $newcat = $env{'form.addcategory_name_'.$item};
9850: my $newdepth = $depth+1;
9851: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9852: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 9853: $adds{$newitem} = 1;
9854: }
9855: if ($env{'form.subcat_'.$item} ne '') {
9856: my $newcat = $env{'form.subcat_'.$item};
9857: my $newdepth = $depth+1;
9858: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9859: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 9860: $adds{$newitem} = 1;
9861: }
9862: }
9863: }
9864: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 9865: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9866: my $newitem = 'instcode::0';
1.57 raeburn 9867: if ($cathash->{$newitem} eq '') {
9868: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9869: $adds{$newitem} = 1;
9870: }
9871: } else {
9872: my $newitem = 'instcode::0';
1.57 raeburn 9873: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9874: $adds{$newitem} = 1;
9875: }
9876: }
1.120 raeburn 9877: if ($env{'form.communities'} eq '1') {
9878: if (ref($cathash) eq 'HASH') {
9879: my $newitem = 'communities::0';
9880: if ($cathash->{$newitem} eq '') {
9881: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9882: $adds{$newitem} = 1;
9883: }
9884: } else {
9885: my $newitem = 'communities::0';
9886: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9887: $adds{$newitem} = 1;
9888: }
9889: }
1.48 raeburn 9890: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 9891: if (($env{'form.addcategory_name'} ne 'instcode') &&
9892: ($env{'form.addcategory_name'} ne 'communities')) {
9893: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9894: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9895: $adds{$newitem} = 1;
9896: }
1.48 raeburn 9897: }
1.57 raeburn 9898: my $putresult;
1.48 raeburn 9899: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9900: if (keys(%deletions) > 0) {
9901: foreach my $key (keys(%deletions)) {
9902: if ($predelallitems{$key} ne '') {
9903: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9904: }
9905: }
9906: }
9907: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 9908: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 9909: if (ref($chkcats[0]) eq 'ARRAY') {
9910: my $depth = 0;
9911: my $chg = 0;
9912: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9913: my $name = $chkcats[0][$i];
9914: my $item;
9915: if ($name eq '') {
9916: $chg ++;
9917: } else {
9918: $item = &escape($name).'::0';
9919: if ($chg) {
1.57 raeburn 9920: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 9921: }
9922: $depth ++;
1.57 raeburn 9923: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 9924: $depth --;
9925: }
9926: }
9927: }
1.57 raeburn 9928: }
9929: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9930: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 9931: if ($putresult eq 'ok') {
1.57 raeburn 9932: my %title = (
1.120 raeburn 9933: togglecats => 'Show/Hide a course in catalog',
9934: categorize => 'Assign a category to a course',
9935: togglecatscomm => 'Show/Hide a community in catalog',
9936: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9937: );
9938: my %level = (
1.120 raeburn 9939: dom => 'set in Domain ("Modify Course/Community")',
9940: crs => 'set in Course ("Course Configuration")',
9941: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 9942: none => 'No catalog',
9943: std => 'Standard catalog',
9944: domonly => 'Domain-only catalog',
9945: codesrch => 'Code search form',
1.57 raeburn 9946: );
1.48 raeburn 9947: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 9948: if ($changes{'togglecats'}) {
9949: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9950: }
9951: if ($changes{'categorize'}) {
9952: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 9953: }
1.120 raeburn 9954: if ($changes{'togglecatscomm'}) {
9955: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9956: }
9957: if ($changes{'categorizecomm'}) {
9958: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9959: }
1.160.6.42 raeburn 9960: if ($changes{'unauth'}) {
9961: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
9962: }
9963: if ($changes{'auth'}) {
9964: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
9965: }
1.57 raeburn 9966: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9967: my $cathash;
9968: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9969: $cathash = $domconfig{'coursecategories'}{'cats'};
9970: } else {
9971: $cathash = {};
9972: }
9973: my (@cats,@trails,%allitems);
9974: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
9975: if (keys(%deletions) > 0) {
9976: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
9977: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
9978: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
9979: }
9980: $resulttext .= '</ul></li>';
9981: }
9982: if (keys(%reorderings) > 0) {
9983: my %sort_by_trail;
9984: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
9985: foreach my $key (keys(%reorderings)) {
9986: if ($allitems{$key} ne '') {
9987: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9988: }
1.48 raeburn 9989: }
1.57 raeburn 9990: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9991: $resulttext .= '<li>'.$trails[$trail].'</li>';
9992: }
9993: $resulttext .= '</ul></li>';
1.48 raeburn 9994: }
1.57 raeburn 9995: if (keys(%adds) > 0) {
9996: my %sort_by_trail;
9997: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
9998: foreach my $key (keys(%adds)) {
9999: if ($allitems{$key} ne '') {
10000: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10001: }
10002: }
10003: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10004: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 10005: }
1.57 raeburn 10006: $resulttext .= '</ul></li>';
1.48 raeburn 10007: }
10008: }
10009: $resulttext .= '</ul>';
1.160.6.43 raeburn 10010: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 10011: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10012: if ($changes{'auth'}) {
10013: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
10014: }
10015: if ($changes{'unauth'}) {
10016: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
10017: }
10018: my $cachetime = 24*60*60;
10019: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 10020: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 10021: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 10022: }
10023: }
1.48 raeburn 10024: } else {
10025: $resulttext = '<span class="LC_error">'.
1.57 raeburn 10026: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 10027: }
10028: } else {
1.120 raeburn 10029: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 10030: }
10031: return $resulttext;
10032: }
10033:
1.69 raeburn 10034: sub modify_serverstatuses {
10035: my ($dom,%domconfig) = @_;
10036: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
10037: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
10038: %currserverstatus = %{$domconfig{'serverstatuses'}};
10039: }
10040: my @pages = &serverstatus_pages();
10041: foreach my $type (@pages) {
10042: $newserverstatus{$type}{'namedusers'} = '';
10043: $newserverstatus{$type}{'machines'} = '';
10044: if (defined($env{'form.'.$type.'_namedusers'})) {
10045: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
10046: my @okusers;
10047: foreach my $user (@users) {
10048: my ($uname,$udom) = split(/:/,$user);
10049: if (($udom =~ /^$match_domain$/) &&
10050: (&Apache::lonnet::domain($udom)) &&
10051: ($uname =~ /^$match_username$/)) {
10052: if (!grep(/^\Q$user\E/,@okusers)) {
10053: push(@okusers,$user);
10054: }
10055: }
10056: }
10057: if (@okusers > 0) {
10058: @okusers = sort(@okusers);
10059: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
10060: }
10061: }
10062: if (defined($env{'form.'.$type.'_machines'})) {
10063: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
10064: my @okmachines;
10065: foreach my $ip (@machines) {
10066: my @parts = split(/\./,$ip);
10067: next if (@parts < 4);
10068: my $badip = 0;
10069: for (my $i=0; $i<4; $i++) {
10070: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
10071: $badip = 1;
10072: last;
10073: }
10074: }
10075: if (!$badip) {
10076: push(@okmachines,$ip);
10077: }
10078: }
10079: @okmachines = sort(@okmachines);
10080: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
10081: }
10082: }
10083: my %serverstatushash = (
10084: serverstatuses => \%newserverstatus,
10085: );
10086: foreach my $type (@pages) {
1.83 raeburn 10087: foreach my $setting ('namedusers','machines') {
1.84 raeburn 10088: my (@current,@new);
1.83 raeburn 10089: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 10090: if ($currserverstatus{$type}{$setting} ne '') {
10091: @current = split(/,/,$currserverstatus{$type}{$setting});
10092: }
10093: }
10094: if ($newserverstatus{$type}{$setting} ne '') {
10095: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 10096: }
10097: if (@current > 0) {
10098: if (@new > 0) {
10099: foreach my $item (@current) {
10100: if (!grep(/^\Q$item\E$/,@new)) {
10101: $changes{$type}{$setting} = 1;
1.82 raeburn 10102: last;
10103: }
10104: }
1.84 raeburn 10105: foreach my $item (@new) {
10106: if (!grep(/^\Q$item\E$/,@current)) {
10107: $changes{$type}{$setting} = 1;
10108: last;
1.82 raeburn 10109: }
10110: }
10111: } else {
1.83 raeburn 10112: $changes{$type}{$setting} = 1;
1.69 raeburn 10113: }
1.83 raeburn 10114: } elsif (@new > 0) {
10115: $changes{$type}{$setting} = 1;
1.69 raeburn 10116: }
10117: }
10118: }
10119: if (keys(%changes) > 0) {
1.81 raeburn 10120: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10121: my $putresult = &Apache::lonnet::put_dom('configuration',
10122: \%serverstatushash,$dom);
10123: if ($putresult eq 'ok') {
10124: $resulttext .= &mt('Changes made:').'<ul>';
10125: foreach my $type (@pages) {
1.84 raeburn 10126: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 10127: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 10128: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 10129: if ($newserverstatus{$type}{'namedusers'} eq '') {
10130: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
10131: } else {
10132: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
10133: }
1.84 raeburn 10134: }
10135: if ($changes{$type}{'machines'}) {
1.69 raeburn 10136: if ($newserverstatus{$type}{'machines'} eq '') {
10137: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
10138: } else {
10139: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
10140: }
10141:
10142: }
10143: $resulttext .= '</ul></li>';
10144: }
10145: }
10146: $resulttext .= '</ul>';
10147: } else {
10148: $resulttext = '<span class="LC_error">'.
10149: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
10150:
10151: }
10152: } else {
10153: $resulttext = &mt('No changes made to access to server status pages');
10154: }
10155: return $resulttext;
10156: }
10157:
1.118 jms 10158: sub modify_helpsettings {
1.122 jms 10159: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 10160: my ($resulttext,$errors,%changes,%helphash);
10161: my %defaultchecked = ('submitbugs' => 'on');
10162: my @offon = ('off','on');
1.118 jms 10163: my @toggles = ('submitbugs');
10164: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
10165: foreach my $item (@toggles) {
1.160.6.5 raeburn 10166: if ($defaultchecked{$item} eq 'on') {
10167: if ($domconfig{'helpsettings'}{$item} eq '') {
10168: if ($env{'form.'.$item} eq '0') {
10169: $changes{$item} = 1;
10170: }
10171: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10172: $changes{$item} = 1;
10173: }
10174: } elsif ($defaultchecked{$item} eq 'off') {
10175: if ($domconfig{'helpsettings'}{$item} eq '') {
10176: if ($env{'form.'.$item} eq '1') {
10177: $changes{$item} = 1;
10178: }
10179: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10180: $changes{$item} = 1;
10181: }
1.160.6.26 raeburn 10182: }
1.160.6.5 raeburn 10183: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
10184: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 10185: }
10186: }
1.118 jms 10187: }
1.123 jms 10188: my $putresult;
10189: if (keys(%changes) > 0) {
1.160.6.5 raeburn 10190: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
10191: if ($putresult eq 'ok') {
10192: $resulttext = &mt('Changes made:').'<ul>';
10193: foreach my $item (sort(keys(%changes))) {
10194: if ($item eq 'submitbugs') {
10195: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
10196: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
10197: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
10198: }
10199: }
10200: $resulttext .= '</ul>';
10201: } else {
10202: $resulttext = &mt('No changes made to help settings');
10203: $errors .= '<li><span class="LC_error">'.
10204: &mt('An error occurred storing the settings: [_1]',
10205: $putresult).'</span></li>';
10206: }
1.118 jms 10207: }
10208: if ($errors) {
1.160.6.5 raeburn 10209: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 10210: $errors.'</ul>';
10211: }
10212: return $resulttext;
10213: }
10214:
1.121 raeburn 10215: sub modify_coursedefaults {
1.160.6.27 raeburn 10216: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 10217: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 10218: my %defaultchecked = (
10219: 'uselcmath' => 'on',
10220: 'usejsme' => 'on'
10221: );
10222: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 10223: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.30 raeburn 10224: 'uploadquota_community','uploadquota_textbook');
10225: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 10226: my %staticdefaults = (
10227: anonsurvey_threshold => 10,
10228: uploadquota => 500,
1.160.6.57 raeburn 10229: postsubmit => 60,
1.160.6.21 raeburn 10230: );
1.121 raeburn 10231:
10232: $defaultshash{'coursedefaults'} = {};
10233:
10234: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
10235: if ($domconfig{'coursedefaults'} eq '') {
10236: $domconfig{'coursedefaults'} = {};
10237: }
10238: }
10239:
10240: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
10241: foreach my $item (@toggles) {
10242: if ($defaultchecked{$item} eq 'on') {
10243: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10244: ($env{'form.'.$item} eq '0')) {
10245: $changes{$item} = 1;
1.160.6.16 raeburn 10246: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 10247: $changes{$item} = 1;
10248: }
10249: } elsif ($defaultchecked{$item} eq 'off') {
10250: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10251: ($env{'form.'.$item} eq '1')) {
10252: $changes{$item} = 1;
10253: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10254: $changes{$item} = 1;
10255: }
10256: }
10257: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
10258: }
1.160.6.21 raeburn 10259: foreach my $item (@numbers) {
10260: my ($currdef,$newdef);
1.160.6.26 raeburn 10261: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 10262: if ($item eq 'anonsurvey_threshold') {
10263: $currdef = $domconfig{'coursedefaults'}{$item};
10264: $newdef =~ s/\D//g;
10265: if ($newdef eq '' || $newdef < 1) {
10266: $newdef = 1;
10267: }
10268: $defaultshash{'coursedefaults'}{$item} = $newdef;
10269: } else {
10270: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
10271: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10272: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
10273: }
10274: $newdef =~ s/[^\w.\-]//g;
10275: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
10276: }
10277: if ($currdef ne $newdef) {
10278: my $staticdef;
10279: if ($item eq 'anonsurvey_threshold') {
10280: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10281: $changes{$item} = 1;
10282: }
10283: } else {
10284: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
10285: $changes{'uploadquota'} = 1;
10286: }
10287: }
1.139 raeburn 10288: }
10289: }
1.160.6.37 raeburn 10290:
1.160.6.57 raeburn 10291: my %credits;
10292: foreach my $type (@types) {
10293: unless ($type eq 'community') {
10294: $credits{$type} = $env{'form.'.$type.'_credits'};
10295: $credits{$type} =~ s/[^\d.]+//g;
10296: }
10297: }
10298: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
10299: ($env{'form.coursecredits'} eq '1')) {
10300: $changes{'coursecredits'} = 1;
10301: foreach my $type (keys(%credits)) {
10302: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10303: }
10304: } else {
10305: if ($env{'form.coursecredits'} eq '1') {
10306: foreach my $type (@types) {
10307: unless ($type eq 'community') {
10308: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
10309: $changes{'coursecredits'} = 1;
10310: }
10311: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10312: }
10313: }
10314: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10315: foreach my $type (@types) {
10316: unless ($type eq 'community') {
10317: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
10318: $changes{'coursecredits'} = 1;
10319: last;
10320: }
10321: }
10322: }
10323: }
10324: }
10325: if ($env{'form.postsubmit'} eq '1') {
10326: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
10327: my %currtimeout;
10328: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10329: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
10330: $changes{'postsubmit'} = 1;
10331: }
10332: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10333: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
10334: }
10335: } else {
10336: $changes{'postsubmit'} = 1;
10337: }
10338: foreach my $type (@types) {
10339: my $timeout = $env{'form.'.$type.'_timeout'};
10340: $timeout =~ s/\D//g;
10341: if ($timeout == $staticdefaults{'postsubmit'}) {
10342: $timeout = '';
10343: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
10344: $timeout = '0';
10345: }
10346: unless ($timeout eq '') {
10347: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
10348: }
10349: if (exists($currtimeout{$type})) {
10350: if ($timeout ne $currtimeout{$type}) {
10351: $changes{'postsubmit'} = 1;
10352: }
10353: } elsif ($timeout ne '') {
10354: $changes{'postsubmit'} = 1;
10355: }
10356: }
10357: } else {
10358: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
10359: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10360: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
10361: $changes{'postsubmit'} = 1;
10362: }
10363: } else {
10364: $changes{'postsubmit'} = 1;
10365: }
1.160.6.16 raeburn 10366: }
1.121 raeburn 10367: }
10368: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10369: $dom);
10370: if ($putresult eq 'ok') {
10371: if (keys(%changes) > 0) {
1.160.6.27 raeburn 10372: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 10373: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
10374: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'})) {
10375: foreach my $item ('uselcmath','usejsme') {
10376: if ($changes{$item}) {
10377: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
10378: }
1.160.6.16 raeburn 10379: }
10380: if ($changes{'coursecredits'}) {
10381: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 10382: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
10383: $domdefaults{$type.'credits'} =
10384: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
10385: }
10386: }
10387: }
10388: if ($changes{'postsubmit'}) {
10389: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10390: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
10391: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10392: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
10393: $domdefaults{$type.'postsubtimeout'} =
10394: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10395: }
10396: }
1.160.6.16 raeburn 10397: }
10398: }
1.160.6.21 raeburn 10399: if ($changes{'uploadquota'}) {
10400: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10401: foreach my $type (@types) {
10402: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10403: }
10404: }
10405: }
1.121 raeburn 10406: my $cachetime = 24*60*60;
10407: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10408: if (ref($lastactref) eq 'HASH') {
10409: $lastactref->{'domdefaults'} = 1;
10410: }
1.121 raeburn 10411: }
10412: $resulttext = &mt('Changes made:').'<ul>';
10413: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 10414: if ($item eq 'uselcmath') {
1.121 raeburn 10415: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 10416: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 10417: } else {
1.160.6.57 raeburn 10418: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
10419: }
10420: } elsif ($item eq 'usejsme') {
10421: if ($env{'form.'.$item} eq '1') {
10422: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
10423: } else {
10424: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 10425: }
1.139 raeburn 10426: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 10427: $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 10428: } elsif ($item eq 'uploadquota') {
10429: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10430: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10431: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10432: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 10433: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10434:
1.160.6.21 raeburn 10435: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10436: '</ul>'.
10437: '</li>';
10438: } else {
10439: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10440: }
1.160.6.57 raeburn 10441: } elsif ($item eq 'postsubmit') {
10442: if ($domdefaults{'postsubmit'} eq 'off') {
10443: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
10444: } else {
10445: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
10446: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10447: $resulttext .= &mt('durations:').'<ul>';
10448: foreach my $type (@types) {
10449: $resulttext .= '<li>';
10450: my $timeout;
10451: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10452: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10453: }
10454: my $display;
10455: if ($timeout eq '0') {
10456: $display = &mt('unlimited');
10457: } elsif ($timeout eq '') {
10458: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
10459: } else {
10460: $display = &mt('[quant,_1,second]',$timeout);
10461: }
10462: if ($type eq 'community') {
10463: $resulttext .= &mt('Communities');
10464: } elsif ($type eq 'official') {
10465: $resulttext .= &mt('Official courses');
10466: } elsif ($type eq 'unofficial') {
10467: $resulttext .= &mt('Unofficial courses');
10468: } elsif ($type eq 'textbook') {
10469: $resulttext .= &mt('Textbook courses');
10470: }
10471: $resulttext .= ' -- '.$display.'</li>';
10472: }
10473: $resulttext .= '</ul>';
10474: }
10475: $resulttext .= '</li>';
10476: }
1.160.6.16 raeburn 10477: } elsif ($item eq 'coursecredits') {
10478: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10479: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 10480: ($domdefaults{'unofficialcredits'} eq '') &&
10481: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 10482: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10483: } else {
10484: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10485: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10486: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 10487: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 10488: '</ul>'.
10489: '</li>';
10490: }
10491: } else {
10492: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10493: }
1.140 raeburn 10494: }
1.121 raeburn 10495: }
10496: $resulttext .= '</ul>';
10497: } else {
10498: $resulttext = &mt('No changes made to course defaults');
10499: }
10500: } else {
10501: $resulttext = '<span class="LC_error">'.
10502: &mt('An error occurred: [_1]',$putresult).'</span>';
10503: }
10504: return $resulttext;
10505: }
10506:
1.160.6.37 raeburn 10507: sub modify_selfenrollment {
10508: my ($dom,$lastactref,%domconfig) = @_;
10509: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10510: my @types = ('official','unofficial','community','textbook');
10511: my %titles = &tool_titles();
10512: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10513: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
10514: $ordered{'default'} = ['types','registered','approval','limit'];
10515:
10516: my (%roles,%shown,%toplevel);
10517: $roles{'0'} = &Apache::lonnet::plaintext('dc');
10518:
10519: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10520: if ($domconfig{'selfenrollment'} eq '') {
10521: $domconfig{'selfenrollment'} = {};
10522: }
10523: }
10524: %toplevel = (
10525: admin => 'Configuration Rights',
10526: default => 'Default settings',
10527: validation => 'Validation of self-enrollment requests',
10528: );
10529: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
10530:
10531: if (ref($ordered{'admin'}) eq 'ARRAY') {
10532: foreach my $item (@{$ordered{'admin'}}) {
10533: foreach my $type (@types) {
10534: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10535: $selfenrollhash{'admin'}{$type}{$item} = 1;
10536: } else {
10537: $selfenrollhash{'admin'}{$type}{$item} = 0;
10538: }
10539: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10540: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10541: if ($selfenrollhash{'admin'}{$type}{$item} ne
10542: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10543: push(@{$changes{'admin'}{$type}},$item);
10544: }
10545: } else {
10546: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10547: push(@{$changes{'admin'}{$type}},$item);
10548: }
10549: }
10550: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10551: push(@{$changes{'admin'}{$type}},$item);
10552: }
10553: }
10554: }
10555: }
10556:
10557: foreach my $item (@{$ordered{'default'}}) {
10558: foreach my $type (@types) {
10559: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10560: if ($item eq 'types') {
10561: unless (($value eq 'all') || ($value eq 'dom')) {
10562: $value = '';
10563: }
10564: } elsif ($item eq 'registered') {
10565: unless ($value eq '1') {
10566: $value = 0;
10567: }
10568: } elsif ($item eq 'approval') {
10569: unless ($value =~ /^[012]$/) {
10570: $value = 0;
10571: }
10572: } else {
10573: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10574: $value = 'none';
10575: }
10576: }
10577: $selfenrollhash{'default'}{$type}{$item} = $value;
10578: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10579: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10580: if ($selfenrollhash{'default'}{$type}{$item} ne
10581: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10582: push(@{$changes{'default'}{$type}},$item);
10583: }
10584: } else {
10585: push(@{$changes{'default'}{$type}},$item);
10586: }
10587: } else {
10588: push(@{$changes{'default'}{$type}},$item);
10589: }
10590: if ($item eq 'limit') {
10591: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10592: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10593: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10594: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10595: }
10596: } else {
10597: $selfenrollhash{'default'}{$type}{'cap'} = '';
10598: }
10599: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10600: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10601: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10602: push(@{$changes{'default'}{$type}},'cap');
10603: }
10604: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10605: push(@{$changes{'default'}{$type}},'cap');
10606: }
10607: }
10608: }
10609: }
10610:
10611: foreach my $item (@{$itemsref}) {
10612: if ($item eq 'fields') {
10613: my @changed;
10614: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10615: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10616: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10617: }
10618: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10619: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10620: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10621: $domconfig{'selfenrollment'}{'validation'}{$item});
10622: } else {
10623: @changed = @{$selfenrollhash{'validation'}{$item}};
10624: }
10625: } else {
10626: @changed = @{$selfenrollhash{'validation'}{$item}};
10627: }
10628: if (@changed) {
10629: if ($selfenrollhash{'validation'}{$item}) {
10630: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10631: } else {
10632: $changes{'validation'}{$item} = &mt('None');
10633: }
10634: }
10635: } else {
10636: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10637: if ($item eq 'markup') {
10638: if ($env{'form.selfenroll_validation_'.$item}) {
10639: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10640: }
10641: }
10642: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10643: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10644: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10645: }
10646: }
10647: }
10648: }
10649:
10650: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10651: $dom);
10652: if ($putresult eq 'ok') {
10653: if (keys(%changes) > 0) {
10654: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10655: $resulttext = &mt('Changes made:').'<ul>';
10656: foreach my $key ('admin','default','validation') {
10657: if (ref($changes{$key}) eq 'HASH') {
10658: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10659: if ($key eq 'validation') {
10660: foreach my $item (@{$itemsref}) {
10661: if (exists($changes{$key}{$item})) {
10662: if ($item eq 'markup') {
10663: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10664: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10665: } else {
10666: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10667: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10668: }
10669: }
10670: }
10671: } else {
10672: foreach my $type (@types) {
10673: if ($type eq 'community') {
10674: $roles{'1'} = &mt('Community personnel');
10675: } else {
10676: $roles{'1'} = &mt('Course personnel');
10677: }
10678: if (ref($changes{$key}{$type}) eq 'ARRAY') {
10679: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10680: if ($key eq 'admin') {
10681: my @mgrdc = ();
10682: if (ref($ordered{$key}) eq 'ARRAY') {
10683: foreach my $item (@{$ordered{'admin'}}) {
10684: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10685: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10686: push(@mgrdc,$item);
10687: }
10688: }
10689: }
10690: if (@mgrdc) {
10691: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10692: } else {
10693: delete($domdefaults{$type.'selfenrolladmdc'});
10694: }
10695: }
10696: } else {
10697: if (ref($ordered{$key}) eq 'ARRAY') {
10698: foreach my $item (@{$ordered{$key}}) {
10699: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10700: $domdefaults{$type.'selfenroll'.$item} =
10701: $selfenrollhash{$key}{$type}{$item};
10702: }
10703: }
10704: }
10705: }
10706: }
10707: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10708: foreach my $item (@{$ordered{$key}}) {
10709: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10710: $resulttext .= '<li>';
10711: if ($key eq 'admin') {
10712: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10713: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10714: } else {
10715: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10716: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10717: }
10718: $resulttext .= '</li>';
10719: }
10720: }
10721: $resulttext .= '</ul></li>';
10722: }
10723: }
10724: $resulttext .= '</ul></li>';
10725: }
10726: }
10727: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10728: my $cachetime = 24*60*60;
10729: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10730: if (ref($lastactref) eq 'HASH') {
10731: $lastactref->{'domdefaults'} = 1;
10732: }
10733: }
10734: }
10735: $resulttext .= '</ul>';
10736: } else {
10737: $resulttext = &mt('No changes made to self-enrollment settings');
10738: }
10739: } else {
10740: $resulttext = '<span class="LC_error">'.
10741: &mt('An error occurred: [_1]',$putresult).'</span>';
10742: }
10743: return $resulttext;
10744: }
10745:
1.137 raeburn 10746: sub modify_usersessions {
1.160.6.27 raeburn 10747: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 10748: my @hostingtypes = ('version','excludedomain','includedomain');
10749: my @offloadtypes = ('primary','default');
10750: my %types = (
10751: remote => \@hostingtypes,
10752: hosted => \@hostingtypes,
10753: spares => \@offloadtypes,
10754: );
10755: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 10756: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 10757: my (%by_ip,%by_location,@intdoms);
10758: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10759: my @locations = sort(keys(%by_location));
1.137 raeburn 10760: my (%defaultshash,%changes);
10761: foreach my $prefix (@prefixes) {
10762: $defaultshash{'usersessions'}{$prefix} = {};
10763: }
1.160.6.27 raeburn 10764: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 10765: my $resulttext;
1.138 raeburn 10766: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 10767: foreach my $prefix (@prefixes) {
1.145 raeburn 10768: next if ($prefix eq 'spares');
10769: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 10770: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10771: if ($type eq 'version') {
10772: my $value = $env{'form.'.$prefix.'_'.$type};
10773: my $okvalue;
10774: if ($value ne '') {
10775: if (grep(/^\Q$value\E$/,@lcversions)) {
10776: $okvalue = $value;
10777: }
10778: }
10779: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10780: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10781: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10782: if ($inuse == 0) {
10783: $changes{$prefix}{$type} = 1;
10784: } else {
10785: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10786: $changes{$prefix}{$type} = 1;
10787: }
10788: if ($okvalue ne '') {
10789: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10790: }
10791: }
10792: } else {
10793: if (($inuse == 1) && ($okvalue ne '')) {
10794: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10795: $changes{$prefix}{$type} = 1;
10796: }
10797: }
10798: } else {
10799: if (($inuse == 1) && ($okvalue ne '')) {
10800: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10801: $changes{$prefix}{$type} = 1;
10802: }
10803: }
10804: } else {
10805: if (($inuse == 1) && ($okvalue ne '')) {
10806: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10807: $changes{$prefix}{$type} = 1;
10808: }
10809: }
10810: } else {
10811: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10812: my @okvals;
10813: foreach my $val (@vals) {
1.138 raeburn 10814: if ($val =~ /:/) {
10815: my @items = split(/:/,$val);
10816: foreach my $item (@items) {
10817: if (ref($by_location{$item}) eq 'ARRAY') {
10818: push(@okvals,$item);
10819: }
10820: }
10821: } else {
10822: if (ref($by_location{$val}) eq 'ARRAY') {
10823: push(@okvals,$val);
10824: }
1.137 raeburn 10825: }
10826: }
10827: @okvals = sort(@okvals);
10828: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10829: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10830: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10831: if ($inuse == 0) {
10832: $changes{$prefix}{$type} = 1;
10833: } else {
10834: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10835: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10836: if (@changed > 0) {
10837: $changes{$prefix}{$type} = 1;
10838: }
10839: }
10840: } else {
10841: if ($inuse == 1) {
10842: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10843: $changes{$prefix}{$type} = 1;
10844: }
10845: }
10846: } else {
10847: if ($inuse == 1) {
10848: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10849: $changes{$prefix}{$type} = 1;
10850: }
10851: }
10852: } else {
10853: if ($inuse == 1) {
10854: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10855: $changes{$prefix}{$type} = 1;
10856: }
10857: }
10858: }
10859: }
10860: }
1.145 raeburn 10861:
10862: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 10863: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 10864: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10865: my $savespares;
10866:
10867: foreach my $lonhost (sort(keys(%servers))) {
10868: my $serverhomeID =
10869: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 10870: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 10871: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10872: my %spareschg;
10873: foreach my $type (@{$types{'spares'}}) {
10874: my @okspares;
10875: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10876: foreach my $server (@checked) {
1.152 raeburn 10877: if (&Apache::lonnet::hostname($server) ne '') {
10878: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10879: unless (grep(/^\Q$server\E$/,@okspares)) {
10880: push(@okspares,$server);
10881: }
1.145 raeburn 10882: }
10883: }
10884: }
10885: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10886: my $newspare;
1.152 raeburn 10887: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10888: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 10889: $newspare = $new;
10890: }
10891: }
1.152 raeburn 10892: my @spares;
10893: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10894: @spares = sort(@okspares,$newspare);
10895: } else {
10896: @spares = sort(@okspares);
10897: }
10898: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 10899: if (ref($spareid{$lonhost}) eq 'HASH') {
10900: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 10901: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 10902: if (@diffs > 0) {
10903: $spareschg{$type} = 1;
10904: }
10905: }
10906: }
10907: }
10908: if (keys(%spareschg) > 0) {
10909: $changes{'spares'}{$lonhost} = \%spareschg;
10910: }
10911: }
10912:
10913: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10914: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10915: if (ref($changes{'spares'}) eq 'HASH') {
10916: if (keys(%{$changes{'spares'}}) > 0) {
10917: $savespares = 1;
10918: }
10919: }
10920: } else {
10921: $savespares = 1;
10922: }
10923: }
10924:
1.147 raeburn 10925: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10926: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 10927: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10928: $dom);
10929: if ($putresult eq 'ok') {
10930: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10931: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
10932: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
10933: }
10934: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
10935: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
10936: }
10937: }
10938: my $cachetime = 24*60*60;
10939: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10940: if (ref($lastactref) eq 'HASH') {
10941: $lastactref->{'domdefaults'} = 1;
10942: }
1.147 raeburn 10943: if (keys(%changes) > 0) {
10944: my %lt = &usersession_titles();
10945: $resulttext = &mt('Changes made:').'<ul>';
10946: foreach my $prefix (@prefixes) {
10947: if (ref($changes{$prefix}) eq 'HASH') {
10948: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
10949: if ($prefix eq 'spares') {
10950: if (ref($changes{$prefix}) eq 'HASH') {
10951: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
10952: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 10953: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 10954: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
10955: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 10956: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
10957: foreach my $type (@{$types{$prefix}}) {
10958: if ($changes{$prefix}{$lonhost}{$type}) {
10959: my $offloadto = &mt('None');
10960: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
10961: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
10962: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
10963: }
1.145 raeburn 10964: }
1.147 raeburn 10965: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 10966: }
1.137 raeburn 10967: }
10968: }
1.147 raeburn 10969: $resulttext .= '</li>';
1.137 raeburn 10970: }
10971: }
1.147 raeburn 10972: } else {
10973: foreach my $type (@{$types{$prefix}}) {
10974: if (defined($changes{$prefix}{$type})) {
10975: my $newvalue;
10976: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10977: if (ref($defaultshash{'usersessions'}{$prefix})) {
10978: if ($type eq 'version') {
10979: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
10980: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10981: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
10982: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
10983: }
1.145 raeburn 10984: }
10985: }
10986: }
1.147 raeburn 10987: if ($newvalue eq '') {
10988: if ($type eq 'version') {
10989: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
10990: } else {
10991: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
10992: }
1.145 raeburn 10993: } else {
1.147 raeburn 10994: if ($type eq 'version') {
10995: $newvalue .= ' '.&mt('(or later)');
10996: }
10997: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 10998: }
1.137 raeburn 10999: }
11000: }
11001: }
1.147 raeburn 11002: $resulttext .= '</ul>';
1.137 raeburn 11003: }
11004: }
1.147 raeburn 11005: $resulttext .= '</ul>';
11006: } else {
11007: $resulttext = $nochgmsg;
1.137 raeburn 11008: }
11009: } else {
11010: $resulttext = '<span class="LC_error">'.
11011: &mt('An error occurred: [_1]',$putresult).'</span>';
11012: }
11013: } else {
1.147 raeburn 11014: $resulttext = $nochgmsg;
1.137 raeburn 11015: }
11016: return $resulttext;
11017: }
11018:
1.150 raeburn 11019: sub modify_loadbalancing {
11020: my ($dom,%domconfig) = @_;
11021: my $primary_id = &Apache::lonnet::domain($dom,'primary');
11022: my $intdom = &Apache::lonnet::internet_dom($primary_id);
11023: my ($othertitle,$usertypes,$types) =
11024: &Apache::loncommon::sorted_inst_types($dom);
11025: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 11026: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 11027: my @sparestypes = ('primary','default');
11028: my %typetitles = &sparestype_titles();
11029: my $resulttext;
1.160.6.7 raeburn 11030: my (%currbalancer,%currtargets,%currrules,%existing);
11031: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11032: %existing = %{$domconfig{'loadbalancing'}};
11033: }
11034: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
11035: \%currtargets,\%currrules);
11036: my ($saveloadbalancing,%defaultshash,%changes);
11037: my ($alltypes,$othertypes,$titles) =
11038: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
11039: my %ruletitles = &offloadtype_text();
11040: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
11041: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
11042: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
11043: if ($balancer eq '') {
11044: next;
11045: }
11046: if (!exists($servers{$balancer})) {
11047: if (exists($currbalancer{$balancer})) {
11048: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 11049: }
1.160.6.7 raeburn 11050: next;
11051: }
11052: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
11053: push(@{$changes{'delete'}},$balancer);
11054: next;
11055: }
11056: if (!exists($currbalancer{$balancer})) {
11057: push(@{$changes{'add'}},$balancer);
11058: }
11059: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
11060: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
11061: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
11062: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11063: $saveloadbalancing = 1;
11064: }
11065: foreach my $sparetype (@sparestypes) {
11066: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
11067: my @offloadto;
11068: foreach my $target (@targets) {
11069: if (($servers{$target}) && ($target ne $balancer)) {
11070: if ($sparetype eq 'default') {
11071: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
11072: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 11073: }
11074: }
1.160.6.7 raeburn 11075: unless(grep(/^\Q$target\E$/,@offloadto)) {
11076: push(@offloadto,$target);
11077: }
1.150 raeburn 11078: }
1.160.6.7 raeburn 11079: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 11080: }
11081: }
1.160.6.7 raeburn 11082: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 11083: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 11084: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
11085: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 11086: if (@targetdiffs > 0) {
1.160.6.7 raeburn 11087: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11088: }
1.160.6.7 raeburn 11089: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11090: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11091: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11092: }
11093: }
11094: }
11095: } else {
1.160.6.7 raeburn 11096: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
11097: foreach my $sparetype (@sparestypes) {
11098: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11099: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11100: $changes{'curr'}{$balancer}{'targets'} = 1;
11101: }
1.150 raeburn 11102: }
11103: }
1.160.6.7 raeburn 11104: }
1.150 raeburn 11105: }
11106: my $ishomedom;
1.160.6.7 raeburn 11107: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
11108: $ishomedom = 1;
1.150 raeburn 11109: }
11110: if (ref($alltypes) eq 'ARRAY') {
11111: foreach my $type (@{$alltypes}) {
11112: my $rule;
1.160.6.7 raeburn 11113: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 11114: (!$ishomedom)) {
1.160.6.7 raeburn 11115: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
11116: }
11117: if ($rule eq 'specific') {
1.160.6.55 raeburn 11118: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
11119: if (exists($servers{$specifiedhost})) {
11120: $rule = $specifiedhost;
11121: }
1.150 raeburn 11122: }
1.160.6.7 raeburn 11123: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
11124: if (ref($currrules{$balancer}) eq 'HASH') {
11125: if ($rule ne $currrules{$balancer}{$type}) {
11126: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11127: }
11128: } elsif ($rule ne '') {
1.160.6.7 raeburn 11129: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11130: }
11131: }
11132: }
1.160.6.7 raeburn 11133: }
11134: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
11135: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
11136: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
11137: $defaultshash{'loadbalancing'} = {};
11138: }
11139: my $putresult = &Apache::lonnet::put_dom('configuration',
11140: \%defaultshash,$dom);
11141: if ($putresult eq 'ok') {
11142: if (keys(%changes) > 0) {
1.160.6.54 raeburn 11143: my %toupdate;
1.160.6.7 raeburn 11144: if (ref($changes{'delete'}) eq 'ARRAY') {
11145: foreach my $balancer (sort(@{$changes{'delete'}})) {
11146: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 11147: $toupdate{$balancer} = 1;
1.150 raeburn 11148: }
1.160.6.7 raeburn 11149: }
11150: if (ref($changes{'add'}) eq 'ARRAY') {
11151: foreach my $balancer (sort(@{$changes{'add'}})) {
11152: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 11153: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 11154: }
11155: }
11156: if (ref($changes{'curr'}) eq 'HASH') {
11157: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 11158: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 11159: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
11160: if ($changes{'curr'}{$balancer}{'targets'}) {
11161: my %offloadstr;
11162: foreach my $sparetype (@sparestypes) {
11163: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11164: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11165: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11166: }
11167: }
1.150 raeburn 11168: }
1.160.6.7 raeburn 11169: if (keys(%offloadstr) == 0) {
11170: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 11171: } else {
1.160.6.7 raeburn 11172: my $showoffload;
11173: foreach my $sparetype (@sparestypes) {
11174: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
11175: if (defined($offloadstr{$sparetype})) {
11176: $showoffload .= $offloadstr{$sparetype};
11177: } else {
11178: $showoffload .= &mt('None');
11179: }
11180: $showoffload .= (' 'x3);
11181: }
11182: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 11183: }
11184: }
11185: }
1.160.6.7 raeburn 11186: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
11187: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
11188: foreach my $type (@{$alltypes}) {
11189: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
11190: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11191: my $balancetext;
11192: if ($rule eq '') {
11193: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 11194: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 11195: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
11196: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 11197: foreach my $sparetype (@sparestypes) {
11198: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11199: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11200: }
11201: }
1.160.6.55 raeburn 11202: foreach my $item (@{$alltypes}) {
11203: next if ($item =~ /^_LC_ipchange/);
11204: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
11205: if ($hasrule eq 'homeserver') {
11206: map { $toupdate{$_} = 1; } (keys(%libraryservers));
11207: } else {
11208: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
11209: if ($servers{$hasrule}) {
11210: $toupdate{$hasrule} = 1;
11211: }
11212: }
11213: }
11214: }
11215: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
11216: $balancetext = $ruletitles{$rule};
11217: } else {
11218: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11219: $balancetext = $ruletitles{'particular'}.' '.$receiver;
11220: if ($receiver) {
11221: $toupdate{$receiver};
11222: }
11223: }
11224: } else {
11225: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 11226: }
1.160.6.7 raeburn 11227: } else {
11228: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
11229: }
1.160.6.26 raeburn 11230: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 11231: }
11232: }
11233: }
11234: }
1.160.6.54 raeburn 11235: if (keys(%toupdate)) {
11236: my %thismachine;
11237: my $updatedhere;
11238: my $cachetime = 60*60*24;
11239: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
11240: foreach my $lonhost (keys(%toupdate)) {
11241: if ($thismachine{$lonhost}) {
11242: unless ($updatedhere) {
11243: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
11244: $defaultshash{'loadbalancing'},
11245: $cachetime);
11246: $updatedhere = 1;
11247: }
11248: } else {
11249: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
11250: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
11251: }
11252: }
11253: }
1.150 raeburn 11254: }
1.160.6.7 raeburn 11255: }
11256: if ($resulttext ne '') {
11257: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 11258: } else {
11259: $resulttext = $nochgmsg;
11260: }
11261: } else {
1.160.6.7 raeburn 11262: $resulttext = $nochgmsg;
1.150 raeburn 11263: }
11264: } else {
1.160.6.7 raeburn 11265: $resulttext = '<span class="LC_error">'.
11266: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 11267: }
11268: } else {
1.160.6.7 raeburn 11269: $resulttext = $nochgmsg;
1.150 raeburn 11270: }
11271: return $resulttext;
11272: }
11273:
1.48 raeburn 11274: sub recurse_check {
11275: my ($chkcats,$categories,$depth,$name) = @_;
11276: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
11277: my $chg = 0;
11278: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
11279: my $category = $chkcats->[$depth]{$name}[$j];
11280: my $item;
11281: if ($category eq '') {
11282: $chg ++;
11283: } else {
11284: my $deeper = $depth + 1;
11285: $item = &escape($category).':'.&escape($name).':'.$depth;
11286: if ($chg) {
11287: $categories->{$item} -= $chg;
11288: }
11289: &recurse_check($chkcats,$categories,$deeper,$category);
11290: $deeper --;
11291: }
11292: }
11293: }
11294: return;
11295: }
11296:
11297: sub recurse_cat_deletes {
11298: my ($item,$coursecategories,$deletions) = @_;
11299: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
11300: my $subdepth = $depth + 1;
11301: if (ref($coursecategories) eq 'HASH') {
11302: foreach my $subitem (keys(%{$coursecategories})) {
11303: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
11304: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
11305: delete($coursecategories->{$subitem});
11306: $deletions->{$subitem} = 1;
11307: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 11308: }
1.48 raeburn 11309: }
11310: }
11311: return;
11312: }
11313:
1.125 raeburn 11314: sub get_active_dcs {
11315: my ($dom) = @_;
1.160.6.16 raeburn 11316: my $now = time;
11317: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 11318: my %domcoords;
11319: my $numdcs = 0;
11320: foreach my $server (keys(%dompersonnel)) {
11321: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
11322: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 11323: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 11324: }
11325: }
11326: return %domcoords;
11327: }
11328:
11329: sub active_dc_picker {
1.160.6.16 raeburn 11330: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.39 raeburn 11331: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 11332: my @domcoord = keys(%domcoords);
11333: if (keys(%currhash)) {
11334: foreach my $dc (keys(%currhash)) {
11335: unless (exists($domcoords{$dc})) {
11336: push(@domcoord,$dc);
11337: }
11338: }
11339: }
11340: @domcoord = sort(@domcoord);
11341: my $numdcs = scalar(@domcoord);
11342: my $rows = 0;
11343: my $table;
1.125 raeburn 11344: if ($numdcs > 1) {
1.160.6.16 raeburn 11345: $table = '<table>';
11346: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 11347: my $rem = $i%($numinrow);
11348: if ($rem == 0) {
11349: if ($i > 0) {
1.160.6.16 raeburn 11350: $table .= '</tr>';
1.125 raeburn 11351: }
1.160.6.16 raeburn 11352: $table .= '<tr>';
11353: $rows ++;
1.125 raeburn 11354: }
1.160.6.16 raeburn 11355: my $check = '';
11356: if ($inputtype eq 'radio') {
11357: if (keys(%currhash) == 0) {
11358: if (!$i) {
11359: $check = ' checked="checked"';
11360: }
11361: } elsif (exists($currhash{$domcoord[$i]})) {
11362: $check = ' checked="checked"';
11363: }
11364: } else {
11365: if (exists($currhash{$domcoord[$i]})) {
11366: $check = ' checked="checked"';
1.125 raeburn 11367: }
11368: }
1.160.6.16 raeburn 11369: if ($i == @domcoord - 1) {
1.125 raeburn 11370: my $colsleft = $numinrow - $rem;
11371: if ($colsleft > 1) {
1.160.6.16 raeburn 11372: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 11373: } else {
1.160.6.16 raeburn 11374: $table .= '<td class="LC_left_item">';
1.125 raeburn 11375: }
11376: } else {
1.160.6.16 raeburn 11377: $table .= '<td class="LC_left_item">';
11378: }
11379: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
11380: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11381: $table .= '<span class="LC_nobreak"><label>'.
11382: '<input type="'.$inputtype.'" name="'.$name.'"'.
11383: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
11384: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 11385: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 11386: }
1.160.6.33 raeburn 11387: $table .= '</label></span></td>';
1.125 raeburn 11388: }
1.160.6.16 raeburn 11389: $table .= '</tr></table>';
11390: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 11391: my ($dcname,$dcdom) = split(':',$domcoord[0]);
11392: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 11393: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 11394: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 11395: if ($user ne $dcname.':'.$dcdom) {
11396: $table .= ' ('.$dcname.':'.$dcdom.')';
11397: }
1.160.6.16 raeburn 11398: } else {
11399: my $check;
11400: if (exists($currhash{$domcoord[0]})) {
11401: $check = ' checked="checked"';
11402: }
1.160.6.50 raeburn 11403: $table = '<span class="LC_nobreak"><label>'.
11404: '<input type="checkbox" name="'.$name.'" '.
11405: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 11406: if ($user ne $dcname.':'.$dcdom) {
11407: $table .= ' ('.$dcname.':'.$dcdom.')';
11408: }
11409: $table .= '</label></span>';
1.160.6.16 raeburn 11410: $rows ++;
11411: }
1.125 raeburn 11412: }
1.160.6.16 raeburn 11413: return ($numdcs,$table,$rows);
1.125 raeburn 11414: }
11415:
1.137 raeburn 11416: sub usersession_titles {
11417: return &Apache::lonlocal::texthash(
11418: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
11419: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 11420: spares => 'Servers offloaded to, when busy',
1.137 raeburn 11421: version => 'LON-CAPA version requirement',
1.138 raeburn 11422: excludedomain => 'Allow all, but exclude specific domains',
11423: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 11424: primary => 'Primary (checked first)',
1.154 raeburn 11425: default => 'Default',
1.137 raeburn 11426: );
11427: }
11428:
1.152 raeburn 11429: sub id_for_thisdom {
11430: my (%servers) = @_;
11431: my %altids;
11432: foreach my $server (keys(%servers)) {
11433: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11434: if ($serverhome ne $server) {
11435: $altids{$serverhome} = $server;
11436: }
11437: }
11438: return %altids;
11439: }
11440:
1.150 raeburn 11441: sub count_servers {
11442: my ($currbalancer,%servers) = @_;
11443: my (@spares,$numspares);
11444: foreach my $lonhost (sort(keys(%servers))) {
11445: next if ($currbalancer eq $lonhost);
11446: push(@spares,$lonhost);
11447: }
11448: if ($currbalancer) {
11449: $numspares = scalar(@spares);
11450: } else {
11451: $numspares = scalar(@spares) - 1;
11452: }
11453: return ($numspares,@spares);
11454: }
11455:
11456: sub lonbalance_targets_js {
1.160.6.7 raeburn 11457: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 11458: my $select = &mt('Select');
11459: my ($alltargets,$allishome,$allinsttypes,@alltypes);
11460: if (ref($servers) eq 'HASH') {
11461: $alltargets = join("','",sort(keys(%{$servers})));
11462: my @homedoms;
11463: foreach my $server (sort(keys(%{$servers}))) {
11464: if (&Apache::lonnet::host_domain($server) eq $dom) {
11465: push(@homedoms,'1');
11466: } else {
11467: push(@homedoms,'0');
11468: }
11469: }
11470: $allishome = join("','",@homedoms);
11471: }
11472: if (ref($types) eq 'ARRAY') {
11473: if (@{$types} > 0) {
11474: @alltypes = @{$types};
11475: }
11476: }
11477: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11478: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 11479: my (%currbalancer,%currtargets,%currrules,%existing);
11480: if (ref($settings) eq 'HASH') {
11481: %existing = %{$settings};
11482: }
11483: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11484: \%currtargets,\%currrules);
11485: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 11486: return <<"END";
11487:
11488: <script type="text/javascript">
11489: // <![CDATA[
11490:
1.160.6.7 raeburn 11491: currBalancers = new Array('$balancers');
11492:
11493: function toggleTargets(balnum) {
11494: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11495: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11496: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11497: var prevbalancer = prevhostitem.value;
11498: var baltotal = document.getElementById('loadbalancing_total').value;
11499: prevhostitem.value = balancer;
11500: if (prevbalancer != '') {
11501: var prevIdx = currBalancers.indexOf(prevbalancer);
11502: if (prevIdx != -1) {
11503: currBalancers.splice(prevIdx,1);
11504: }
11505: }
1.150 raeburn 11506: if (balancer == '') {
1.160.6.7 raeburn 11507: hideSpares(balnum);
1.150 raeburn 11508: } else {
1.160.6.7 raeburn 11509: var currIdx = currBalancers.indexOf(balancer);
11510: if (currIdx == -1) {
11511: currBalancers.push(balancer);
11512: }
1.150 raeburn 11513: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 11514: var ishomedom = homedoms[lonhostitem.selectedIndex];
11515: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 11516: }
1.160.6.7 raeburn 11517: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 11518: return;
11519: }
11520:
1.160.6.7 raeburn 11521: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 11522: var alltargets = new Array('$alltargets');
11523: var insttypes = new Array('$allinsttypes');
1.151 raeburn 11524: var offloadtypes = new Array('primary','default');
11525:
1.160.6.7 raeburn 11526: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11527: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 11528:
1.151 raeburn 11529: for (var i=0; i<offloadtypes.length; i++) {
11530: var count = 0;
11531: for (var j=0; j<alltargets.length; j++) {
11532: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 11533: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11534: item.value = alltargets[j];
11535: item.style.textAlign='left';
11536: item.style.textFace='normal';
11537: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11538: if (currBalancers.indexOf(alltargets[j]) == -1) {
11539: item.disabled = '';
11540: } else {
11541: item.disabled = 'disabled';
11542: item.checked = false;
11543: }
1.151 raeburn 11544: count ++;
11545: }
1.150 raeburn 11546: }
11547: }
1.151 raeburn 11548: for (var k=0; k<insttypes.length; k++) {
11549: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 11550: if (ishomedom == 1) {
1.160.6.7 raeburn 11551: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11552: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11553: } else {
1.160.6.7 raeburn 11554: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11555: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 11556: }
11557: } else {
1.160.6.7 raeburn 11558: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11559: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11560: }
1.151 raeburn 11561: if ((insttypes[k] != '_LC_external') &&
11562: ((insttypes[k] != '_LC_internetdom') ||
11563: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 11564: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11565: item.options.length = 0;
11566: item.options[0] = new Option("","",true,true);
11567: var idx = 0;
1.151 raeburn 11568: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 11569: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11570: idx ++;
11571: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 11572: }
11573: }
11574: }
11575: }
11576: return;
11577: }
11578:
1.160.6.7 raeburn 11579: function hideSpares(balnum) {
1.150 raeburn 11580: var alltargets = new Array('$alltargets');
11581: var insttypes = new Array('$allinsttypes');
11582: var offloadtypes = new Array('primary','default');
11583:
1.160.6.7 raeburn 11584: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11585: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 11586:
11587: var total = alltargets.length - 1;
11588: for (var i=0; i<offloadtypes; i++) {
11589: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 11590: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11591: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11592: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 11593: }
1.150 raeburn 11594: }
11595: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 11596: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11597: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 11598: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 11599: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11600: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 11601: }
11602: }
11603: return;
11604: }
11605:
1.160.6.7 raeburn 11606: function checkOffloads(item,balnum,type) {
1.150 raeburn 11607: var alltargets = new Array('$alltargets');
11608: var offloadtypes = new Array('primary','default');
11609: if (item.checked) {
11610: var total = alltargets.length - 1;
11611: var other;
11612: if (type == offloadtypes[0]) {
1.151 raeburn 11613: other = offloadtypes[1];
1.150 raeburn 11614: } else {
1.151 raeburn 11615: other = offloadtypes[0];
1.150 raeburn 11616: }
11617: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 11618: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 11619: if (server == item.value) {
1.160.6.7 raeburn 11620: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11621: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 11622: }
11623: }
11624: }
11625: }
11626: return;
11627: }
11628:
1.160.6.7 raeburn 11629: function singleServerToggle(balnum,type) {
11630: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 11631: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 11632: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11633: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11634:
11635: } else {
1.160.6.7 raeburn 11636: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11637: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 11638: }
11639: return;
11640: }
11641:
1.160.6.7 raeburn 11642: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 11643: if (type == '_LC_external') {
1.160.6.26 raeburn 11644: return;
1.150 raeburn 11645: }
1.160.6.7 raeburn 11646: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 11647: for (var i=0; i<typesRules.length; i++) {
11648: if (formname.elements[typesRules[i]].checked) {
11649: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 11650: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11651: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11652: } else {
1.160.6.7 raeburn 11653: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11654: }
11655: }
11656: }
11657: return;
11658: }
11659:
11660: function balancerDeleteChange(balnum) {
11661: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11662: var baltotal = document.getElementById('loadbalancing_total').value;
11663: var addtarget;
11664: var removetarget;
11665: var action = 'delete';
11666: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11667: var lonhost = hostitem.value;
11668: var currIdx = currBalancers.indexOf(lonhost);
11669: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11670: if (currIdx != -1) {
11671: currBalancers.splice(currIdx,1);
11672: }
11673: addtarget = lonhost;
11674: } else {
11675: if (currIdx == -1) {
11676: currBalancers.push(lonhost);
11677: }
11678: removetarget = lonhost;
11679: action = 'undelete';
11680: }
11681: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11682: }
11683: return;
11684: }
11685:
11686: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11687: if (baltotal > 1) {
11688: var offloadtypes = new Array('primary','default');
11689: var alltargets = new Array('$alltargets');
11690: var insttypes = new Array('$allinsttypes');
11691: for (var i=0; i<baltotal; i++) {
11692: if (i != balnum) {
11693: for (var j=0; j<offloadtypes.length; j++) {
11694: var total = alltargets.length - 1;
11695: for (var k=0; k<total; k++) {
11696: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11697: var server = serveritem.value;
11698: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11699: if (server == addtarget) {
11700: serveritem.disabled = '';
11701: }
11702: }
11703: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11704: if (server == removetarget) {
11705: serveritem.disabled = 'disabled';
11706: serveritem.checked = false;
11707: }
11708: }
11709: }
11710: }
11711: for (var j=0; j<insttypes.length; j++) {
11712: if (insttypes[j] != '_LC_external') {
11713: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11714: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11715: var currSel = singleserver.selectedIndex;
11716: var currVal = singleserver.options[currSel].value;
11717: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11718: var numoptions = singleserver.options.length;
11719: var needsnew = 1;
11720: for (var k=0; k<numoptions; k++) {
11721: if (singleserver.options[k] == addtarget) {
11722: needsnew = 0;
11723: break;
11724: }
11725: }
11726: if (needsnew == 1) {
11727: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11728: }
11729: }
11730: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11731: singleserver.options.length = 0;
11732: if ((currVal) && (currVal != removetarget)) {
11733: singleserver.options[0] = new Option("","",false,false);
11734: } else {
11735: singleserver.options[0] = new Option("","",true,true);
11736: }
11737: var idx = 0;
11738: for (var m=0; m<alltargets.length; m++) {
11739: if (currBalancers.indexOf(alltargets[m]) == -1) {
11740: idx ++;
11741: if (currVal == alltargets[m]) {
11742: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11743: } else {
11744: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11745: }
11746: }
11747: }
11748: }
11749: }
11750: }
11751: }
1.150 raeburn 11752: }
11753: }
11754: }
11755: return;
11756: }
11757:
1.152 raeburn 11758: // ]]>
11759: </script>
11760:
11761: END
11762: }
11763:
11764: sub new_spares_js {
11765: my @sparestypes = ('primary','default');
11766: my $types = join("','",@sparestypes);
11767: my $select = &mt('Select');
11768: return <<"END";
11769:
11770: <script type="text/javascript">
11771: // <![CDATA[
11772:
11773: function updateNewSpares(formname,lonhost) {
11774: var types = new Array('$types');
11775: var include = new Array();
11776: var exclude = new Array();
11777: for (var i=0; i<types.length; i++) {
11778: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11779: for (var j=0; j<spareboxes.length; j++) {
11780: if (formname.elements[spareboxes[j]].checked) {
11781: exclude.push(formname.elements[spareboxes[j]].value);
11782: } else {
11783: include.push(formname.elements[spareboxes[j]].value);
11784: }
11785: }
11786: }
11787: for (var i=0; i<types.length; i++) {
11788: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11789: var selIdx = newSpare.selectedIndex;
11790: var currnew = newSpare.options[selIdx].value;
11791: var okSpares = new Array();
11792: for (var j=0; j<newSpare.options.length; j++) {
11793: var possible = newSpare.options[j].value;
11794: if (possible != '') {
11795: if (exclude.indexOf(possible) == -1) {
11796: okSpares.push(possible);
11797: } else {
11798: if (currnew == possible) {
11799: selIdx = 0;
11800: }
11801: }
11802: }
11803: }
11804: for (var k=0; k<include.length; k++) {
11805: if (okSpares.indexOf(include[k]) == -1) {
11806: okSpares.push(include[k]);
11807: }
11808: }
11809: okSpares.sort();
11810: newSpare.options.length = 0;
11811: if (selIdx == 0) {
11812: newSpare.options[0] = new Option("$select","",true,true);
11813: } else {
11814: newSpare.options[0] = new Option("$select","",false,false);
11815: }
11816: for (var m=0; m<okSpares.length; m++) {
11817: var idx = m+1;
11818: var selThis = 0;
11819: if (selIdx != 0) {
11820: if (okSpares[m] == currnew) {
11821: selThis = 1;
11822: }
11823: }
11824: if (selThis == 1) {
11825: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11826: } else {
11827: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11828: }
11829: }
11830: }
11831: return;
11832: }
11833:
11834: function checkNewSpares(lonhost,type) {
11835: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11836: var chosen = newSpare.options[newSpare.selectedIndex].value;
11837: if (chosen != '') {
11838: var othertype;
11839: var othernewSpare;
11840: if (type == 'primary') {
11841: othernewSpare = document.getElementById('newspare_default_'+lonhost);
11842: }
11843: if (type == 'default') {
11844: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11845: }
11846: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11847: othernewSpare.selectedIndex = 0;
11848: }
11849: }
11850: return;
11851: }
11852:
11853: // ]]>
11854: </script>
11855:
11856: END
11857:
11858: }
11859:
11860: sub common_domprefs_js {
11861: return <<"END";
11862:
11863: <script type="text/javascript">
11864: // <![CDATA[
11865:
1.150 raeburn 11866: function getIndicesByName(formname,item) {
1.152 raeburn 11867: var group = new Array();
1.150 raeburn 11868: for (var i=0;i<formname.elements.length;i++) {
11869: if (formname.elements[i].name == item) {
1.152 raeburn 11870: group.push(formname.elements[i].id);
1.150 raeburn 11871: }
11872: }
1.152 raeburn 11873: return group;
1.150 raeburn 11874: }
11875:
11876: // ]]>
11877: </script>
11878:
11879: END
1.152 raeburn 11880:
1.150 raeburn 11881: }
11882:
1.160.6.5 raeburn 11883: sub recaptcha_js {
11884: my %lt = &captcha_phrases();
11885: return <<"END";
11886:
11887: <script type="text/javascript">
11888: // <![CDATA[
11889:
11890: function updateCaptcha(caller,context) {
11891: var privitem;
11892: var pubitem;
11893: var privtext;
11894: var pubtext;
11895: if (document.getElementById(context+'_recaptchapub')) {
11896: pubitem = document.getElementById(context+'_recaptchapub');
11897: } else {
11898: return;
11899: }
11900: if (document.getElementById(context+'_recaptchapriv')) {
11901: privitem = document.getElementById(context+'_recaptchapriv');
11902: } else {
11903: return;
11904: }
11905: if (document.getElementById(context+'_recaptchapubtxt')) {
11906: pubtext = document.getElementById(context+'_recaptchapubtxt');
11907: } else {
11908: return;
11909: }
11910: if (document.getElementById(context+'_recaptchaprivtxt')) {
11911: privtext = document.getElementById(context+'_recaptchaprivtxt');
11912: } else {
11913: return;
11914: }
11915: if (caller.checked) {
11916: if (caller.value == 'recaptcha') {
11917: pubitem.type = 'text';
11918: privitem.type = 'text';
11919: pubitem.size = '40';
11920: privitem.size = '40';
11921: pubtext.innerHTML = "$lt{'pub'}";
11922: privtext.innerHTML = "$lt{'priv'}";
11923: } else {
11924: pubitem.type = 'hidden';
11925: privitem.type = 'hidden';
11926: pubtext.innerHTML = '';
11927: privtext.innerHTML = '';
11928: }
11929: }
11930: return;
11931: }
11932:
11933: // ]]>
11934: </script>
11935:
11936: END
11937:
11938: }
11939:
1.160.6.40 raeburn 11940: sub toggle_display_js {
1.160.6.16 raeburn 11941: return <<"END";
11942:
11943: <script type="text/javascript">
11944: // <![CDATA[
11945:
1.160.6.40 raeburn 11946: function toggleDisplay(domForm,caller) {
11947: if (document.getElementById(caller)) {
11948: var divitem = document.getElementById(caller);
11949: var optionsElement = domForm.coursecredits;
11950: if (caller == 'emailoptions') {
11951: optionsElement = domForm.cancreate_email;
11952: }
1.160.6.57 raeburn 11953: if (caller == 'studentsubmission') {
11954: optionsElement = domForm.postsubmit;
11955: }
1.160.6.40 raeburn 11956: if (optionsElement.length) {
1.160.6.16 raeburn 11957: var currval;
1.160.6.40 raeburn 11958: for (var i=0; i<optionsElement.length; i++) {
11959: if (optionsElement[i].checked) {
11960: currval = optionsElement[i].value;
1.160.6.16 raeburn 11961: }
11962: }
11963: if (currval == 1) {
1.160.6.40 raeburn 11964: divitem.style.display = 'block';
1.160.6.16 raeburn 11965: } else {
1.160.6.40 raeburn 11966: divitem.style.display = 'none';
1.160.6.16 raeburn 11967: }
11968: }
11969: }
11970: return;
11971: }
11972:
11973: // ]]>
11974: </script>
11975:
11976: END
11977:
11978: }
11979:
1.160.6.5 raeburn 11980: sub captcha_phrases {
11981: return &Apache::lonlocal::texthash (
11982: priv => 'Private key',
11983: pub => 'Public key',
11984: original => 'original (CAPTCHA)',
11985: recaptcha => 'successor (ReCAPTCHA)',
11986: notused => 'unused',
11987: );
11988: }
11989:
1.160.6.24 raeburn 11990: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 11991: my ($dom,$cachekeys) = @_;
11992: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 11993: my %servers = &Apache::lonnet::internet_dom_servers($dom);
11994: my %thismachine;
11995: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.27 raeburn 11996: my @posscached = ('domainconfig','domdefaults');
1.160.6.24 raeburn 11997: if (keys(%servers) > 1) {
11998: foreach my $server (keys(%servers)) {
11999: next if ($thismachine{$server});
1.160.6.27 raeburn 12000: my @cached;
12001: foreach my $name (@posscached) {
12002: if ($cachekeys->{$name}) {
12003: push(@cached,&escape($name).':'.&escape($dom));
12004: }
12005: }
12006: if (@cached) {
12007: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
12008: }
1.160.6.24 raeburn 12009: }
12010: }
12011: return;
12012: }
12013:
1.3 raeburn 12014: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>